/*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
MemChunk::MemChunk(MemPoolChunked *aPool)
{
/* should have a pool for this too -
- * note that this requres:
+ * note that this requires:
* allocate one chunk for the pool of chunks's first chunk
* allocate a chunk from that pool
* move the contents of one chunk into the other
nextFreeChunk = pool->nextFreeChunk;
pool->nextFreeChunk = this;
- memMeterAdd(pool->getMeter().alloc, pool->chunk_capacity);
- memMeterAdd(pool->getMeter().idle, pool->chunk_capacity);
+ pool->getMeter().alloc += pool->chunk_capacity;
+ pool->getMeter().idle += pool->chunk_capacity;
++pool->chunkCount;
lastref = squid_curtime;
pool->allChunks.insert(this, memCompChunks);
}
-MemPoolChunked::MemPoolChunked(const char *aLabel, size_t aSize) : MemImplementingAllocator(aLabel, aSize)
+MemPoolChunked::MemPoolChunked(const char *aLabel, size_t aSize) :
+ MemImplementingAllocator(aLabel, aSize), chunk_size(0),
+ chunk_capacity(0), chunkCount(0), freeCache(0), nextFreeChunk(0),
+ Chunks(0), allChunks(Splay<MemChunk *>())
{
- chunk_size = 0;
- chunk_capacity = 0;
- chunkCount = 0;
- freeCache = 0;
- nextFreeChunk = 0;
- Chunks = 0;
- next = 0;
-
setChunkSize(MEM_CHUNK_SIZE);
#if HAVE_MALLOPT && M_MMAP_MAX
MemChunk::~MemChunk()
{
- memMeterDel(pool->getMeter().alloc, pool->chunk_capacity);
- memMeterDel(pool->getMeter().idle, pool->chunk_capacity);
+ pool->getMeter().alloc -= pool->chunk_capacity;
+ pool->getMeter().idle -= pool->chunk_capacity;
-- pool->chunkCount;
pool->allChunks.remove(this, memCompChunks);
xfree(objCache);
newChunk = new MemChunk(this);
chunk = Chunks;
- if (chunk == NULL) { /* first chunk in pool */
+ if (chunk == NULL) { /* first chunk in pool */
Chunks = newChunk;
return;
}
int cap;
size_t csize = chunksize;
- if (Chunks) /* unsafe to tamper */
+ if (Chunks) /* unsafe to tamper */
return;
- csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE; /* round up to page size */
+ csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE; /* round up to page size */
cap = csize / obj_size;
if (cap < MEM_MIN_FREE)
cap = 1;
csize = cap * obj_size;
- csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE; /* round up to page size */
+ csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE; /* round up to page size */
cap = csize / obj_size;
chunk_capacity = cap;
flushMetersFull();
clean(0);
- assert(meter.inuse.level == 0);
+ assert(meter.inuse.currentLevel() == 0);
chunk = Chunks;
while ( (fchunk = chunk) != NULL) {
int
MemPoolChunked::getInUseCount()
{
- return meter.inuse.level;
+ return meter.inuse.currentLevel();
}
void *
MemPoolChunked::allocate()
{
void *p = get();
- assert(meter.idle.level > 0);
- memMeterDec(meter.idle);
- memMeterInc(meter.inuse);
+ assert(meter.idle.currentLevel() > 0);
+ --meter.idle;
+ ++meter.inuse;
return p;
}
void
-MemPoolChunked::deallocate(void *obj, bool aggressive)
+MemPoolChunked::deallocate(void *obj, bool)
{
push(obj);
- assert(meter.inuse.level > 0);
- memMeterDec(meter.inuse);
- memMeterInc(meter.idle);
+ assert(meter.inuse.currentLevel() > 0);
+ --meter.inuse;
+ ++meter.idle;
}
void
assert(chunk->inuse_count > 0);
-- chunk->inuse_count;
(void) VALGRIND_MAKE_MEM_DEFINED(Free, sizeof(void *));
- freeCache = *(void **)Free; /* remove from global cache */
- *(void **)Free = chunk->freeList; /* stuff into chunks freelist */
+ freeCache = *(void **)Free; /* remove from global cache */
+ *(void **)Free = chunk->freeList; /* stuff into chunks freelist */
(void) VALGRIND_MAKE_MEM_NOACCESS(Free, sizeof(void *));
chunk->freeList = Free;
chunk->lastref = squid_curtime;
bool
MemPoolChunked::idleTrigger(int shift) const
{
- return meter.idle.level > (chunk_capacity << shift);
+ return meter.idle.currentLevel() > (chunk_capacity << shift);
}
/*
int chunks_free = 0;
int chunks_partial = 0;
- if (!accumulate) /* need skip memset for GlobalStats accumulation */
+ if (!accumulate) /* need skip memset for GlobalStats accumulation */
memset(stats, 0, sizeof(MemPoolStats));
- clean((time_t) 555555); /* don't want to get chunks released before reporting */
+ clean((time_t) 555555); /* don't want to get chunks released before reporting */
stats->pool = this;
stats->label = objectType();
stats->chunks_partial += chunks_partial;
stats->chunks_free += chunks_free;
- stats->items_alloc += meter.alloc.level;
- stats->items_inuse += meter.inuse.level;
- stats->items_idle += meter.idle.level;
+ stats->items_alloc += meter.alloc.currentLevel();
+ stats->items_inuse += meter.inuse.currentLevel();
+ stats->items_idle += meter.idle.currentLevel();
stats->overhead += sizeof(MemPoolChunked) + chunkCount * sizeof(MemChunk) + strlen(objectType()) + 1;
- return meter.inuse.level;
+ return meter.inuse.currentLevel();
}
+