]>
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.
41 #include "MemPoolMalloc.h"
48 * XXX This is a boundary violation between lib and src.. would be good
49 * if it could be solved otherwise, but left for now.
51 extern time_t squid_curtime
;
54 MemPoolMalloc::allocate()
56 void *obj
= freelist
.pop();
58 memMeterDec(meter
.idle
);
61 obj
= xcalloc(1, obj_size
);
62 memMeterInc(meter
.alloc
);
64 memMeterInc(meter
.inuse
);
69 MemPoolMalloc::deallocate(void *obj
, bool aggressive
)
71 memMeterDec(meter
.inuse
);
74 memMeterDec(meter
.alloc
);
77 memset(obj
, 0, obj_size
);
78 memMeterInc(meter
.idle
);
79 freelist
.push_back(obj
);
83 /* TODO extract common logic to MemAllocate */
85 MemPoolMalloc::getStats(MemPoolStats
* stats
, int accumulate
)
87 if (!accumulate
) /* need skip memset for GlobalStats accumulation */
88 memset(stats
, 0, sizeof(MemPoolStats
));
91 stats
->label
= objectType();
92 stats
->meter
= &meter
;
93 stats
->obj_size
= obj_size
;
94 stats
->chunk_capacity
= 0;
96 stats
->chunks_alloc
+= 0;
97 stats
->chunks_inuse
+= 0;
98 stats
->chunks_partial
+= 0;
99 stats
->chunks_free
+= 0;
101 stats
->items_alloc
+= meter
.alloc
.level
;
102 stats
->items_inuse
+= meter
.inuse
.level
;
103 stats
->items_idle
+= meter
.idle
.level
;
105 stats
->overhead
+= sizeof(MemPoolMalloc
) + strlen(objectType()) + 1;
107 return meter
.inuse
.level
;
111 MemPoolMalloc::getInUseCount()
113 return meter
.inuse
.level
;
116 MemPoolMalloc::MemPoolMalloc(char const *aLabel
, size_t aSize
) : MemImplementingAllocator(aLabel
, aSize
)
120 MemPoolMalloc::~MemPoolMalloc()
122 assert(meter
.inuse
.level
== 0);
127 MemPoolMalloc::idleTrigger(int shift
) const
129 return freelist
.count
>> (shift
? 8 : 0);
133 MemPoolMalloc::clean(time_t maxage
)
135 while (void *obj
= freelist
.pop()) {
136 memMeterDec(meter
.idle
);
137 memMeterDec(meter
.alloc
);