[PATCH] xfs: allow kmem_zalloc_greedy to fail

From: Michal Hocko
Date: Thu Mar 02 2017 - 05:31:11 EST


Even though kmem_zalloc_greedy is documented it might fail the current
code doesn't really implement this properly and loops on the smallest
allowed size for ever. This is a problem because vzalloc might fail
permanently. Since 5d17a73a2ebe ("vmalloc: back off when the current
task is killed") such a failure is much more probable than it used to
be. Fix this by bailing out if the minimum size request failed.

This has been noticed by a hung generic/269 xfstest by Xiong Zhou.

Reported-by: Xiong Zhou <xzhou@xxxxxxxxxx>
Analyzed-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
fs/xfs/kmem.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
index 339c696bbc01..ee95f5c6db45 100644
--- a/fs/xfs/kmem.c
+++ b/fs/xfs/kmem.c
@@ -34,6 +34,8 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize)
size_t kmsize = maxsize;

while (!(ptr = vzalloc(kmsize))) {
+ if (kmsize == minsize)
+ break;
if ((kmsize >>= 1) <= minsize)
kmsize = minsize;
}
--
2.11.0

--
Michal Hocko
SUSE Labs