Skip to content

Commit 1286667

Browse files
committed
Merge branch 'jk/drop-release-pack-memory'
xmalloc() used to have a mechanism to ditch memory and address space resources as the last resort upon seeing an allocation failure from the underlying malloc(), which made the code complex and thread-unsafe with dubious benefit, as major memory resource users already do limit their uses with various other mechanisms. It has been simplified away. * jk/drop-release-pack-memory: packfile: drop release_pack_memory()
2 parents 917a319 + 9827d4c commit 1286667

File tree

6 files changed

+15
-90
lines changed

6 files changed

+15
-90
lines changed

builtin/pack-objects.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,15 +2342,6 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
23422342
free(array);
23432343
}
23442344

2345-
static void try_to_free_from_threads(size_t size)
2346-
{
2347-
packing_data_lock(&to_pack);
2348-
release_pack_memory(size);
2349-
packing_data_unlock(&to_pack);
2350-
}
2351-
2352-
static try_to_free_t old_try_to_free_routine;
2353-
23542345
/*
23552346
* The main object list is split into smaller lists, each is handed to
23562347
* one worker.
@@ -2391,12 +2382,10 @@ static void init_threaded_search(void)
23912382
pthread_mutex_init(&cache_mutex, NULL);
23922383
pthread_mutex_init(&progress_mutex, NULL);
23932384
pthread_cond_init(&progress_cond, NULL);
2394-
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
23952385
}
23962386

23972387
static void cleanup_threaded_search(void)
23982388
{
2399-
set_try_to_free_routine(old_try_to_free_routine);
24002389
pthread_cond_destroy(&progress_cond);
24012390
pthread_mutex_destroy(&cache_mutex);
24022391
pthread_mutex_destroy(&progress_mutex);

git-compat-util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
818818
int git_atexit(void (*handler)(void));
819819
#endif
820820

821-
typedef void (*try_to_free_t)(size_t);
822-
try_to_free_t set_try_to_free_routine(try_to_free_t);
823-
824821
static inline size_t st_add(size_t a, size_t b)
825822
{
826823
if (unsigned_add_overflows(a, b))

packfile.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,6 @@ static int unuse_one_window(struct packed_git *current)
287287
return 0;
288288
}
289289

290-
void release_pack_memory(size_t need)
291-
{
292-
size_t cur = pack_mapped;
293-
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
294-
; /* nothing */
295-
}
296-
297290
void close_pack_windows(struct packed_git *p)
298291
{
299292
while (p->windows) {
@@ -710,23 +703,12 @@ void unuse_pack(struct pack_window **w_cursor)
710703
}
711704
}
712705

713-
static void try_to_free_pack_memory(size_t size)
714-
{
715-
release_pack_memory(size);
716-
}
717-
718706
struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
719707
{
720-
static int have_set_try_to_free_routine;
721708
struct stat st;
722709
size_t alloc;
723710
struct packed_git *p;
724711

725-
if (!have_set_try_to_free_routine) {
726-
have_set_try_to_free_routine = 1;
727-
set_try_to_free_routine(try_to_free_pack_memory);
728-
}
729-
730712
/*
731713
* Make sure a corresponding .pack file exists and that
732714
* the index looks sane.

sha1-file.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,12 +952,8 @@ void *xmmap_gently(void *start, size_t length,
952952

953953
mmap_limit_check(length);
954954
ret = mmap(start, length, prot, flags, fd, offset);
955-
if (ret == MAP_FAILED) {
956-
if (!length)
957-
return NULL;
958-
release_pack_memory(length);
959-
ret = mmap(start, length, prot, flags, fd, offset);
960-
}
955+
if (ret == MAP_FAILED && !length)
956+
ret = NULL;
961957
return ret;
962958
}
963959

trace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ static int prepare_trace_line(const char *file, int line,
8888
if (!trace_want(key))
8989
return 0;
9090

91-
set_try_to_free_routine(NULL); /* is never reset */
92-
9391
/* unit tests may want to disable additional trace output */
9492
if (trace_want(&trace_bare))
9593
return 1;

wrapper.c

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
#include "cache.h"
55
#include "config.h"
66

7-
static void do_nothing(size_t size)
8-
{
9-
}
10-
11-
static void (*try_to_free_routine)(size_t size) = do_nothing;
12-
137
static int memory_limit_check(size_t size, int gentle)
148
{
159
static size_t limit = 0;
@@ -30,24 +24,11 @@ static int memory_limit_check(size_t size, int gentle)
3024
return 0;
3125
}
3226

33-
try_to_free_t set_try_to_free_routine(try_to_free_t routine)
34-
{
35-
try_to_free_t old = try_to_free_routine;
36-
if (!routine)
37-
routine = do_nothing;
38-
try_to_free_routine = routine;
39-
return old;
40-
}
41-
4227
char *xstrdup(const char *str)
4328
{
4429
char *ret = strdup(str);
45-
if (!ret) {
46-
try_to_free_routine(strlen(str) + 1);
47-
ret = strdup(str);
48-
if (!ret)
49-
die("Out of memory, strdup failed");
50-
}
30+
if (!ret)
31+
die("Out of memory, strdup failed");
5132
return ret;
5233
}
5334

@@ -61,19 +42,13 @@ static void *do_xmalloc(size_t size, int gentle)
6142
if (!ret && !size)
6243
ret = malloc(1);
6344
if (!ret) {
64-
try_to_free_routine(size);
65-
ret = malloc(size);
66-
if (!ret && !size)
67-
ret = malloc(1);
68-
if (!ret) {
69-
if (!gentle)
70-
die("Out of memory, malloc failed (tried to allocate %lu bytes)",
71-
(unsigned long)size);
72-
else {
73-
error("Out of memory, malloc failed (tried to allocate %lu bytes)",
74-
(unsigned long)size);
75-
return NULL;
76-
}
45+
if (!gentle)
46+
die("Out of memory, malloc failed (tried to allocate %lu bytes)",
47+
(unsigned long)size);
48+
else {
49+
error("Out of memory, malloc failed (tried to allocate %lu bytes)",
50+
(unsigned long)size);
51+
return NULL;
7752
}
7853
}
7954
#ifdef XMALLOC_POISON
@@ -138,14 +113,8 @@ void *xrealloc(void *ptr, size_t size)
138113
ret = realloc(ptr, size);
139114
if (!ret && !size)
140115
ret = realloc(ptr, 1);
141-
if (!ret) {
142-
try_to_free_routine(size);
143-
ret = realloc(ptr, size);
144-
if (!ret && !size)
145-
ret = realloc(ptr, 1);
146-
if (!ret)
147-
die("Out of memory, realloc failed");
148-
}
116+
if (!ret)
117+
die("Out of memory, realloc failed");
149118
return ret;
150119
}
151120

@@ -160,14 +129,8 @@ void *xcalloc(size_t nmemb, size_t size)
160129
ret = calloc(nmemb, size);
161130
if (!ret && (!nmemb || !size))
162131
ret = calloc(1, 1);
163-
if (!ret) {
164-
try_to_free_routine(nmemb * size);
165-
ret = calloc(nmemb, size);
166-
if (!ret && (!nmemb || !size))
167-
ret = calloc(1, 1);
168-
if (!ret)
169-
die("Out of memory, calloc failed");
170-
}
132+
if (!ret)
133+
die("Out of memory, calloc failed");
171134
return ret;
172135
}
173136

0 commit comments

Comments
 (0)