Lines Matching defs:pool
930 * Enable by default since it allows larger pool sizes. Can be disabled
982 # error "pool size must be equal to system page size"
988 # error "arena size not an exact multiple of pool size"
1004 block *freeblock; /* pool's free list head */
1005 struct pool_header *nextpool; /* next pool of this size class */
1006 struct pool_header *prevpool; /* previous pool "" */
1024 /* Pool-aligned pointer to the next pool to be carved off. */
1044 * with at least one available pool, both members are used in the
1060 /* Round pointer P down to the closest pool-aligned address <= P, as a poolp */
1063 /* Return total number of blocks in pool of size index I, as a uint. */
1077 member) as needed. Once carved off, a pool is in one of three states forever
1081 At least one block in the pool is currently allocated, and at least one
1082 block in the pool is not currently allocated (note this implies a pool
1084 This is a pool's initial state, as a pool is created only when malloc
1086 The pool holds blocks of a fixed size, and is in the circular list headed
1093 full == all the pool's blocks are currently allocated
1094 On transition to full, a pool is unlinked from its usedpools[] list.
1097 A free of a block in a full pool puts the pool back in the used state.
1101 empty == all the pool's blocks are currently available for allocation
1102 On transition to empty, a pool is unlinked from its usedpools[] list,
1106 an empty list in usedpools[], it takes the first pool off of freepools.
1107 If the size class needed happens to be the same as the size class the pool
1108 last had, some pool initialization can be skipped.
1113 Blocks within pools are again carved out as needed. pool->freeblock points to
1114 the start of a singly-linked list of free blocks within the pool. When a
1115 block is freed, it's inserted at the front of its pool's freeblock list. Note
1116 that the available blocks in a pool are *not* linked all together when a pool
1118 set up, returning the first such block, and setting pool->freeblock to a
1120 pymalloc strives at all levels (arena, pool, and block) never to touch a piece
1123 So long as a pool is in the used state, we're certain there *is* a block
1124 available for allocating, and pool->freeblock is not NULL. If pool->freeblock
1125 points to the end of the free list before we've carved the entire pool into
1130 pool is initialized. All the blocks in a pool have been passed out at least
1289 /* visit every pool in the arena */
1582 uint excess; /* number of bytes above pool alignment */
1666 /* pool_address <- first pool-aligned address in the arena
1687 address_in_range(void *p, poolp pool)
1696 POOL must be the pool address associated with P, i.e., POOL = POOL_ADDR(P)
1702 Tricky: Let B be the arena base address associated with the pool, B =
1721 stores, etc), POOL is the correct address of P's pool, AO.address is the
1722 correct base address of the pool's arena, and P must be within ARENA_SIZE of
1770 address_in_range(void *p, poolp pool)
1773 // by Python, it is important that pool->arenaindex is read only once, as
1775 // the GIL. The following dance forces the compiler to read pool->arenaindex
1777 uint arenaindex = *((volatile uint *)&pool->arenaindex);
1788 // space for a block. Otherwise, remove this pool from usedpools.
1790 pymalloc_pool_extend(poolp pool, uint size)
1792 if (UNLIKELY(pool->nextoffset <= pool->maxnextoffset)) {
1794 pool->freeblock = (block*)pool + pool->nextoffset;
1795 pool->nextoffset += INDEX2SIZE(size);
1796 *(block **)(pool->freeblock) = NULL;
1802 next = pool->nextpool;
1803 pool = pool->prevpool;
1804 next->prevpool = pool;
1805 pool->nextpool = next;
1809 * This function takes new pool and allocate a block from it.
1814 /* There isn't a pool of the right size class immediately
1815 * available: use a free pool.
1818 /* No arena has a free pool: allocate a new arena. */
1850 /* Try to get a cached free pool. */
1851 poolp pool = usable_arenas->freepools;
1852 if (LIKELY(pool != NULL)) {
1854 usable_arenas->freepools = pool->nextpool;
1881 /* Carve off a new pool. */
1884 pool = (poolp)usable_arenas->pool_address;
1885 assert((block*)pool <= (block*)usable_arenas->address +
1887 pool->arenaindex = (uint)(usable_arenas - arenas);
1888 assert(&arenas[pool->arenaindex] == usable_arenas);
1889 pool->szidx = DUMMY_SIZE_IDX;
1909 pool->nextpool = next;
1910 pool->prevpool = next;
1911 next->nextpool = pool;
1912 next->prevpool = pool;
1913 pool->ref.count = 1;
1914 if (pool->szidx == size) {
1915 /* Luckily, this pool last contained blocks
1919 bp = pool->freeblock;
1921 pool->freeblock = *(block **)bp;
1925 * Initialize the pool header, set up the free list to
1929 pool->szidx = size;
1931 bp = (block *)pool + POOL_OVERHEAD;
1932 pool->nextoffset = POOL_OVERHEAD + (size << 1);
1933 pool->maxnextoffset = POOL_SIZE - size;
1934 pool->freeblock = bp + size;
1935 *(block **)(pool->freeblock) = NULL;
1967 poolp pool = usedpools[size + size];
1970 if (LIKELY(pool != pool->nextpool)) {
1972 * There is a used pool for this size class.
1975 ++pool->ref.count;
1976 bp = pool->freeblock;
1979 if (UNLIKELY((pool->freeblock = *(block **)bp) == NULL)) {
1981 pymalloc_pool_extend(pool, size);
1985 /* There isn't a pool of the right size class immediately
1986 * available: use a free pool.
2032 insert_to_usedpool(poolp pool)
2034 assert(pool->ref.count > 0); /* else the pool is empty */
2036 uint size = pool->szidx;
2040 /* insert pool before next: prev <-> pool <-> next */
2041 pool->nextpool = next;
2042 pool->prevpool = prev;
2043 next->prevpool = pool;
2044 prev->nextpool = pool;
2048 insert_to_freepool(poolp pool)
2050 poolp next = pool->nextpool;
2051 poolp prev = pool->prevpool;
2055 /* Link the pool to freepools. This is a singly-linked
2056 * list, and pool->prevpool isn't used there.
2058 struct arena_object *ao = &arenas[pool->arenaindex];
2059 pool->nextpool = ao->freepools;
2060 ao->freepools = pool;
2080 * a pool, and there are 4 cases for arena mgmt:
2088 * 2. If this is the only free pool in the arena,
2228 poolp pool = POOL_ADDR(p);
2229 if (UNLIKELY(!address_in_range(p, pool))) {
2234 /* Link p to the start of the pool's freeblock list. Since
2235 * the pool had at least the p block outstanding, the pool
2240 assert(pool->ref.count > 0); /* else it was empty */
2241 block *lastfree = pool->freeblock;
2243 pool->freeblock = (block *)p;
2244 pool->ref.count--;
2249 * This mimics LRU pool usage for new allocations and
2253 insert_to_usedpool(pool);
2257 /* freeblock wasn't NULL, so the pool wasn't full,
2258 * and the pool is in a usedpools[] list.
2260 if (LIKELY(pool->ref.count != 0)) {
2261 /* pool isn't empty: leave it in usedpools */
2270 insert_to_freepool(pool);
2304 poolp pool;
2316 pool = POOL_ADDR(p);
2317 if (!address_in_range(p, pool)) {
2334 size = INDEX2SIZE(pool->szidx);
3011 /* round up to pool alignment */
3018 /* visit every pool in the arena */
3091 total += printone(out, "# bytes lost to pool headers", pool_header_bytes);