source: git/omalloc/omBin.c @ 5ef600

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