1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
7 #include <linux/backing-dev.h>
8 #include "xfs_message.h"
12 kmem_alloc(size_t size, xfs_km_flags_t flags)
15 gfp_t lflags = kmem_flags_convert(flags);
18 trace_kmem_alloc(size, flags, _RET_IP_);
21 ptr = kmalloc(size, lflags);
22 if (ptr || (flags & KM_MAYFAIL))
24 if (!(++retries % 100))
26 "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
27 current->comm, current->pid,
28 (unsigned int)size, __func__, lflags);
29 congestion_wait(BLK_RW_ASYNC, HZ/50);
34 kmem_alloc_large(size_t size, xfs_km_flags_t flags)
36 unsigned nofs_flag = 0;
40 trace_kmem_alloc_large(size, flags, _RET_IP_);
42 ptr = kmem_alloc(size, flags | KM_MAYFAIL);
47 * __vmalloc() will allocate data pages and auxillary structures (e.g.
48 * pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context
49 * here. Hence we need to tell memory reclaim that we are in such a
50 * context via PF_MEMALLOC_NOFS to prevent memory reclaim re-entering
51 * the filesystem here and potentially deadlocking.
54 nofs_flag = memalloc_nofs_save();
56 lflags = kmem_flags_convert(flags);
57 ptr = __vmalloc(size, lflags, PAGE_KERNEL);
60 memalloc_nofs_restore(nofs_flag);
66 kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags)
69 gfp_t lflags = kmem_flags_convert(flags);
72 trace_kmem_realloc(newsize, flags, _RET_IP_);
75 ptr = krealloc(old, newsize, lflags);
76 if (ptr || (flags & KM_MAYFAIL))
78 if (!(++retries % 100))
80 "%s(%u) possible memory allocation deadlock size %zu in %s (mode:0x%x)",
81 current->comm, current->pid,
82 newsize, __func__, lflags);
83 congestion_wait(BLK_RW_ASYNC, HZ/50);
88 kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
91 gfp_t lflags = kmem_flags_convert(flags);
94 trace_kmem_zone_alloc(kmem_cache_size(zone), flags, _RET_IP_);
96 ptr = kmem_cache_alloc(zone, lflags);
97 if (ptr || (flags & KM_MAYFAIL))
99 if (!(++retries % 100))
101 "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)",
102 current->comm, current->pid,
104 congestion_wait(BLK_RW_ASYNC, HZ/50);