abseil-cpp/absl/base/internal/low_level_alloc.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // A low-level allocator that can be used by other low-level
16 // modules without introducing dependency cycles.
17 // This allocator is slow and wasteful of memory;
18 // it should not be used when performance is key.
19 
20 #include "absl/base/internal/low_level_alloc.h"
21 
22 #include <type_traits>
23 
24 #include "absl/base/call_once.h"
25 #include "absl/base/config.h"
26 #include "absl/base/internal/direct_mmap.h"
27 #include "absl/base/internal/scheduling_mode.h"
28 #include "absl/base/macros.h"
29 #include "absl/base/thread_annotations.h"
30 
31 // LowLevelAlloc requires that the platform support low-level
32 // allocation of virtual memory. Platforms lacking this cannot use
33 // LowLevelAlloc.
34 #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING
35 
36 #ifndef _WIN32
37 #include <pthread.h>
38 #include <signal.h>
39 #include <sys/mman.h>
40 #include <unistd.h>
41 #else
42 #include <windows.h>
43 #endif
44 
45 #include <string.h>
46 #include <algorithm>
47 #include <atomic>
48 #include <cerrno>
49 #include <cstddef>
50 #include <new> // for placement-new
51 
52 #include "absl/base/dynamic_annotations.h"
53 #include "absl/base/internal/raw_logging.h"
54 #include "absl/base/internal/spinlock.h"
55 
56 // MAP_ANONYMOUS
57 #if defined(__APPLE__)
58 // For mmap, Linux defines both MAP_ANONYMOUS and MAP_ANON and says MAP_ANON is
59 // deprecated. In Darwin, MAP_ANON is all there is.
60 #if !defined MAP_ANONYMOUS
61 #define MAP_ANONYMOUS MAP_ANON
62 #endif // !MAP_ANONYMOUS
63 #endif // __APPLE__
64 
65 namespace absl {
67 namespace base_internal {
68 
69 // A first-fit allocator with amortized logarithmic free() time.
70 
71 // ---------------------------------------------------------------------------
72 static const int kMaxLevel = 30;
73 
74 namespace {
75 // This struct describes one allocated block, or one free block.
76 struct AllocList {
77  struct Header {
78  // Size of entire region, including this field. Must be
79  // first. Valid in both allocated and unallocated blocks.
81 
82  // kMagicAllocated or kMagicUnallocated xor this.
84 
85  // Pointer to parent arena.
87 
88  // Aligns regions to 0 mod 2*sizeof(void*).
90  } header;
91 
92  // Next two fields: in unallocated blocks: freelist skiplist data
93  // in allocated blocks: overlaps with client data
94 
95  // Levels in skiplist used.
96  int levels;
97 
98  // Actually has levels elements. The AllocList node may not have room
99  // for all kMaxLevel entries. See max_fit in LLA_SkiplistLevels().
100  AllocList *next[kMaxLevel];
101 };
102 } // namespace
103 
104 // ---------------------------------------------------------------------------
105 // A trivial skiplist implementation. This is used to keep the freelist
106 // in address order while taking only logarithmic time per insert and delete.
107 
108 // An integer approximation of log2(size/base)
109 // Requires size >= base.
110 static int IntLog2(size_t size, size_t base) {
111  int result = 0;
112  for (size_t i = size; i > base; i >>= 1) { // i == floor(size/2**result)
113  result++;
114  }
115  // floor(size / 2**result) <= base < floor(size / 2**(result-1))
116  // => log2(size/(base+1)) <= result < 1+log2(size/base)
117  // => result ~= log2(size/base)
118  return result;
119 }
120 
121 // Return a random integer n: p(n)=1/(2**n) if 1 <= n; p(n)=0 if n < 1.
122 static int Random(uint32_t *state) {
123  uint32_t r = *state;
124  int result = 1;
125  while ((((r = r*1103515245 + 12345) >> 30) & 1) == 0) {
126  result++;
127  }
128  *state = r;
129  return result;
130 }
131 
132 // Return a number of skiplist levels for a node of size bytes, where
133 // base is the minimum node size. Compute level=log2(size / base)+n
134 // where n is 1 if random is false and otherwise a random number generated with
135 // the standard distribution for a skiplist: See Random() above.
136 // Bigger nodes tend to have more skiplist levels due to the log2(size / base)
137 // term, so first-fit searches touch fewer nodes. "level" is clipped so
138 // level<kMaxLevel and next[level-1] will fit in the node.
139 // 0 < LLA_SkiplistLevels(x,y,false) <= LLA_SkiplistLevels(x,y,true) < kMaxLevel
140 static int LLA_SkiplistLevels(size_t size, size_t base, uint32_t *random) {
141  // max_fit is the maximum number of levels that will fit in a node for the
142  // given size. We can't return more than max_fit, no matter what the
143  // random number generator says.
144  size_t max_fit = (size - offsetof(AllocList, next)) / sizeof(AllocList *);
145  int level = IntLog2(size, base) + (random != nullptr ? Random(random) : 1);
146  if (static_cast<size_t>(level) > max_fit) level = static_cast<int>(max_fit);
147  if (level > kMaxLevel-1) level = kMaxLevel - 1;
148  ABSL_RAW_CHECK(level >= 1, "block not big enough for even one level");
149  return level;
150 }
151 
152 // Return "atleast", the first element of AllocList *head s.t. *atleast >= *e.
153 // For 0 <= i < head->levels, set prev[i] to "no_greater", where no_greater
154 // points to the last element at level i in the AllocList less than *e, or is
155 // head if no such element exists.
156 static AllocList *LLA_SkiplistSearch(AllocList *head,
157  AllocList *e, AllocList **prev) {
158  AllocList *p = head;
159  for (int level = head->levels - 1; level >= 0; level--) {
160  for (AllocList *n; (n = p->next[level]) != nullptr && n < e; p = n) {
161  }
162  prev[level] = p;
163  }
164  return (head->levels == 0) ? nullptr : prev[0]->next[0];
165 }
166 
167 // Insert element *e into AllocList *head. Set prev[] as LLA_SkiplistSearch.
168 // Requires that e->levels be previously set by the caller (using
169 // LLA_SkiplistLevels())
170 static void LLA_SkiplistInsert(AllocList *head, AllocList *e,
171  AllocList **prev) {
172  LLA_SkiplistSearch(head, e, prev);
173  for (; head->levels < e->levels; head->levels++) { // extend prev pointers
174  prev[head->levels] = head; // to all *e's levels
175  }
176  for (int i = 0; i != e->levels; i++) { // add element to list
177  e->next[i] = prev[i]->next[i];
178  prev[i]->next[i] = e;
179  }
180 }
181 
182 // Remove element *e from AllocList *head. Set prev[] as LLA_SkiplistSearch().
183 // Requires that e->levels be previous set by the caller (using
184 // LLA_SkiplistLevels())
185 static void LLA_SkiplistDelete(AllocList *head, AllocList *e,
186  AllocList **prev) {
187  AllocList *found = LLA_SkiplistSearch(head, e, prev);
188  ABSL_RAW_CHECK(e == found, "element not in freelist");
189  for (int i = 0; i != e->levels && prev[i]->next[i] == e; i++) {
190  prev[i]->next[i] = e->next[i];
191  }
192  while (head->levels > 0 && head->next[head->levels - 1] == nullptr) {
193  head->levels--; // reduce head->levels if level unused
194  }
195 }
196 
197 // ---------------------------------------------------------------------------
198 // Arena implementation
199 
200 // Metadata for an LowLevelAlloc arena instance.
202  // Constructs an arena with the given LowLevelAlloc flags.
203  explicit Arena(uint32_t flags_value);
204 
206  // Head of free list, sorted by address
207  AllocList freelist ABSL_GUARDED_BY(mu);
208  // Count of allocated blocks
210  // flags passed to NewArena
212  // Result of sysconf(_SC_PAGESIZE)
213  const size_t pagesize;
214  // Lowest power of two >= max(16, sizeof(AllocList))
215  const size_t round_up;
216  // Smallest allocation block size
217  const size_t min_size;
218  // PRNG state
219  uint32_t random ABSL_GUARDED_BY(mu);
220 };
221 
222 namespace {
223 // Static storage space for the lazily-constructed, default global arena
224 // instances. We require this space because the whole point of LowLevelAlloc
225 // is to avoid relying on malloc/new.
226 alignas(LowLevelAlloc::Arena) unsigned char default_arena_storage[sizeof(
228 alignas(LowLevelAlloc::Arena) unsigned char unhooked_arena_storage[sizeof(
230 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
231 alignas(
232  LowLevelAlloc::Arena) unsigned char unhooked_async_sig_safe_arena_storage
233  [sizeof(LowLevelAlloc::Arena)];
234 #endif
235 
236 // We must use LowLevelCallOnce here to construct the global arenas, rather than
237 // using function-level statics, to avoid recursively invoking the scheduler.
238 absl::once_flag create_globals_once;
239 
240 void CreateGlobalArenas() {
241  new (&default_arena_storage)
243  new (&unhooked_arena_storage) LowLevelAlloc::Arena(0);
244 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
245  new (&unhooked_async_sig_safe_arena_storage)
247 #endif
248 }
249 
250 // Returns a global arena that does not call into hooks. Used by NewArena()
251 // when kCallMallocHook is not set.
252 LowLevelAlloc::Arena* UnhookedArena() {
253  base_internal::LowLevelCallOnce(&create_globals_once, CreateGlobalArenas);
254  return reinterpret_cast<LowLevelAlloc::Arena*>(&unhooked_arena_storage);
255 }
256 
257 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
258 // Returns a global arena that is async-signal safe. Used by NewArena() when
259 // kAsyncSignalSafe is set.
260 LowLevelAlloc::Arena *UnhookedAsyncSigSafeArena() {
261  base_internal::LowLevelCallOnce(&create_globals_once, CreateGlobalArenas);
262  return reinterpret_cast<LowLevelAlloc::Arena *>(
263  &unhooked_async_sig_safe_arena_storage);
264 }
265 #endif
266 
267 } // namespace
268 
269 // Returns the default arena, as used by LowLevelAlloc::Alloc() and friends.
271  base_internal::LowLevelCallOnce(&create_globals_once, CreateGlobalArenas);
272  return reinterpret_cast<LowLevelAlloc::Arena*>(&default_arena_storage);
273 }
274 
275 // magic numbers to identify allocated and unallocated blocks
276 static const uintptr_t kMagicAllocated = 0x4c833e95U;
278 
279 namespace {
280 class ABSL_SCOPED_LOCKABLE ArenaLock {
281  public:
282  explicit ArenaLock(LowLevelAlloc::Arena *arena)
284  : arena_(arena) {
285 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
286  if ((arena->flags & LowLevelAlloc::kAsyncSignalSafe) != 0) {
287  sigset_t all;
288  sigfillset(&all);
289  mask_valid_ = pthread_sigmask(SIG_BLOCK, &all, &mask_) == 0;
290  }
291 #endif
292  arena_->mu.Lock();
293  }
294  ~ArenaLock() { ABSL_RAW_CHECK(left_, "haven't left Arena region"); }
295  void Leave() ABSL_UNLOCK_FUNCTION() {
296  arena_->mu.Unlock();
297 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
298  if (mask_valid_) {
299  const int err = pthread_sigmask(SIG_SETMASK, &mask_, nullptr);
300  if (err != 0) {
301  ABSL_RAW_LOG(FATAL, "pthread_sigmask failed: %d", err);
302  }
303  }
304 #endif
305  left_ = true;
306  }
307 
308  private:
309  bool left_ = false; // whether left region
310 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
311  bool mask_valid_ = false;
312  sigset_t mask_; // old mask of blocked signals
313 #endif
315  ArenaLock(const ArenaLock &) = delete;
316  ArenaLock &operator=(const ArenaLock &) = delete;
317 };
318 } // namespace
319 
320 // create an appropriate magic number for an object at "ptr"
321 // "magic" should be kMagicAllocated or kMagicUnallocated
322 inline static uintptr_t Magic(uintptr_t magic, AllocList::Header *ptr) {
323  return magic ^ reinterpret_cast<uintptr_t>(ptr);
324 }
325 
326 namespace {
327 size_t GetPageSize() {
328 #ifdef _WIN32
329  SYSTEM_INFO system_info;
330  GetSystemInfo(&system_info);
331  return std::max(system_info.dwPageSize, system_info.dwAllocationGranularity);
332 #elif defined(__wasm__) || defined(__asmjs__)
333  return getpagesize();
334 #else
335  return sysconf(_SC_PAGESIZE);
336 #endif
337 }
338 
339 size_t RoundedUpBlockSize() {
340  // Round up block sizes to a power of two close to the header size.
341  size_t round_up = 16;
342  while (round_up < sizeof(AllocList::Header)) {
343  round_up += round_up;
344  }
345  return round_up;
346 }
347 
348 } // namespace
349 
351  : mu(base_internal::SCHEDULE_KERNEL_ONLY),
352  allocation_count(0),
353  flags(flags_value),
354  pagesize(GetPageSize()),
355  round_up(RoundedUpBlockSize()),
356  min_size(2 * round_up),
357  random(0) {
358  freelist.header.size = 0;
359  freelist.header.magic =
360  Magic(kMagicUnallocated, &freelist.header);
361  freelist.header.arena = this;
362  freelist.levels = 0;
363  memset(freelist.next, 0, sizeof(freelist.next));
364 }
365 
366 // L < meta_data_arena->mu
368  Arena *meta_data_arena = DefaultArena();
369 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
370  if ((flags & LowLevelAlloc::kAsyncSignalSafe) != 0) {
371  meta_data_arena = UnhookedAsyncSigSafeArena();
372  } else // NOLINT(readability/braces)
373 #endif
374  if ((flags & LowLevelAlloc::kCallMallocHook) == 0) {
375  meta_data_arena = UnhookedArena();
376  }
377  Arena *result =
378  new (AllocWithArena(sizeof (*result), meta_data_arena)) Arena(flags);
379  return result;
380 }
381 
382 // L < arena->mu, L < arena->arena->mu
385  arena != nullptr && arena != DefaultArena() && arena != UnhookedArena(),
386  "may not delete default arena");
387  ArenaLock section(arena);
388  if (arena->allocation_count != 0) {
389  section.Leave();
390  return false;
391  }
392  while (arena->freelist.next[0] != nullptr) {
393  AllocList *region = arena->freelist.next[0];
394  size_t size = region->header.size;
395  arena->freelist.next[0] = region->next[0];
397  region->header.magic == Magic(kMagicUnallocated, &region->header),
398  "bad magic number in DeleteArena()");
399  ABSL_RAW_CHECK(region->header.arena == arena,
400  "bad arena pointer in DeleteArena()");
401  ABSL_RAW_CHECK(size % arena->pagesize == 0,
402  "empty arena has non-page-aligned block size");
403  ABSL_RAW_CHECK(reinterpret_cast<uintptr_t>(region) % arena->pagesize == 0,
404  "empty arena has non-page-aligned block");
405  int munmap_result;
406 #ifdef _WIN32
407  munmap_result = VirtualFree(region, 0, MEM_RELEASE);
408  ABSL_RAW_CHECK(munmap_result != 0,
409  "LowLevelAlloc::DeleteArena: VitualFree failed");
410 #else
411 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
412  if ((arena->flags & LowLevelAlloc::kAsyncSignalSafe) == 0) {
413  munmap_result = munmap(region, size);
414  } else {
415  munmap_result = base_internal::DirectMunmap(region, size);
416  }
417 #else
418  munmap_result = munmap(region, size);
419 #endif // ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
420  if (munmap_result != 0) {
421  ABSL_RAW_LOG(FATAL, "LowLevelAlloc::DeleteArena: munmap failed: %d",
422  errno);
423  }
424 #endif // _WIN32
425  }
426  section.Leave();
427  arena->~Arena();
428  Free(arena);
429  return true;
430 }
431 
432 // ---------------------------------------------------------------------------
433 
434 // Addition, checking for overflow. The intent is to die if an external client
435 // manages to push through a request that would cause arithmetic to fail.
437  uintptr_t sum = a + b;
438  ABSL_RAW_CHECK(sum >= a, "LowLevelAlloc arithmetic overflow");
439  return sum;
440 }
441 
442 // Return value rounded up to next multiple of align.
443 // align must be a power of two.
445  return CheckedAdd(addr, align - 1) & ~(align - 1);
446 }
447 
448 // Equivalent to "return prev->next[i]" but with sanity checking
449 // that the freelist is in the correct order, that it
450 // consists of regions marked "unallocated", and that no two regions
451 // are adjacent in memory (they should have been coalesced).
452 // L >= arena->mu
453 static AllocList *Next(int i, AllocList *prev, LowLevelAlloc::Arena *arena) {
454  ABSL_RAW_CHECK(i < prev->levels, "too few levels in Next()");
455  AllocList *next = prev->next[i];
456  if (next != nullptr) {
458  next->header.magic == Magic(kMagicUnallocated, &next->header),
459  "bad magic number in Next()");
460  ABSL_RAW_CHECK(next->header.arena == arena, "bad arena pointer in Next()");
461  if (prev != &arena->freelist) {
462  ABSL_RAW_CHECK(prev < next, "unordered freelist");
463  ABSL_RAW_CHECK(reinterpret_cast<char *>(prev) + prev->header.size <
464  reinterpret_cast<char *>(next),
465  "malformed freelist");
466  }
467  }
468  return next;
469 }
470 
471 // Coalesce list item "a" with its successor if they are adjacent.
472 static void Coalesce(AllocList *a) {
473  AllocList *n = a->next[0];
474  if (n != nullptr && reinterpret_cast<char *>(a) + a->header.size ==
475  reinterpret_cast<char *>(n)) {
476  LowLevelAlloc::Arena *arena = a->header.arena;
477  a->header.size += n->header.size;
478  n->header.magic = 0;
479  n->header.arena = nullptr;
480  AllocList *prev[kMaxLevel];
481  LLA_SkiplistDelete(&arena->freelist, n, prev);
482  LLA_SkiplistDelete(&arena->freelist, a, prev);
483  a->levels = LLA_SkiplistLevels(a->header.size, arena->min_size,
484  &arena->random);
485  LLA_SkiplistInsert(&arena->freelist, a, prev);
486  }
487 }
488 
489 // Adds block at location "v" to the free list
490 // L >= arena->mu
492  AllocList *f = reinterpret_cast<AllocList *>(
493  reinterpret_cast<char *>(v) - sizeof (f->header));
494  ABSL_RAW_CHECK(f->header.magic == Magic(kMagicAllocated, &f->header),
495  "bad magic number in AddToFreelist()");
496  ABSL_RAW_CHECK(f->header.arena == arena,
497  "bad arena pointer in AddToFreelist()");
498  f->levels = LLA_SkiplistLevels(f->header.size, arena->min_size,
499  &arena->random);
500  AllocList *prev[kMaxLevel];
501  LLA_SkiplistInsert(&arena->freelist, f, prev);
502  f->header.magic = Magic(kMagicUnallocated, &f->header);
503  Coalesce(f); // maybe coalesce with successor
504  Coalesce(prev[0]); // maybe coalesce with predecessor
505 }
506 
507 // Frees storage allocated by LowLevelAlloc::Alloc().
508 // L < arena->mu
509 void LowLevelAlloc::Free(void *v) {
510  if (v != nullptr) {
511  AllocList *f = reinterpret_cast<AllocList *>(
512  reinterpret_cast<char *>(v) - sizeof (f->header));
513  LowLevelAlloc::Arena *arena = f->header.arena;
514  ArenaLock section(arena);
516  ABSL_RAW_CHECK(arena->allocation_count > 0, "nothing in arena to free");
517  arena->allocation_count--;
518  section.Leave();
519  }
520 }
521 
522 // allocates and returns a block of size bytes, to be freed with Free()
523 // L < arena->mu
525  void *result = nullptr;
526  if (request != 0) {
527  AllocList *s; // will point to region that satisfies request
528  ArenaLock section(arena);
529  // round up with header
530  size_t req_rnd = RoundUp(CheckedAdd(request, sizeof (s->header)),
531  arena->round_up);
532  for (;;) { // loop until we find a suitable region
533  // find the minimum levels that a block of this size must have
534  int i = LLA_SkiplistLevels(req_rnd, arena->min_size, nullptr) - 1;
535  if (i < arena->freelist.levels) { // potential blocks exist
536  AllocList *before = &arena->freelist; // predecessor of s
537  while ((s = Next(i, before, arena)) != nullptr &&
538  s->header.size < req_rnd) {
539  before = s;
540  }
541  if (s != nullptr) { // we found a region
542  break;
543  }
544  }
545  // we unlock before mmap() both because mmap() may call a callback hook,
546  // and because it may be slow.
547  arena->mu.Unlock();
548  // mmap generous 64K chunks to decrease
549  // the chances/impact of fragmentation:
550  size_t new_pages_size = RoundUp(req_rnd, arena->pagesize * 16);
551  void *new_pages;
552 #ifdef _WIN32
553  new_pages = VirtualAlloc(0, new_pages_size,
554  MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
555  ABSL_RAW_CHECK(new_pages != nullptr, "VirtualAlloc failed");
556 #else
557 #ifndef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
558  if ((arena->flags & LowLevelAlloc::kAsyncSignalSafe) != 0) {
559  new_pages = base_internal::DirectMmap(nullptr, new_pages_size,
560  PROT_WRITE|PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
561  } else {
562  new_pages = mmap(nullptr, new_pages_size, PROT_WRITE | PROT_READ,
563  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
564  }
565 #else
566  new_pages = mmap(nullptr, new_pages_size, PROT_WRITE | PROT_READ,
567  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
568 #endif // ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
569  if (new_pages == MAP_FAILED) {
570  ABSL_RAW_LOG(FATAL, "mmap error: %d", errno);
571  }
572 
573 #endif // _WIN32
574  arena->mu.Lock();
575  s = reinterpret_cast<AllocList *>(new_pages);
576  s->header.size = new_pages_size;
577  // Pretend the block is allocated; call AddToFreelist() to free it.
578  s->header.magic = Magic(kMagicAllocated, &s->header);
579  s->header.arena = arena;
580  AddToFreelist(&s->levels, arena); // insert new region into free list
581  }
582  AllocList *prev[kMaxLevel];
583  LLA_SkiplistDelete(&arena->freelist, s, prev); // remove from free list
584  // s points to the first free region that's big enough
585  if (CheckedAdd(req_rnd, arena->min_size) <= s->header.size) {
586  // big enough to split
587  AllocList *n = reinterpret_cast<AllocList *>
588  (req_rnd + reinterpret_cast<char *>(s));
589  n->header.size = s->header.size - req_rnd;
590  n->header.magic = Magic(kMagicAllocated, &n->header);
591  n->header.arena = arena;
592  s->header.size = req_rnd;
593  AddToFreelist(&n->levels, arena);
594  }
595  s->header.magic = Magic(kMagicAllocated, &s->header);
596  ABSL_RAW_CHECK(s->header.arena == arena, "");
597  arena->allocation_count++;
598  section.Leave();
599  result = &s->levels;
600  }
602  return result;
603 }
604 
607  return result;
608 }
609 
611  ABSL_RAW_CHECK(arena != nullptr, "must pass a valid arena");
613  return result;
614 }
615 
616 } // namespace base_internal
618 } // namespace absl
619 
620 #endif // ABSL_LOW_LEVEL_ALLOC_MISSING
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
ABSL_RAW_CHECK
#define ABSL_RAW_CHECK(condition, message)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:59
test_group_name.all
all
Definition: test_group_name.py:241
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
Arena
struct Arena Arena
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:189
section
OPENSSL_EXPORT const char * section
Definition: conf.h:114
memset
return memset(p, 0, total)
absl::base_internal::LowLevelAlloc::Arena::pagesize
const size_t pagesize
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:213
magic
uintptr_t magic
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:83
absl::base_internal::Magic
static uintptr_t Magic(uintptr_t magic, AllocList::Header *ptr)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:322
grpc::testing::sum
double sum(const T &container, F functor)
Definition: test/cpp/qps/stats.h:30
string.h
absl::base_internal::LowLevelAlloc::NewArena
static Arena * NewArena(int32_t flags)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:367
benchmark.request
request
Definition: benchmark.py:77
absl::base_internal::LLA_SkiplistSearch
static AllocList * LLA_SkiplistSearch(AllocList *head, AllocList *e, AllocList **prev)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:156
error_ref_leak.err
err
Definition: error_ref_leak.py:35
absl::base_internal::DoAllocWithArena
static void * DoAllocWithArena(size_t request, LowLevelAlloc::Arena *arena)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:524
absl::base_internal::SpinLock
Definition: third_party/abseil-cpp/absl/base/internal/spinlock.h:52
absl::base_internal::LowLevelAlloc::Arena::Arena
Arena(uint32_t flags_value)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:350
absl::FormatConversionChar::s
@ s
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
levels
int levels
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:96
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::base_internal::Next
static AllocList * Next(int i, AllocList *prev, LowLevelAlloc::Arena *arena)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:453
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
before
IntBeforeRegisterTypedTestSuiteP before
Definition: googletest/googletest/test/gtest-typed-test_test.cc:376
absl::base_internal::LowLevelAlloc::Arena::min_size
const size_t min_size
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:217
mask_
sigset_t mask_
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:312
absl::FormatConversionChar::e
@ e
absl::base_internal::AddToFreelist
static void AddToFreelist(void *v, LowLevelAlloc::Arena *arena)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:491
allocation_count
int allocation_count
Definition: message_allocator_end2end_test.cc:246
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
gen_stats_data.found
bool found
Definition: gen_stats_data.py:61
absl::base_internal::LowLevelAlloc::Free
static void Free(void *s) ABSL_ATTRIBUTE_SECTION(malloc_hook)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:509
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
mu
Mutex mu
Definition: server_config_selector_filter.cc:74
absl::base_internal::LowLevelAlloc::Arena
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:201
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
absl::base_internal::LowLevelAlloc::Arena::ABSL_GUARDED_BY
AllocList freelist ABSL_GUARDED_BY(mu)
absl::base_internal::LowLevelAlloc::Arena::round_up
const size_t round_up
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:215
header
struct absl::base_internal::@2940::AllocList::Header header
absl::base_internal::LowLevelAlloc::kCallMallocHook
@ kCallMallocHook
Definition: abseil-cpp/absl/base/internal/low_level_alloc.h:94
left_
bool left_
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:309
absl::base_internal::LowLevelAlloc::Arena::flags
const uint32_t flags
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:211
dummy_for_alignment
void * dummy_for_alignment
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:89
absl::base_internal::LLA_SkiplistLevels
static int LLA_SkiplistLevels(size_t size, size_t base, uint32_t *random)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:140
gen_synthetic_protos.base
base
Definition: gen_synthetic_protos.py:31
uintptr_t
_W64 unsigned int uintptr_t
Definition: stdint-msvc2008.h:119
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
absl::base_internal::LowLevelAlloc::kAsyncSignalSafe
@ kAsyncSignalSafe
Definition: abseil-cpp/absl/base/internal/low_level_alloc.h:99
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
mask_valid_
bool mask_valid_
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:311
section
Definition: loader.h:337
absl::base_internal::kMaxLevel
static const int kMaxLevel
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:72
ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED
#define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size)
Definition: third_party/abseil-cpp/absl/base/dynamic_annotations.h:265
absl::base_internal::LowLevelCallOnce
void LowLevelCallOnce(absl::once_flag *flag, Callable &&fn, Args &&... args)
Definition: abseil-cpp/absl/base/call_once.h:193
FATAL
#define FATAL(msg)
Definition: task.h:88
absl::base_internal::RoundUp
static uintptr_t RoundUp(uintptr_t addr, uintptr_t align)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:444
absl::base_internal::SCHEDULE_KERNEL_ONLY
@ SCHEDULE_KERNEL_ONLY
Definition: abseil-cpp/absl/base/internal/scheduling_mode.h:50
size
uintptr_t size
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:80
ABSL_EXCLUSIVE_LOCK_FUNCTION
#define ABSL_EXCLUSIVE_LOCK_FUNCTION(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:207
absl::time_internal::cctz::detail::align
CONSTEXPR_F fields align(second_tag, fields f) noexcept
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h:325
absl::base_internal::Coalesce
static void Coalesce(AllocList *a)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:472
absl::base_internal::LowLevelAlloc::DeleteArena
static bool DeleteArena(Arena *arena)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:383
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
arena
LowLevelAlloc::Arena * arena
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:86
absl::base_internal::LowLevelAlloc::Alloc
static void * Alloc(size_t request) ABSL_ATTRIBUTE_SECTION(malloc_hook)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:605
absl::base_internal::kMagicAllocated
static const uintptr_t kMagicAllocated
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:276
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
fix_build_deps.r
r
Definition: fix_build_deps.py:491
absl::base_internal::kMagicUnallocated
static const uintptr_t kMagicUnallocated
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:277
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::base_internal::Random
static int Random(uint32_t *state)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:122
absl::base_internal::LLA_SkiplistInsert
static void LLA_SkiplistInsert(AllocList *head, AllocList *e, AllocList **prev)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:170
absl::base_internal::LLA_SkiplistDelete
static void LLA_SkiplistDelete(AllocList *head, AllocList *e, AllocList **prev)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:185
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
client.level
level
Definition: examples/python/async_streaming/client.py:118
absl::base_internal::IntLog2
static int IntLog2(size_t size, size_t base)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:110
absl::once_flag
Definition: abseil-cpp/absl/base/call_once.h:85
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
absl::base_internal::LowLevelAlloc::Arena::mu
base_internal::SpinLock mu
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:205
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
ABSL_UNLOCK_FUNCTION
#define ABSL_UNLOCK_FUNCTION(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:228
arena_
LowLevelAlloc::Arena * arena_
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:314
ABSL_RAW_LOG
#define ABSL_RAW_LOG(severity,...)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:44
absl::base_internal::CheckedAdd
static uintptr_t CheckedAdd(uintptr_t a, uintptr_t b)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:436
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
absl::base_internal::LowLevelAlloc::AllocWithArena
static void * AllocWithArena(size_t request, Arena *arena) ABSL_ATTRIBUTE_SECTION(malloc_hook)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:610
ABSL_SCOPED_LOCKABLE
#define ABSL_SCOPED_LOCKABLE
Definition: abseil-cpp/absl/base/thread_annotations.h:196
absl::base_internal::LowLevelAlloc::DefaultArena
static Arena * DefaultArena()
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:270
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:16