linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tomohiro Misono <misono.tomohiro@fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: jiaqiyan@google.com, misono.tomohiro@fujitsu.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] mm: memory-failure: add soft-offline stat in mf_stats
Date: Thu, 21 Nov 2024 04:55:04 +0000	[thread overview]
Message-ID: <20241121045504.2233544-1-misono.tomohiro@fujitsu.com> (raw)

commit 44b8f8bf2438 ("mm: memory-failure: add memory failure stats
to sysfs") introduces per NUMA memory error stats which show
breakdown of HardwareCorrupted of /proc/meminfo in
/sys/devices/system/node/nodeX/memory_failure.

However, HardwareCorrupted also counts soft-offline pages. So, add
soft-offline stats in mf_stats too to represent more accurate status.

This updates total count as:
  total = recovered + ignored + failed + delayed + soft_offline

Test example:
1) # grep HardwareCorrupted /proc/meminfo
     HardwareCorrupted:     0 kB
2) soft-offline 1 page by madvise(MADV_SOFT_OFFLINE)
3) # grep HardwareCorrupted /proc/meminfo
     HardwareCorrupted:     4 kB
   # grep -r "" /sys/devices/system/node/node0/memory_failure
   /sys/devices/system/node/node0/memory_failure/total:1
   /sys/devices/system/node/node0/memory_failure/soft_offline:1
   /sys/devices/system/node/node0/memory_failure/recovered:0
   /sys/devices/system/node/node0/memory_failure/ignored:0
   /sys/devices/system/node/node0/memory_failure/failed:0
   /sys/devices/system/node/node0/memory_failure/delayed:0

Signed-off-by: Tomohiro Misono <misono.tomohiro@fujitsu.com>
---
Hello

This is RFC because I'm not sure adding SOFT_OFFLINE in enum
mf_result is a right approach. Also, maybe is it better to move
update_per_node_mf_stats() into num_poisoned_pages_inc()?

I omitted some cleanups and sysfs doc update in this version to
highlight changes. I'd appreciate any suggestions.

Regards,
Tomohiro Misono

 include/linux/mm.h     | 2 ++
 include/linux/mmzone.h | 4 +++-
 mm/memory-failure.c    | 9 +++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 5d6cd523c7c0..7f93f6883760 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3991,6 +3991,8 @@ enum mf_result {
 	MF_FAILED,	/* Error: handling failed */
 	MF_DELAYED,	/* Will be handled later */
 	MF_RECOVERED,	/* Successfully recovered */
+
+	MF_RES_SOFT_OFFLINE, /* Soft-offline */
 };
 
 enum mf_action_page_type {
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index b36124145a16..6a030610cba3 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1282,13 +1282,15 @@ struct memory_failure_stats {
 	/*
 	 * Recovery results of poisoned raw pages handled by memory_failure,
 	 * in sync with mf_result.
-	 * total = ignored + failed + delayed + recovered.
+	 * total = ignored + failed + delayed + recovered + soft_offline.
 	 * total * PAGE_SIZE * #nodes = /proc/meminfo/HardwareCorrupted.
 	 */
 	unsigned long ignored;
 	unsigned long failed;
 	unsigned long delayed;
 	unsigned long recovered;
+
+	unsigned long soft_offline;
 };
 #endif
 
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index a7b8ccd29b6f..02f845a222cc 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -109,6 +109,7 @@ MF_ATTR_RO(ignored);
 MF_ATTR_RO(failed);
 MF_ATTR_RO(delayed);
 MF_ATTR_RO(recovered);
+MF_ATTR_RO(soft_offline);
 
 static struct attribute *memory_failure_attr[] = {
 	&dev_attr_total.attr,
@@ -116,6 +117,7 @@ static struct attribute *memory_failure_attr[] = {
 	&dev_attr_failed.attr,
 	&dev_attr_delayed.attr,
 	&dev_attr_recovered.attr,
+	&dev_attr_soft_offline.attr,
 	NULL,
 };
 
@@ -185,6 +187,9 @@ static int __page_handle_poison(struct page *page)
 	return ret;
 }
 
+static void update_per_node_mf_stats(unsigned long pfn,
+		enum mf_result result);
+
 static bool page_handle_poison(struct page *page, bool hugepage_or_freepage, bool release)
 {
 	if (hugepage_or_freepage) {
@@ -208,6 +213,7 @@ static bool page_handle_poison(struct page *page, bool hugepage_or_freepage, boo
 		put_page(page);
 	page_ref_inc(page);
 	num_poisoned_pages_inc(page_to_pfn(page));
+	update_per_node_mf_stats(page_to_pfn(page), MF_RES_SOFT_OFFLINE);
 
 	return true;
 }
@@ -1314,6 +1320,9 @@ static void update_per_node_mf_stats(unsigned long pfn,
 	case MF_RECOVERED:
 		++mf_stats->recovered;
 		break;
+	case MF_RES_SOFT_OFFLINE:
+		++mf_stats->soft_offline;
+		break;
 	default:
 		WARN_ONCE(1, "Memory failure: mf_result=%d is not properly handled", result);
 		break;
-- 
2.34.1



             reply	other threads:[~2024-11-21  4:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-21  4:55 Tomohiro Misono [this message]
2024-11-26  3:09 ` Miaohe Lin
2024-11-27  2:32   ` Tomohiro Misono (Fujitsu)
2024-11-27  7:06     ` Jiaqi Yan
2024-11-28  5:46       ` Tomohiro Misono (Fujitsu)
2024-11-29  7:07         ` Miaohe Lin
2024-11-29  8:26           ` Tomohiro Misono (Fujitsu)
2024-11-29  9:07             ` Miaohe Lin
2024-12-07  0:17           ` jane.chu
2024-12-10  8:46             ` Tomohiro Misono (Fujitsu)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241121045504.2233544-1-misono.tomohiro@fujitsu.com \
    --to=misono.tomohiro@fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=jiaqiyan@google.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nao.horiguchi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox