]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/MemPoolMalloc.cc
5 * DEBUG: section 63 Low Level Memory Pool Management
6 * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins, Henrik Nordstrom
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * the Regents of the University of California. Please see the
16 * COPYRIGHT file for full details. Squid incorporates software
17 * developed and/or copyrighted by other sources. Please see the
18 * CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
42 #include "MemPoolMalloc.h"
49 * XXX This is a boundary violation between lib and src.. would be good
50 * if it could be solved otherwise, but left for now.
52 extern time_t squid_curtime
;
55 MemPoolMalloc::allocate()
57 void *obj
= freelist
.pop();
59 memMeterDec(meter
.idle
);
62 obj
= xcalloc(1, obj_size
);
63 memMeterInc(meter
.alloc
);
65 memMeterInc(meter
.inuse
);
70 MemPoolMalloc::deallocate(void *obj
, bool aggressive
)
72 memMeterDec(meter
.inuse
);
75 memMeterDec(meter
.alloc
);
78 memset(obj
, 0, obj_size
);
79 memMeterInc(meter
.idle
);
80 freelist
.push_back(obj
);
84 /* TODO extract common logic to MemAllocate */
86 MemPoolMalloc::getStats(MemPoolStats
* stats
, int accumulate
)
88 if (!accumulate
) /* need skip memset for GlobalStats accumulation */
89 memset(stats
, 0, sizeof(MemPoolStats
));
92 stats
->label
= objectType();
93 stats
->meter
= &meter
;
94 stats
->obj_size
= obj_size
;
95 stats
->chunk_capacity
= 0;
97 stats
->chunks_alloc
+= 0;
98 stats
->chunks_inuse
+= 0;
99 stats
->chunks_partial
+= 0;
100 stats
->chunks_free
+= 0;
102 stats
->items_alloc
+= meter
.alloc
.level
;
103 stats
->items_inuse
+= meter
.inuse
.level
;
104 stats
->items_idle
+= meter
.idle
.level
;
106 stats
->overhead
+= sizeof(MemPoolMalloc
) + strlen(objectType()) + 1;
108 return meter
.inuse
.level
;
112 MemPoolMalloc::getInUseCount()
114 return meter
.inuse
.level
;
117 MemPoolMalloc::MemPoolMalloc(char const *aLabel
, size_t aSize
) : MemImplementingAllocator(aLabel
, aSize
)
121 MemPoolMalloc::~MemPoolMalloc()
123 assert(meter
.inuse
.level
== 0);
128 MemPoolMalloc::idleTrigger(int shift
) const
130 return freelist
.count
>> (shift
? 8 : 0);
134 MemPoolMalloc::clean(time_t maxage
)
136 while (void *obj
= freelist
.pop()) {
137 memMeterDec(meter
.idle
);
138 memMeterDec(meter
.alloc
);