When there is memory pressure causing OOM, fully reclaim objects from the
global list that have not reached the threshold.
Signed-off-by: Lei Liu <liulei.rjpt@vivo.com>
---
include/linux/swapfile.h | 1 +
mm/page_alloc.c | 4 ++++
mm/swapfile.c | 2 +-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h
index dc43464cd838..04c660aae7a0 100644
--- a/include/linux/swapfile.h
+++ b/include/linux/swapfile.h
@@ -5,6 +5,7 @@
extern unsigned long generic_max_swapfile_size(void);
unsigned long arch_max_swapfile_size(void);
int add_to_swap_gather_cache(struct mm_struct *mm, swp_entry_t entry, int nr);
+void flush_cache_if_needed(bool check_ache_entries);
/* Maximum swapfile size supported for the arch (not inclusive). */
extern unsigned long swapfile_maximum_size;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d1d037f97c5f..7c5990c24df7 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -55,6 +55,7 @@
#include <linux/delayacct.h>
#include <linux/cacheinfo.h>
#include <linux/pgalloc_tag.h>
+#include <linux/swapfile.h>
#include <asm/div64.h>
#include "internal.h"
#include "shuffle.h"
@@ -3967,6 +3968,9 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
*did_some_progress = 0;
+ /* flash async swap cache pool */
+ flush_cache_if_needed(false);
+
/*
* Acquire the oom lock. If that fails, somebody else is
* making progress for us.
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 7c69e726b075..26640ec34fc6 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -229,7 +229,7 @@ static void async_release_func(struct work_struct *work)
kfree(work);
}
-static void flush_cache_if_needed(bool check_cache_count)
+void flush_cache_if_needed(bool check_cache_count)
{
struct work_struct *release_work;
--
2.34.1
Hi Lei, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] url: https://github.com/intel-lab-lkp/linux/commits/Lei-Liu/mm-swap-Gather-swap-entries-and-batch-async-release-core/20250909-145620 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20250909065349.574894-3-liulei.rjpt%40vivo.com patch subject: [PATCH v0 2/2] mm: swap: Forced swap entries release under memory pressure config: sparc-randconfig-002-20250910 (https://download.01.org/0day-ci/archive/20250910/202509101302.pptHT8X8-lkp@intel.com/config) compiler: sparc64-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250910/202509101302.pptHT8X8-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202509101302.pptHT8X8-lkp@intel.com/ All errors (new ones prefixed by >>): sparc64-linux-ld: kernel/exit.o: in function `do_exit': exit.c:(.text+0x19f0): undefined reference to `exiting_task_count' sparc64-linux-ld: exit.c:(.text+0x1a14): undefined reference to `exiting_task_count' sparc64-linux-ld: exit.c:(.text+0x2124): undefined reference to `exiting_task_count' sparc64-linux-ld: mm/memory.o: in function `unmap_page_range': memory.c:(.text+0x46a4): undefined reference to `add_to_swap_gather_cache' sparc64-linux-ld: mm/page_alloc.o: in function `__alloc_pages_slowpath.constprop.124': >> page_alloc.c:(.text+0xb44c): undefined reference to `flush_cache_if_needed' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.