]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolMalloc.cc
2 * Copyright (C) 1996-2022 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"
15 #include "mem/Stats.h"
20 extern time_t squid_curtime
;
23 MemPoolMalloc::allocate()
26 if (!freelist
.empty()) {
35 obj
= xcalloc(1, obj_size
);
37 obj
= xmalloc(obj_size
);
45 MemPoolMalloc::deallocate(void *obj
, bool aggressive
)
53 memset(obj
, 0, obj_size
);
59 /* TODO extract common logic to MemAllocate */
61 MemPoolMalloc::getStats(Mem::PoolStats
&stats
)
64 stats
.label
= objectType();
66 stats
.obj_size
= obj_size
;
67 stats
.chunk_capacity
= 0;
69 stats
.chunks_alloc
+= 0;
70 stats
.chunks_inuse
+= 0;
71 stats
.chunks_partial
+= 0;
72 stats
.chunks_free
+= 0;
74 stats
.items_alloc
+= meter
.alloc
.currentLevel();
75 stats
.items_inuse
+= meter
.inuse
.currentLevel();
76 stats
.items_idle
+= meter
.idle
.currentLevel();
78 stats
.overhead
+= sizeof(MemPoolMalloc
) + strlen(objectType()) + 1;
80 return meter
.inuse
.currentLevel();
84 MemPoolMalloc::getInUseCount()
86 return meter
.inuse
.currentLevel();
89 MemPoolMalloc::MemPoolMalloc(char const *aLabel
, size_t aSize
) : MemImplementingAllocator(aLabel
, aSize
)
93 MemPoolMalloc::~MemPoolMalloc()
95 assert(meter
.inuse
.currentLevel() == 0);
100 MemPoolMalloc::idleTrigger(int shift
) const
102 return freelist
.size() >> (shift
? 8 : 0);
106 MemPoolMalloc::clean(time_t)
108 while (!freelist
.empty()) {
109 void *obj
= freelist
.top();