1 From 8a6458035591dccd033b8e7a37102d9b203c05eb Mon Sep 17 00:00:00 2001
2 From: "Kyle J. McKay" <mackyle@gmail.com>
3 Date: Wed, 31 Dec 2014 10:07:44 -0800
4 Subject: [PATCH] pack-objects.c: change pack.windowmemory default
6 The default value of pack.windowmemory = 0 allows unlimited memory
7 use while repacking. In the case of a gc --aggressive running with
8 a 64-bit memory space, this can easily lead to memory thrashing and
9 bring the system to its knees.
11 Instead of using a default pack.windowmemory = 0 value, use a default
12 value of system-memory-size / 2 / number-of-packing-threads but cap
13 it to no more than 2G - 1 on a 32-bit address space.
15 The memory thrashing behavior can still be restored by explicitly
16 setting pack.windowmemory = 0 in a config file or using an explicit
17 --window-memory=0 option.
19 Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
21 builtin/pack-objects.c | 41 +++++++++++++++++++++++++++++++++++++++--
22 1 file changed, 39 insertions(+), 2 deletions(-)
24 diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
25 index d8165878..b0e8eee7 100644
26 --- a/builtin/pack-objects.c
27 +++ b/builtin/pack-objects.c
29 #include "reachable.h"
30 #include "sha1-array.h"
31 #include "argv-array.h"
33 +# include <sys/types.h>
34 +# include <sys/sysctl.h>
35 +# include <AvailabilityMacros.h>
38 static const char *pack_usage[] = {
39 N_("git pack-objects --stdout [options...] [< ref-list | < object-list]"),
40 @@ -73,7 +78,7 @@ static unsigned long delta_cache_size = 0;
41 static unsigned long max_delta_cache_size = 256 * 1024 * 1024;
42 static unsigned long cache_max_small_delta_size = 1000;
44 -static unsigned long window_memory_limit = 0;
45 +static unsigned long window_memory_limit = (unsigned long)-1L;
49 @@ -2562,6 +2567,34 @@ static void get_object_list(int ac, const char **av)
50 sha1_array_clear(&recent_objects);
53 +static void set_default_window_memory_limit(void)
55 +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1020
61 + window_memory_limit = 0;
62 +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1020
64 + mib[1] = HW_MEMSIZE;
65 + len = sizeof(memsize);
66 + if (!sysctl(mib, 2, &memsize, &len, NULL, 0)) {
68 + if (!delta_search_threads) /* --threads=0 means autodetect */
69 + delta_search_threads = online_cpus();
70 + if (delta_search_threads > 1)
71 + memsize /= (unsigned)delta_search_threads;
73 + if (memsize >= 2U * 1024U * 1024U * 1024U)
74 + memsize = 2U * 1024U * 1024U * 1024U - 1U;
76 + window_memory_limit = (unsigned long)memsize;
81 static int option_parse_index_version(const struct option *opt,
82 const char *arg, int unset)
84 @@ -2748,9 +2781,13 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
85 delta_search_threads = online_cpus();
88 - if (delta_search_threads != 1)
89 + if (delta_search_threads != 1) {
90 + delta_search_threads = 1;
91 warning("no threads support, ignoring --threads");
94 + if (window_memory_limit == (unsigned long)-1L)
95 + set_default_window_memory_limit();
96 if (!pack_to_stdout && !pack_size_limit)
97 pack_size_limit = pack_size_limit_cfg;
98 if (pack_to_stdout && pack_size_limit)