From: Sweet Tea Dorminy Date: Wed, 6 Apr 2022 18:24:18 +0000 (-0400) Subject: btrfs: wait between incomplete batch memory allocations X-Git-Tag: v6.6.17~7062^2~122 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=395cb57e85604715110bc28bd51bdf532394b68d;p=platform%2Fkernel%2Flinux-rpi.git btrfs: wait between incomplete batch memory allocations When allocating memory in a loop, each iteration should call memalloc_retry_wait() in order to prevent starving memory-freeing processes (and to mark where allocation loops are). Other filesystems do that as well. The bulk page allocation is the only place in btrfs with an allocation retry loop, so add an appropriate call to it. Signed-off-by: Sweet Tea Dorminy Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index cfcbfd5..50626f4 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -3153,6 +3154,9 @@ int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array) allocated = alloc_pages_bulk_array(GFP_NOFS, nr_pages, page_array); + if (allocated == nr_pages) + return 0; + /* * During this iteration, no page could be allocated, even * though alloc_pages_bulk_array() falls back to alloc_page() @@ -3160,6 +3164,8 @@ int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array) */ if (allocated == last) return -ENOMEM; + + memalloc_retry_wait(GFP_NOFS); } return 0; }