Cleanup and fixups for memory hotplug
Subsystems (2)
cover Cleanup and fixups for memory hotplug
Hi all,
This series contains cleanup to use helper function to simplify the code. Also we fix some potential bugs. More details can be found in the respective changelogs. Thanks!
Miaohe Lin (3):
mm/memory_hotplug: use helper zone_is_zone_device() to simplify the
code
mm/memory_hotplug: fix potential permanent lru cache disable mm/memory_hotplug: make HWPoisoned dirty swapcache pages unmovable
mm/memory_hotplug.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/3 mm/memory_hotplug: use helper zone_is_zone_device() to simplify the code
Use helper zone_is_zone_device() to simplify the code and remove some explicit CONFIG_ZONE_DEVICE codes.
--- mm/memory_hotplug.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/memory_hotplug.c +1 -3
@@ -477,15 +477,13 @@ void __ref remove_pfn_range_from_zone(struct zone *zone, sizeof(struct page) * cur_nr_pages); } -#ifdef CONFIG_ZONE_DEVICE /* * Zone shrinking code cannot properly deal with ZONE_DEVICE. So * we will not try to shrink the zones - which is okay as * set_zone_contiguous() cannot deal with ZONE_DEVICE either way. */ -if (zone_idx (zone) ==ZONE_DEVICE ) +if (zone_is_zone_device (zone))return ; -#endif clear_zone_contiguous (zone);
Signature · 1 line
2.23.0
Re: [PATCH 1/3] mm/memory_hotplug: use helper zone_is_zone_device() to simplify the code
Quoted 4 lines · Miaohe Lin
Use helper
zone_is_zone_device()to simplify the code and remove some explicitCONFIG_ZONE_DEVICEcodes.Signed-off-by Miaohe Lin <[email protected]>
Re: [PATCH 1/3] mm/memory_hotplug: use helper zone_is_zone_device() to simplify the code
In reply to Miaohe LinQuoted 4 lines · Miaohe Lin
Use helper
zone_is_zone_device()to simplify the code and remove some explicitCONFIG_ZONE_DEVICEcodes.Signed-off-by Miaohe Lin <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE L3
Re: [PATCH 1/3] mm/memory_hotplug: use helper zone_is_zone_device() to simplify the code
In reply to Miaohe LinQuoted 20 lines · Miaohe Lin
Use helper
zone_is_zone_device()to simplify the code and remove some explicitCONFIG_ZONE_DEVICEcodes.Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)mm/memory_hotplug.c +0
-1@@ -477,15 +477,13 @@ void __ref remove_pfn_range_from_zone(struct zone *zone, sizeof(struct page) * cur_nr_pages); } -#ifdef CONFIG_ZONE_DEVICE /* * Zone shrinking code cannot properly deal with ZONE_DEVICE. So
mm/memory_hotplug.c void __ref remove_pfn_range_from_zone(struct zone *zone, · line 489
Quoted 10 lines
mm/memory_hotplug.c +1
-2* we will not try to shrink the zones - which is okay as * set_zone_contiguous() cannot deal with ZONE_DEVICE either way. */ -if (zone_idx (zone) ==ZONE_DEVICE ) +if (zone_is_zone_device (zone))return ; -#endif clear_zone_contiguous (zone);
Signature · 3 lines
Thanks, David / dhildenb
PATCH 2/3 mm/memory_hotplug: fix potential permanent lru cache disable
In reply to Miaohe LinIf offline_pages failed after lru_cache_disable(), it forgot to do lru_cache_enable() in error path. So we would have lru cache disabled permanently in this case.
--- mm/memory_hotplug.c | 1 + 1 file changed, 1 insertion(+)
mm/memory_hotplug.c +1 -0
@@ -2033,6 +2033,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,undo_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled: +lru_cache_enable ();zone_pcp_enable (zone); failed_removal: pr_debug("memory offlining [mem %#010llx-%#010llx] failed due to %s\n",
Signature · 1 line
2.23.0
Re: [PATCH 2/3] mm/memory_hotplug: fix potential permanent lru cache disable
Quoted 6 lines · Miaohe Lin
If
offline_pagesfailed afterlru_cache_disable(), it forgot to dolru_cache_enable()in error path. So we would have lru cache disabled permanently in this case.Fixes d479960e44f2 ("mm: disable LRU pagevec during the migration temporarily")Signed-off-by Miaohe Lin <[email protected]>
Re: [PATCH 2/3] mm/memory_hotplug: fix potential permanent lru cache disable
In reply to Miaohe LinQuoted 6 lines · Miaohe Lin
If
offline_pagesfailed afterlru_cache_disable(), it forgot to dolru_cache_enable()in error path. So we would have lru cache disabled permanently in this case.Fixes d479960e44f2 ("mm: disable LRU pagevec during the migration temporarily")Signed-off-by Miaohe Lin <[email protected]>
Should this go to stable?
In case we fail to enable it again, we will bypass the pvec cache anytime we add a new page to the LRU which might lead to severe performance regression?
Quoted 18 lines
--- mm/memory_hotplug.c | 1 + 1 file changed, 1 insertion(+)mm/memory_hotplug.c +1
-0@@ -2033,6 +2033,7 @@ int __ref offline_pages(unsigned long start_pfn,unsigned long nr_pages,undo_isolate_page_range (start_pfn ,end_pfn ,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled: +lru_cache_enable ();zone_pcp_enable (zone); failed_removal:pr_debug("memory offlining [mem %#010llx-%#010llx] failed due to
%s\n",
Signature · 2 lines
Oscar Salvador SUSE L3
Re: [PATCH 2/3] mm/memory_hotplug: fix potential permanent lru cache disable
Quoted 10 lines · Oscar Salvador
Quoted 6 lines · Miaohe Lin
If
offline_pagesfailed afterlru_cache_disable(), it forgot to dolru_cache_enable()in error path. So we would have lru cache disabled permanently in this case.Fixes d479960e44f2 ("mm: disable LRU pagevec during the migration temporarily")Signed-off-by Miaohe Lin <[email protected]>Reviewed-by Oscar Salvador <[email protected]>
Many thanks for your review and reply. :)
Quoted 3 lines
Should this go to stable?
In case we fail to enable it again, we will bypass the pvec cache anytime we add a new page to the LRU which might lead to severe performance regression?
Agree with you. I think this should go to stable too.
Quoted 18 lines
Quoted 17 lines
---
mm/memory_hotplug.c | 1 +1 file changed, 1 insertion(+)mm/memory_hotplug.c +0
-0@@ -2033,6 +2033,7 @@ int __ref offline_pages(unsigned long start_pfn,unsigned long nr_pages, undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); memory_notify(MEM_CANCEL_OFFLINE, &arg);failed_removal_pcplists_disabled:
+lru_cache_enable();
zone_pcp_enable(zone);
failed_removal:
pr_debug("memory offlining [mem %#010llx-%#010llx] failed due to %s\n",
Re: [PATCH 2/3] mm/memory_hotplug: fix potential permanent lru cache disable
In reply to Miaohe LinQuoted 16 lines · Miaohe Lin
If
offline_pagesfailed afterlru_cache_disable(), it forgot to dolru_cache_enable()in error path. So we would have lru cache disabled permanently in this case.Fixes d479960e44f2 ("mm: disable LRU pagevec during the migration temporarily")Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 1 + 1 file changed, 1 insertion(+)mm/memory_hotplug.c +0
-0
mm/memory_hotplug.c int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, · line 2039
Quoted 7 lines
mm/memory_hotplug.c +1
-0@@ -2033,6 +2033,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,undo_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE );memory_notify (MEM_CANCEL_OFFLINE , &arg); failed_removal_pcplists_disabled: +lru_cache_enable ();zone_pcp_enable (zone); failed_removal: pr_debug("memory offlining [mem %#010llx-%#010llx] failed due to %s\n",
As mentioned, this should be backported to stable.
Signature · 3 lines
Thanks, David / dhildenb
PATCH 3/3 mm/memory_hotplug: make HWPoisoned dirty swapcache pages unmovable
In reply to Miaohe LinHWPoisoned dirty swapcache pages are kept for killing owner processes. We should not offline these pages or do_swap_page() would access the offline pages and lead to bad ending.
--- mm/memory_hotplug.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/memory_hotplug.c +6 -0
@@ -1664,6 +1664,12 @@ static int scan_movable_pages(unsigned long start, unsigned long end,*/ if (PageOffline (page) &&page_count (page))return -EBUSY ; +/* +* HWPoisoned dirty swapcache pages are definitely unmovable +* because they are kept for killing owner processes. +*/ +if (PageHWPoison (page) &&PageSwapCache (page)) +return -EBUSY ;if (!PageHuge (page))continue ;
Signature · 1 line
2.23.0
Re: [PATCH 3/3] mm/memory_hotplug: make HWPoisoned dirty swapcache pages unmovable
Quoted 4 lines · Miaohe Lin
HWPoisoned dirty swapcache pages are kept for killing owner processes. We should not offline these pages or
do_swap_page()would access the offline pages and lead to bad ending.
Thank you for the report. I'm not yet sure of the whole picture of this issue. do_swap_page() is expected to return with fault VM_FAULT_HWPOISON when called via the access to the error page, so I wonder why this doesn't work for your situation. And what is the "bad ending" in the description?
I feel that aborting memory hotremove due to a hwpoisoned dirty swapcache might be too hard, so I'd like to find another solution if we have. # You may separate this patch from former two to make them merged to
# mainline soon.
Thanks,
Naoya Horiguchi
Quoted 19 lines
Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/memory_hotplug.c +6
-0@@ -1664,6 +1664,12 @@ static int scan_movable_pages(unsigned long start, unsigned long end,*/ if (PageOffline (page) &&page_count (page))return -EBUSY ; +/* +* HWPoisoned dirty swapcache pages are definitely unmovable +* because they are kept for killing owner processes. +*/ +if (PageHWPoison (page) &&PageSwapCache (page)) +return -EBUSY ;
Re: [PATCH 3/3] mm/memory_hotplug: make HWPoisoned dirty swapcache pages unmovable
Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 4 lines · Miaohe Lin
HWPoisoned dirty swapcache pages are kept for killing owner processes. We should not offline these pages or
do_swap_page()would access the offline pages and lead to bad ending.Thank you for the report. I'm not yet sure of the whole picture of this issue.
do_swap_page()is expected to return with faultVM_FAULT_HWPOISONwhen called via the access to the error page, so I wonder why this doesn't work for your situation. And what is the "bad ending" in the description?
IMO we might hotremove the page while SwapCache still have ref to it. Thus the page struct would be accessed after offlined. The page struct should be invalid in this case and this would make do_swap_page fragile. Or am I miss something?
Quoted 2 lines
I feel that aborting memory hotremove due to a hwpoisoned dirty swapcache might be too hard, so I'd like to find another solution if we have.
If there is a better way, we can just drop this one.
Many thanks for your review and reply! :)
Quoted 25 lines
# You may separate this patch from former two to make them merged to
# mainline soon.Thanks,
Naoya HoriguchiQuoted 19 lines
Signed-off-by Miaohe Lin <[email protected]>--- mm/memory_hotplug.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/memory_hotplug.c +6
-0@@ -1664,6 +1664,12 @@ static int scan_movable_pages(unsigned long start, unsigned long end,*/ if (PageOffline (page) &&page_count (page))return -EBUSY ; +/* +* HWPoisoned dirty swapcache pages are definitely unmovable +* because they are kept for killing owner processes. +*/ +if (PageHWPoison (page) &&PageSwapCache (page)) +return -EBUSY ;
Andrew Morton
maintainerRe: [PATCH 3/3] mm/memory_hotplug: make HWPoisoned dirty swapcache pages unmovable
Quoted 29 lines · On Mon, 23 Aug 2021 17:14:29 +0800 Miaohe Lin <[email protected]> wrote:
Quoted 11 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 4 lines · Miaohe Lin
HWPoisoned dirty swapcache pages are kept for killing owner processes. We should not offline these pages or
do_swap_page()would access the offline pages and lead to bad ending.Thank you for the report. I'm not yet sure of the whole picture of this issue.
do_swap_page()is expected to return with faultVM_FAULT_HWPOISONwhen called via the access to the error page, so I wonder why this doesn't work for your situation. And what is the "bad ending" in the description?IMO we might hotremove the page while SwapCache still have ref to it. Thus the page struct would be accessed after offlined. The page struct should be invalid in this case and this would make
do_swap_pagefragile. Or am I miss something?Quoted 2 lines
I feel that aborting memory hotremove due to a hwpoisoned dirty swapcache might be too hard, so I'd like to find another solution if we have.
If there is a better way, we can just drop this one.
Many thanks for your review and reply! :)
Quoted 2 lines
# You may separate this patch from former two to make them merged to
# mainline soon....
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
mm/memory_hotplug.c +0
-0@@ -1664,6 +1664,12 @@ static int scan_movable_pages(unsigned long start, unsigned long end,*/ Quoted 8 lines
mm/memory_hotplug.c static int scan_movable_pages(unsigned long start, unsigned long end, · line 1672
Quoted 8 lines
mm/memory_hotplug.c +6
-0if (PageOffline (page) &&page_count (page))return -EBUSY ; +/* +* HWPoisoned dirty swapcache pages are definitely unmovable +* because they are kept for killing owner processes. +*/ +if (PageHWPoison (page) &&PageSwapCache (page)) +return -EBUSY ;
I'll drop this. Please resend something if you still believe that changes are desirable.