This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GC special object sizes


Zack Weinberg <zack@codesourcery.com> writes:

  > As long as you're hacking the GC, you could implement something I've
  > been meaning to do for at least two years, which is allocate
  > everything bigger than half a page on a special "large object" chain
  > so that we do not waste ridiculous amounts of memory on them.  We very
  > rarely need such objects, so they can go through a slow path.


I have a small hack that prints the allocation overheads for the
different bucket sizes when using -fmem-report. The *_under* stuff can
be used to determine if any extra buckets need to be added to
extra_order_size_table.

Is this useful? Should it be turned in a proper patch? If yes, it
should probably not be compiled in by default. What switch should be
used to control that? Any other suggestions? 


Index: ggc-page.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-page.c,v
retrieving revision 1.65
diff -c -3 -p -c -r1.65 ggc-page.c
*** ggc-page.c	30 Apr 2003 21:44:23 -0000	1.65
--- ggc-page.c	6 May 2003 12:03:50 -0000
*************** static unsigned char size_lookup[257] =
*** 1020,1025 ****
--- 1031,1051 ----
  
  /* Allocate a chunk of memory of SIZE bytes.  Its contents are undefined.  */
  
+ static unsigned long long TOTAL_ALLOCATED = 0;
+ static unsigned long long TOTAL_ALLOCATION_REQUESTS = 0;
+ static unsigned long long TOTAL_OVERHEAD = 0;
+ 
+ static unsigned long long TOTAL_ALLOCATED_under32 = 0;
+ static unsigned long long TOTAL_OVERHEAD_under32 = 0;
+ 
+ static unsigned long long TOTAL_ALLOCATED_under64 = 0;
+ static unsigned long long TOTAL_OVERHEAD_under64 = 0;
+ 
+ static unsigned long long TOTAL_ALLOCATED_under128 = 0;
+ static unsigned long long TOTAL_OVERHEAD_under128 = 0;
+ 
+ static unsigned long long bucket_TOTAL_OVERHEAD[NUM_ORDERS];
+ 
  void *
  ggc_alloc (size)
       size_t size;
*************** ggc_alloc (size)
*** 1145,1150 ****
--- 1171,1196 ----
       information is used in deciding when to collect.  */
    G.allocated += OBJECT_SIZE (order);
  
+   TOTAL_OVERHEAD += OBJECT_SIZE (order) - size;
+   bucket_TOTAL_OVERHEAD[order] += OBJECT_SIZE (order) - size;
+   TOTAL_ALLOCATION_REQUESTS += size;
+   TOTAL_ALLOCATED += OBJECT_SIZE(order);
+ 
+   if (size <= 32){
+     TOTAL_OVERHEAD_under32 += OBJECT_SIZE (order) - size;
+     TOTAL_ALLOCATED_under32 += OBJECT_SIZE(order);
+   }
+ 
+   if (size <= 64){
+     TOTAL_OVERHEAD_under64 += OBJECT_SIZE (order) - size;
+     TOTAL_ALLOCATED_under64 += OBJECT_SIZE(order);
+   }
+   
+   if (size <= 128){
+     TOTAL_OVERHEAD_under128 += OBJECT_SIZE (order) - size;
+     TOTAL_ALLOCATED_under128 += OBJECT_SIZE(order);
+   }
+ 
    if (GGC_DEBUG_LEVEL >= 3)
      fprintf (G.debug_file,
  	     "Allocating object, requested size=%lu, actual=%lu at %p on %p\n",
*************** ggc_print_statistics ()
*** 1837,1842 ****
--- 1883,1909 ----
  	   SCALE (G.bytes_mapped), LABEL (G.bytes_mapped),
  	   SCALE (G.allocated), LABEL(G.allocated),
  	   SCALE (total_overhead), LABEL (total_overhead));
+   fprintf (stderr, "Total Overhead:                      %lld\n", TOTAL_OVERHEAD);
+   fprintf (stderr, "Total Allocation Requests:           %lld\n", TOTAL_ALLOCATION_REQUESTS);
+   fprintf (stderr, "Total Allocated:                     %lld\n", TOTAL_ALLOCATED);
+ 
+   fprintf (stderr, "Total Overhead under   32:           %lld\n", TOTAL_OVERHEAD_under32);
+   fprintf (stderr, "Total Allocated under  32:           %lld\n", TOTAL_ALLOCATED_under32);
+ 
+   fprintf (stderr, "Total Overhead under   64:           %lld\n", TOTAL_OVERHEAD_under64);
+   fprintf (stderr, "Total Allocated under  64:           %lld\n", TOTAL_ALLOCATED_under64);
+   
+   fprintf (stderr, "Total Overhead under  128:           %lld\n", TOTAL_OVERHEAD_under128);
+   fprintf (stderr, "Total Allocated under 128:           %lld\n", TOTAL_ALLOCATED_under128);
+  
+   
+   for (i = 0; i < NUM_ORDERS; i++)
+     if (!bucket_TOTAL_OVERHEAD[i])
+       continue;
+     else
+       fprintf (stderr, "Total Overhead order %2d:            %lld\n",
+                i, bucket_TOTAL_OVERHEAD[i]);
+   
  }
  
  struct ggc_pch_data





Some results: 

On x86 for  gcc -O3 combine.i 

Total Overhead:            2793392
Total Allocation Requests: 59779504
Total Allocated:           62572896
Total Overhead under 32:            17544
Total Allocated under 32:           42372920
Total Overhead under 64:            620320
Total Allocated under 64:           49559432
Total Overhead under 128:            764096
Total Allocated under 128:           53108320
Total Overhead order  3:            348
Total Overhead order  5:            17196
Total Overhead order  6:            134432
Total Overhead order  7:            64660
Total Overhead order  8:            51664
Total Overhead order  9:            58376
Total Overhead order 10:            159724
Total Overhead order 11:            277320
Total Overhead order 12:            219132
Total Overhead order 13:            389660
Total Overhead order 14:            364340
Total Overhead order 15:            470660
Total Overhead order 16:            38420
Total Overhead order 32:            79116
Total Overhead order 36:            468344

g++ -O3 -fno-unit-at-a-time generate-3.4.ii  (the testcase from PR8361)

Total Overhead:            32795498
Total Allocation Requests: 357109778
Total Allocated:           389905276
Total Overhead under 32:            666904
Total Allocated under 32:           189618724
Total Overhead under 64:            6557256
Total Allocated under 64:           260585800
Total Overhead under 128:            9681068
Total Allocated under 128:           310022012
Total Overhead order  3:            1652
Total Overhead order  5:            665252
Total Overhead order  6:            639472
Total Overhead order  7:            69652
Total Overhead order  8:            1711934
Total Overhead order  9:            2519380
Total Overhead order 10:            5473096
Total Overhead order 11:            1052716
Total Overhead order 12:            2207400
Total Overhead order 13:            2843360
Total Overhead order 14:            3483776
Total Overhead order 15:            2992304
Total Overhead order 16:            536460
Total Overhead order 17:            293884
Total Overhead order 18:            120
Total Overhead order 32:            3054160
Total Overhead order 36:            5250880


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]