From de17832e73a53e0d069099cb085b93bb02d6db70 Mon Sep 17 00:00:00 2001
From: Johan Erlandsson <johan.erlandsson@sony.com>
Date: Wed, 19 Apr 2023 11:26:04 +0200
Subject: [PATCH] read swapcache usage when nr_swapper_spaces isn't available

In 5.12 the following change was introduced:
b6038942480e574c697ea1a80019bbe586c1d654

Then the variable 'nr_swapper_spaces' is not read (unless
CONFIG_DEBUG_VM=y).  In GKI builds this variable is then optimized
out. But the same change provided a new way to obtain the same
information, using NR_SWAPCACHE.

Signed-off-by: Johan Erlandsson <johan.erlandsson@sony.com>
---
 memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index 791194a..439e6e3 100644
--- a/memory.c
+++ b/memory.c
@@ -8609,7 +8609,8 @@ dump_kmeminfo(void)
 		char *swapper_space = GETBUF(SIZE(address_space));
 
 		swapper_space_nrpages = 0;
-		if (symbol_exists("nr_swapper_spaces") &&
+		if (dump_vm_stat("NR_SWAPCACHE", &swapper_space_nrpages, 0)) {
+		} else if (symbol_exists("nr_swapper_spaces") &&
 			(len = get_array_length("nr_swapper_spaces",
 				NULL, 0))) {
 			char *nr_swapper_space =
-- 
2.42.0

