From f32fe4d7d3c683d0f7a43a1fcbfabae77338b4dc Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Wed, 11 Oct 2023 16:56:04 +0530 Subject: [PATCH] lmkd: Ensure node stats are being parsed The kernel will print node stats within the first populated zone in the zoneinfo file. The LMKD tries parsing node stats when it reads the first "Node %d, zone %8s" line in zoneinfo. However if the first zone is empty, LMKD could iterate over to the next populated zone i.e. the next "Node %d, zone %8s" line while attempting to read node stats. It thus reads the incorrect zone name for this next zone. To fix this, ensure whether node stats are indeed being parsed by checking for the " per node-stats" line. Bug: 292476676 Change-Id: I72cd111dac9032de506e1ab7f1c4dc96585a1e80 Signed-off-by: Jaskaran Singh --- lmkd.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lmkd.cpp b/lmkd.cpp index 0c5479c..ae982dc 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -94,6 +94,7 @@ static inline void trace_kill_end() {} #define PROC_STATUS_TGID_FIELD "Tgid:" #define PROC_STATUS_RSS_FIELD "VmRSS:" #define PROC_STATUS_SWAP_FIELD "VmSwap:" +#define NODE_STATS_MARKER " per-node stats" #define PERCEPTIBLE_APP_ADJ 200 #define PREVIOUS_APP_ADJ 700 @@ -1859,6 +1860,15 @@ static int zoneinfo_parse(struct zoneinfo *zi) { int node_id; if (sscanf(line, "Node %d, zone %" STRINGIFY(LINE_MAX) "s", &node_id, zone_name) == 2) { if (!node || node->id != node_id) { + line = strtok_r(NULL, "\n", &save_ptr); + if (strncmp(line, NODE_STATS_MARKER, strlen(NODE_STATS_MARKER)) != 0) { + /* + * per-node stats are only present in the first non-empty zone of + * the node. + */ + continue; + } + /* new node is found */ if (node) { node->zone_count = zone_idx + 1;