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