src/backend/utils/mmgr/aset.c
static void *
AllocSetAlloc(MemoryContext context, Size size)
{
	AllocSet	set = (AllocSet) context;
	AllocBlock	block;
	AllocChunk	chunk;
	int			fidx;
	Size		chunk_size;
	Size		blksize;

	AssertArg(AllocSetIsValid(set));

	/*
	 * If requested size exceeds maximum for chunks, allocate an entire block
	 * for this request.
	 */
	if (size > set->allocChunkLimit)
	{
		chunk_size = MAXALIGN(size);
		blksize = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ;
		block = (AllocBlock) malloc(blksize);
		if (block == NULL)
			return NULL;

		context->mem_allocated += blksize;

		block->aset = set;
		block->freeptr = block->endptr = ((char *) block) + blksize;

		chunk = (AllocChunk) (((char *) block) + ALLOC_BLOCKHDRSZ);
		chunk->aset = set;
		chunk->size = chunk_size;
#ifdef MEMORY_CONTEXT_CHECKING
		chunk->requested_size = size;
		/* set mark to catch clobber of "unused" space */
		if (size < chunk_size)
			set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
		/* fill the allocated space with junk */
		randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif

		/*
		 * Stick the new block underneath the active allocation block, if any,
		 * so that we don't lose the use of the space remaining therein.
		 */
		if (set->blocks != NULL)
		{
			block->prev = set->blocks;
			block->next = set->blocks->next;
			if (block->next)
				block->next->prev = block;
			set->blocks->next = block;
		}
		else
		{
			block->prev = NULL;
			block->next = NULL;
			set->blocks = block;
		}

		/* Ensure any padding bytes are marked NOACCESS. */
		VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
								   chunk_size - size);

		/* Disallow external access to private part of chunk header. */
		VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);

		return AllocChunkGetPointer(chunk);
	}

	/*
	 * Request is small enough to be treated as a chunk.  Look in the
	 * corresponding free list to see if there is a free chunk we could reuse.
	 * If one is found, remove it from the free list, make it again a member
	 * of the alloc set and return its data address.
	 */
	fidx = AllocSetFreeIndex(size);
	chunk = set->freelist[fidx];
	if (chunk != NULL)
	{
		Assert(chunk->size >= size);

		set->freelist[fidx] = (AllocChunk) chunk->aset;

		chunk->aset = (void *) set;

#ifdef MEMORY_CONTEXT_CHECKING
		chunk->requested_size = size;
		/* set mark to catch clobber of "unused" space */
		if (size < chunk->size)
			set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
		/* fill the allocated space with junk */
		randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif

		/* Ensure any padding bytes are marked NOACCESS. */
		VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
								   chunk->size - size);

		/* Disallow external access to private part of chunk header. */
		VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);

		return AllocChunkGetPointer(chunk);
	}

	/*
	 * Choose the actual chunk size to allocate.
	 */
	chunk_size = (1 << ALLOC_MINBITS) << fidx;
	Assert(chunk_size >= size);

	/*
	 * If there is enough room in the active allocation block, we will put the
	 * chunk into that block.  Else must start a new one.
	 */
	if ((block = set->blocks) != NULL)
	{
		Size		availspace = block->endptr - block->freeptr;

		if (availspace < (chunk_size + ALLOC_CHUNKHDRSZ))
		{
			/*
			 * The existing active (top) block does not have enough room for
			 * the requested allocation, but it might still have a useful
			 * amount of space in it.  Once we push it down in the block list,
			 * we'll never try to allocate more space from it. So, before we
			 * do that, carve up its free space into chunks that we can put on
			 * the set's freelists.
			 *
			 * Because we can only get here when there's less than
			 * ALLOC_CHUNK_LIMIT left in the block, this loop cannot iterate
			 * more than ALLOCSET_NUM_FREELISTS-1 times.
			 */
			while (availspace >= ((1 << ALLOC_MINBITS) + ALLOC_CHUNKHDRSZ))
			{
				Size		availchunk = availspace - ALLOC_CHUNKHDRSZ;
				int			a_fidx = AllocSetFreeIndex(availchunk);

				/*
				 * In most cases, we'll get back the index of the next larger
				 * freelist than the one we need to put this chunk on.  The
				 * exception is when availchunk is exactly a power of 2.
				 */
				if (availchunk != ((Size) 1 << (a_fidx + ALLOC_MINBITS)))
				{
					a_fidx--;
					Assert(a_fidx >= 0);
					availchunk = ((Size) 1 << (a_fidx + ALLOC_MINBITS));
				}

				chunk = (AllocChunk) (block->freeptr);

				/* Prepare to initialize the chunk header. */
				VALGRIND_MAKE_MEM_UNDEFINED(chunk, ALLOC_CHUNKHDRSZ);

				block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
				availspace -= (availchunk + ALLOC_CHUNKHDRSZ);

				chunk->size = availchunk;
#ifdef MEMORY_CONTEXT_CHECKING
				chunk->requested_size = 0;	/* mark it free */
#endif
				chunk->aset = (void *) set->freelist[a_fidx];
				set->freelist[a_fidx] = chunk;
			}

			/* Mark that we need to create a new block */
			block = NULL;
		}
	}

	/*
	 * Time to create a new regular (multi-chunk) block?
	 */
	if (block == NULL)
	{
		Size		required_size;

		/*
		 * The first such block has size initBlockSize, and we double the
		 * space in each succeeding block, but not more than maxBlockSize.
		 */
		blksize = set->nextBlockSize;
		set->nextBlockSize <<= 1;
		if (set->nextBlockSize > set->maxBlockSize)
			set->nextBlockSize = set->maxBlockSize;

		/*
		 * If initBlockSize is less than ALLOC_CHUNK_LIMIT, we could need more
		 * space... but try to keep it a power of 2.
		 */
		required_size = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ;
		while (blksize < required_size)
			blksize <<= 1;

		/* Try to allocate it */
		block = (AllocBlock) malloc(blksize);

		/*
		 * We could be asking for pretty big blocks here, so cope if malloc
		 * fails.  But give up if there's less than 1 MB or so available...
		 */
		while (block == NULL && blksize > 1024 * 1024)
		{
			blksize >>= 1;
			if (blksize < required_size)
				break;
			block = (AllocBlock) malloc(blksize);
		}

		if (block == NULL)
			return NULL;

		context->mem_allocated += blksize;

		block->aset = set;
		block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
		block->endptr = ((char *) block) + blksize;

		/* Mark unallocated space NOACCESS. */
		VALGRIND_MAKE_MEM_NOACCESS(block->freeptr,
								   blksize - ALLOC_BLOCKHDRSZ);

		block->prev = NULL;
		block->next = set->blocks;
		if (block->next)
			block->next->prev = block;
		set->blocks = block;
	}

	/*
	 * OK, do the allocation
	 */
	chunk = (AllocChunk) (block->freeptr);

	/* Prepare to initialize the chunk header. */
	VALGRIND_MAKE_MEM_UNDEFINED(chunk, ALLOC_CHUNKHDRSZ);

	block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
	Assert(block->freeptr <= block->endptr);

	chunk->aset = (void *) set;
	chunk->size = chunk_size;
