0010776
From c15da07526291a5c357010cb4aaf4bde6151e642 Mon Sep 17 00:00:00 2001
0010776
From: Johan Erlandsson <johan.erlandsson@sony.com>
0010776
Date: Wed, 19 Apr 2023 11:26:04 +0200
0010776
Subject: [PATCH 06/14] use NR_SWAPCACHE when nr_swapper_spaces isn't available
0010776
0010776
In 5.12 the following change was introduced:
0010776
b6038942480e ("mm: memcg: add swapcache stat for memcg v2")
0010776
0010776
Then the variable 'nr_swapper_spaces' is not read (unless
0010776
CONFIG_DEBUG_VM=y).  In GKI builds this variable is then optimized
0010776
out. But the same change provided a new way to obtain the same
0010776
information, using NR_SWAPCACHE.
0010776
0010776
Reported-by: xueguolun <xueguolun@xiaomi.com>
0010776
Signed-off-by: Johan Erlandsson <johan.erlandsson@sony.com>
0010776
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
0010776
---
0010776
 memory.c | 6 ++++--
0010776
 1 file changed, 4 insertions(+), 2 deletions(-)
0010776
0010776
diff --git a/memory.c b/memory.c
0010776
index 791194a405d4..b84e974a3325 100644
0010776
--- a/memory.c
0010776
+++ b/memory.c
0010776
@@ -8486,7 +8486,7 @@ dump_kmeminfo(void)
0010776
 	ulong hugetlb_total_pages, hugetlb_total_free_pages = 0;
0010776
 	int done_hugetlb_calc = 0; 
0010776
 	long nr_file_pages, nr_slab;
0010776
-	ulong swapper_space_nrpages;
0010776
+	long swapper_space_nrpages;
0010776
 	ulong pct;
0010776
 	uint tmp;
0010776
 	struct meminfo meminfo;
0010776
@@ -8609,7 +8609,9 @@ dump_kmeminfo(void)
0010776
 		char *swapper_space = GETBUF(SIZE(address_space));
0010776
 
0010776
 		swapper_space_nrpages = 0;
0010776
-		if (symbol_exists("nr_swapper_spaces") &&
0010776
+		if (dump_vm_stat("NR_SWAPCACHE", &swapper_space_nrpages, 0)) {
0010776
+			;
0010776
+		} else if (symbol_exists("nr_swapper_spaces") &&
0010776
 			(len = get_array_length("nr_swapper_spaces",
0010776
 				NULL, 0))) {
0010776
 			char *nr_swapper_space =
0010776
-- 
0010776
2.41.0
0010776