Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Dave Chinner | 0ad9568 | 2019-08-26 12:08:10 -0700 | [diff] [blame] | 6 | #include "xfs.h" |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 7 | #include "xfs_message.h" |
Dave Chinner | 0ad9568 | 2019-08-26 12:08:10 -0700 | [diff] [blame] | 8 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | void * |
Al Viro | 77ba787 | 2012-04-02 06:24:04 -0400 | [diff] [blame] | 11 | kmem_alloc(size_t size, xfs_km_flags_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | { |
Al Viro | 27496a8 | 2005-10-21 03:20:48 -0400 | [diff] [blame] | 13 | int retries = 0; |
| 14 | gfp_t lflags = kmem_flags_convert(flags); |
| 15 | void *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Dave Chinner | 0ad9568 | 2019-08-26 12:08:10 -0700 | [diff] [blame] | 17 | trace_kmem_alloc(size, flags, _RET_IP_); |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | do { |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 20 | ptr = kmalloc(size, lflags); |
Tetsuo Handa | 707e0dd | 2019-08-26 12:06:22 -0700 | [diff] [blame] | 21 | if (ptr || (flags & KM_MAYFAIL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | return ptr; |
| 23 | if (!(++retries % 100)) |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 24 | xfs_err(NULL, |
Eric Sandeen | 847f9f6 | 2015-10-12 16:04:45 +1100 | [diff] [blame] | 25 | "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)", |
Tetsuo Handa | 5bf97b1 | 2015-10-12 15:41:29 +1100 | [diff] [blame] | 26 | current->comm, current->pid, |
Eric Sandeen | 847f9f6 | 2015-10-12 16:04:45 +1100 | [diff] [blame] | 27 | (unsigned int)size, __func__, lflags); |
NeilBrown | 4034247 | 2022-01-14 14:07:14 -0800 | [diff] [blame] | 28 | memalloc_retry_wait(lflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } while (1); |
| 30 | } |