mm/page_alloc: make percpu_pagelist_high_fraction reads lock-free
Subsystems (2)
PATCH 1/1 mm/page_alloc: make percpu_pagelist_high_fraction reads lock-free
When page isolation loops indefinitely during memory offline, reading /proc/sys/vm/percpu_pagelist_high_fraction blocks on pcp_batch_high_lock, causing hung task warnings.
Make procfs reads lock-free since percpu_pagelist_high_fraction is a simple integer with naturally atomic reads, writers still serialize via the mutex.
This prevents hung task warnings when reading the procfs file during long-running memory offline operations.
--- mm/page_alloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/page_alloc.c +4 -1
@@ -6611,11 +6611,14 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *int old_percpu_pagelist_high_fraction;int ret; +if (!write) +return proc_dointvec_minmax (table, write, buffer, length, ppos); +mutex_lock (&pcp_batch_high_lock); old_percpu_pagelist_high_fraction = percpu_pagelist_high_fraction; ret =proc_dointvec_minmax (table, write, buffer, length, ppos); -if (!write || ret <0 ) +if (ret <0 ) goto out;/* Sanity checking to avoid pcp imbalance */
Signature · 1 line
2.50.1
Andrew Morton
maintainerQuoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.
That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
It would be better to address the lengthy hold time rather that having to work around it in one impacted site.
Quoted 16 lines
Make procfs reads lock-free since
percpu_pagelist_high_fractionis a simple integer with naturally atomic reads, writers still serialize via the mutex.This prevents hung task warnings when reading the procfs file during long-running memory offline operations.
...
mm/page_alloc.c +2
-0@@ -6611,11 +6611,14 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *int old_percpu_pagelist_high_fraction;int ret; +if (!write) +return proc_dointvec_minmax (table, write, buffer, length, ppos);
mm/page_alloc.c static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table * · line 6624
Quoted 10 lines
mm/page_alloc.c +2
-1+mutex_lock (&pcp_batch_high_lock); old_percpu_pagelist_high_fraction = percpu_pagelist_high_fraction; ret =proc_dointvec_minmax (table, write, buffer, length, ppos); -if (!write || ret <0 ) +if (ret <0 ) goto out;/* Sanity checking to avoid pcp imbalance */
That being said, I'll grab the patch and shall put a cc:stable on it, see what people think about this hold-time issue.
Michal Hocko
reviewerLet me add Oscar and David.
Quoted 10 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
pcp_batch_high_lock is not taken in any performance critical path. It is true that memory offlining can take long when memory is not free but I am not sure we can do much better. I guess we could check contention on the lock and drop it to make cpu hotplug events and sysctl_min_unmapped_ratio_sysctl_handler smoother. The question is whether this is a practical problem hit in real life.
Quoted 32 lines
It would be better to address the lengthy hold time rather that having to work around it in one impacted site.
Quoted 16 lines
Make procfs reads lock-free since
percpu_pagelist_high_fractionis a simple integer with naturally atomic reads, writers still serialize via the mutex.This prevents hung task warnings when reading the procfs file during long-running memory offline operations.
...
mm/page_alloc.c +2
-0@@ -6611,11 +6611,14 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *int old_percpu_pagelist_high_fraction;int ret; +if (!write) +return proc_dointvec_minmax (table, write, buffer, length, ppos);mm/page_alloc.c static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table * · line 6624
Quoted 10 lines
mm/page_alloc.c +2
-1+mutex_lock (&pcp_batch_high_lock); old_percpu_pagelist_high_fraction = percpu_pagelist_high_fraction; ret =proc_dointvec_minmax (table, write, buffer, length, ppos); -if (!write || ret <0 ) +if (ret <0 ) goto out;/* Sanity checking to avoid pcp imbalance */ That being said, I'll grab the patch and shall put a cc:stable on it, see what people think about this hold-time issue.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 14 lines · Michal Hocko
Let me add Oscar and David.
Quoted 10 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
Quoted 7 lines
pcp_batch_high_lockis not taken in any performance critical path. It is true that memory offlining can take long when memory is not free but I am not sure we can do much better. I guess we could check contention on the lock and drop it to make cpu hotplug events andsysctl_min_unmapped_ratio_sysctl_handlersmoother. The question is whether this is a practical problem hit in real life.
I just today hit a scenario where offlining was blocked on migration failures that took an exceedingly long time to offline (many minutes) even on a relatively small block (256MB).
Now that I'm looking at the double-do-while loop in memory_hotplug.c
zone_pcp_disable(zone); /* (pcp_batch_high_lock) */
...
do {
do {
...
cond_resched();
ret = scan_movable_pages(pfn, end_pfn, &pfn);
if (!ret) {
/*
* TODO: fatal migration failures should bail
* out
*/
do_migrate_range(pfn, end_pfn);
}
} while (!ret);
} while (ret);...zone_pcp_enable(zone); /* (pcp_batch_high_lock) */
Maybe it's time to implement the bail out?
~Gregory
Michal Hocko
reviewerQuoted 45 lines · Gregory Price
Quoted 14 lines · Michal Hocko
Let me add Oscar and David.
Quoted 10 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
Quoted 7 lines
pcp_batch_high_lockis not taken in any performance critical path. It is true that memory offlining can take long when memory is not free but I am not sure we can do much better. I guess we could check contention on the lock and drop it to make cpu hotplug events andsysctl_min_unmapped_ratio_sysctl_handlersmoother. The question is whether this is a practical problem hit in real life.I just today hit a scenario where offlining was blocked on migration failures that took an exceedingly long time to offline (many minutes) even on a relatively small block (256MB).
Now that I'm looking at the double-do-while loop in
memory_hotplug.c
zone_pcp_disable(zone); /* (pcp_batch_high_lock) */
...do { do { ... cond_resched(); ret = scan_movable_pages(pfn, end_pfn, &pfn); if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); } } while (!ret); } while (ret);
Quoted 5 lines
...
zone_pcp_enable(zone); /* (pcp_batch_high_lock) */Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
Quoted 2 lines
~Gregory
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 50 lines · Michal Hocko
Quoted 49 lines · Gregory Price
Quoted 14 lines · Michal Hocko
Let me add Oscar and David.
Quoted 10 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
Quoted 7 lines
pcp_batch_high_lockis not taken in any performance critical path. It is true that memory offlining can take long when memory is not free but I am not sure we can do much better. I guess we could check contention on the lock and drop it to make cpu hotplug events andsysctl_min_unmapped_ratio_sysctl_handlersmoother. The question is whether this is a practical problem hit in real life.I just today hit a scenario where offlining was blocked on migration failures that took an exceedingly long time to offline (many minutes) even on a relatively small block (256MB).
Now that I'm looking at the double-do-while loop in
memory_hotplug.c
zone_pcp_disable(zone); /* (pcp_batch_high_lock) */
...do { do { ... cond_resched(); ret = scan_movable_pages(pfn, end_pfn, &pfn); if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); } } while (!ret); } while (ret);...
zone_pcp_enable(zone); /* (pcp_batch_high_lock) */
Quoted 4 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
Did we try offline a ZONE_MOVABLE block or a ZONE_NORMAL block? In case of ZONE_MOABLE, bailing out is not really the right thing to do.
Signature · 3 lines
Cheers David
Quoted 10 lines · David Hildenbrand (Red Hat)
Quoted 9 lines · Michal Hocko
Quoted 9 lines
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
Did we try offline a
ZONE_MOVABLEblock or aZONE_NORMALblock? In case ofZONE_MOABLE, bailing out is not really the right thing to do.
My transient failure (although i'm not sure it was actually transient, i killed it and retried after a few minutes and it succeeded immediately) was on a ZONE_MOVABLE block.
Kind of suggested to me there was some bad condition the resolved once I took a second to release the lock and try again.
Can't speak for Aboorva's situation.
~Gregory
Quoted 16 lines · Gregory Price
Quoted 15 lines · David Hildenbrand (Red Hat)
Quoted 13 lines · Michal Hocko
Quoted 10 lines
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }...
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
Quoted 7 lines
Quoted 3 lines
Did we try offline a
ZONE_MOVABLEblock or aZONE_NORMALblock? In case ofZONE_MOABLE, bailing out is not really the right thing to do.My transient failure (although i'm not sure it was actually transient, i killed it and retried after a few minutes and it succeeded immediately) was on a
ZONE_MOVABLEblock.
Okay, so that one should not bail out. Longterm pinnins must never end up on such memory, and if it happens, we have to identify why and fix it.
We have this known problem of "stream of short-term pinnings" that can temporarily turn memory effectively unmovable. Juan will talk about that at LPC [1].
We have another set of problematic cases (vmsplice(), fuse) but I would assume that these are not the cases you are hitting.
So not sure what exact problem you were hitting.
[1] https://lpc.events/event/19/contributions/2144/
Quoted 3 lines
Kind of suggested to me there was some bad condition the resolved once I took a second to release the lock and try again.
Hard to tell I'm afraid. Do you still have the dump_folio() calls we print when migration fails?
Signature · 3 lines
Cheers David
Quoted 6 lines · David Hildenbrand (Red Hat)
Quoted 4 lines · Gregory Price
My transient failure (although i'm not sure it was actually transient, i killed it and retried after a few minutes and it succeeded immediately) was on a
ZONE_MOVABLEblock.
Quoted 6 lines
Okay, so that one should not bail out. Longterm pinnins must never end up on such memory, and if it happens, we have to identify why and fix it.
We have this known problem of "stream of short-term pinnings" that can temporarily turn memory effectively unmovable. Juan will talk about that at LPC [1].
Nice, fun, good topic. Looking forward to Japan n_n
Quoted 4 lines
We have another set of problematic cases (
vmsplice(), fuse) but I would assume that these are not the cases you are hitting.
We do use fuse, but this system was relatively quiet when i tried this.
We do have some proactive reclaim / demotion going on, but i don't think it was that (see below).
Quoted 7 lines
Quoted 3 lines
Kind of suggested to me there was some bad condition the resolved once I took a second to release the lock and try again.
Hard to tell I'm afraid. Do you still have the
dump_folio()calls we print when migration fails?
What luck, I do! :D
And i just noticed it's the same page over and over
[ 3404.119270] migrating pfn c06f176 failed ret:1 [ 3404.129152] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.148284] memcg:ffff88842e855000 [ 3404.155834] aops:btree_aops ino:1 [ 3404.163193] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.185408] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.202603] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.219779] page dumped because: migration failure
[ 3404.230610] migrating pfn c06f176 failed ret:1 [ 3404.240483] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.259603] memcg:ffff88842e855000 [ 3404.267152] aops:btree_aops ino:1 [ 3404.274511] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.296716] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.313909] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.331102] page dumped because: migration failure
[ 3404.341778] migrating pfn c06f176 failed ret:1 [ 3404.351658] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.370781] memcg:ffff88842e855000 [ 3404.378331] aops:btree_aops ino:1 [ 3404.385687] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.407895] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.425073] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.442264] page dumped because: migration failure
[ 3404.452928] migrating pfn c06f176 failed ret:1 [ 3404.462809] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.481948] memcg:ffff88842e855000 [ 3404.489511] aops:btree_aops ino:1 [ 3404.496899] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.519128] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.536332] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.553534] page dumped because: migration failure
[ 3404.564200] migrating pfn c06f176 failed ret:1 [ 3404.574077] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.593208] memcg:ffff88842e855000 [ 3404.600769] aops:btree_aops ino:1 [ 3404.608138] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.630355] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.647558] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.664761] page dumped because: migration failure
Quoted 3 lines · Gregory Price
What luck, I do! :D
And i just noticed it's the same page over and over
Should have noted: 6.13.2
but it's kind of a frankenstein's 6.13.2 with stable backports, so I don't know what's been fixed between 6.13 and latest. If there are relevant patches I can search for whether we have them.
Quoted 9 lines
[ 3404.119270] migrating pfn c06f176 failed ret:1 [ 3404.129152] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.148284] memcg:ffff88842e855000 [ 3404.155834] aops:btree_aops ino:1 [ 3404.163193] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff) [ 3404.185408] raw: 17ffff066c00420c ffffc90066a13ca0 ffffc90066a13ca0 ffff88812b8502f8 [ 3404.202603] raw: 000000000ad28e5b ffff888859fd42d0 00000004ffffffff ffff88842e855000 [ 3404.219779] page dumped because: migration failure
~Gregory
Quoted 27 lines · Gregory Price
Quoted 6 lines · David Hildenbrand (Red Hat)
Quoted 4 lines · Gregory Price
My transient failure (although i'm not sure it was actually transient, i killed it and retried after a few minutes and it succeeded immediately) was on a
ZONE_MOVABLEblock.Quoted 6 lines
Okay, so that one should not bail out. Longterm pinnins must never end up on such memory, and if it happens, we have to identify why and fix it.
We have this known problem of "stream of short-term pinnings" that can temporarily turn memory effectively unmovable. Juan will talk about that at LPC [1].
Nice, fun, good topic. Looking forward to Japan
n_nQuoted 4 lines
We have another set of problematic cases (
vmsplice(), fuse) but I would assume that these are not the cases you are hitting.We do use fuse, but this system was relatively quiet when i tried this.
We do have some proactive reclaim / demotion going on, but i don't think it was that (see below).
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Kind of suggested to me there was some bad condition the resolved once I took a second to release the lock and try again.
Hard to tell I'm afraid. Do you still have the
dump_folio()calls we print when migration fails?What luck, I do! :D
:)
Quoted 6 lines
And i just noticed it's the same page over and over
[ 3404.119270] migrating pfn c06f176 failed ret:1 [ 3404.129152] page: refcount:4 mapcount:0 mapping:0000000061ca20ba index:0xad28e5b pfn:0xc06f176 [ 3404.148284] memcg:ffff88842e855000 [ 3404.155834] aops:btree_aops ino:1
Small folio. Not GUP-pinned (FOLL_PIN, otherwise our refcount would be >= 1024.
It could be ordinary GUP (FOLL_GET) e.g., from vmsplice or some older O_DIRECT user that was not converted to FOLL_PIN yet. But maybe it's just btrfs / something else that temporarily holds a folio reference.
Given that this is from 6.13 ... hard to tell :)
Quoted 1 line
[ 3404.163193] flags: 0x17ffff066c00420c(referenced|uptodate|workingset|private|node=1|zone=3|lastcpupid=0x1ffff)
Neither dirty nor under writeback.
Signature · 3 lines
Cheers David
Quoted 9 lines · Michal Hocko
Quoted 8 lines · Gregory Price
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }
Quoted 5 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
I see deep in migration code migrate_pages_batch() we would return "Some other failure" as fatal:
switch(rc) {
case -ENOMEM:
...
/* Note: some long-term pin handing is done here */
break;
case -EAGAIN:
...
break;
case 0:
...
list_move_tail(&folio->lru, &unmap_folios);
list_add_tail(&dst->lru, &dst_folios);
break;
default:
/*
* Permanent failure (-EBUSY, etc.):
* unlike -EAGAIN case, the failed folio is
* removed from migration folio list and not
* retried in the next outer loop.
*/
nr_failed++;
stats->nr_thp_failed += is_thp;
stats->nr_failed_pages += nr_pages;
break;
}So at a minimum we could at least check for !(ENOMEM,EAGAIN) I suppose?
It's unclear to me based on this code here how longerm pinning would return. Maybe David knows.
~Gregory
Quoted 45 lines · Gregory Price
Quoted 9 lines · Michal Hocko
Quoted 8 lines · Gregory Price
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }Quoted 5 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
I see deep in migration code
migrate_pages_batch()we would return "Some other failure" as fatal:switch(rc) { case -ENOMEM: ... /* Note: some long-term pin handing is done here */ break; case -EAGAIN: ... break; case 0: ... list_move_tail(&folio->lru, &unmap_folios); list_add_tail(&dst->lru, &dst_folios); break; default: /* * Permanent failure (-EBUSY, etc.): * unlike -EAGAIN case, the failed folio is * removed from migration folio list and not * retried in the next outer loop. */ nr_failed++; stats->nr_thp_failed += is_thp; stats->nr_failed_pages += nr_pages; break; }
Quoted 4 lines
So at a minimum we could at least check for !(ENOMEM,EAGAIN) I suppose?
It's unclear to me based on this code here how longerm pinning would return. Maybe David knows.
I would assume that additional references will always result in -EAGAIN. Remember that we cannot distinguish short-term pins from long-term pins.
We should never have longterm-pins on ZONE_MOVABLE, unless something broke that contract and needs to be fixed.
Signature · 3 lines
Cheers David
Michal Hocko
reviewerQuoted 48 lines · David Hildenbrand (Red Hat)
Quoted 47 lines · Gregory Price
Quoted 9 lines · Michal Hocko
Quoted 8 lines · Gregory Price
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }Quoted 5 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
I see deep in migration code
migrate_pages_batch()we would return "Some other failure" as fatal:switch(rc) { case -ENOMEM: ... /* Note: some long-term pin handing is done here */ break; case -EAGAIN: ... break; case 0: ... list_move_tail(&folio->lru, &unmap_folios); list_add_tail(&dst->lru, &dst_folios); break; default: /* * Permanent failure (-EBUSY, etc.): * unlike -EAGAIN case, the failed folio is * removed from migration folio list and not * retried in the next outer loop. */ nr_failed++; stats->nr_thp_failed += is_thp; stats->nr_failed_pages += nr_pages; break; }So at a minimum we could at least check for !(ENOMEM,EAGAIN) I suppose?
Quoted 8 lines
Quoted 2 lines
It's unclear to me based on this code here how longerm pinning would return. Maybe David knows.
I would assume that additional references will always result in
-EAGAIN. Remember that we cannot distinguish short-term pins from long-term pins.We should never have longterm-pins on
ZONE_MOVABLE, unless something broke that contract and needs to be fixed.
Right. But what should the hotplug code do under that condition. Loop for ever or fail reporting the broken contract? I would lean towards the latter. We have never promised that offlining will not fail ever for movable zones. We just guarantee that the operation is resistant against recovarable failures.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 55 lines · Michal Hocko
Quoted 54 lines · David Hildenbrand (Red Hat)
Quoted 45 lines · Gregory Price
Quoted 9 lines · Michal Hocko
Quoted 8 lines · Gregory Price
if (!ret) { /* * TODO: fatal migration failures should bail * out */ do_migrate_range(pfn, end_pfn); }Quoted 5 lines
Quoted 1 line
Maybe it's time to implement the bail out?
That would be great but can we tell transient from permanent migration failures? Maybe long term pins could be treated as permanent failure.
I see deep in migration code
migrate_pages_batch()we would return "Some other failure" as fatal:switch(rc) { case -ENOMEM: ... /* Note: some long-term pin handing is done here */ break; case -EAGAIN: ... break; case 0: ... list_move_tail(&folio->lru, &unmap_folios); list_add_tail(&dst->lru, &dst_folios); break; default: /* * Permanent failure (-EBUSY, etc.): * unlike -EAGAIN case, the failed folio is * removed from migration folio list and not * retried in the next outer loop. */ nr_failed++; stats->nr_thp_failed += is_thp; stats->nr_failed_pages += nr_pages; break; }Quoted 4 lines
So at a minimum we could at least check for !(ENOMEM,EAGAIN) I suppose?
It's unclear to me based on this code here how longerm pinning would return. Maybe David knows.
I would assume that additional references will always result in
-EAGAIN. Remember that we cannot distinguish short-term pins from long-term pins.
Quoted 6 lines
Quoted 2 lines
We should never have longterm-pins on
ZONE_MOVABLE, unless something broke that contract and needs to be fixed.Right. But what should the hotplug code do under that condition. Loop for ever or fail reporting the broken contract? I would lean towards the latter.
If you can detect it reliably.
Quoted 3 lines
We have never promised that offlining will not fail ever for movable zones. We just guarantee that the operation is resistant against recovarable failures.
Right, but we don't want it to fail for reasons where retrying a bit longer would just have worked.
What we document is:
Memory Offlining and ZONE_MOVABLE
---------------------------------
Even with ZONE_MOVABLE, there are some corner cases where offlining a memory block might fail:
... list of corner cases
Further, when running into out of memory situations while migrating pages, or when still encountering permanently unmovable pages within ZONE_MOVABLE (-> BUG), memory offlining will keep retrying until it eventually succeeds.
When offlining is triggered from user space, the offlining context can be terminated by sending a signal. A timeout based offlining can easily be implemented via::
% timeout $TIMEOUT offline_block | failure_handling
Signature · 3 lines
Cheers David
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.
Quoted 7 lines
That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
It would be better to address the lengthy hold time rather that having to work around it in one impacted site.
Sorry for the delayed response, I spent some time recreating this issue.
I've encountered this lengthy hold time several times during memory hot-unplug, with operations hanging indefinitely (20+ hours). It occurs intermittently, and it has different failure signatures, here's one example where isolation fails on a single slab page continuously:
..
[83310.373699] page dumped because: isolation failed [83310.373704] failed to isolate pfn 4dc68 [83310.373708] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373714] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373722] page_type: f5(slab) [83310.373727] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373735] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373741] page dumped because: isolation failed [83310.373749] failed to isolate pfn 4dc68 [83310.373753] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373760] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373767] page_type: f5(slab) [83310.373770] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373774] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373778] page dumped because: isolation failed [83310.373788] failed to isolate pfn 4dc68 [83310.373791] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373794] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373797] page_type: f5(slab) [83310.373799] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373803] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373809] page dumped because: isolation failed [83315.383370] do_migrate_range: 1098409 callbacks suppressed [83315.383377] failed to isolate pfn 4dc68 [83315.383406] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83315.383411] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83315.383416] page_type: f5(slab) [83315.383420] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83315.383423] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83315.383426] page dumped because: isolation failed [83315.383431] failed to isolate pfn 4dc68 [83315.383433] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83315.383442] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83315.383448] page_type: f5(slab) [83315.383454] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83315.383462] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83315.383470] page dumped because: isolation failed
...
...
...
Given the following statement in the documentation, should this behavior be considered expected?
From Documentation/admin-guide/mm/memory-hotplug.rst:
"Further, memory offlining might retry for a long time (or even forever), until aborted by the user."
There's also a TODO in the code that confirms this issue:
mm/memory_hotplug.c
/*
* TODO: fatal migration failures should bail
* out
*/do_migrate_range(pfn, end_pfn);
A possible improvement would be to add a retry limit or timeout for pages that repeatedly fail isolation, returning -EBUSY after N attempts instead of looping indefinitely for umovable pages. This would make the behavior more predictable.
-----
In addition to the above, I've also seen test_pages_isolated() return -EBUSY at the final isolation check for the same page-block continuously
int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
enum pb_isolate_mode mode)
{
...
/* Check all pages are free or marked as ISOLATED */
zone = page_zone(page);
spin_lock_irqsave(&zone->lock, flags);
pfn = __test_page_isolated_in_pageblock(start_pfn, end_pfn, mode);
spin_unlock_irqrestore(&zone->lock, flags);
ret = pfn < end_pfn ? -EBUSY : 0;
...out:
... return ret; }
When __test_page_isolated_in_pageblock() encounters a page that isn't PageBuddy, PageHWPoison, or PageOffline with count 0, it returns that pfn, causing -EBUSY.
I'll work on capturing more traces for this failure scenario and follow up.
Quoted 22 lines
Quoted 22 lines
Make procfs reads lock-free since
percpu_pagelist_high_fractionis a simple integer with naturally atomic reads, writers still serialize via the mutex.This prevents hung task warnings when reading the procfs file during long-running memory offline operations.
...
mm/page_alloc.c +0
-0@@ -6611,11 +6611,14 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table * int old_percpu_pagelist_high_fraction; int ret;mm/page_alloc.c +3
-0+if (!write) +return proc_dointvec_minmax (table, write, buffer, length, ppos); +
mutex_lock(&pcp_batch_high_lock);old_percpu_pagelist_high_fraction=percpu_pagelist_high_fraction;
ret =proc_dointvec_minmax(table, write, buffer, length, ppos);
Quoted 8 lines
Quoted 5 lines
mm/page_alloc.c +1
-1-if (!write || ret <0 ) +if (ret <0 )goto out;
/* Sanity checking to avoid pcp imbalance */That being said, I'll grab the patch and shall put a cc:stable on it, see what people think about this hold-time issue.
Thanks.
Regards,
Aboorva
Michal Hocko
reviewerQuoted 2 lines · Aboorva Devarajan
Quoted 1 line · Andrew Morton
On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]> wrote:
[...]
Quoted 11 lines
[83315.383433] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83315.383442] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83315.383448] page_type: f5(slab) [83315.383454] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83315.383462] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83315.383470] page dumped because: isolation failed...
...
...
Quoted 6 lines
Given the following statement in the documentation, should this behavior be considered expected?
Quoted 1 line
From
Documentation/admin-guide/mm/memory-hotplug.rst:"Further, memory offlining might retry for a long time (or even forever), until aborted by the user."
This is in line with trying to offline memory blocks containing the kernel memory as seen above. Retrying for ever on movable zones is a different issue as discussed in other reply.
Quoted 10 lines
There's also a TODO in the code that confirms this issue:
mm/memory_hotplug.c
/*
* TODO: fatal migration failures should bail
* out
*/do_migrate_range(pfn, end_pfn);
Quoted 3 lines
A possible improvement would be to add a retry limit or timeout for pages that repeatedly fail isolation, returning
-EBUSYafter N attempts instead of looping indefinitely for umovable pages. This would make the behavior more predictable.
I disagree. It is trivial to implement timeout retry in the userspace. Any retry attempts limit behavior will be much less predictable. It could have been a matter of timing that an operation succeeds. We've had exactly that kind of behavior before.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 54 lines · Aboorva Devarajan
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Mon, 1 Dec 2025 11:30:09 +0530 Aboorva Devarajan <[email protected]>…
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.Quoted 7 lines
That's pretty bad behavior.
I wonder if there are other problems which can be caused by this lengthy hold time.
It would be better to address the lengthy hold time rather that having to work around it in one impacted site.
Sorry for the delayed response, I spent some time recreating this issue.
I've encountered this lengthy hold time several times during memory hot-unplug, with operations hanging indefinitely (20+ hours). It occurs intermittently, and it has different failure signatures, here's one example where isolation fails on a single slab page continuously:
..
[83310.373699] page dumped because: isolation failed [83310.373704] failed to isolate pfn 4dc68 [83310.373708] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373714] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373722] page_type: f5(slab) [83310.373727] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373735] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373741] page dumped because: isolation failed [83310.373749] failed to isolate pfn 4dc68 [83310.373753] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373760] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373767] page_type: f5(slab) [83310.373770] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373774] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373778] page dumped because: isolation failed [83310.373788] failed to isolate pfn 4dc68 [83310.373791] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83310.373794] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83310.373797] page_type: f5(slab) [83310.373799] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83310.373803] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83310.373809] page dumped because: isolation failed [83315.383370] do_migrate_range: 1098409 callbacks suppressed [83315.383377] failed to isolate pfn 4dc68 [83315.383406] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83315.383411] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83315.383416] page_type: f5(slab) [83315.383420] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83315.383423] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000
Quoted 8 lines
[83315.383426] page dumped because: isolation failed [83315.383431] failed to isolate pfn 4dc68 [83315.383433] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4dc68 [83315.383442] flags: 0x23ffffe00000000(node=2|zone=0|lastcpupid=0x1fffff) [83315.383448] page_type: f5(slab) [83315.383454] raw: 023ffffe00000000 c0000028e001fa00 5deadbeef0000100 5deadbeef0000122 [83315.383462] raw: 0000000000000000 0000000001e101e1 00000002f5000000 0000000000000000 [83315.383470] page dumped because: isolation failed
When starting memory offlining we do a racy check whether memory offlining will succeed in has_unmovable_pages().
It's racy because briefly after the check, a kernel page could get allocated, before we isolate all the free pages.
I assume that's what happened here.
But even performing another has_unmovable_pages() check after isolating the free pages will not catch all cases: in particular movable pages that are longterm-pinned.
Signature · 3 lines
Cheers David
Quoted 11 lines · Aboorva Devarajan
When page isolation loops indefinitely during memory offline, reading
/proc/sys/vm/percpu_pagelist_high_fractionblocks onpcp_batch_high_lock, causing hung task warnings.Make procfs reads lock-free since
percpu_pagelist_high_fractionis a simple integer with naturally atomic reads, writers still serialize via the mutex.This prevents hung task warnings when reading the procfs file during long-running memory offline operations.
Signed-off-by Aboorva Devarajan <[email protected]>
Looks OK. I would just add a short comment explaining that in the code. See below.
mm/page_alloc.c static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table * · line 6613
Quoted 12 lines
--- mm/page_alloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)mm/page_alloc.c +0
-0@@ -6611,11 +6611,14 @@ static int percpu_pagelist_high_fraction_sysctl_handler(const struct ctl_table *int old_percpu_pagelist_high_fraction;int ret;
/* * Avoid using pcp_batch_high_lock for reads as the value is * read atomicaly and race with offlining is harmless. */
Quoted 14 lines
mm/page_alloc.c +4
-1+if (!write) +return proc_dointvec_minmax (table, write, buffer, length, ppos); +mutex_lock (&pcp_batch_high_lock); old_percpu_pagelist_high_fraction = percpu_pagelist_high_fraction; ret =proc_dointvec_minmax (table, write, buffer, length, ppos); -if (!write || ret <0 ) +if (ret <0 ) goto out;/* Sanity checking to avoid pcp imbalance */ Signature · 1 line
2.50.1
Signature · 2 lines
Michal Hocko SUSE Labs