Merge branch 'stable/for-linus-5.15' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.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 */
0ad95687 6#include "xfs.h"
3fcfab16 7#include <linux/backing-dev.h>
4f10700a 8#include "xfs_message.h"
0ad95687 9#include "xfs_trace.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 17
0ad95687
DC
18 trace_kmem_alloc(size, flags, _RET_IP_);
19
1da177e4 20 do {
bdfb0430 21 ptr = kmalloc(size, lflags);
707e0dda 22 if (ptr || (flags & KM_MAYFAIL))
1da177e4
LT
23 return ptr;
24 if (!(++retries % 100))
4f10700a 25 xfs_err(NULL,
847f9f68 26 "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
5bf97b1c 27 current->comm, current->pid,
847f9f68 28 (unsigned int)size, __func__, lflags);
8aa7e847 29 congestion_wait(BLK_RW_ASYNC, HZ/50);
1da177e4
LT
30 } while (1);
31}