linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] mm: memory-failure: add soft-offline stat in mf_stats
@ 2024-11-21  4:55 Tomohiro Misono
  2024-11-26  3:09 ` Miaohe Lin
  0 siblings, 1 reply; 10+ messages in thread
From: Tomohiro Misono @ 2024-11-21  4:55 UTC (permalink / raw)
  To: Andrew Morton, Miaohe Lin, Naoya Horiguchi
  Cc: jiaqiyan, misono.tomohiro, linux-mm, linux-kernel

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



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-12-10  8:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-21  4:55 [RFC PATCH] mm: memory-failure: add soft-offline stat in mf_stats Tomohiro Misono
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)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox