]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolMalloc.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins, Henrik Nordstrom
14 #include "mem/PoolMalloc.h"
19 extern time_t squid_curtime
;
22 MemPoolMalloc::allocate()
25 if (!freelist
.empty()) {
34 obj
= xcalloc(1, obj_size
);
36 obj
= xmalloc(obj_size
);
44 MemPoolMalloc::deallocate(void *obj
, bool aggressive
)
52 memset(obj
, 0, obj_size
);
58 /* TODO extract common logic to MemAllocate */
60 MemPoolMalloc::getStats(MemPoolStats
* stats
, int accumulate
)
62 if (!accumulate
) /* need skip memset for GlobalStats accumulation */
63 memset(stats
, 0, sizeof(MemPoolStats
));
66 stats
->label
= objectType();
67 stats
->meter
= &meter
;
68 stats
->obj_size
= obj_size
;
69 stats
->chunk_capacity
= 0;
71 stats
->chunks_alloc
+= 0;
72 stats
->chunks_inuse
+= 0;
73 stats
->chunks_partial
+= 0;
74 stats
->chunks_free
+= 0;
76 stats
->items_alloc
+= meter
.alloc
.currentLevel();
77 stats
->items_inuse
+= meter
.inuse
.currentLevel();
78 stats
->items_idle
+= meter
.idle
.currentLevel();
80 stats
->overhead
+= sizeof(MemPoolMalloc
) + strlen(objectType()) + 1;
82 return meter
.inuse
.currentLevel();
86 MemPoolMalloc::getInUseCount()
88 return meter
.inuse
.currentLevel();
91 MemPoolMalloc::MemPoolMalloc(char const *aLabel
, size_t aSize
) : MemImplementingAllocator(aLabel
, aSize
)
95 MemPoolMalloc::~MemPoolMalloc()
97 assert(meter
.inuse
.currentLevel() == 0);
102 MemPoolMalloc::idleTrigger(int shift
) const
104 return freelist
.size() >> (shift
? 8 : 0);
108 MemPoolMalloc::clean(time_t)
110 while (!freelist
.empty()) {
111 void *obj
= freelist
.top();