xref: /openbmc/linux/fs/xfs/kmem.c (revision 808709d7)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #include "xfs.h"
7 #include <linux/backing-dev.h>
8 #include "xfs_message.h"
9 #include "xfs_trace.h"
10 
11 void *
12 kmem_alloc(size_t size, xfs_km_flags_t flags)
13 {
14 	int	retries = 0;
15 	gfp_t	lflags = kmem_flags_convert(flags);
16 	void	*ptr;
17 
18 	trace_kmem_alloc(size, flags, _RET_IP_);
19 
20 	do {
21 		ptr = kmalloc(size, lflags);
22 		if (ptr || (flags & KM_MAYFAIL))
23 			return ptr;
24 		if (!(++retries % 100))
25 			xfs_err(NULL,
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);
30 	} while (1);
31 }
32