mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
Retry memory allocation failures
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
a6390a8012
commit
617dc6dd68
@ -16,20 +16,23 @@
|
||||
|
||||
static inline void *kmalloc(size_t size, gfp_t flags)
|
||||
{
|
||||
unsigned i = 0;
|
||||
void *p;
|
||||
|
||||
run_shrinkers();
|
||||
do {
|
||||
run_shrinkers();
|
||||
|
||||
if (size) {
|
||||
size_t alignment = min(rounddown_pow_of_two(size), (size_t)PAGE_SIZE);
|
||||
alignment = max(sizeof(void *), alignment);
|
||||
if (posix_memalign(&p, alignment, size))
|
||||
p = NULL;
|
||||
} else {
|
||||
p = malloc(0);
|
||||
}
|
||||
if (p && (flags & __GFP_ZERO))
|
||||
memset(p, 0, size);
|
||||
if (size) {
|
||||
size_t alignment = min(rounddown_pow_of_two(size), (size_t)PAGE_SIZE);
|
||||
alignment = max(sizeof(void *), alignment);
|
||||
if (posix_memalign(&p, alignment, size))
|
||||
p = NULL;
|
||||
} else {
|
||||
p = malloc(0);
|
||||
}
|
||||
if (p && (flags & __GFP_ZERO))
|
||||
memset(p, 0, size);
|
||||
} while (!p && i++ < 10);
|
||||
|
||||
return p;
|
||||
}
|
||||
@ -38,8 +41,6 @@ static inline void *krealloc(void *old, size_t size, gfp_t flags)
|
||||
{
|
||||
void *new;
|
||||
|
||||
run_shrinkers();
|
||||
|
||||
new = kmalloc(size, flags);
|
||||
if (!new)
|
||||
return NULL;
|
||||
@ -74,13 +75,16 @@ static inline void *krealloc(void *old, size_t size, gfp_t flags)
|
||||
static inline struct page *alloc_pages(gfp_t flags, unsigned int order)
|
||||
{
|
||||
size_t size = PAGE_SIZE << order;
|
||||
unsigned i = 0;
|
||||
void *p;
|
||||
|
||||
run_shrinkers();
|
||||
do {
|
||||
run_shrinkers();
|
||||
|
||||
p = aligned_alloc(PAGE_SIZE, size);
|
||||
if (p && (flags & __GFP_ZERO))
|
||||
memset(p, 0, size);
|
||||
p = aligned_alloc(PAGE_SIZE, size);
|
||||
if (p && (flags & __GFP_ZERO))
|
||||
memset(p, 0, size);
|
||||
} while (!p && i++ < 10);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -14,18 +14,18 @@
|
||||
|
||||
static inline void *__vmalloc(unsigned long size, gfp_t gfp_mask)
|
||||
{
|
||||
unsigned i = 0;
|
||||
void *p;
|
||||
|
||||
size = round_up(size, PAGE_SIZE);
|
||||
|
||||
run_shrinkers();
|
||||
do {
|
||||
run_shrinkers();
|
||||
|
||||
p = aligned_alloc(PAGE_SIZE, size);
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
if (gfp_mask & __GFP_ZERO)
|
||||
memset(p, 0, size);
|
||||
p = aligned_alloc(PAGE_SIZE, size);
|
||||
if (p && gfp_mask & __GFP_ZERO)
|
||||
memset(p, 0, size);
|
||||
} while (!p && i++ < 10);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user