#ifdef MEMORY_CONTEXT_CHECKING
	chunk->requested_size = size;
	/* set mark to catch clobber of "unused" space */
	if (size < chunk->size)
		set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
	/* fill the allocated space with junk */
	randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif

	/* Ensure any padding bytes are marked NOACCESS. */
	VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
							   chunk_size - size);

	/* Disallow external access to private part of chunk header. */
	VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);

	return AllocChunkGetPointer(chunk);
}
/*
 * AllocSetAlloc
 *		Returns pointer to allocated memory of given size or NULL if
 *		request could not be completed; memory is added to the set.
 *
 * No request may exceed:
 *		MAXALIGN_DOWN(SIZE_MAX) - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ
 * All callers use a much-lower limit.
 *
 * Note: when using valgrind, it doesn't matter how the returned allocation
 * is marked, as mcxt.c will set it to UNDEFINED.  In some paths we will
 * return space that is marked NOACCESS - AllocSetRealloc has to beware!
 */
AllocSetAlloc
Returns pointer to allocated memory of given size or NULL if
request could not be completed; memory is added to the set.

No request may exceed:
MAXALIGN_DOWN(SIZE_MAX) - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ
All callers use a much-lower limit.

when using valgrind, it doesn't matter how the returned allocation
is marked, as mcxt.c will set it to UNDEFINED.  In some paths we will
return space that is marked NOACCESS - AllocSetRealloc has to beware!
AllocSetAlloc Returns pointer to allocated memory of given size or NULL if request could not be completed ; memory is added to the set . No request may exceed : MAXALIGN_DOWN ( SIZE_MAX ) - ALLOC_BLOCKHDRSZ - ALLOC_CHUNKHDRSZ All callers use a much - lower limit . when using valgrind it doesn ' t matter how the returned allocation is marked as mcxt . c will set it to UNDEFINED . In some paths we will return space that is marked NOACCESS - AllocSetRealloc has to beware!
static void *
AllocSetAlloc(MemoryContext context, Size size)
{
	AllocSet	set = (AllocSet) context;
	AllocBlock	block;
	AllocChunk	chunk;
	int			fidx;
	Size		chunk_size;
	Size		blksize;
	AssertArg(AllocSetIsValid(set));
	if (size > set->allocChunkLimit)
	{
		chunk_size = MAXALIGN(size);
		blksize = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ;
		block = (AllocBlock) malloc(blksize);
		if (block == NULL)
			return NULL;
		context->mem_allocated += blksize;
		block->aset = set;
		block->freeptr = block->endptr = ((char *) block) + blksize;
		chunk = (AllocChunk) (((char *) block) + ALLOC_BLOCKHDRSZ);
		chunk->aset = set;
		chunk->size = chunk_size;
#ifdef MEMORY_CONTEXT_CHECKING
		chunk->requested_size = size;
		if (size < chunk_size)
			set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
		randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif
		if (set->blocks != NULL)
		{
			block->prev = set->blocks;
			block->next = set->blocks->next;
			if (block->next)
				block->next->prev = block;
			set->blocks->next = block;
		}
		else
		{
			block->prev = NULL;
			block->next = NULL;
			set->blocks = block;
		}
		VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
								   chunk_size - size);
		VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);
		return AllocChunkGetPointer(chunk);
	}
	fidx = AllocSetFreeIndex(size);
	chunk = set->freelist[fidx];
	if (chunk != NULL)
	{
		Assert(chunk->size >= size);
		set->freelist[fidx] = (AllocChunk) chunk->aset;
		chunk->aset = (void *) set;
#ifdef MEMORY_CONTEXT_CHECKING
		chunk->requested_size = size;
		if (size < chunk->size)
			set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
		randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif
		VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
								   chunk->size - size);
		VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);
		return AllocChunkGetPointer(chunk);
	}
	chunk_size = (1 << ALLOC_MINBITS) << fidx;
	Assert(chunk_size >= size);
	if ((block = set->blocks) != NULL)
	{
		Size		availspace = block->endptr - block->freeptr;
		if (availspace < (chunk_size + ALLOC_CHUNKHDRSZ))
		{
			while (availspace >= ((1 << ALLOC_MINBITS) + ALLOC_CHUNKHDRSZ))
			{
				Size		availchunk = availspace - ALLOC_CHUNKHDRSZ;
				int			a_fidx = AllocSetFreeIndex(availchunk);
				if (availchunk != ((Size) 1 << (a_fidx + ALLOC_MINBITS)))
				{
					a_fidx--;
					Assert(a_fidx >= 0);
					availchunk = ((Size) 1 << (a_fidx + ALLOC_MINBITS));
				}
				chunk = (AllocChunk) (block->freeptr);
				VALGRIND_MAKE_MEM_UNDEFINED(chunk, ALLOC_CHUNKHDRSZ);
				block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
				availspace -= (availchunk + ALLOC_CHUNKHDRSZ);
				chunk->size = availchunk;
#ifdef MEMORY_CONTEXT_CHECKING
				chunk->requested_size = 0;	
#endif
				chunk->aset = (void *) set->freelist[a_fidx];
				set->freelist[a_fidx] = chunk;
			}
			block = NULL;
		}
	}
	if (block == NULL)
	{
		Size		required_size;
		blksize = set->nextBlockSize;
		set->nextBlockSize <<= 1;
		if (set->nextBlockSize > set->maxBlockSize)
			set->nextBlockSize = set->maxBlockSize;
		required_size = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ;
		while (blksize < required_size)
			blksize <<= 1;
		block = (AllocBlock) malloc(blksize);
		while (block == NULL && blksize > 1024 * 1024)
		{
			blksize >>= 1;
			if (blksize < required_size)
				break;
			block = (AllocBlock) malloc(blksize);
		}
		if (block == NULL)
			return NULL;
		context->mem_allocated += blksize;
		block->aset = set;
		block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
		block->endptr = ((char *) block) + blksize;
		VALGRIND_MAKE_MEM_NOACCESS(block->freeptr,
								   blksize - ALLOC_BLOCKHDRSZ);
		block->prev = NULL;
		block->next = set->blocks;
		if (block->next)
			block->next->prev = block;
		set->blocks = block;
	}
	chunk = (AllocChunk) (block->freeptr);
	VALGRIND_MAKE_MEM_UNDEFINED(chunk, ALLOC_CHUNKHDRSZ);
	block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
	Assert(block->freeptr <= block->endptr);
	chunk->aset = (void *) set;
	chunk->size = chunk_size;
#ifdef MEMORY_CONTEXT_CHECKING
	chunk->requested_size = size;
	if (size < chunk->size)
		set_sentinel(AllocChunkGetPointer(chunk), size);
#endif
#ifdef RANDOMIZE_ALLOCATED_MEMORY
	randomize_mem((char *) AllocChunkGetPointer(chunk), size);
#endif
	VALGRIND_MAKE_MEM_NOACCESS((char *) AllocChunkGetPointer(chunk) + size,
							   chunk_size - size);
	VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOCCHUNK_PRIVATE_LEN);
	return AllocChunkGetPointer(chunk);
}
static void * AllocSetAlloc ( MemoryContext context , Size size ) { AllocSet set = ( AllocSet ) context ; AllocBlock block ; AllocChunk chunk ; int fidx ; Size chunk_size ; Size blksize ; AssertArg ( AllocSetIsValid ( set ) ) ; if ( size > set -> allocChunkLimit ) { chunk_size = MAXALIGN ( size ) ; blksize = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ ; block = ( AllocBlock ) malloc ( blksize ) ; if ( block == NULL ) return NULL ; context -> mem_allocated += blksize ; block -> aset = set ; block -> freeptr = block -> endptr = ( ( char * ) block ) + blksize ; chunk = ( AllocChunk ) ( ( ( char * ) block ) + ALLOC_BLOCKHDRSZ ) ; chunk -> aset = set ; chunk -> size = chunk_size ; #ifdef MEMORY_CONTEXT_CHECKING chunk -> requested_size = size ; if ( size < chunk_size ) set_sentinel ( AllocChunkGetPointer ( chunk ) , size ) ; #endif #ifdef RANDOMIZE_ALLOCATED_MEMORY randomize_mem ( ( char * ) AllocChunkGetPointer ( chunk ) , size ) ; #endif if ( set -> blocks != NULL ) { block -> prev = set -> blocks ; block -> next = set -> blocks -> next ; if ( block -> next ) block -> next -> prev = block ; set -> blocks -> next = block ; } else { block -> prev = NULL ; block -> next = NULL ; set -> blocks = block ; } VALGRIND_MAKE_MEM_NOACCESS ( ( char * ) AllocChunkGetPointer ( chunk ) + size , chunk_size - size ) ; VALGRIND_MAKE_MEM_NOACCESS ( chunk , ALLOCCHUNK_PRIVATE_LEN ) ; return AllocChunkGetPointer ( chunk ) ; } fidx = AllocSetFreeIndex ( size ) ; chunk = set -> freelist [ fidx ] ; if ( chunk != NULL ) { Assert ( chunk -> size >= size ) ; set -> freelist [ fidx ] = ( AllocChunk ) chunk -> aset ; chunk -> aset = ( void * ) set ; #ifdef MEMORY_CONTEXT_CHECKING chunk -> requested_size = size ; if ( size < chunk -> size ) set_sentinel ( AllocChunkGetPointer ( chunk ) , size ) ; #endif #ifdef RANDOMIZE_ALLOCATED_MEMORY randomize_mem ( ( char * ) AllocChunkGetPointer ( chunk ) , size ) ; #endif VALGRIND_MAKE_MEM_NOACCESS ( ( char * ) AllocChunkGetPointer ( chunk ) + size , chunk -> size - size ) ; VALGRIND_MAKE_MEM_NOACCESS ( chunk , ALLOCCHUNK_PRIVATE_LEN ) ; return AllocChunkGetPointer ( chunk ) ; } chunk_size = ( 1 << ALLOC_MINBITS ) << fidx ; Assert ( chunk_size >= size ) ; if ( ( block = set -> blocks ) != NULL ) { Size availspace = block -> endptr - block -> freeptr ; if ( availspace < ( chunk_size + ALLOC_CHUNKHDRSZ ) ) { while ( availspace >= ( ( 1 << ALLOC_MINBITS ) + ALLOC_CHUNKHDRSZ ) ) { Size availchunk = availspace - ALLOC_CHUNKHDRSZ ; int a_fidx = AllocSetFreeIndex ( availchunk ) ; if ( availchunk != ( ( Size ) 1 << ( a_fidx + ALLOC_MINBITS ) ) ) { a_fidx -- ; Assert ( a_fidx >= 0 ) ; availchunk = ( ( Size ) 1 << ( a_fidx + ALLOC_MINBITS ) ) ; } chunk = ( AllocChunk ) ( block -> freeptr ) ; VALGRIND_MAKE_MEM_UNDEFINED ( chunk , ALLOC_CHUNKHDRSZ ) ; block -> freeptr += ( availchunk + ALLOC_CHUNKHDRSZ ) ; availspace -= ( availchunk + ALLOC_CHUNKHDRSZ ) ; chunk -> size = availchunk ; #ifdef MEMORY_CONTEXT_CHECKING chunk -> requested_size = 0 ; #endif chunk -> aset = ( void * ) set -> freelist [ a_fidx ] ; set -> freelist [ a_fidx ] = chunk ; } block = NULL ; } } if ( block == NULL ) { Size required_size ; blksize = set -> nextBlockSize ; set -> nextBlockSize <<= 1 ; if ( set -> nextBlockSize > set -> maxBlockSize ) set -> nextBlockSize = set -> maxBlockSize ; required_size = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ ; while ( blksize < required_size ) blksize <<= 1 ; block = ( AllocBlock ) malloc ( blksize ) ; while ( block == NULL && blksize > 1024 * 1024 ) { blksize >>= 1 ; if ( blksize < required_size ) break ; block = ( AllocBlock ) malloc ( blksize ) ; } if ( block == NULL ) return NULL ; context -> mem_allocated += blksize ; block -> aset = set ; block -> freeptr = ( ( char * ) block ) + ALLOC_BLOCKHDRSZ ; block -> endptr = ( ( char * ) block ) + blksize ; VALGRIND_MAKE_MEM_NOACCESS ( block -> freeptr , blksize - ALLOC_BLOCKHDRSZ ) ; block -> prev = NULL ; block -> next = set -> blocks ; if ( block -> next ) block -> next -> prev = block ; set -> blocks = block ; } chunk = ( AllocChunk ) ( block -> freeptr ) ; VALGRIND_MAKE_MEM_UNDEFINED ( chunk , ALLOC_CHUNKHDRSZ ) ; block -> freeptr += ( chunk_size + ALLOC_CHUNKHDRSZ ) ; Assert ( block -> freeptr <= block -> endptr ) ; chunk -> aset = ( void * ) set ; chunk -> size = chunk_size ; #ifdef MEMORY_CONTEXT_CHECKING chunk -> requested_size = size ; if ( size < chunk -> size ) set_sentinel ( AllocChunkGetPointer ( chunk ) , size ) ; #endif #ifdef RANDOMIZE_ALLOCATED_MEMORY randomize_mem ( ( char * ) AllocChunkGetPointer ( chunk ) , size ) ; #endif VALGRIND_MAKE_MEM_NOACCESS ( ( char * ) AllocChunkGetPointer ( chunk ) + size , chunk_size - size ) ; VALGRIND_MAKE_MEM_NOACCESS ( chunk , ALLOCCHUNK_PRIVATE_LEN ) ; return AllocChunkGetPointer ( chunk ) ; }
AllocSetAlloc
              Returns pointer to allocated memory of given size or NULL if
              request could not be completed; memory is added to the set.
AllocSetAlloc Returns pointer to allocated memory of given size or NULL if request could not be completed ; memory is added to the set .
/*
	 * If requested size exceeds maximum for chunks, allocate an entire block
	 * for this request.
	 */ /* set mark to catch clobber of "unused" space */ /* fill the allocated space with junk */ /*
		 * Stick the new block underneath the active allocation block, if any,
		 * so that we don't lose the use of the space remaining therein.
		 */ /* Ensure any padding bytes are marked NOACCESS. */ /* Disallow external access to private part of chunk header. */ /*
	 * Request is small enough to be treated as a chunk.  Look in the
	 * corresponding free list to see if there is a free chunk we could reuse.
	 * If one is found, remove it from the free list, make it again a member
	 * of the alloc set and return its data address.
	 */ /* set mark to catch clobber of "unused" space */ /* fill the allocated space with junk */ /* Ensure any padding bytes are marked NOACCESS. */ /* Disallow external access to private part of chunk header. */ /*
	 * Choose the actual chunk size to allocate.
	 */ /*
	 * If there is enough room in the active allocation block, we will put the
	 * chunk into that block.  Else must start a new one.
	 */ /*
			 * The existing active (top) block does not have enough room for
			 * the requested allocation, but it might still have a useful
			 * amount of space in it.  Once we push it down in the block list,
			 * we'll never try to allocate more space from it. So, before we
			 * do that, carve up its free space into chunks that we can put on
			 * the set's freelists.
			 *
			 * Because we can only get here when there's less than
			 * ALLOC_CHUNK_LIMIT left in the block, this loop cannot iterate
			 * more than ALLOCSET_NUM_FREELISTS-1 times.
			 */ /*
				 * In most cases, we'll get back the index of the next larger
				 * freelist than the one we need to put this chunk on.  The
				 * exception is when availchunk is exactly a power of 2.
				 */ /* Prepare to initialize the chunk header. */ /* mark it free */ /* Mark that we need to create a new block */ /*
	 * Time to create a new regular (multi-chunk) block?
	 */ /*
		 * The first such block has size initBlockSize, and we double the
		 * space in each succeeding block, but not more than maxBlockSize.
		 */ /*
		 * If initBlockSize is less than ALLOC_CHUNK_LIMIT, we could need more
		 * space... but try to keep it a power of 2.
		 */ /* Try to allocate it */ /*
		 * We could be asking for pretty big blocks here, so cope if malloc
		 * fails.  But give up if there's less than 1 MB or so available...
		 */ /* Mark unallocated space NOACCESS. */ /*
	 * OK, do the allocation
	 */ /* Prepare to initialize the chunk header. */ /* set mark to catch clobber of "unused" space */ /* fill the allocated space with junk */ /* Ensure any padding bytes are marked NOACCESS. */ /* Disallow external access to private part of chunk header. */