]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/xfs/kmem.c
fs: xfs: Remove KM_NOSLEEP and KM_SLEEP.
[mirror_ubuntu-hirsute-kernel.git] / fs / xfs / kmem.c
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
7b718769
NS
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
1da177e4 5 */
5b3cc15a 6#include <linux/sched/mm.h>
3fcfab16 7#include <linux/backing-dev.h>
1da177e4 8#include "kmem.h"
4f10700a 9#include "xfs_message.h"
1da177e4 10
1da177e4 11void *
77ba7877 12kmem_alloc(size_t size, xfs_km_flags_t flags)
1da177e4 13{
27496a8c
AV
14 int retries = 0;
15 gfp_t lflags = kmem_flags_convert(flags);
16 void *ptr;
1da177e4
LT
17
18 do {
bdfb0430 19 ptr = kmalloc(size, lflags);
707e0dda 20 if (ptr || (flags & KM_MAYFAIL))
1da177e4
LT
21 return ptr;
22 if (!(++retries % 100))
4f10700a 23 xfs_err(NULL,
847f9f68 24 "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
5bf97b1c 25 current->comm, current->pid,
847f9f68 26 (unsigned int)size, __func__, lflags);
8aa7e847 27 congestion_wait(BLK_RW_ASYNC, HZ/50);
1da177e4
LT
28 } while (1);
29}
30
fdd3ccee 31void *
cb0a8d23 32kmem_alloc_large(size_t size, xfs_km_flags_t flags)
fdd3ccee 33{
9ba1fb2c 34 unsigned nofs_flag = 0;
fdd3ccee 35 void *ptr;
ae687e58 36 gfp_t lflags;
fdd3ccee 37
cb0a8d23 38 ptr = kmem_alloc(size, flags | KM_MAYFAIL);
fdd3ccee
DC
39 if (ptr)
40 return ptr;
ae687e58
DC
41
42 /*
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
9ba1fb2c 46 * context via PF_MEMALLOC_NOFS to prevent memory reclaim re-entering
ae687e58
DC
47 * the filesystem here and potentially deadlocking.
48 */
9ba1fb2c
MH
49 if (flags & KM_NOFS)
50 nofs_flag = memalloc_nofs_save();
ae687e58
DC
51
52 lflags = kmem_flags_convert(flags);
cb0a8d23 53 ptr = __vmalloc(size, lflags, PAGE_KERNEL);
ae687e58 54
9ba1fb2c
MH
55 if (flags & KM_NOFS)
56 memalloc_nofs_restore(nofs_flag);
ae687e58
DC
57
58 return ptr;
fdd3ccee
DC
59}
60
1da177e4 61void *
664b60f6 62kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags)
1da177e4 63{
664b60f6
CH
64 int retries = 0;
65 gfp_t lflags = kmem_flags_convert(flags);
66 void *ptr;
1da177e4 67
664b60f6
CH
68 do {
69 ptr = krealloc(old, newsize, lflags);
707e0dda 70 if (ptr || (flags & KM_MAYFAIL))
664b60f6
CH
71 return ptr;
72 if (!(++retries % 100))
73 xfs_err(NULL,
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);
78 } while (1);
1da177e4
LT
79}
80
81void *
77ba7877 82kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
1da177e4 83{
27496a8c
AV
84 int retries = 0;
85 gfp_t lflags = kmem_flags_convert(flags);
86 void *ptr;
1da177e4
LT
87
88 do {
89 ptr = kmem_cache_alloc(zone, lflags);
707e0dda 90 if (ptr || (flags & KM_MAYFAIL))
1da177e4
LT
91 return ptr;
92 if (!(++retries % 100))
4f10700a 93 xfs_err(NULL,
5bf97b1c
TH
94 "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)",
95 current->comm, current->pid,
96 __func__, lflags);
8aa7e847 97 congestion_wait(BLK_RW_ASYNC, HZ/50);
1da177e4
LT
98 } while (1);
99}