2
2
#define PACK_OBJECTS_H
3
3
4
4
#include "object-store.h"
5
+ #include "thread-utils.h"
5
6
6
7
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
7
8
14
15
* above this limit. Don't lower it too much.
15
16
*/
16
17
#define OE_SIZE_BITS 31
17
- #define OE_DELTA_SIZE_BITS 20
18
+ #define OE_DELTA_SIZE_BITS 23
18
19
19
20
/*
20
21
* State flags for depth-first search used for analyzing delta cycles.
@@ -94,11 +95,12 @@ struct object_entry {
94
95
*/
95
96
unsigned delta_size_ :OE_DELTA_SIZE_BITS ; /* delta data size (uncompressed) */
96
97
unsigned delta_size_valid :1 ;
98
+ unsigned char in_pack_header_size ;
97
99
unsigned in_pack_idx :OE_IN_PACK_BITS ; /* already in pack */
98
100
unsigned z_delta_size :OE_Z_DELTA_BITS ;
99
101
unsigned type_valid :1 ;
100
- unsigned type_ :TYPE_BITS ;
101
102
unsigned no_try_delta :1 ;
103
+ unsigned type_ :TYPE_BITS ;
102
104
unsigned in_pack_type :TYPE_BITS ; /* could be delta */
103
105
unsigned preferred_base :1 ; /*
104
106
* we do not pack this, but is available
@@ -108,17 +110,16 @@ struct object_entry {
108
110
unsigned tagged :1 ; /* near the very tip of refs */
109
111
unsigned filled :1 ; /* assigned write-order */
110
112
unsigned dfs_state :OE_DFS_STATE_BITS ;
111
- unsigned char in_pack_header_size ;
112
113
unsigned depth :OE_DEPTH_BITS ;
113
114
114
115
/*
115
116
* pahole results on 64-bit linux (gcc and clang)
116
117
*
117
- * size: 80, bit_padding: 20 bits, holes: 8 bits
118
+ * size: 80, bit_padding: 9 bits
118
119
*
119
120
* and on 32-bit (gcc)
120
121
*
121
- * size: 76, bit_padding: 20 bits, holes: 8 bits
122
+ * size: 76, bit_padding: 9 bits
122
123
*/
123
124
};
124
125
@@ -130,6 +131,7 @@ struct packing_data {
130
131
uint32_t index_size ;
131
132
132
133
unsigned int * in_pack_pos ;
134
+ unsigned long * delta_size ;
133
135
134
136
/*
135
137
* Only one of these can be non-NULL and they have different
@@ -140,10 +142,29 @@ struct packing_data {
140
142
struct packed_git * * in_pack_by_idx ;
141
143
struct packed_git * * in_pack ;
142
144
145
+ #ifndef NO_PTHREADS
146
+ pthread_mutex_t lock ;
147
+ #endif
148
+
143
149
uintmax_t oe_size_limit ;
150
+ uintmax_t oe_delta_size_limit ;
144
151
};
145
152
146
153
void prepare_packing_data (struct packing_data * pdata );
154
+
155
+ static inline void packing_data_lock (struct packing_data * pdata )
156
+ {
157
+ #ifndef NO_PTHREADS
158
+ pthread_mutex_lock (& pdata -> lock );
159
+ #endif
160
+ }
161
+ static inline void packing_data_unlock (struct packing_data * pdata )
162
+ {
163
+ #ifndef NO_PTHREADS
164
+ pthread_mutex_unlock (& pdata -> lock );
165
+ #endif
166
+ }
167
+
147
168
struct object_entry * packlist_alloc (struct packing_data * pdata ,
148
169
const unsigned char * sha1 ,
149
170
uint32_t index_pos );
@@ -332,18 +353,34 @@ static inline unsigned long oe_delta_size(struct packing_data *pack,
332
353
{
333
354
if (e -> delta_size_valid )
334
355
return e -> delta_size_ ;
335
- return oe_size (pack , e );
356
+
357
+ /*
358
+ * pack->detla_size[] can't be NULL because oe_set_delta_size()
359
+ * must have been called when a new delta is saved with
360
+ * oe_set_delta().
361
+ * If oe_delta() returns NULL (i.e. default state, which means
362
+ * delta_size_valid is also false), then the caller must never
363
+ * call oe_delta_size().
364
+ */
365
+ return pack -> delta_size [e - pack -> objects ];
336
366
}
337
367
338
368
static inline void oe_set_delta_size (struct packing_data * pack ,
339
369
struct object_entry * e ,
340
370
unsigned long size )
341
371
{
342
- e -> delta_size_ = size ;
343
- e -> delta_size_valid = e -> delta_size_ == size ;
344
- if (!e -> delta_size_valid && size != oe_size (pack , e ))
345
- BUG ("this can only happen in check_object() "
346
- "where delta size is the same as entry size" );
372
+ if (size < pack -> oe_delta_size_limit ) {
373
+ e -> delta_size_ = size ;
374
+ e -> delta_size_valid = 1 ;
375
+ } else {
376
+ packing_data_lock (pack );
377
+ if (!pack -> delta_size )
378
+ ALLOC_ARRAY (pack -> delta_size , pack -> nr_alloc );
379
+ packing_data_unlock (pack );
380
+
381
+ pack -> delta_size [e - pack -> objects ] = size ;
382
+ e -> delta_size_valid = 0 ;
383
+ }
347
384
}
348
385
349
386
#endif
0 commit comments