old_api.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 13 High Level Memory Pool Management */
10 
11 #include "squid.h"
12 #include "base/PackableStream.h"
13 #include "ClientInfo.h"
14 #include "dlink.h"
15 #include "event.h"
16 #include "fs_io.h"
17 #include "icmp/net_db.h"
18 #include "md5.h"
19 #include "mem/forward.h"
20 #include "mem/Meter.h"
21 #include "mem/Pool.h"
22 #include "MemBuf.h"
23 #include "mgr/Registration.h"
24 #include "SquidConfig.h"
25 #include "SquidTime.h"
26 #include "Store.h"
27 
28 #include <iomanip>
29 
30 /* forward declarations */
31 static void memFree2K(void *);
32 static void memFree4K(void *);
33 static void memFree8K(void *);
34 static void memFree16K(void *);
35 static void memFree32K(void *);
36 static void memFree64K(void *);
37 
38 /* local prototypes */
39 static void memStringStats(std::ostream &);
40 
41 /* module locals */
42 static double xm_time = 0;
43 static double xm_deltat = 0;
44 
45 /* string pools */
46 #define mem_str_pool_count 6
47 
48 struct PoolMeta {
49  const char *name;
50  size_t obj_size;
51 };
52 
55 
58 
59 /* local routines */
60 
61 // XXX: refactor objects using these pools to use MEMPROXY classes instead
62 // then remove this function entirely
63 static MemAllocator *&
64 GetPool(size_t type)
65 {
66  static MemAllocator *pools[MEM_MAX];
67  static bool initialized = false;
68 
69  if (!initialized) {
70  memset(pools, '\0', sizeof(pools));
71  initialized = true;
72  // Mem::Init() makes use of GetPool(type) to initialize
73  // the actual pools. So must come after the flag is true
74  Mem::Init();
75  }
76 
77  return pools[type];
78 }
79 
80 static MemAllocator &
82 {
83  static MemAllocator *strPools[mem_str_pool_count];
84  static bool initialized = false;
85 
86  static const PoolMeta PoolAttrs[mem_str_pool_count] = {
87  {"Short Strings", MemAllocator::RoundedSize(36)}, /* to fit rfc1123 and similar */
88  {"Medium Strings", MemAllocator::RoundedSize(128)}, /* to fit most urls */
89  {"Long Strings", MemAllocator::RoundedSize(512)},
90  {"1KB Strings", MemAllocator::RoundedSize(1024)},
91  {"4KB Strings", MemAllocator::RoundedSize(4*1024)},
92  {"16KB Strings", MemAllocator::RoundedSize(16*1024)}
93  };
94 
95  if (!initialized) {
96  memset(strPools, '\0', sizeof(strPools));
97 
99  for (int i = 0; i < mem_str_pool_count; ++i) {
100  strPools[i] = memPoolCreate(PoolAttrs[i].name, PoolAttrs[i].obj_size);
101  strPools[i]->zeroBlocks(false);
102 
103  if (strPools[i]->objectSize() != PoolAttrs[i].obj_size)
104  debugs(13, DBG_IMPORTANT, "NOTICE: " << PoolAttrs[i].name <<
105  " is " << strPools[i]->objectSize() <<
106  " bytes instead of requested " <<
107  PoolAttrs[i].obj_size << " bytes");
108  }
109 
110  initialized = true;
111  }
112 
113  return *strPools[type];
114 }
115 
117 static MemAllocator *
118 memFindStringPool(size_t net_size, bool fuzzy)
119 {
120  for (unsigned int i = 0; i < mem_str_pool_count; ++i) {
121  auto &pool = GetStrPool(i);
122  if (fuzzy && net_size < pool.objectSize())
123  return &pool;
124  if (net_size == pool.objectSize())
125  return &pool;
126  }
127  return nullptr;
128 }
129 
130 static void
131 memStringStats(std::ostream &stream)
132 {
133  int i;
134  int pooled_count = 0;
135  size_t pooled_volume = 0;
136  /* heading */
137  stream << "String Pool\t Impact\t\t\n \t (%strings)\t (%volume)\n";
138  /* table body */
139 
140  for (i = 0; i < mem_str_pool_count; ++i) {
141  const auto &pool = GetStrPool(i);
142  const auto plevel = pool.getMeter().inuse.currentLevel();
143  stream << std::setw(20) << std::left << pool.objectType();
144  stream << std::right << "\t " << xpercentInt(plevel, StrCountMeter.currentLevel());
145  stream << "\t " << xpercentInt(plevel * pool.objectSize(), StrVolumeMeter.currentLevel()) << "\n";
146  pooled_count += plevel;
147  pooled_volume += plevel * pool.objectSize();
148  }
149 
150  /* malloc strings */
151  stream << std::setw(20) << std::left << "Other Strings";
152  stream << std::right << "\t ";
153  stream << xpercentInt(StrCountMeter.currentLevel() - pooled_count, StrCountMeter.currentLevel()) << "\t ";
154  stream << xpercentInt(StrVolumeMeter.currentLevel() - pooled_volume, StrVolumeMeter.currentLevel()) << "\n\n";
155 }
156 
157 static void
158 memBufStats(std::ostream & stream)
159 {
160  stream << "Large buffers: " <<
161  HugeBufCountMeter.currentLevel() << " (" <<
162  HugeBufVolumeMeter.currentLevel() / 1024 << " KB)\n";
163 }
164 
165 void
167 {
168  PackableStream stream(*sentry);
169  Report(stream);
170  memStringStats(stream);
171  memBufStats(stream);
172 #if WITH_VALGRIND
173  if (RUNNING_ON_VALGRIND) {
174  long int leaked = 0, dubious = 0, reachable = 0, suppressed = 0;
175  stream << "Valgrind Report:\n";
176  stream << "Type\tAmount\n";
177  debugs(13, DBG_IMPORTANT, "Asking valgrind for memleaks");
178  VALGRIND_DO_LEAK_CHECK;
179  debugs(13, DBG_IMPORTANT, "Getting valgrind statistics");
180  VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed);
181  stream << "Leaked\t" << leaked << "\n";
182  stream << "Dubious\t" << dubious << "\n";
183  stream << "Reachable\t" << reachable << "\n";
184  stream << "Suppressed\t" << suppressed << "\n";
185  }
186 #endif
187  stream.flush();
188 }
189 
190 /*
191  * public routines
192  */
193 
194 /*
195  * we have a limit on _total_ amount of idle memory so we ignore max_pages for now.
196  * Will ignore repeated calls for the same pool type.
197  *
198  * Relies on Mem::Init() having been called beforehand.
199  */
200 void
201 memDataInit(mem_type type, const char *name, size_t size, int, bool doZero)
202 {
203  assert(name && size);
204 
205  if (GetPool(type) != NULL)
206  return;
207 
208  GetPool(type) = memPoolCreate(name, size);
209  GetPool(type)->zeroBlocks(doZero);
210 }
211 
212 /* find appropriate pool and use it (pools always init buffer with 0s) */
213 void *
215 {
216  assert(GetPool(type));
217  return GetPool(type)->alloc();
218 }
219 
220 /* give memory back to the pool */
221 void
222 memFree(void *p, int type)
223 {
224  assert(GetPool(type));
225  GetPool(type)->freeOne(p);
226 }
227 
228 /* allocate a variable size buffer using best-fit string pool */
229 void *
230 memAllocString(size_t net_size, size_t * gross_size)
231 {
232  assert(gross_size);
233 
234  if (const auto pool = memFindStringPool(net_size, true)) {
235  *gross_size = pool->objectSize();
236  assert(*gross_size >= net_size);
237  ++StrCountMeter;
238  StrVolumeMeter += *gross_size;
239  return pool->alloc();
240  }
241 
242  *gross_size = net_size;
243  ++StrCountMeter;
244  StrVolumeMeter += *gross_size;
245  return xcalloc(1, net_size);
246 }
247 
248 void *
249 memAllocRigid(size_t net_size)
250 {
251  // TODO: Use memAllocString() instead (after it stops zeroing memory).
252 
253  if (const auto pool = memFindStringPool(net_size, true)) {
254  ++StrCountMeter;
255  StrVolumeMeter += pool->objectSize();
256  return pool->alloc();
257  }
258 
259  ++StrCountMeter;
260  StrVolumeMeter += net_size;
261  return xmalloc(net_size);
262 }
263 
264 size_t
266 {
267  size_t result = 0;
268 
269  for (int counter = 0; counter < mem_str_pool_count; ++counter)
270  result += GetStrPool(counter).inUseCount();
271 
272  return result;
273 }
274 
275 /* free buffer allocated with memAllocString() */
276 void
277 memFreeString(size_t size, void *buf)
278 {
279  assert(buf);
280 
281  if (const auto pool = memFindStringPool(size, false))
282  pool->freeOne(buf);
283  else
284  xfree(buf);
285 
286  --StrCountMeter;
287  StrVolumeMeter -= size;
288 }
289 
290 void
291 memFreeRigid(void *buf, size_t net_size)
292 {
293  // TODO: Use memFreeString() instead (after removing fuzzy=false pool search).
294 
295  if (const auto pool = memFindStringPool(net_size, true)) {
296  pool->freeOne(buf);
297  StrVolumeMeter -= pool->objectSize();
298  --StrCountMeter;
299  return;
300  }
301 
302  xfree(buf);
303  StrVolumeMeter -= net_size;
304  --StrCountMeter;
305 }
306 
307 /* Find the best fit MEM_X_BUF type */
308 static mem_type
309 memFindBufSizeType(size_t net_size, size_t * gross_size)
310 {
311  mem_type type;
312  size_t size;
313 
314  if (net_size <= 2 * 1024) {
315  type = MEM_2K_BUF;
316  size = 2 * 1024;
317  } else if (net_size <= 4 * 1024) {
318  type = MEM_4K_BUF;
319  size = 4 * 1024;
320  } else if (net_size <= 8 * 1024) {
321  type = MEM_8K_BUF;
322  size = 8 * 1024;
323  } else if (net_size <= 16 * 1024) {
324  type = MEM_16K_BUF;
325  size = 16 * 1024;
326  } else if (net_size <= 32 * 1024) {
327  type = MEM_32K_BUF;
328  size = 32 * 1024;
329  } else if (net_size <= 64 * 1024) {
330  type = MEM_64K_BUF;
331  size = 64 * 1024;
332  } else {
333  type = MEM_NONE;
334  size = net_size;
335  }
336 
337  if (gross_size)
338  *gross_size = size;
339 
340  return type;
341 }
342 
343 /* allocate a variable size buffer using best-fit pool */
344 void *
345 memAllocBuf(size_t net_size, size_t * gross_size)
346 {
347  mem_type type = memFindBufSizeType(net_size, gross_size);
348 
349  if (type != MEM_NONE)
350  return memAllocate(type);
351  else {
353  HugeBufVolumeMeter += *gross_size;
354  return xcalloc(1, net_size);
355  }
356 }
357 
358 /* resize a variable sized buffer using best-fit pool */
359 void *
360 memReallocBuf(void *oldbuf, size_t net_size, size_t * gross_size)
361 {
362  /* XXX This can be optimized on very large buffers to use realloc() */
363  /* TODO: if the existing gross size is >= new gross size, do nothing */
364  size_t new_gross_size;
365  void *newbuf = memAllocBuf(net_size, &new_gross_size);
366 
367  if (oldbuf) {
368  size_t data_size = *gross_size;
369 
370  if (data_size > net_size)
371  data_size = net_size;
372 
373  memcpy(newbuf, oldbuf, data_size);
374 
375  memFreeBuf(*gross_size, oldbuf);
376  }
377 
378  *gross_size = new_gross_size;
379  return newbuf;
380 }
381 
382 /* free buffer allocated with memAllocBuf() */
383 void
384 memFreeBuf(size_t size, void *buf)
385 {
387 
388  if (type != MEM_NONE)
389  memFree(buf, type);
390  else {
391  xfree(buf);
393  HugeBufVolumeMeter -= size;
394  }
395 }
396 
397 static double clean_interval = 15.0; /* time to live of idle chunk before release */
398 
399 void
401 {
402  MemPools::GetInstance().clean(static_cast<time_t>(clean_interval));
403  eventAdd("memPoolCleanIdlePools", CleanIdlePools, NULL, clean_interval, 1);
404 }
405 
406 void
408 {
409  int64_t new_pool_limit;
410 
412  if (!Config.onoff.mem_pools)
413  new_pool_limit = 0;
414  else if (Config.MemPools.limit > 0)
415  new_pool_limit = Config.MemPools.limit;
416  else {
417  if (Config.MemPools.limit == 0)
418  debugs(13, DBG_IMPORTANT, "memory_pools_limit 0 has been chagned to memory_pools_limit none. Please update your config");
419  new_pool_limit = -1;
420  }
421 
422 #if 0
423 
429  if (MemPools::GetInstance().idleLimit() > new_pool_limit)
430  debugs(13, DBG_IMPORTANT, "Shrinking idle mem pools to "<< std::setprecision(3) << toMB(new_pool_limit) << " MB");
431 #endif
432 
433  MemPools::GetInstance().setIdleLimit(new_pool_limit);
434 }
435 
436 void
438 {
439  /* all pools are ready to be used */
440  static bool MemIsInitialized = false;
441  if (MemIsInitialized)
442  return;
443 
461  memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10, false);
462  memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10, false);
463  memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10, false);
464  memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10, false);
465  memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
466  memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
467  memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0);
468  memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0);
470  GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);
471 
472  MemIsInitialized = true;
473 
474  // finally register with the cache manager
475  Mgr::RegisterAction("mem", "Memory Utilization", Mem::Stats, 0, 1);
476 }
477 
478 void
480 {
481  debugs(13, 3, "Memory pools are '" <<
482  (Config.onoff.mem_pools ? "on" : "off") << "'; limit: " <<
483  std::setprecision(3) << toMB(MemPools::GetInstance().idleLimit()) <<
484  " MB");
485 }
486 
488 {
489  int tmp = (int)aMem;
490  aMem = (mem_type)(++tmp);
491  return aMem;
492 }
493 
494 /*
495  * Test that all entries are initialized
496  */
497 void
499 {
500  mem_type t = MEM_NONE;
501 
502  while (++t < MEM_MAX) {
503  /*
504  * If you hit this assertion, then you forgot to add a
505  * memDataInit() line for type 't'.
506  */
507  assert(GetPool(t));
508  }
509 }
510 
511 void
512 memClean(void)
513 {
515  if (Config.MemPools.limit > 0) // do not reset if disabled or same
518  memPoolGetGlobalStats(&stats);
519 
520  if (stats.tot_items_inuse)
521  debugs(13, 2, "memCleanModule: " << stats.tot_items_inuse <<
522  " items in " << stats.tot_chunks_inuse << " chunks and " <<
523  stats.tot_pools_inuse << " pools are left dirty");
524 }
525 
526 int
528 {
529  return GetPool(type)->inUseCount();
530 }
531 
532 /* ick */
533 
534 void
535 memFree2K(void *p)
536 {
537  memFree(p, MEM_2K_BUF);
538 }
539 
540 void
541 memFree4K(void *p)
542 {
543  memFree(p, MEM_4K_BUF);
544 }
545 
546 void
547 memFree8K(void *p)
548 {
549  memFree(p, MEM_8K_BUF);
550 }
551 
552 void
553 memFree16K(void *p)
554 {
555  memFree(p, MEM_16K_BUF);
556 }
557 
558 void
559 memFree32K(void *p)
560 {
561  memFree(p, MEM_32K_BUF);
562 }
563 
564 void
565 memFree64K(void *p)
566 {
567  memFree(p, MEM_64K_BUF);
568 }
569 
570 static void
571 cxx_xfree(void * ptr)
572 {
573  xfree(ptr);
574 }
575 
576 FREE *
578 {
579  switch (size) {
580 
581  case 2 * 1024:
582  return memFree2K;
583 
584  case 4 * 1024:
585  return memFree4K;
586 
587  case 8 * 1024:
588  return memFree8K;
589 
590  case 16 * 1024:
591  return memFree16K;
592 
593  case 32 * 1024:
594  return memFree32K;
595 
596  case 64 * 1024:
597  return memFree64K;
598 
599  default:
601  HugeBufVolumeMeter -= size;
602  return cxx_xfree;
603  }
604 }
605 
606 /* MemPoolMeter */
607 
608 void
609 Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, std::ostream &stream)
610 {
611  int excess = 0;
612  int needed = 0;
613  MemPoolMeter *pm = mp_st->meter;
614  const char *delim = "\t ";
615 
616  stream.setf(std::ios_base::fixed);
617  stream << std::setw(20) << std::left << mp_st->label << delim;
618  stream << std::setw(4) << std::right << mp_st->obj_size << delim;
619 
620  /* Chunks */
621  if (mp_st->chunk_capacity) {
622  stream << std::setw(4) << toKB(mp_st->obj_size * mp_st->chunk_capacity) << delim;
623  stream << std::setw(4) << mp_st->chunk_capacity << delim;
624 
625  needed = mp_st->items_inuse / mp_st->chunk_capacity;
626 
627  if (mp_st->items_inuse % mp_st->chunk_capacity)
628  ++needed;
629 
630  excess = mp_st->chunks_inuse - needed;
631 
632  stream << std::setw(4) << mp_st->chunks_alloc << delim;
633  stream << std::setw(4) << mp_st->chunks_inuse << delim;
634  stream << std::setw(4) << mp_st->chunks_free << delim;
635  stream << std::setw(4) << mp_st->chunks_partial << delim;
636  stream << std::setprecision(3) << xpercent(excess, needed) << delim;
637  } else {
638  stream << delim;
639  stream << delim;
640  stream << delim;
641  stream << delim;
642  stream << delim;
643  stream << delim;
644  stream << delim;
645  }
646  /*
647  * Fragmentation calculation:
648  * needed = inuse.currentLevel() / chunk_capacity
649  * excess = used - needed
650  * fragmentation = excess / needed * 100%
651  *
652  * Fragm = (alloced - (inuse / obj_ch) ) / alloced
653  */
654  /* allocated */
655  stream << mp_st->items_alloc << delim;
656  stream << toKB(mp_st->obj_size * pm->alloc.currentLevel()) << delim;
657  stream << toKB(mp_st->obj_size * pm->alloc.peak()) << delim;
658  stream << std::setprecision(2) << ((squid_curtime - pm->alloc.peakTime()) / 3600.) << delim;
659  stream << std::setprecision(3) << xpercent(mp_st->obj_size * pm->alloc.currentLevel(), AllMeter->alloc.currentLevel()) << delim;
660  /* in use */
661  stream << mp_st->items_inuse << delim;
662  stream << toKB(mp_st->obj_size * pm->inuse.currentLevel()) << delim;
663  stream << toKB(mp_st->obj_size * pm->inuse.peak()) << delim;
664  stream << std::setprecision(2) << ((squid_curtime - pm->inuse.peakTime()) / 3600.) << delim;
665  stream << std::setprecision(3) << xpercent(pm->inuse.currentLevel(), pm->alloc.currentLevel()) << delim;
666  /* idle */
667  stream << mp_st->items_idle << delim;
668  stream << toKB(mp_st->obj_size * pm->idle.currentLevel()) << delim;
669  stream << toKB(mp_st->obj_size * pm->idle.peak()) << delim;
670  /* saved */
671  stream << (int)pm->gb_saved.count << delim;
672  stream << std::setprecision(3) << xpercent(pm->gb_saved.count, AllMeter->gb_allocated.count) << delim;
673  stream << std::setprecision(3) << xpercent(pm->gb_saved.bytes, AllMeter->gb_allocated.bytes) << delim;
674  stream << std::setprecision(3) << xdiv(pm->gb_allocated.count - pm->gb_oallocated.count, xm_deltat) << "\n";
676 }
677 
678 static int
679 MemPoolReportSorter(const void *a, const void *b)
680 {
681  const MemPoolStats *A = (MemPoolStats *) a;
682  const MemPoolStats *B = (MemPoolStats *) b;
683 
684  // use this to sort on %Total Allocated
685  //
686  double pa = (double) A->obj_size * A->meter->alloc.currentLevel();
687  double pb = (double) B->obj_size * B->meter->alloc.currentLevel();
688 
689  if (pa > pb)
690  return -1;
691 
692  if (pb > pa)
693  return 1;
694 
695 #if 0
696  // use this to sort on In Use high(hrs)
697  //
698  if (A->meter->inuse.peakTime() > B->meter->inuse.peakTime())
699  return -1;
700 
701  if (B->meter->inuse.peakTime() > A->meter->inuse.peakTime())
702  return 1;
703 
704 #endif
705 
706  return 0;
707 }
708 
709 void
710 Mem::Report(std::ostream &stream)
711 {
712  static char buf[64];
713  static MemPoolStats mp_stats;
714  static MemPoolGlobalStats mp_total;
715  int not_used = 0;
716  MemPoolIterator *iter;
717  MemAllocator *pool;
718 
719  /* caption */
720  stream << "Current memory usage:\n";
721  /* heading */
722  stream << "Pool\t Obj Size\t"
723  "Chunks\t\t\t\t\t\t\t"
724  "Allocated\t\t\t\t\t"
725  "In Use\t\t\t\t\t"
726  "Idle\t\t\t"
727  "Allocations Saved\t\t\t"
728  "Rate\t"
729  "\n"
730  " \t (bytes)\t"
731  "KB/ch\t obj/ch\t"
732  "(#)\t used\t free\t part\t %Frag\t "
733  "(#)\t (KB)\t high (KB)\t high (hrs)\t %Tot\t"
734  "(#)\t (KB)\t high (KB)\t high (hrs)\t %alloc\t"
735  "(#)\t (KB)\t high (KB)\t"
736  "(#)\t %cnt\t %vol\t"
737  "(#)/sec\t"
738  "\n";
740  xm_time = current_dtime;
741 
742  /* Get stats for Totals report line */
743  memPoolGetGlobalStats(&mp_total);
744 
745  MemPoolStats *sortme = (MemPoolStats *) xcalloc(mp_total.tot_pools_alloc,sizeof(*sortme));
746  int npools = 0;
747 
748  /* main table */
749  iter = memPoolIterate();
750 
751  while ((pool = memPoolIterateNext(iter))) {
752  pool->getStats(&mp_stats);
753 
754  if (!mp_stats.pool) /* pool destroyed */
755  continue;
756 
757  if (mp_stats.pool->getMeter().gb_allocated.count > 0) {
758  /* this pool has been used */
759  sortme[npools] = mp_stats;
760  ++npools;
761  } else {
762  ++not_used;
763  }
764  }
765 
766  memPoolIterateDone(&iter);
767 
768  qsort(sortme, npools, sizeof(*sortme), MemPoolReportSorter);
769 
770  for (int i = 0; i< npools; ++i) {
771  PoolReport(&sortme[i], mp_total.TheMeter, stream);
772  }
773 
774  xfree(sortme);
775 
776  mp_stats.pool = NULL;
777  mp_stats.label = "Total";
778  mp_stats.meter = mp_total.TheMeter;
779  mp_stats.obj_size = 1;
780  mp_stats.chunk_capacity = 0;
781  mp_stats.chunk_size = 0;
782  mp_stats.chunks_alloc = mp_total.tot_chunks_alloc;
783  mp_stats.chunks_inuse = mp_total.tot_chunks_inuse;
784  mp_stats.chunks_partial = mp_total.tot_chunks_partial;
785  mp_stats.chunks_free = mp_total.tot_chunks_free;
786  mp_stats.items_alloc = mp_total.tot_items_alloc;
787  mp_stats.items_inuse = mp_total.tot_items_inuse;
788  mp_stats.items_idle = mp_total.tot_items_idle;
789  mp_stats.overhead = mp_total.tot_overhead;
790 
791  PoolReport(&mp_stats, mp_total.TheMeter, stream);
792 
793  /* Cumulative */
794  stream << "Cumulative allocated volume: "<< double_to_str(buf, 64, mp_total.TheMeter->gb_allocated.bytes) << "\n";
795  /* overhead */
796  stream << "Current overhead: " << mp_total.tot_overhead << " bytes (" <<
797  std::setprecision(3) << xpercent(mp_total.tot_overhead, mp_total.TheMeter->inuse.currentLevel()) << "%)\n";
798  /* limits */
799  if (mp_total.mem_idle_limit >= 0)
800  stream << "Idle pool limit: " << std::setprecision(2) << toMB(mp_total.mem_idle_limit) << " MB\n";
801  /* limits */
802  stream << "Total Pools created: " << mp_total.tot_pools_alloc << "\n";
803  stream << "Pools ever used: " << mp_total.tot_pools_alloc - not_used << " (shown above)\n";
804  stream << "Currently in use: " << mp_total.tot_pools_inuse << "\n";
805 }
806 
int chunks_partial
Definition: Pool.h:291
static MemAllocator * memFindStringPool(size_t net_size, bool fuzzy)
Definition: old_api.cc:118
SQUIDCEXTERN const char * double_to_str(char *buf, int buf_size, double value)
Definition: util.c:109
size_t obj_size
Definition: old_api.cc:50
static double xm_deltat
Definition: old_api.cc:43
#define assert(EX)
Definition: assert.h:17
MemImplementingAllocator * memPoolIterateNext(MemPoolIterator *iter)
Definition: Pool.cc:55
const char * name
Definition: old_api.cc:49
static Mem::Meter StrCountMeter
Definition: old_api.cc:53
int chunks_inuse
Definition: Pool.h:290
static Mem::Meter HugeBufCountMeter
Definition: old_api.cc:56
void Stats(StoreEntry *)
Definition: old_api.cc:166
MemPoolMeter * meter
Definition: Pool.h:284
int items_idle
Definition: Pool.h:296
struct SquidConfig::@117 MemPools
SQUIDCEXTERN double xpercent(double part, double whole)
Definition: util.c:54
static MemPools & GetInstance()
Definition: Pool.cc:30
static mem_type memFindBufSizeType(size_t net_size, size_t *gross_size)
Definition: old_api.cc:309
int items_alloc
Definition: Pool.h:294
int type
Definition: errorpage.cc:78
static uint32 B
Definition: md4.c:43
size_t memStringCount()
Definition: old_api.cc:265
virtual void freeOne(void *)=0
#define xcalloc
Definition: membanger.c:57
int items_inuse
Definition: Pool.h:295
void Report()
Definition: old_api.cc:479
int i
Definition: membanger.c:49
void CleanIdlePools(void *unused)
Definition: old_api.cc:400
void memConfigure(void)
Definition: old_api.cc:407
int overhead
Definition: Pool.h:298
int tot_pools_alloc
Definition: Pool.h:306
void PoolReport(const MemPoolStats *, const MemPoolMeter *, std::ostream &)
Definition: stub_libmem.cc:28
class Ping::pingStats_ stats
#define mem_str_pool_count
Definition: old_api.cc:46
int obj_size
Definition: Pool.h:285
static size_t RoundedSize(size_t minSize)
Definition: Pool.cc:293
int64_t limit
Definition: SquidConfig.h:440
int chunks_alloc
Definition: Pool.h:289
mgb_t gb_allocated
Definition: Pool.h:103
mgb_t gb_saved
Definition: Pool.h:107
static void memFree2K(void *)
Definition: old_api.cc:535
int tot_items_alloc
Definition: Pool.h:315
char * p
Definition: membanger.c:43
void FREE(void *)
Definition: forward.h:36
int chunk_capacity
Definition: Pool.h:286
static void memStringStats(std::ostream &)
Definition: old_api.cc:131
ssize_t peak() const
Definition: Meter.h:29
int tot_chunks_inuse
Definition: Pool.h:311
void * memReallocBuf(void *buf, size_t net_size, size_t *gross_size)
Definition: old_api.cc:360
ssize_t mem_idle_limit
Definition: Pool.h:320
time_t squid_curtime
Definition: stub_time.cc:17
void * memAllocBuf(size_t net_size, size_t *gross_size)
Definition: old_api.cc:345
Mem::Meter idle
Definition: Pool.h:100
static double xm_time
Definition: old_api.cc:42
void Report(std::ostream &)
Definition: stub_libmem.cc:27
Definition: fs_io.h:34
SQUIDCEXTERN int xpercentInt(double part, double whole)
Definition: util.c:60
MemAllocator * pool
Definition: Pool.h:282
#define memPoolCreate
Definition: Pool.h:325
void * memAllocRigid(size_t net_size)
Definition: old_api.cc:249
int tot_chunks_alloc
Definition: Pool.h:310
static void memFree4K(void *)
Definition: old_api.cc:541
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
int chunks_free
Definition: Pool.h:292
#define DBG_IMPORTANT
Definition: Debug.h:46
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
void * memAllocate(mem_type)
Allocate one element from the typed pool.
Definition: old_api.cc:214
err_type & operator++(err_type &anErr)
Definition: errorpage.cc:143
static int MemPoolReportSorter(const void *a, const void *b)
Definition: old_api.cc:679
virtual void setChunkSize(size_t)
Definition: Pool.h:218
#define SQUID_MD5_DIGEST_LENGTH
Definition: md5.h:66
void Init()
Definition: old_api.cc:437
int inUseCount()
Definition: Pool.cc:113
Mem::Meter alloc
Definition: Pool.h:98
static double clean_interval
Definition: old_api.cc:397
int tot_pools_inuse
Definition: Pool.h:307
void memFreeRigid(void *, size_t net_size)
Definition: old_api.cc:291
void clean(time_t maxage)
Definition: Pool.cc:224
int memPoolGetGlobalStats(MemPoolGlobalStats *stats)
Definition: Pool.cc:250
int chunk_size
Definition: Pool.h:287
int tot_chunks_partial
Definition: Pool.h:312
const char * label
Definition: Pool.h:283
virtual int getStats(MemPoolStats *stats, int accumulate=0)=0
int tot_items_inuse
Definition: Pool.h:316
Mem::Meter inuse
Definition: Pool.h:99
int tot_chunks_free
Definition: Pool.h:313
void CleanIdlePools(void *)
Definition: stub_libmem.cc:26
void const char * buf
Definition: stub_helper.cc:16
time_t peakTime() const
Definition: Meter.h:30
void * memAllocString(size_t net_size, size_t *gross_size)
Definition: old_api.cc:230
struct SquidConfig::@112 onoff
static uint32 A
Definition: md4.c:43
MemPoolMeter * TheMeter
Definition: Pool.h:304
void memFreeBuf(size_t size, void *)
Definition: old_api.cc:384
int memInUse(mem_type)
Definition: old_api.cc:527
virtual MemPoolMeter const & getMeter() const =0
bool SIGHDLR int STUB void int
Definition: stub_tools.cc:68
static void memFree64K(void *)
Definition: old_api.cc:565
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:109
int tot_items_idle
Definition: Pool.h:317
static void cxx_xfree(void *ptr)
Definition: old_api.cc:571
#define xmalloc
static void memFree32K(void *)
Definition: old_api.cc:559
double count
Definition: Pool.h:84
void memDataInit(mem_type, const char *, size_t, int, bool doZero=true)
Definition: old_api.cc:201
SQUIDCEXTERN double xdiv(double nom, double denom)
Definition: util.c:72
void memFree(void *, int type)
Free a element allocated by memAllocate()
Definition: old_api.cc:222
#define toKB(size)
Definition: Pool.h:52
#define toMB(size)
Definition: Pool.h:50
void memFreeString(size_t size, void *)
Definition: old_api.cc:277
double current_dtime
Definition: stub_time.cc:16
static MemAllocator & GetStrPool(size_t type)
Definition: old_api.cc:81
static MemAllocator *& GetPool(size_t type)
Definition: old_api.cc:64
mem_type
Types of memory pool which do not yet use MEMPROXY_CLASS() API.
Definition: forward.h:39
void memPoolIterateDone(MemPoolIterator **iter)
Definition: Pool.cc:47
int a
Definition: membanger.c:50
static void memBufStats(std::ostream &stream)
Definition: old_api.cc:158
void memCheckInit(void)
Definition: old_api.cc:498
static Mem::Meter HugeBufVolumeMeter
Definition: old_api.cc:57
void memClean(void)
Main cleanup handler.
Definition: old_api.cc:512
#define xfree
ssize_t currentLevel() const
Definition: Meter.h:28
MemPoolIterator * memPoolIterate(void)
Definition: Pool.cc:40
static void memFree16K(void *)
Definition: old_api.cc:553
void zeroBlocks(bool doIt)
Definition: Pool.h:205
FREE * memFreeBufFunc(size_t size)
Definition: old_api.cc:577
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
int size
Definition: ModDevPoll.cc:77
void setIdleLimit(ssize_t new_idle_limit)
Definition: Pool.cc:69
static Mem::Meter StrVolumeMeter
Definition: old_api.cc:54
mgb_t gb_oallocated
Definition: Pool.h:104
virtual void * alloc()=0
double bytes
Definition: Pool.h:85
void PoolReport(const MemPoolStats *mp_st, const MemPoolMeter *AllMeter, std::ostream &)
Definition: old_api.cc:609
static void memFree8K(void *)
Definition: old_api.cc:547

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors