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()
This commit is contained in:
commit
128666753b
@ -2342,15 +2342,6 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
|
|||||||
free(array);
|
free(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void try_to_free_from_threads(size_t size)
|
|
||||||
{
|
|
||||||
packing_data_lock(&to_pack);
|
|
||||||
release_pack_memory(size);
|
|
||||||
packing_data_unlock(&to_pack);
|
|
||||||
}
|
|
||||||
|
|
||||||
static try_to_free_t old_try_to_free_routine;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The main object list is split into smaller lists, each is handed to
|
* The main object list is split into smaller lists, each is handed to
|
||||||
* one worker.
|
* one worker.
|
||||||
@ -2391,12 +2382,10 @@ static void init_threaded_search(void)
|
|||||||
pthread_mutex_init(&cache_mutex, NULL);
|
pthread_mutex_init(&cache_mutex, NULL);
|
||||||
pthread_mutex_init(&progress_mutex, NULL);
|
pthread_mutex_init(&progress_mutex, NULL);
|
||||||
pthread_cond_init(&progress_cond, NULL);
|
pthread_cond_init(&progress_cond, NULL);
|
||||||
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup_threaded_search(void)
|
static void cleanup_threaded_search(void)
|
||||||
{
|
{
|
||||||
set_try_to_free_routine(old_try_to_free_routine);
|
|
||||||
pthread_cond_destroy(&progress_cond);
|
pthread_cond_destroy(&progress_cond);
|
||||||
pthread_mutex_destroy(&cache_mutex);
|
pthread_mutex_destroy(&cache_mutex);
|
||||||
pthread_mutex_destroy(&progress_mutex);
|
pthread_mutex_destroy(&progress_mutex);
|
||||||
|
@ -818,9 +818,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
|||||||
int git_atexit(void (*handler)(void));
|
int git_atexit(void (*handler)(void));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*try_to_free_t)(size_t);
|
|
||||||
try_to_free_t set_try_to_free_routine(try_to_free_t);
|
|
||||||
|
|
||||||
static inline size_t st_add(size_t a, size_t b)
|
static inline size_t st_add(size_t a, size_t b)
|
||||||
{
|
{
|
||||||
if (unsigned_add_overflows(a, b))
|
if (unsigned_add_overflows(a, b))
|
||||||
|
18
packfile.c
18
packfile.c
@ -287,13 +287,6 @@ static int unuse_one_window(struct packed_git *current)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void release_pack_memory(size_t need)
|
|
||||||
{
|
|
||||||
size_t cur = pack_mapped;
|
|
||||||
while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
|
|
||||||
; /* nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
void close_pack_windows(struct packed_git *p)
|
void close_pack_windows(struct packed_git *p)
|
||||||
{
|
{
|
||||||
while (p->windows) {
|
while (p->windows) {
|
||||||
@ -710,23 +703,12 @@ void unuse_pack(struct pack_window **w_cursor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void try_to_free_pack_memory(size_t size)
|
|
||||||
{
|
|
||||||
release_pack_memory(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
|
struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
|
||||||
{
|
{
|
||||||
static int have_set_try_to_free_routine;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
size_t alloc;
|
size_t alloc;
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
|
||||||
if (!have_set_try_to_free_routine) {
|
|
||||||
have_set_try_to_free_routine = 1;
|
|
||||||
set_try_to_free_routine(try_to_free_pack_memory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure a corresponding .pack file exists and that
|
* Make sure a corresponding .pack file exists and that
|
||||||
* the index looks sane.
|
* the index looks sane.
|
||||||
|
@ -952,12 +952,8 @@ void *xmmap_gently(void *start, size_t length,
|
|||||||
|
|
||||||
mmap_limit_check(length);
|
mmap_limit_check(length);
|
||||||
ret = mmap(start, length, prot, flags, fd, offset);
|
ret = mmap(start, length, prot, flags, fd, offset);
|
||||||
if (ret == MAP_FAILED) {
|
if (ret == MAP_FAILED && !length)
|
||||||
if (!length)
|
ret = NULL;
|
||||||
return NULL;
|
|
||||||
release_pack_memory(length);
|
|
||||||
ret = mmap(start, length, prot, flags, fd, offset);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
trace.c
2
trace.c
@ -88,8 +88,6 @@ static int prepare_trace_line(const char *file, int line,
|
|||||||
if (!trace_want(key))
|
if (!trace_want(key))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
set_try_to_free_routine(NULL); /* is never reset */
|
|
||||||
|
|
||||||
/* unit tests may want to disable additional trace output */
|
/* unit tests may want to disable additional trace output */
|
||||||
if (trace_want(&trace_bare))
|
if (trace_want(&trace_bare))
|
||||||
return 1;
|
return 1;
|
||||||
|
63
wrapper.c
63
wrapper.c
@ -4,12 +4,6 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
static void do_nothing(size_t size)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void (*try_to_free_routine)(size_t size) = do_nothing;
|
|
||||||
|
|
||||||
static int memory_limit_check(size_t size, int gentle)
|
static int memory_limit_check(size_t size, int gentle)
|
||||||
{
|
{
|
||||||
static size_t limit = 0;
|
static size_t limit = 0;
|
||||||
@ -30,24 +24,11 @@ static int memory_limit_check(size_t size, int gentle)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try_to_free_t set_try_to_free_routine(try_to_free_t routine)
|
|
||||||
{
|
|
||||||
try_to_free_t old = try_to_free_routine;
|
|
||||||
if (!routine)
|
|
||||||
routine = do_nothing;
|
|
||||||
try_to_free_routine = routine;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *xstrdup(const char *str)
|
char *xstrdup(const char *str)
|
||||||
{
|
{
|
||||||
char *ret = strdup(str);
|
char *ret = strdup(str);
|
||||||
if (!ret) {
|
if (!ret)
|
||||||
try_to_free_routine(strlen(str) + 1);
|
die("Out of memory, strdup failed");
|
||||||
ret = strdup(str);
|
|
||||||
if (!ret)
|
|
||||||
die("Out of memory, strdup failed");
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,19 +42,13 @@ static void *do_xmalloc(size_t size, int gentle)
|
|||||||
if (!ret && !size)
|
if (!ret && !size)
|
||||||
ret = malloc(1);
|
ret = malloc(1);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
try_to_free_routine(size);
|
if (!gentle)
|
||||||
ret = malloc(size);
|
die("Out of memory, malloc failed (tried to allocate %lu bytes)",
|
||||||
if (!ret && !size)
|
(unsigned long)size);
|
||||||
ret = malloc(1);
|
else {
|
||||||
if (!ret) {
|
error("Out of memory, malloc failed (tried to allocate %lu bytes)",
|
||||||
if (!gentle)
|
(unsigned long)size);
|
||||||
die("Out of memory, malloc failed (tried to allocate %lu bytes)",
|
return NULL;
|
||||||
(unsigned long)size);
|
|
||||||
else {
|
|
||||||
error("Out of memory, malloc failed (tried to allocate %lu bytes)",
|
|
||||||
(unsigned long)size);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef XMALLOC_POISON
|
#ifdef XMALLOC_POISON
|
||||||
@ -138,14 +113,8 @@ void *xrealloc(void *ptr, size_t size)
|
|||||||
ret = realloc(ptr, size);
|
ret = realloc(ptr, size);
|
||||||
if (!ret && !size)
|
if (!ret && !size)
|
||||||
ret = realloc(ptr, 1);
|
ret = realloc(ptr, 1);
|
||||||
if (!ret) {
|
if (!ret)
|
||||||
try_to_free_routine(size);
|
die("Out of memory, realloc failed");
|
||||||
ret = realloc(ptr, size);
|
|
||||||
if (!ret && !size)
|
|
||||||
ret = realloc(ptr, 1);
|
|
||||||
if (!ret)
|
|
||||||
die("Out of memory, realloc failed");
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,14 +129,8 @@ void *xcalloc(size_t nmemb, size_t size)
|
|||||||
ret = calloc(nmemb, size);
|
ret = calloc(nmemb, size);
|
||||||
if (!ret && (!nmemb || !size))
|
if (!ret && (!nmemb || !size))
|
||||||
ret = calloc(1, 1);
|
ret = calloc(1, 1);
|
||||||
if (!ret) {
|
if (!ret)
|
||||||
try_to_free_routine(nmemb * size);
|
die("Out of memory, calloc failed");
|
||||||
ret = calloc(nmemb, size);
|
|
||||||
if (!ret && (!nmemb || !size))
|
|
||||||
ret = calloc(1, 1);
|
|
||||||
if (!ret)
|
|
||||||
die("Out of memory, calloc failed");
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user