[RFC][PATCH 03/13] mm/vmscan: replace implicit RECLAIM_ZONE checks with explicit checks

From: Dave Hansen
Date: Mon Jan 25 2021 - 20:35:40 EST



From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>

RECLAIM_ZONE was assumed to be unused because it was never explicitly
used in the kernel. However, there were a number of places where it
was checked implicitly by checking 'node_reclaim_mode' for a zero
value.

These zero checks are not great because it is not obvious what a zero
mode *means* in the code. Replace them with a helper which makes it
more obvious: node_reclaim_enabled().

This helper also provides a handy place to explicitly check the
RECLAIM_ZONE bit itself. Check it explicitly there to make it more
obvious where the bit can affect behavior.

This should have no functional impact.

Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Reviewed-by: Ben Widawsky <ben.widawsky@xxxxxxxxx>
Acked-by: Christoph Lameter <cl@xxxxxxxxx>
Cc: Alex Shi <alex.shi@xxxxxxxxxxxxxxxxx>
Cc: "Tobin C. Harding" <tobin@xxxxxxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Huang Ying <ying.huang@xxxxxxxxx>
Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
Cc: Qian Cai <cai@xxxxxx>
Cc: Daniel Wagner <dwagner@xxxxxxx>
Cc: osalvador <osalvador@xxxxxxx>

--

Note: This is not cc'd to stable. It does not fix any bugs.
---

b/include/linux/swap.h | 7 +++++++
b/mm/khugepaged.c | 2 +-
b/mm/page_alloc.c | 2 +-
3 files changed, 9 insertions(+), 2 deletions(-)

diff -puN include/linux/swap.h~mm-vmscan-node_reclaim_mode_helper include/linux/swap.h
--- a/include/linux/swap.h~mm-vmscan-node_reclaim_mode_helper 2021-01-25 16:23:08.330866712 -0800
+++ b/include/linux/swap.h 2021-01-25 16:23:08.339866712 -0800
@@ -12,6 +12,7 @@
#include <linux/fs.h>
#include <linux/atomic.h>
#include <linux/page-flags.h>
+#include <uapi/linux/mempolicy.h>
#include <asm/page.h>

struct notifier_block;
@@ -380,6 +381,12 @@ extern int sysctl_min_slab_ratio;
#define node_reclaim_mode 0
#endif

+static inline bool node_reclaim_enabled(void)
+{
+ /* Is any node_reclaim_mode bit set? */
+ return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
+}
+
extern void check_move_unevictable_pages(struct pagevec *pvec);

extern int kswapd_run(int nid);
diff -puN mm/khugepaged.c~mm-vmscan-node_reclaim_mode_helper mm/khugepaged.c
--- a/mm/khugepaged.c~mm-vmscan-node_reclaim_mode_helper 2021-01-25 16:23:08.332866712 -0800
+++ b/mm/khugepaged.c 2021-01-25 16:23:08.340866712 -0800
@@ -797,7 +797,7 @@ static bool khugepaged_scan_abort(int ni
* If node_reclaim_mode is disabled, then no extra effort is made to
* allocate memory locally.
*/
- if (!node_reclaim_mode)
+ if (!node_reclaim_enabled())
return false;

/* If there is a count for this node already, it must be acceptable */
diff -puN mm/page_alloc.c~mm-vmscan-node_reclaim_mode_helper mm/page_alloc.c
--- a/mm/page_alloc.c~mm-vmscan-node_reclaim_mode_helper 2021-01-25 16:23:08.335866712 -0800
+++ b/mm/page_alloc.c 2021-01-25 16:23:08.342866712 -0800
@@ -3875,7 +3875,7 @@ retry:
if (alloc_flags & ALLOC_NO_WATERMARKS)
goto try_this_zone;

- if (node_reclaim_mode == 0 ||
+ if (!node_reclaim_enabled() ||
!zone_allows_reclaim(ac->preferred_zoneref->zone, zone))
continue;

_