mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-02 12:57:14 -05:00
Adds a workaround to avoid the OOM killer in Linux.
This commit is contained in:
parent
026954e41e
commit
89339e24d3
1 changed files with 10 additions and 1 deletions
11
util.c
11
util.c
|
|
@ -669,10 +669,19 @@ void* malloc_nofail(size_t size)
|
||||||
void* ptr = malloc(size);
|
void* ptr = malloc(size);
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
fprintf(stderr, "Low memory\n");
|
/* don't use printf to avoid any possible extra allocation */
|
||||||
|
write(2, "Low Memory\n", 11);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Here we preinitialize the memory to ensure that the OS is really allocating it */
|
||||||
|
/* and not only reserving the addressable space. */
|
||||||
|
/* Otherwise we are risking that the OOM (Out Of Memory) killer in Linux will kill the process. */
|
||||||
|
/* Filling the memory doesn't ensure to disable OOM, but it increase a lot the chances to */
|
||||||
|
/* get a real error from malloc() instead than a process killed. */
|
||||||
|
/* Note that calloc() doesn't have the same effect. */
|
||||||
|
memset(ptr, 0xA5, size);
|
||||||
|
|
||||||
mcounter += size;
|
mcounter += size;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue