Skip to content

Commit 39efb72

Browse files
KarthikNayakttaylorr
authored andcommitted
config: make delta_base_cache_limit a non-global variable
The `delta_base_cache_limit` variable is a global config variable used by multiple subsystems. Let's make this non-global, by adding this variable to the stack of each of the subsystems where it is used. In `gc.c` we add it to the `gc_config` struct and also the constructor function. In `index-pack.c` we add it to the `pack_idx_option` struct and its constructor. Finally, in `packfile.c` we dynamically retrieve this value from the repository config, since the value is only used once in the entire subsystem. These changes are made to remove the usage of `delta_base_cache_limit` as a global variable in `packfile.c`. This brings us one step closer to removing the `USE_THE_REPOSITORY_VARIABLE` definition in `packfile.c` which we complete in the next patch. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent f5f79ac commit 39efb72

File tree

9 files changed

+26
-14
lines changed

9 files changed

+26
-14
lines changed

builtin/gc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct gc_config {
138138
char *repack_filter_to;
139139
unsigned long big_pack_threshold;
140140
unsigned long max_delta_cache_size;
141+
unsigned long delta_base_cache_limit;
141142
};
142143

143144
#define GC_CONFIG_INIT { \
@@ -153,6 +154,7 @@ struct gc_config {
153154
.prune_expire = xstrdup("2.weeks.ago"), \
154155
.prune_worktrees_expire = xstrdup("3.months.ago"), \
155156
.max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \
157+
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
156158
}
157159

158160
static void gc_config_release(struct gc_config *cfg)
@@ -205,6 +207,7 @@ static void gc_config(struct gc_config *cfg)
205207

206208
git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
207209
git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
210+
git_config_get_ulong("core.deltabasecachelimit", &cfg->delta_base_cache_limit);
208211

209212
if (!git_config_get_string("gc.repackfilter", &owned)) {
210213
free(cfg->repack_filter);
@@ -416,7 +419,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg,
416419
* read_sha1_file() (either at delta calculation phase, or
417420
* writing phase) also fills up the delta base cache
418421
*/
419-
heap += delta_base_cache_limit;
422+
heap += cfg->delta_base_cache_limit;
420423
/* and of course pack-objects has its own delta cache */
421424
heap += cfg->max_delta_cache_size;
422425

builtin/index-pack.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ static void parse_pack_objects(unsigned char *hash)
12381238
* recursively checking if the resulting object is used as a base
12391239
* for some more deltas.
12401240
*/
1241-
static void resolve_deltas(void)
1241+
static void resolve_deltas(struct pack_idx_option *opts)
12421242
{
12431243
int i;
12441244

@@ -1254,7 +1254,7 @@ static void resolve_deltas(void)
12541254
nr_ref_deltas + nr_ofs_deltas);
12551255

12561256
nr_dispatched = 0;
1257-
base_cache_limit = delta_base_cache_limit * nr_threads;
1257+
base_cache_limit = opts->delta_base_cache_limit * nr_threads;
12581258
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
12591259
init_thread();
12601260
work_lock();
@@ -1604,6 +1604,10 @@ static int git_index_pack_config(const char *k, const char *v,
16041604
else
16051605
opts->flags &= ~WRITE_REV;
16061606
}
1607+
if (!strcmp(k, "core.deltabasecachelimit")) {
1608+
opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);
1609+
return 0;
1610+
}
16071611
return git_default_config(k, v, ctx, cb);
16081612
}
16091613

@@ -1930,7 +1934,7 @@ int cmd_index_pack(int argc,
19301934
parse_pack_objects(pack_hash);
19311935
if (report_end_of_input)
19321936
write_in_full(2, "\0", 1);
1933-
resolve_deltas();
1937+
resolve_deltas(&opts);
19341938
conclude_pack(fix_thin_pack, curr_pack, pack_hash);
19351939
free(ofs_deltas);
19361940
free(ref_deltas);

config.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,11 +1515,6 @@ static int git_default_core_config(const char *var, const char *value,
15151515
return 0;
15161516
}
15171517

1518-
if (!strcmp(var, "core.deltabasecachelimit")) {
1519-
delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
1520-
return 0;
1521-
}
1522-
15231518
if (!strcmp(var, "core.autocrlf")) {
15241519
if (value && !strcasecmp(value, "input")) {
15251520
auto_crlf = AUTO_CRLF_INPUT;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
5151
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
5252
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
5353
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
54-
size_t delta_base_cache_limit = 96 * 1024 * 1024;
5554
unsigned long big_file_threshold = 512 * 1024 * 1024;
5655
char *editor_program;
5756
char *askpass_program;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ extern int zlib_compression_level;
165165
extern int pack_compression_level;
166166
extern size_t packed_git_window_size;
167167
extern size_t packed_git_limit;
168-
extern size_t delta_base_cache_limit;
169168
extern unsigned long big_file_threshold;
170169
extern unsigned long pack_size_limit_cfg;
171170
extern int max_allowed_tree_depth;

pack-objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
struct repository;
99

10-
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
10+
#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)
11+
#define DEFAULT_DELTA_BASE_CACHE_LIMIT (96 * 1024 * 1024)
1112

1213
#define OE_DFS_STATE_BITS 2
1314
#define OE_DEPTH_BITS 12

pack-write.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void reset_pack_idx_option(struct pack_idx_option *opts)
2121
memset(opts, 0, sizeof(*opts));
2222
opts->version = 2;
2323
opts->off32_limit = 0x7fffffff;
24+
opts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;
2425
}
2526

2627
static int sha1_compare(const void *_a, const void *_b)

pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct pack_idx_option {
5858
*/
5959
int anomaly_alloc, anomaly_nr;
6060
uint32_t *anomaly;
61+
unsigned long delta_base_cache_limit;
6162
};
6263

6364
void reset_pack_idx_option(struct pack_idx_option *);

packfile.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "commit-graph.h"
2525
#include "pack-revindex.h"
2626
#include "promisor-remote.h"
27+
#include "config.h"
28+
#include "pack-objects.h"
2729

2830
char *odb_pack_name(struct repository *r, struct strbuf *buf,
2931
const unsigned char *hash, const char *ext)
@@ -1496,7 +1498,9 @@ void clear_delta_base_cache(void)
14961498
}
14971499

14981500
static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
1499-
void *base, unsigned long base_size, enum object_type type)
1501+
void *base, unsigned long base_size,
1502+
unsigned long delta_base_cache_limit,
1503+
enum object_type type)
15001504
{
15011505
struct delta_base_cache_entry *ent;
15021506
struct list_head *lru, *tmp;
@@ -1697,6 +1701,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
16971701
struct unpack_entry_stack_ent *delta_stack = small_delta_stack;
16981702
int delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;
16991703
int base_from_cache = 0;
1704+
unsigned long delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;
1705+
1706+
repo_config_get_ulong(r, "core.deltabasecachelimit", &delta_base_cache_limit);
17001707

17011708
write_pack_access_log(p, obj_offset);
17021709

@@ -1878,7 +1885,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
18781885
* before we are done using it.
18791886
*/
18801887
if (!external_base)
1881-
add_delta_base_cache(p, base_obj_offset, base, base_size, type);
1888+
add_delta_base_cache(p, base_obj_offset, base,
1889+
base_size, delta_base_cache_limit,
1890+
type);
18821891

18831892
free(delta_data);
18841893
free(external_base);

0 commit comments

Comments
 (0)