@@ -170,6 +170,7 @@ Format of STDIN stream:
170
170
#include "run-command.h"
171
171
#include "packfile.h"
172
172
#include "object-store.h"
173
+ #include "mem-pool.h"
173
174
174
175
#define PACK_ID_BITS 16
175
176
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -211,13 +212,6 @@ struct last_object {
211
212
unsigned no_swap : 1 ;
212
213
};
213
214
214
- struct mem_pool {
215
- struct mem_pool * next_pool ;
216
- char * next_free ;
217
- char * end ;
218
- uintmax_t space [FLEX_ARRAY ]; /* more */
219
- };
220
-
221
215
struct atom_str {
222
216
struct atom_str * next_atom ;
223
217
unsigned short str_len ;
@@ -306,9 +300,8 @@ static int global_argc;
306
300
static const char * * global_argv ;
307
301
308
302
/* Memory pools */
309
- static size_t mem_pool_alloc = 2 * 1024 * 1024 - sizeof (struct mem_pool );
310
- static size_t total_allocd ;
311
- static struct mem_pool * mem_pool ;
303
+ static struct mem_pool fi_mem_pool = {NULL , 2 * 1024 * 1024 -
304
+ sizeof (struct mp_block ), 0 };
312
305
313
306
/* Atom management */
314
307
static unsigned int atom_table_sz = 4451 ;
@@ -343,6 +336,7 @@ static unsigned int tree_entry_alloc = 1000;
343
336
static void * avail_tree_entry ;
344
337
static unsigned int avail_tree_table_sz = 100 ;
345
338
static struct avail_tree_content * * avail_tree_table ;
339
+ static size_t tree_entry_allocd ;
346
340
static struct strbuf old_tree = STRBUF_INIT ;
347
341
static struct strbuf new_tree = STRBUF_INIT ;
348
342
@@ -636,49 +630,10 @@ static unsigned int hc_str(const char *s, size_t len)
636
630
return r ;
637
631
}
638
632
639
- static void * pool_alloc (size_t len )
640
- {
641
- struct mem_pool * p ;
642
- void * r ;
643
-
644
- /* round up to a 'uintmax_t' alignment */
645
- if (len & (sizeof (uintmax_t ) - 1 ))
646
- len += sizeof (uintmax_t ) - (len & (sizeof (uintmax_t ) - 1 ));
647
-
648
- for (p = mem_pool ; p ; p = p -> next_pool )
649
- if ((p -> end - p -> next_free >= len ))
650
- break ;
651
-
652
- if (!p ) {
653
- if (len >= (mem_pool_alloc /2 )) {
654
- total_allocd += len ;
655
- return xmalloc (len );
656
- }
657
- total_allocd += sizeof (struct mem_pool ) + mem_pool_alloc ;
658
- p = xmalloc (st_add (sizeof (struct mem_pool ), mem_pool_alloc ));
659
- p -> next_pool = mem_pool ;
660
- p -> next_free = (char * ) p -> space ;
661
- p -> end = p -> next_free + mem_pool_alloc ;
662
- mem_pool = p ;
663
- }
664
-
665
- r = p -> next_free ;
666
- p -> next_free += len ;
667
- return r ;
668
- }
669
-
670
- static void * pool_calloc (size_t count , size_t size )
671
- {
672
- size_t len = count * size ;
673
- void * r = pool_alloc (len );
674
- memset (r , 0 , len );
675
- return r ;
676
- }
677
-
678
633
static char * pool_strdup (const char * s )
679
634
{
680
635
size_t len = strlen (s ) + 1 ;
681
- char * r = pool_alloc ( len );
636
+ char * r = mem_pool_alloc ( & fi_mem_pool , len );
682
637
memcpy (r , s , len );
683
638
return r ;
684
639
}
@@ -687,7 +642,7 @@ static void insert_mark(uintmax_t idnum, struct object_entry *oe)
687
642
{
688
643
struct mark_set * s = marks ;
689
644
while ((idnum >> s -> shift ) >= 1024 ) {
690
- s = pool_calloc ( 1 , sizeof (struct mark_set ));
645
+ s = mem_pool_calloc ( & fi_mem_pool , 1 , sizeof (struct mark_set ));
691
646
s -> shift = marks -> shift + 10 ;
692
647
s -> data .sets [0 ] = marks ;
693
648
marks = s ;
@@ -696,7 +651,7 @@ static void insert_mark(uintmax_t idnum, struct object_entry *oe)
696
651
uintmax_t i = idnum >> s -> shift ;
697
652
idnum -= i << s -> shift ;
698
653
if (!s -> data .sets [i ]) {
699
- s -> data .sets [i ] = pool_calloc ( 1 , sizeof (struct mark_set ));
654
+ s -> data .sets [i ] = mem_pool_calloc ( & fi_mem_pool , 1 , sizeof (struct mark_set ));
700
655
s -> data .sets [i ]-> shift = s -> shift - 10 ;
701
656
}
702
657
s = s -> data .sets [i ];
@@ -734,7 +689,7 @@ static struct atom_str *to_atom(const char *s, unsigned short len)
734
689
if (c -> str_len == len && !strncmp (s , c -> str_dat , len ))
735
690
return c ;
736
691
737
- c = pool_alloc ( sizeof (struct atom_str ) + len + 1 );
692
+ c = mem_pool_alloc ( & fi_mem_pool , sizeof (struct atom_str ) + len + 1 );
738
693
c -> str_len = len ;
739
694
memcpy (c -> str_dat , s , len );
740
695
c -> str_dat [len ] = 0 ;
@@ -765,7 +720,7 @@ static struct branch *new_branch(const char *name)
765
720
if (check_refname_format (name , REFNAME_ALLOW_ONELEVEL ))
766
721
die ("Branch name doesn't conform to GIT standards: %s" , name );
767
722
768
- b = pool_calloc ( 1 , sizeof (struct branch ));
723
+ b = mem_pool_calloc ( & fi_mem_pool , 1 , sizeof (struct branch ));
769
724
b -> name = pool_strdup (name );
770
725
b -> table_next_branch = branch_table [hc ];
771
726
b -> branch_tree .versions [0 ].mode = S_IFDIR ;
@@ -801,7 +756,7 @@ static struct tree_content *new_tree_content(unsigned int cnt)
801
756
avail_tree_table [hc ] = f -> next_avail ;
802
757
} else {
803
758
cnt = cnt & 7 ? ((cnt / 8 ) + 1 ) * 8 : cnt ;
804
- f = pool_alloc ( sizeof (* t ) + sizeof (t -> entries [0 ]) * cnt );
759
+ f = mem_pool_alloc ( & fi_mem_pool , sizeof (* t ) + sizeof (t -> entries [0 ]) * cnt );
805
760
f -> entry_capacity = cnt ;
806
761
}
807
762
@@ -846,7 +801,7 @@ static struct tree_entry *new_tree_entry(void)
846
801
847
802
if (!avail_tree_entry ) {
848
803
unsigned int n = tree_entry_alloc ;
849
- total_allocd += n * sizeof (struct tree_entry );
804
+ tree_entry_allocd += n * sizeof (struct tree_entry );
850
805
ALLOC_ARRAY (e , n );
851
806
avail_tree_entry = e ;
852
807
while (n -- > 1 ) {
@@ -2867,7 +2822,7 @@ static void parse_new_tag(const char *arg)
2867
2822
enum object_type type ;
2868
2823
const char * v ;
2869
2824
2870
- t = pool_alloc ( sizeof (struct tag ));
2825
+ t = mem_pool_alloc ( & fi_mem_pool , sizeof (struct tag ));
2871
2826
memset (t , 0 , sizeof (struct tag ));
2872
2827
t -> name = pool_strdup (arg );
2873
2828
if (last_tag )
@@ -3466,12 +3421,12 @@ int cmd_main(int argc, const char **argv)
3466
3421
atom_table = xcalloc (atom_table_sz , sizeof (struct atom_str * ));
3467
3422
branch_table = xcalloc (branch_table_sz , sizeof (struct branch * ));
3468
3423
avail_tree_table = xcalloc (avail_tree_table_sz , sizeof (struct avail_tree_content * ));
3469
- marks = pool_calloc ( 1 , sizeof (struct mark_set ));
3424
+ marks = mem_pool_calloc ( & fi_mem_pool , 1 , sizeof (struct mark_set ));
3470
3425
3471
3426
global_argc = argc ;
3472
3427
global_argv = argv ;
3473
3428
3474
- rc_free = pool_alloc ( cmd_save * sizeof (* rc_free ));
3429
+ rc_free = mem_pool_alloc ( & fi_mem_pool , cmd_save * sizeof (* rc_free ));
3475
3430
for (i = 0 ; i < (cmd_save - 1 ); i ++ )
3476
3431
rc_free [i ].next = & rc_free [i + 1 ];
3477
3432
rc_free [cmd_save - 1 ].next = NULL ;
@@ -3545,8 +3500,8 @@ int cmd_main(int argc, const char **argv)
3545
3500
fprintf (stderr , "Total branches: %10lu (%10lu loads )\n" , branch_count , branch_load_count );
3546
3501
fprintf (stderr , " marks: %10" PRIuMAX " (%10" PRIuMAX " unique )\n" , (((uintmax_t )1 ) << marks -> shift ) * 1024 , marks_set_count );
3547
3502
fprintf (stderr , " atoms: %10u\n" , atom_cnt );
3548
- fprintf (stderr , "Memory total: %10" PRIuMAX " KiB\n" , (total_allocd + alloc_count * sizeof (struct object_entry ))/1024 );
3549
- fprintf (stderr , " pools: %10lu KiB\n" , (unsigned long )(total_allocd /1024 ));
3503
+ fprintf (stderr , "Memory total: %10" PRIuMAX " KiB\n" , (tree_entry_allocd + fi_mem_pool . pool_alloc + alloc_count * sizeof (struct object_entry ))/1024 );
3504
+ fprintf (stderr , " pools: %10lu KiB\n" , (unsigned long )(( tree_entry_allocd + fi_mem_pool . pool_alloc ) /1024 ));
3550
3505
fprintf (stderr , " objects: %10" PRIuMAX " KiB\n" , (alloc_count * sizeof (struct object_entry ))/1024 );
3551
3506
fprintf (stderr , "---------------------------------------------------------------------\n" );
3552
3507
pack_report ();
0 commit comments