]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolMalloc.cc
2 * Copyright (C) 1996-2017 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 * DEBUG: section 63 Low Level Memory Pool Management
11 * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins, Henrik Nordstrom
15 #include "mem/PoolMalloc.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(MemPoolStats
* stats
, int accumulate
)
63 if (!accumulate
) /* need skip memset for GlobalStats accumulation */
64 memset(stats
, 0, sizeof(MemPoolStats
));
67 stats
->label
= objectType();
68 stats
->meter
= &meter
;
69 stats
->obj_size
= obj_size
;
70 stats
->chunk_capacity
= 0;
72 stats
->chunks_alloc
+= 0;
73 stats
->chunks_inuse
+= 0;
74 stats
->chunks_partial
+= 0;
75 stats
->chunks_free
+= 0;
77 stats
->items_alloc
+= meter
.alloc
.currentLevel();
78 stats
->items_inuse
+= meter
.inuse
.currentLevel();
79 stats
->items_idle
+= meter
.idle
.currentLevel();
81 stats
->overhead
+= sizeof(MemPoolMalloc
) + strlen(objectType()) + 1;
83 return meter
.inuse
.currentLevel();
87 MemPoolMalloc::getInUseCount()
89 return meter
.inuse
.currentLevel();
92 MemPoolMalloc::MemPoolMalloc(char const *aLabel
, size_t aSize
) : MemImplementingAllocator(aLabel
, aSize
)
96 MemPoolMalloc::~MemPoolMalloc()
98 assert(meter
.inuse
.currentLevel() == 0);
103 MemPoolMalloc::idleTrigger(int shift
) const
105 return freelist
.size() >> (shift
? 8 : 0);
109 MemPoolMalloc::clean(time_t)
111 while (!freelist
.empty()) {
112 void *obj
= freelist
.top();