2018-06-06 10:42:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-11-02 11:58:39 +08:00
|
|
|
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2019-08-27 03:08:10 +08:00
|
|
|
#include "xfs.h"
|
2006-10-20 14:28:16 +08:00
|
|
|
#include <linux/backing-dev.h>
|
2011-03-07 07:00:35 +08:00
|
|
|
#include "xfs_message.h"
|
2019-08-27 03:08:10 +08:00
|
|
|
#include "xfs_trace.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void *
|
2012-04-02 18:24:04 +08:00
|
|
|
kmem_alloc(size_t size, xfs_km_flags_t flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-10-21 15:20:48 +08:00
|
|
|
int retries = 0;
|
|
|
|
gfp_t lflags = kmem_flags_convert(flags);
|
|
|
|
void *ptr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-08-27 03:08:10 +08:00
|
|
|
trace_kmem_alloc(size, flags, _RET_IP_);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
2010-01-21 05:55:30 +08:00
|
|
|
ptr = kmalloc(size, lflags);
|
2019-08-27 03:06:22 +08:00
|
|
|
if (ptr || (flags & KM_MAYFAIL))
|
2005-04-17 06:20:36 +08:00
|
|
|
return ptr;
|
|
|
|
if (!(++retries % 100))
|
2011-03-07 07:00:35 +08:00
|
|
|
xfs_err(NULL,
|
2015-10-12 13:04:45 +08:00
|
|
|
"%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
|
2015-10-12 12:41:29 +08:00
|
|
|
current->comm, current->pid,
|
2015-10-12 13:04:45 +08:00
|
|
|
(unsigned int)size, __func__, lflags);
|
2009-07-09 20:52:32 +08:00
|
|
|
congestion_wait(BLK_RW_ASYNC, HZ/50);
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (1);
|
|
|
|
}
|