1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
6 #include <linux/sched/mm.h>
7 #include <linux/backing-dev.h>
9 #include "xfs_message.h"
12 kmem_alloc(size_t size, xfs_km_flags_t flags)
15 gfp_t lflags = kmem_flags_convert(flags);
19 ptr = kmalloc(size, lflags);
20 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
22 if (!(++retries % 100))
24 "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
25 current->comm, current->pid,
26 (unsigned int)size, __func__, lflags);
27 congestion_wait(BLK_RW_ASYNC, HZ/50);
32 kmem_alloc_large(size_t size, xfs_km_flags_t flags)
34 unsigned nofs_flag = 0;
38 ptr = kmem_alloc(size, flags | KM_MAYFAIL);
43 * __vmalloc() will allocate data pages and auxillary structures (e.g.
44 * pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context
45 * here. Hence we need to tell memory reclaim that we are in such a
46 * context via PF_MEMALLOC_NOFS to prevent memory reclaim re-entering
47 * the filesystem here and potentially deadlocking.
50 nofs_flag = memalloc_nofs_save();
52 lflags = kmem_flags_convert(flags);
53 ptr = __vmalloc(size, lflags, PAGE_KERNEL);
56 memalloc_nofs_restore(nofs_flag);
62 kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags)
65 gfp_t lflags = kmem_flags_convert(flags);
69 ptr = krealloc(old, newsize, lflags);
70 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
72 if (!(++retries % 100))
74 "%s(%u) possible memory allocation deadlock size %zu in %s (mode:0x%x)",
75 current->comm, current->pid,
76 newsize, __func__, lflags);
77 congestion_wait(BLK_RW_ASYNC, HZ/50);
82 kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
85 gfp_t lflags = kmem_flags_convert(flags);
89 ptr = kmem_cache_alloc(zone, lflags);
90 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
92 if (!(++retries % 100))
94 "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)",
95 current->comm, current->pid,
97 congestion_wait(BLK_RW_ASYNC, HZ/50);