source: git/omalloc/omBin.c @ 599326

spielwiese
Last change on this file since 599326 was 599326, checked in by Kai Krüger <krueger@…>, 14 years ago
Anne, Kai, Frank: - changes to #include "..." statements to allow cleaner build structure - affected directories: omalloc, kernel, Singular - not yet done: IntergerProgramming git-svn-id: file:///usr/local/Singular/svn/trunk@13032 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.6 KB
Line 
1/*******************************************************************
2 *  File:    omBin.c
3 *  Purpose: definitions of routines for working with bins
4 *  Author:  obachman (Olaf Bachmann)
5 *  Created: 11/99
6 *  Version: $Id$
7 *******************************************************************/
8
9#include <omalloc/om_Alloc.h>
10/* this should go away */
11
12#ifdef OM_INTERNAL_DEBUG
13size_t omSizeOfBinAddr(void* addr)
14{
15  return _omSizeOfBinAddr(addr);
16}
17#endif
18
19/*****************************************************************
20 *
21 * SpecBin business
22 *
23 *****************************************************************/
24#define om_LargeBin ((omBin) 1)
25omBin _omGetSpecBin(size_t size, int align, int track)
26
27{
28  omBin om_new_specBin;
29  long max_blocks;
30  long sizeW;
31
32
33  size = OM_ALIGN_SIZE(size);
34#ifdef OM_ALIGNMENT_NEEDS_WORK
35  if (align || size >= OM_SIZEOF_UNIQUE_MAX_BLOCK_THRESHOLD)
36  {
37    align = 1;
38    size = OM_STRICT_ALIGN_SIZE(size);
39  }
40#else
41  align = 0;
42#endif
43
44  if (size > SIZEOF_OM_BIN_PAGE)
45  {
46    /* need page header */
47    max_blocks = - (long)
48      ((size+(SIZEOF_SYSTEM_PAGE-SIZEOF_OM_BIN_PAGE))+SIZEOF_SYSTEM_PAGE-1)
49      / SIZEOF_SYSTEM_PAGE;
50    sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) -
51             (SIZEOF_SYSTEM_PAGE - SIZEOF_OM_BIN_PAGE)) / SIZEOF_LONG;
52    om_new_specBin = om_LargeBin;
53  }
54  else
55  {
56    /* SIZEOF_OM_BIN_PAGE == max_blocks*size + r1; r1 < size */
57    /* r1 = max_blocks*(size_padding) + r2; r2 < max_blocks */
58    max_blocks = SIZEOF_OM_BIN_PAGE / size;
59    sizeW = (SIZEOF_OM_BIN_PAGE % size) / max_blocks;
60#ifdef OM_ALIGNMENT_NEEDS_WORK
61    if (align)
62      sizeW = ((size + sizeW) & ~ (SIZEOF_STRICT_ALIGNMENT - 1));
63    else
64#endif
65      sizeW = ((size + sizeW) & ~ (SIZEOF_OM_ALIGNMENT - 1));
66
67    omAssume(sizeW >= size);
68    omAssume(max_blocks*sizeW <= SIZEOF_OM_BIN_PAGE);
69    omAssume((max_blocks+1)*sizeW > SIZEOF_OM_BIN_PAGE ||
70             max_blocks*(sizeW + SIZEOF_STRICT_ALIGNMENT) > SIZEOF_OM_BIN_PAGE);
71
72    sizeW = sizeW >> LOG_SIZEOF_LONG;
73    if (size > OM_MAX_BLOCK_SIZE)
74    {
75      om_new_specBin = om_LargeBin;
76    }
77#ifdef OM_ALIGNMENT_NEEDS_WORK
78    else if (align)
79    {
80      om_new_specBin = omSmallSize2AlignedBin( size );
81    }
82#endif
83#ifdef OM_HAVE_TRACK
84    else if (track)
85    {
86      om_new_specBin = omSmallSize2TrackBin( size );
87    }
88#endif
89    else
90    {
91      om_new_specBin = omSmallSize2Bin( size );
92    }
93  }
94
95  if (om_new_specBin == om_LargeBin ||
96      om_new_specBin->max_blocks < max_blocks)
97  {
98    omSpecBin s_bin;
99#ifdef OM_HAVE_TRACK
100    if (track)
101      s_bin = omFindInSortedGList(om_SpecTrackBin, next, max_blocks, max_blocks);
102    else
103#endif
104      s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, max_blocks);
105
106    if (s_bin != NULL)
107    {
108      (s_bin->ref)++;
109      omAssume(s_bin->bin != NULL &&
110             s_bin->bin->max_blocks == s_bin->max_blocks &&
111             s_bin->bin->sizeW == sizeW);
112      return s_bin->bin;
113    }
114    s_bin = (omSpecBin) omAlloc(sizeof(omSpecBin_t));
115    s_bin->ref = 1;
116    s_bin->next = NULL;
117    s_bin->max_blocks = max_blocks;
118    s_bin->bin = (omBin) omAlloc(sizeof(omBin_t));
119    s_bin->bin->current_page = om_ZeroPage;
120    s_bin->bin->last_page = NULL;
121    s_bin->bin->next = NULL;
122    s_bin->bin->sizeW = sizeW;
123    s_bin->bin->max_blocks = max_blocks;
124    s_bin->bin->sticky = 0;
125#ifdef OM_HAVE_TRACK
126    if (track)
127    {
128      om_SpecTrackBin = omInsertInSortedGList(om_SpecTrackBin, next, max_blocks, s_bin);
129    }
130    else
131#endif
132      om_SpecBin = omInsertInSortedGList(om_SpecBin, next, max_blocks, s_bin);
133    return s_bin->bin;
134  }
135  else
136  {
137    return om_new_specBin;
138  }
139}
140
141void _omUnGetSpecBin(omBin *bin_p, int force)
142{
143  omBin bin = *bin_p;
144  if (! omIsStaticBin(bin))
145  {
146#ifdef OM_HAVE_TRACK
147    int track_bin = 0;
148#endif
149    omSpecBin s_bin;
150
151#ifdef OM_HAVE_TRACK
152    s_bin = omFindInGList(om_SpecTrackBin, next, bin, bin);
153    if (s_bin != NULL)
154      track_bin = 1;
155    else
156#endif
157        s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
158
159    omAssume(s_bin != NULL && bin == s_bin->bin);
160    if (s_bin != NULL)
161    {
162      (s_bin->ref)--;
163      if (s_bin->ref == 0 || force)
164      {
165#ifdef OM_HAVE_TRACK
166        if (! track_bin)
167#endif
168          omFreeKeptAddrFromBin(s_bin->bin);
169        if(s_bin->bin->last_page == NULL || force)
170        {
171#ifdef OM_HAVE_TRACK
172          if (track_bin)
173            om_SpecTrackBin = omRemoveFromSortedGList(om_SpecTrackBin, next, max_blocks, s_bin);
174          else
175#endif
176            om_SpecBin = omRemoveFromSortedGList(om_SpecBin, next, max_blocks, s_bin);
177          omFreeSize(s_bin->bin, sizeof(omBin_t));
178          omFreeSize(s_bin, sizeof(omSpecBin_t));
179        }
180      }
181    }
182  }
183  *bin_p = NULL;
184}
185
186
187/*****************************************************************
188 *
189 * Sticky business
190 *
191 *****************************************************************/
192#define omGetStickyBin(bin, sticky_tag) \
193   omFindInGList(bin, next, sticky, sticky_tag)
194
195static omBin omCreateStickyBin(omBin bin, unsigned long sticky)
196{
197  omBin s_bin = (omBin) omAlloc(sizeof(omBin_t));
198  s_bin->sticky = sticky;
199  s_bin->current_page = om_ZeroPage;
200  s_bin->last_page = NULL;
201  s_bin->max_blocks = bin->max_blocks;
202  s_bin->sizeW = bin->sizeW;
203  s_bin->next = bin->next;
204  bin->next = s_bin;
205  return s_bin;
206}
207
208unsigned long omGetMaxStickyBinTag(omBin bin)
209{
210  unsigned long sticky = 0;
211  do
212  {
213    if (bin->sticky > sticky) sticky = bin->sticky;
214    bin = bin->next;
215  }
216  while (bin != NULL);
217  return sticky;
218}
219
220unsigned long omGetNewStickyBinTag(omBin bin)
221{
222  unsigned long sticky = omGetMaxStickyBinTag(bin);
223  if (sticky < BIT_SIZEOF_LONG - 2)
224  {
225    sticky++;
226    omCreateStickyBin(bin, sticky);
227    return sticky;
228  }
229  else
230  {
231    omAssume(sticky == BIT_SIZEOF_LONG - 1);
232  }
233  return sticky;
234}
235
236void omSetStickyBinTag(omBin bin, unsigned long sticky_tag)
237{
238  omBin s_bin;
239  s_bin = omGetStickyBin(bin, sticky_tag);
240
241  if (s_bin != bin)
242  {
243    omBinPage tc, tl;
244    unsigned long ts;
245
246    if (s_bin == NULL) s_bin = omCreateStickyBin(bin, sticky_tag);
247    ts = bin->sticky;
248    tl = bin->last_page;
249    tc = bin->current_page;
250    bin->sticky = s_bin->sticky;
251    bin->current_page = s_bin->current_page;
252    bin->last_page = s_bin->last_page;
253    s_bin->sticky = ts;
254    s_bin->last_page = tl;
255    s_bin->current_page = tc;
256  }
257}
258
259void omUnSetStickyBinTag(omBin bin, unsigned long sticky)
260{
261  omAssume(omGetStickyBin(bin, 0) != NULL);
262  if (bin->sticky == sticky)
263    omSetStickyBinTag(bin, 0);
264}
265
266static void omMergeStickyPages(omBin to_bin, omBin from_bin)
267{
268#ifdef HAVE_OM_ASSUME
269  int length = omGListLength(to_bin->last_page, prev) +
270    omGListLength(from_bin->last_page, prev);
271#endif
272
273  omBinPage page = from_bin->last_page;
274  omAssume(to_bin->sizeW == from_bin->sizeW);
275  omAssume(to_bin != from_bin);
276
277  if (page == NULL) return;
278  do
279  {
280    omSetTopBinAndStickyOfPage(page, to_bin, to_bin->sticky);
281    if (page->prev == NULL) break;
282    page = page->prev;
283  }
284  while(1);
285
286  if (to_bin->last_page == NULL)
287  {
288    omAssume(to_bin->current_page == om_ZeroPage);
289    to_bin->last_page = from_bin->last_page;
290    to_bin->current_page = from_bin->current_page;
291    return;
292  }
293
294  omAssume(to_bin->current_page != om_ZeroPage &&
295           to_bin->current_page != NULL);
296
297  if (to_bin->current_page->current != NULL)
298  {
299    if (to_bin->current_page->prev == NULL)
300    {
301      from_bin->last_page->next = to_bin->current_page;
302      to_bin->current_page->prev = from_bin->last_page;
303      to_bin->current_page = from_bin->current_page;
304      return;
305    }
306    to_bin->current_page = to_bin->current_page->prev;
307  }
308  else
309  {
310    /* need to reset this here, since new current_page is going to be
311       from_bin->current_page, and only for current_page may we have
312       used_blocks != 0 && current == NULL */
313    to_bin->current_page->used_blocks = 0;
314  }
315
316
317  omAssume(to_bin->current_page != NULL &&
318           to_bin->current_page->current == NULL &&
319           to_bin->current_page->used_blocks == 0);
320
321  from_bin->last_page->next = to_bin->current_page->next;
322  if (to_bin->current_page->next != NULL)
323    to_bin->current_page->next->prev =  from_bin->last_page;
324  else
325  {
326    omAssume(to_bin->current_page == to_bin->last_page);
327    to_bin->last_page = from_bin->last_page;
328  }
329  to_bin->current_page->next = page;
330  page->prev = to_bin->current_page;
331  to_bin->current_page = from_bin->current_page;
332
333#ifdef HAVE_OM_ASSUME
334  omAssume(omGListLength(to_bin->last_page, prev) == length);
335#endif
336}
337
338void omDeleteStickyBinTag(omBin bin, unsigned long sticky)
339{
340  omBin no_sticky_bin = NULL;
341  omBin sticky_bin = NULL;
342
343  if (sticky == 0)
344  {
345    omAssume(0);
346    return;
347  }
348
349  sticky_bin = omGetStickyBin(bin, sticky);
350  if (sticky_bin != NULL)
351  {
352    no_sticky_bin = omGetStickyBin(bin, 0);
353    omAssume(no_sticky_bin != NULL && sticky_bin != no_sticky_bin);
354
355    omMergeStickyPages(no_sticky_bin, sticky_bin);
356
357    if (bin == sticky_bin)
358    {
359      sticky_bin = no_sticky_bin;
360      omSetStickyBinTag(bin, 0);
361    }
362    bin->next = omRemoveFromGList(bin->next, next, sticky_bin);
363    omFreeSize(sticky_bin, sizeof(omBin_t));
364  }
365}
366
367
368/*****************************************************************
369 *
370 * Sticky bins
371 *
372 *****************************************************************/
373omBin om_StickyBins = NULL;
374omBin omGetStickyBinOfBin(omBin bin)
375{
376  omBin new_bin = omAlloc(sizeof(omBin_t));
377  omAssume(omIsKnownTopBin(bin, 1) && ! omIsStickyBin(bin));
378  new_bin->sticky = SIZEOF_VOIDP;
379  new_bin->max_blocks = bin->max_blocks;
380  new_bin->sizeW = bin->sizeW;
381  new_bin->next = om_StickyBins;
382  om_StickyBins = new_bin;
383  new_bin->last_page = NULL;
384  new_bin->current_page = om_ZeroPage;
385#if 0
386  if (omIsSpecBin(bin))
387  {
388    omSpecBin s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
389    omAssume(s_bin != NULL);
390    if (s_bin != NULL)
391      s_bin->ref++;
392  }
393#endif
394  return new_bin;
395}
396
397void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
398{
399  if (! omIsOnGList(om_StickyBins, next, sticky_bin) ||
400      !sticky_bin->sticky ||
401      sticky_bin->max_blocks != into_bin->max_blocks ||
402      sticky_bin == into_bin ||
403      !omIsKnownTopBin(into_bin, 1) ||
404      omIsStickyBin(into_bin))
405  {
406#ifndef OM_NDEBUG
407    omReportError(omError_StickyBin, omError_NoError, OM_FLR,
408                  (! omIsOnGList(om_StickyBins, next, sticky_bin)  ? "unknown sticky_bin" :
409                   (!sticky_bin->sticky ? "sticky_bin is not sticky" :
410                    (sticky_bin->max_blocks != into_bin->max_blocks ? "sticky_bin and into_bin have different block sizes" :
411                     (sticky_bin == into_bin ? "sticky_bin == into_bin" :
412                      (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" :
413                       (omIsStickyBin(into_bin) ? "into_bin is sticky" :
414                        "unknown sticky_bin error")))))));
415#endif
416    return;
417  }
418  omFreeKeptAddrFromBin(sticky_bin);
419  om_StickyBins = omRemoveFromGList(om_StickyBins, next, sticky_bin);
420  omMergeStickyPages(into_bin, sticky_bin);
421
422#if 0
423  if (! omIsStaticBin(into_bin))
424  {
425    omBin _ibin = into_bin;
426    omUnGetSpecBin(&_ibin);
427  }
428#endif
429  omFreeSize(sticky_bin, sizeof(omBin_t));
430#if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG)
431  omTestBin(into_bin, 2);
432#endif
433}
434
435/*****************************************************************
436*
437* AllBin business
438*
439*****************************************************************/
440#ifndef OM_NDEBUG
441int omIsKnownTopBin(omBin bin, int normal_bin)
442{
443  omBin to_check;
444  omSpecBin s_bin;
445  int i;
446
447  omAssume(normal_bin == 1 || normal_bin == 0);
448
449#ifdef OM_HAVE_TRACK
450  if (! normal_bin)
451  {
452    to_check = om_StaticTrackBin;
453    s_bin = om_SpecTrackBin;
454  }
455  else
456#endif
457  {
458    omAssume(normal_bin);
459    to_check = om_StaticBin;
460    s_bin = om_SpecBin;
461  }
462
463  for (i=0; i<= OM_MAX_BIN_INDEX; i++)
464  {
465    if (bin == &(to_check[i]))
466      return 1;
467  }
468
469  while (s_bin != NULL)
470  {
471    if (bin == s_bin->bin) return 1;
472    s_bin = s_bin->next;
473  }
474  to_check = om_StickyBins;
475
476  while (to_check != NULL)
477  {
478    if (bin == to_check) return 1;
479    to_check = to_check->next;
480  }
481  return 0;
482}
483#endif
484
485unsigned long omGetNewStickyAllBinTag()
486{
487  unsigned long sticky = 0, new_sticky;
488  int i;
489  omSpecBin s_bin;
490  // first, find new sticky tag
491  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
492  {
493    new_sticky = omGetMaxStickyBinTag(&(om_StaticBin[i]));
494    if (new_sticky > sticky) sticky = new_sticky;
495  }
496  s_bin = om_SpecBin;
497  while (s_bin != NULL)
498  {
499    new_sticky = omGetMaxStickyBinTag(s_bin->bin);
500    if (new_sticky > sticky) sticky = new_sticky;
501    s_bin = s_bin->next;
502  }
503  if (sticky < BIT_SIZEOF_LONG - 2)
504  {
505    sticky++;
506    for (i=0; i<=OM_MAX_BIN_INDEX; i++)
507    {
508      omCreateStickyBin(&(om_StaticBin[i]), sticky);
509    }
510    s_bin = om_SpecBin;
511    while (s_bin != NULL)
512    {
513      omCreateStickyBin(s_bin->bin, sticky);
514      s_bin = s_bin->next;
515    }
516    return sticky;
517  }
518  else
519  {
520    omBin bin;
521    omAssume(sticky == BIT_SIZEOF_LONG - 1);
522    for (i=0; i<=OM_MAX_BIN_INDEX; i++)
523    {
524      bin = &om_StaticBin[i];
525      if (omGetStickyBin(bin, BIT_SIZEOF_LONG -1) == NULL)
526        omCreateStickyBin(bin, BIT_SIZEOF_LONG -1);
527    }
528    s_bin = om_SpecBin;
529    while (s_bin != NULL)
530    {
531      if (omGetStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1) == NULL)
532        omCreateStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1);
533      s_bin = s_bin->next;
534    }
535    return BIT_SIZEOF_LONG - 1;
536  }
537}
538
539void omSetStickyAllBinTag(unsigned long sticky)
540{
541  omSpecBin s_bin = om_SpecBin;
542  int i;
543  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
544  {
545    omSetStickyBinTag(&(om_StaticBin[i]), sticky);
546  }
547  while (s_bin != NULL)
548  {
549    omSetStickyBinTag(s_bin->bin, sticky);
550    s_bin = s_bin->next;
551  }
552}
553
554void omUnSetStickyAllBinTag(unsigned long sticky)
555{
556  omSpecBin s_bin = om_SpecBin;
557  int i;
558  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
559  {
560    omUnSetStickyBinTag(&(om_StaticBin[i]), sticky);
561  }
562  while (s_bin != NULL)
563  {
564    omUnSetStickyBinTag(s_bin->bin, sticky);
565    s_bin = s_bin->next;
566  }
567}
568
569void omDeleteStickyAllBinTag(unsigned long sticky)
570{
571  omSpecBin s_bin = om_SpecBin;
572  int i;
573  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
574  {
575    omDeleteStickyBinTag(&(om_StaticBin[i]), sticky);
576  }
577  while (s_bin != NULL)
578  {
579    omDeleteStickyBinTag(s_bin->bin, sticky);
580    s_bin = s_bin->next;
581  }
582}
583
584#if 0
585void omPrintMissing(omBin bin)
586{
587  omBinPage page = bin->last_page;
588
589  while (page != NULL)
590  {
591    void* addr = (void*) page + SIZEOF_OM_BIN_PAGE_HEADER;
592    int i;
593
594    for (i=0; i<bin->max_blocks; i++)
595    {
596      if (! omIsOnList(page->current, addr))
597        printf("%d:%p\n", i, addr);
598      addr += bin->sizeW*SIZEOF_LONG;
599    }
600    page = page->prev;
601  }
602}
603#endif
604
605/*****************************************************************
606 *
607 * Statistics
608 *
609 *****************************************************************/
610static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p,
611                          int *free_blocks_p)
612{
613  int pages = 0, used_blocks = 0, free_blocks = 0;
614  int where = 1;
615
616  omBinPage page = bin->last_page;
617  while (page != NULL)
618  {
619    pages++; if (where == 1)
620    {
621      used_blocks += omGetUsedBlocksOfPage(page) + 1;
622      if (bin->max_blocks > 0)
623        free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1;
624    }
625    else
626    {
627      if (bin->max_blocks > 1)
628        used_blocks += bin->max_blocks;
629      else
630        used_blocks++;
631    }
632    if (page == bin->current_page) where = -1;
633    page = page->prev;
634  }
635  *pages_p = pages;
636  *used_blocks_p = used_blocks;
637  *free_blocks_p = free_blocks;
638}
639
640static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p,
641                               int *free_blocks_p)
642{
643  int t_pages = 0, t_used_blocks = 0, t_free_blocks = 0;
644  int pages = 0, used_blocks = 0, free_blocks = 0;
645
646  while (bin != NULL)
647  {
648    omGetBinStat(bin, &pages, &used_blocks, &free_blocks);
649    t_pages += pages;
650    t_used_blocks += used_blocks;
651    t_free_blocks += free_blocks;
652    if (!omIsStickyBin(bin))
653      bin = bin->next;
654    else
655      bin = NULL;
656  }
657  *pages_p = t_pages;
658  *used_blocks_p = t_used_blocks;
659  *free_blocks_p = t_free_blocks;
660}
661
662static void omPrintBinStat(FILE * fd, omBin bin, int track, int* pages, int* used_blocks, int* free_blocks)
663{
664  if (track)
665  {
666    fprintf(fd, "T \t \t");
667  }
668  else
669  {
670    fprintf(fd, "%s%ld\t%ld\t", (omIsStaticNormalBin(bin) ? " " :
671                                (omIsStickyBin(bin) ? "S" :
672                                 (omIsTrackBin(bin) ? "T" : "*"))),
673            bin->sizeW, bin->max_blocks);
674  }
675  omGetTotalBinStat(bin, pages, used_blocks, free_blocks);
676  fprintf(fd, "%d\t%d\t%d\n", *pages, *free_blocks, *used_blocks);
677  if (bin->next != NULL && !omIsStickyBin(bin))
678  {
679    int s_pages, s_free_blocks, s_used_blocks;
680    while (bin != NULL)
681    {
682      omGetBinStat(bin, &s_pages, &s_used_blocks, &s_free_blocks);
683      fprintf(fd, " \t \t%d\t%d\t%d\t%d\n", s_pages, s_free_blocks, s_used_blocks,
684              (int) bin->sticky);
685      bin = bin->next;
686      *pages += s_pages;
687      *used_blocks += s_used_blocks;
688      *free_blocks += s_free_blocks;
689    }
690  }
691}
692
693void omPrintBinStats(FILE* fd)
694{
695  int i = OM_MAX_BIN_INDEX, pages=0, used_blocks=0, free_blocks=0;
696  int pages_p, used_blocks_p, free_blocks_p;
697  omSpecBin s_bin = om_SpecBin;
698  omBin sticky;
699
700  fprintf(fd, " SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n");
701  fflush(fd);
702  while (s_bin != NULL || i >= 0)
703  {
704    if (s_bin == NULL || (i >= 0 && (unsigned long) om_StaticBin[i].max_blocks < (unsigned long) s_bin->bin->max_blocks))
705    {
706       omPrintBinStat(fd, &om_StaticBin[i], 0, &pages_p, &used_blocks_p, &free_blocks_p);
707       pages += pages_p;
708       used_blocks += used_blocks_p;
709       free_blocks += free_blocks_p;
710#ifdef OM_HAVE_TRACK
711       if (om_StaticTrackBin[i].current_page != om_ZeroPage)
712       {
713         omPrintBinStat(fd, &om_StaticTrackBin[i], 1, &pages_p, &used_blocks_p, &free_blocks_p);
714         pages += pages_p;
715         used_blocks += used_blocks_p;
716         free_blocks += free_blocks_p;
717       }
718#endif
719       i--;
720    }
721    else
722    {
723      omPrintBinStat(fd, s_bin->bin,0, &pages_p, &used_blocks_p, &free_blocks_p);
724      pages += pages_p;
725      used_blocks += used_blocks_p;
726      free_blocks += free_blocks_p;
727      s_bin = s_bin->next;
728    }
729  }
730#ifdef OM_HAVE_TRACK
731  s_bin = om_SpecTrackBin;
732  while (s_bin != NULL)
733  {
734    omPrintBinStat(fd, s_bin->bin, 0,  &pages_p, &used_blocks_p, &free_blocks_p);
735    s_bin = s_bin->next;
736    pages += pages_p;
737    used_blocks += used_blocks_p;
738    free_blocks += free_blocks_p;
739  }
740#endif
741  sticky = om_StickyBins;
742  while (sticky != NULL)
743  {
744    omPrintBinStat(fd, sticky, 0,  &pages_p, &used_blocks_p, &free_blocks_p);
745    sticky = sticky->next;
746    pages += pages_p;
747    used_blocks += used_blocks_p;
748    free_blocks += free_blocks_p;
749  }
750  fprintf(fd, "----------------------------------------\n");
751  fprintf(fd, "      \t      \t%d\t%d\t%d\n", pages, free_blocks, used_blocks);
752}
753
754static  int omGetUsedBytesOfBin(omBin bin)
755{
756  int pages = 0, used_blocks = 0, free_blocks = 0;
757  omGetTotalBinStat(bin, &pages, &used_blocks, &free_blocks);
758  return used_blocks*bin->sizeW*SIZEOF_LONG;
759}
760
761size_t omGetUsedBinBytes()
762{
763  int i = OM_MAX_BIN_INDEX;
764  omSpecBin s_bin = om_SpecBin;
765  size_t used = 0;
766  omBin sticky;
767
768  for (; i>=0; i--)
769  {
770    used += omGetUsedBytesOfBin(&om_StaticBin[i]);
771  }
772  while (s_bin != NULL)
773  {
774    used += omGetUsedBytesOfBin(s_bin->bin);
775    s_bin = s_bin->next;
776  }
777#ifdef OM_HAVE_TRACK
778  for (i=OM_MAX_BIN_INDEX; i>=0; i--)
779  {
780    used += omGetUsedBytesOfBin(&om_StaticTrackBin[i]);
781  }
782  s_bin = om_SpecTrackBin;
783  while (s_bin != NULL)
784  {
785    used += omGetUsedBytesOfBin(s_bin->bin);
786    s_bin = s_bin->next;
787  }
788#endif
789
790  sticky = om_StickyBins;
791  while (sticky != NULL)
792  {
793    used += omGetUsedBytesOfBin(sticky);
794    sticky = sticky->next;
795  }
796  return used;
797}
Note: See TracBrowser for help on using the repository browser.