[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7e533422-1707-4fea-9350-0e832cf24a83@redhat.com>
Date: Thu, 16 Oct 2025 12:46:55 +0200
From: David Hildenbrand <david@...hat.com>
To: Longlong Xia <xialonglong2025@....com>, linmiaohe@...wei.com,
lance.yang@...ux.dev
Cc: markus.elfring@....de, nao.horiguchi@...il.com,
akpm@...ux-foundation.org, wangkefeng.wang@...wei.com, qiuxu.zhuo@...el.com,
xu.xin16@....com.cn, linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v2 0/1] mm/ksm: recover from memory failure on KSM page by
migrating to healthy duplicate
On 16.10.25 12:18, Longlong Xia wrote:
> When a hardware memory error occurs on a KSM page, the current
> behavior is to kill all processes mapping that page. This can
> be overly aggressive when KSM has multiple duplicate pages in
> a chain where other duplicates are still healthy.
>
> This patch introduces a recovery mechanism that attempts to
> migrate mappings from the failing KSM page to a newly
> allocated KSM page or another healthy duplicate already
> present in the same chain, before falling back to the
> process-killing procedure.
>
> The recovery process works as follows:
> 1. Identify if the failing KSM page belongs to a stable node chain.
> 2. Locate a healthy duplicate KSM page within the same chain.
> 3. For each process mapping the failing page:
> a. Attempt to allocate a new KSM page copy from healthy duplicate
> KSM page. If successful, migrate the mapping to this new KSM page.
> b. If allocation fails, migrate the mapping to the existing healthy
> duplicate KSM page.
> 4. If all migrations succeed, remove the failing KSM page from the chain.
> 5. Only if recovery fails (e.g., no healthy duplicate found or migration
> error) does the kernel fall back to killing the affected processes.
>
> The original idea came from Naoya Horiguchi.
> https://lore.kernel.org/all/20230331054243.GB1435482@hori.linux.bs1.fc.nec.co.jp/
>
> I test it with einj in physical machine x86_64 CPU Intel(R) Xeon(R) Gold 6430.
>
> test shell script
> modprobe einj 2>/dev/null
> echo 0x10 > /sys/kernel/debug/apei/einj/error_type
> echo $ADDRESS > /sys/kernel/debug/apei/einj/param1
> echo 0xfffffffffffff000 > /sys/kernel/debug/apei/einj/param2
> echo 1 > /sys/kernel/debug/apei/einj/error_inject
>
> FIRST WAY: allocate a new KSM page copy from healthy duplicate
> 1. alloc 1024 page with same content and enable KSM to merge
> after merge (same phy_addr only print once)
> virtual addr = 0x71582be00000 phy_addr =0x124802000
> virtual addr = 0x71582bf2c000 phy_addr =0x124902000
> virtual addr = 0x71582c026000 phy_addr =0x125402000
> virtual addr = 0x71582c120000 phy_addr =0x125502000
>
>
> 2. echo 0x124802000 > /sys/kernel/debug/apei/einj/param1
> virtual addr = 0x71582be00000 phy_addr =0x1363b1000 (new allocated)
> virtual addr = 0x71582bf2c000 phy_addr =0x124902000
> virtual addr = 0x71582c026000 phy_addr =0x125402000
> virtual addr = 0x71582c120000 phy_addr =0x125502000
>
>
> 3. echo 0x124902000 > /sys/kernel/debug/apei/einj/param1
> virtual addr = 0x71582be00000 phy_addr =0x1363b1000
> virtual addr = 0x71582bf2c000 phy_addr =0x13099a000 (new allocated)
> virtual addr = 0x71582c026000 phy_addr =0x125402000
> virtual addr = 0x71582c120000 phy_addr =0x125502000
>
> kernel-log:
> mce: [Hardware Error]: Machine check events logged
> ksm: recovery successful, no need to kill processes
> Memory failure: 0x124802: recovery action for dirty LRU page: Recovered
> Memory failure: 0x124802: recovery action for already poisoned page: Failed
> ksm: recovery successful, no need to kill processes
> Memory failure: 0x124902: recovery action for dirty LRU page: Recovered
> Memory failure: 0x124902: recovery action for already poisoned page: Failed
>
>
> SECOND WAY: Migrate the mapping to the existing healthy duplicate KSM page
> 1. alloc 1024 page with same content and enable KSM to merge
> after merge (same phy_addr only print once)
> virtual addr = 0x79a172000000 phy_addr =0x141802000
> virtual addr = 0x79a17212c000 phy_addr =0x141902000
> virtual addr = 0x79a172226000 phy_addr =0x13cc02000
> virtual addr = 0x79a172320000 phy_addr =0x13cd02000
>
> 2 echo 0x141802000 > /sys/kernel/debug/apei/einj/param1
> a.virtual addr = 0x79a172000000 phy_addr =0x13cd02000
> b.virtual addr = 0x79a17212c000 phy_addr =0x141902000
> c.virtual addr = 0x79a172226000 phy_addr =0x13cc02000
> d.virtual addr = 0x79a172320000 phy_addr =0x13cd02000 (share with a)
>
> 3.echo 0x141902000 > /sys/kernel/debug/apei/einj/param1
> a.virtual addr = 0x79a172000000 phy_addr =0x13cd02000
> b.virtual addr = 0x79a172032000 phy_addr =0x13cd02000 (share with a)
> c.virtual addr = 0x79a172226000 phy_addr =0x13cc02000
> d.virtual addr = 0x79a172320000 phy_addr =0x13cd02000 (share with a)
>
> 4. echo 0x13cd02000 > /sys/kernel/debug/apei/einj/param1
> a.virtual addr = 0x79a172000000 phy_addr =0x13cc02000
> b.virtual addr = 0x79a172032000 phy_addr =0x13cc02000 (share with a)
> c.virtual addr = 0x79a172226000 phy_addr =0x13cc02000 (share with a)
> d.virtual addr = 0x79a172320000 phy_addr =0x13cc02000 (share with a)
>
> 5. echo 0x13cc02000 > /sys/kernel/debug/apei/einj/param1
> Bus error (core dumped)
>
> kernel-log:
> mce: [Hardware Error]: Machine check events logged
> ksm: recovery successful, no need to kill processes
> Memory failure: 0x141802: recovery action for dirty LRU page: Recovered
> Memory failure: 0x141802: recovery action for already poisoned page: Failed
> ksm: recovery successful, no need to kill processes
> Memory failure: 0x141902: recovery action for dirty LRU page: Recovered
> Memory failure: 0x141902: recovery action for already poisoned page: Failed
> ksm: recovery successful, no need to kill processes
> Memory failure: 0x13cd02: recovery action for dirty LRU page: Recovered
> Memory failure: 0x13cd02: recovery action for already poisoned page: Failed
> Memory failure: 0x13cc02: recovery action for dirty LRU page: Recovered
> Memory failure: 0x13cc02: recovery action for already poisoned page: Failed
> MCE: Killing ksm_addr:5221 due to hardware memory corruption fault at 79a172000000
>
> ZERO PAGE TEST:
> when I test in physical machine x86_64 CPU Intel(R) Xeon(R) Gold 6430
> [shell]# ./einj.sh 0x193f908000
> ./einj.sh: line 25: echo: write error: Address already in use
>
> when I test in qemu-x86_64.
> Injecting memory failure at pfn 0x3a9d0c
> Memory failure: 0x3a9d0c: unhandlable page.
> Memory failure: 0x3a9d0c: recovery action for get hwpoison page: Ignored
>
> It seems return early before enter this patch's functions.
>
> Thanks for review and comments!
>
> Changes in v2:
>
> - Implemented a two-tier recovery strategy: preferring newly allocated
> pages over existing duplicates to avoid concentrating mappings on a
> single page suggested by David Hildenbrand
I also asked how relevant this is in practice [1]
"
But how realistic do we consider that in practice? We need quite a bunch
of processes to dedup the same page to end up getting duplicates in the
chain IIRC.
So isn't this rather an improvement only for less likely scenarios in
practice?
"
In particular for your test "alloc 1024 page with same content".
It certainly adds complexity, so we should clarify if this is really
worth it.
[1]
https://lore.kernel.org/all/8c4d8ebe-885e-40f0-a10e-7290067c7b96@redhat.com/
--
Cheers
David / dhildenb
Powered by blists - more mailing lists