mm, memory_hotplug: Don't bail out in do_migrate_range prematurely
Subsystems (2)
Oscar Salvador
maintainerPATCH 1/1 mm, memory_hotplug: Don't bail out in do_migrate_range prematurely
do_migrate_ranges() takes a memory range and tries to isolate the pages to put them into a list.
This list will be later on used in migrate_pages() to know the pages we need to migrate.
Currently, if we fail to isolate a single page, we put all already isolated pages back to their LRU and we bail out from the function. This is quite suboptimal, as this will force us to start over again because scan_movable_pages will give us the same range.
If there is no chance that we can isolate that page, we will loop here forever.
Issue debugged in 4d0c7db96 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") has proved that.
During the debugging of that issue, it was noticed that if do_migrate_ranges() fails to isolate a single page, we will just discard the work we have done so far and bail out, which means that scan_movable_pages() will find again the same set of pages.
Instead, we can just skip the error, keep isolating as much pages as possible and then proceed with the call to migrate_pages(). This will allow us to do some work at least.
There is no danger in the skipped pages to be lost, because scan_movable_pages() will give us them as they could not be isolated and therefore migrated.
Although this patch has proved to be useful when dealing with 4d0c7db96 because it allows us to move forward as long as the page is not in LRU, we still need 4d0c7db96
("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") to handle the LRU case and the unmapping of the page if needed. So, this is just a follow-up cleanup.
--- mm/memory_hotplug.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
mm/memory_hotplug.c +1 -18
@@ -1339,7 +1339,6 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)unsigned long pfn;struct page *page;int move_pages =NR_OFFLINE_AT_ONCE_PAGES ; -int not_managed =0 ;int ret =0 ;LIST_HEAD (source);
@@ -1395,25 +1394,9 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); - }else { -pr_warn ("failed to isolate pfn %lx\n" , pfn); -dump_page (page,"isolation failed" ); -put_page (page); -/* Because we don't have big zone->lock. we should -check this again here. */ -if (page_count (page)) { - not_managed++; - ret = -EBUSY ; -break ; - } } }if (!list_empty (&source)) { -if (not_managed) { -putback_movable_pages (&source); - goto out; - } -/* Allocate a new page from the nearest neighbor node */ ret =migrate_pages (&source, new_node_page,NULL ,0 ,MIGRATE_SYNC ,MR_MEMORY_HOTPLUG );
@@ -1426,7 +1409,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)putback_movable_pages (&source); } } -out: +return ret; }
Signature · 1 line
2.13.7
[email protected]
maintainerReview
Quoted 10 lines · Oscar Salvador
(quoted diff) +0
-10- } else { - pr_warn("failed to isolate pfn %lx\n", pfn); - dump_page(page, "isolation failed"); - put_page(page); - /* Because we don't have big zone->lock. we should - check this again here. */ - if (page_count(page)) { - not_managed++; - ret = -EBUSY; - break;
I forgot that here we should at least leave the put_page(). But leave also the dump_page() and the pr_warn().
mm/memory_hotplug.c +0 -0
@@ -1394,6 +1394,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) inc_node_page_state(page,
NR_ISOLATED_ANON +
page_is_file_cache(page));
+ } else {
+ pr_warn("failed to isolate pfn %lx\n", pfn);
+ dump_page(page, "isolation failed");
+ put_page(page);
}
}
if (!list_empty(&source)) {Quoted 25 lines · On 11.12.18 09:57, [email protected] wrote:
Review
Quoted 10 lines · Oscar Salvador
(quoted diff) +0
-10- } else { - pr_warn("failed to isolate pfn %lx\n", pfn); - dump_page(page, "isolation failed"); - put_page(page); - /* Because we don't have big zone->lock. we should - check this again here. */ - if (page_count(page)) { - not_managed++; - ret = -EBUSY; - break;I forgot that here we should at least leave the
put_page(). But leave also thedump_page()and thepr_warn().mm/memory_hotplug.c +0
-0@@ -1394,6 +1394,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) inc_node_page_state(page,
NR_ISOLATED_ANON+
page_is_file_cache(page));
mm/memory_hotplug.c
Quoted 4 lines
mm/memory_hotplug.c +4
-0+ }else { +pr_warn ("failed to isolate pfn %lx\n" , pfn); +dump_page (page,"isolation failed" ); +put_page (page);
When we're stuck with one problematic page, and we keep looping over that function, won't that print out *way too much* messages? Shouldn't that be rate limited somehow (same applies to other callers in this file)
Quoted 4 lines
}
}
if (!list_empty(&source)) {Signature · 3 lines
Thanks, David / dhildenb
Quoted 27 lines · Oscar Salvador
do_migrate_ranges()takes a memory range and tries to isolate the pages to put them into a list.
This list will be later on used inmigrate_pages()to know the pages we need to migrate.Currently, if we fail to isolate a single page, we put all already isolated pages back to their LRU and we bail out from the function. This is quite suboptimal, as this will force us to start over again because
scan_movable_pageswill give us the same range.
If there is no chance that we can isolate that page, we will loop here forever.Issue debugged in
4d0c7db96("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") has proved that.
During the debugging of that issue, it was noticed that ifdo_migrate_ranges()fails to isolate a single page, we will just discard the work we have done so far and bail out, which means thatscan_movable_pages()will find again the same set of pages.Instead, we can just skip the error, keep isolating as much pages as possible and then proceed with the call to
migrate_pages(). This will allow us to do some work at least.There is no danger in the skipped pages to be lost, because
scan_movable_pages()will give us them as they could not be isolated and therefore migrated.
Quoted 6 lines
Although this patch has proved to be useful when dealing with
4d0c7db96because it allows us to move forward as long as the page is not in LRU, we still need4d0c7db96
("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") to handle the LRU case and the unmapping of the page if needed. So, this is just a follow-up cleanup.
So if I get it right the behavior of the function is now
"If at least one page could be migrated, return 0. If no pages could be migrated, return an error."
Don't we want that to be
"If all pages could be migrated, return 0. If only a subset could be migrated, return -EAGAIN. If no pages could be migrated, return the causing error."
So somehow remember if we had issues with one page and instead of reporting 0, report e.g. -EAGAIN?
Meaning something like "If you get -EAGAIN, try again to get the real reason".
Quoted 54 lines
Signed-off-by Oscar Salvador <[email protected]>--- mm/memory_hotplug.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)mm/memory_hotplug.c +1
-18@@ -1339,7 +1339,6 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)unsigned long pfn;struct page *page;int move_pages =NR_OFFLINE_AT_ONCE_PAGES ; -int not_managed =0 ;int ret =0 ;LIST_HEAD (source);@@ -1395,25 +1394,9 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); - }else { -pr_warn ("failed to isolate pfn %lx\n" , pfn); -dump_page (page,"isolation failed" ); -put_page (page); -/* Because we don't have big zone->lock. we should -check this again here. */ -if (page_count (page)) { - not_managed++; - ret = -EBUSY ; -break ; - } } }if (!list_empty (&source)) { -if (not_managed) { -putback_movable_pages (&source); - goto out; - } -/* Allocate a new page from the nearest neighbor node */ ret =migrate_pages (&source, new_node_page,NULL ,0 ,MIGRATE_SYNC ,MR_MEMORY_HOTPLUG );@@ -1426,7 +1409,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)putback_movable_pages (&source); } } -out: +return ret; }
Signature · 3 lines
Thanks, David / dhildenb
Quoted 2 lines · David Hildenbrand
So somehow remember if we had issues with one page and instead of reporting 0, report e.g.
-EAGAIN?
There is no consumer of the return value right now and it is not really clear whether we need one. I would just make do_migrate_range return void.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 7 lines · Michal Hocko
Quoted 2 lines · David Hildenbrand
So somehow remember if we had issues with one page and instead of reporting 0, report e.g.
-EAGAIN?There is no consumer of the return value right now and it is not really clear whether we need one. I would just make
do_migrate_rangereturn void.
Well, this would allow optimizations like "No need to check if everything has been migrated, I can tell you right away that it has been done".
Signature · 3 lines
Thanks, David / dhildenb
Quoted 11 lines · Oscar Salvador
do_migrate_ranges()takes a memory range and tries to isolate the pages to put them into a list.
This list will be later on used inmigrate_pages()to know the pages we need to migrate.Currently, if we fail to isolate a single page, we put all already isolated pages back to their LRU and we bail out from the function. This is quite suboptimal, as this will force us to start over again because
scan_movable_pageswill give us the same range.
If there is no chance that we can isolate that page, we will loop here forever.
This is true but reorganizing the code will not help the underlying issue. Because the permanently failing page will be still there for scan_movable_pages to encounter.
Quoted 2 lines
Issue debugged in
4d0c7db96("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") has proved that.
I assume that 4d0c7db96 is a sha1 from the linux-next. Please note that this is not going to be the case when merged upstream. So I would use a link.
Quoted 8 lines
During the debugging of that issue, it was noticed that if
do_migrate_ranges()fails to isolate a single page, we will just discard the work we have done so far and bail out, which means thatscan_movable_pages()will find again the same set of pages.Instead, we can just skip the error, keep isolating as much pages as possible and then proceed with the call to
migrate_pages(). This will allow us to do some work at least.
Yes, this makes sense to me.
Quoted 10 lines
There is no danger in the skipped pages to be lost, because
scan_movable_pages()will give us them as they could not be isolated and therefore migrated.Although this patch has proved to be useful when dealing with
4d0c7db96because it allows us to move forward as long as the page is not in LRU, we still need4d0c7db96
("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") to handle the LRU case and the unmapping of the page if needed. So, this is just a follow-up cleanup.
I suspect the above paragraph is adding more confusion than necessary. I would just drop it.
The main question here is. Do we want to migrate as much as possible or do we want to be conservative and bail out early. The later could be an advantage if the next attempt could fail the whole operation because the impact of the failed operation would be somehow reduced. The former should be better for throughput because easily done stuff is done first.
I would go with the throuput because our failure mode is to bail out much earlier - even before we try to migrate. Even though the detection is not perfect it works reasonably well for most usecases.
[...]
Quoted 6 lines
mm/memory_hotplug.c +0
-2@@ -1395,25 +1394,9 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); - }else { -pr_warn ("failed to isolate pfn %lx\n" , pfn);
mm/memory_hotplug.c do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) · line 1397
Quoted 10 lines
mm/memory_hotplug.c +0
-9-dump_page (page,"isolation failed" ); -put_page (page); -/* Because we don't have big zone->lock. we should -check this again here. */ -if (page_count (page)) { - not_managed++; - ret = -EBUSY ; -break ; - } }
you really want to keep this branch. You just do not want to bail out. We want to know about pages which fail to isolate and you definitely do not want to keep the reference elevated behind. not_managed stuff can go away.
Signature · 2 lines
Michal Hocko SUSE Labs
[email protected]
maintainerQuoted 10 lines · Michal Hocko
Quoted 6 lines
Currently, if we fail to isolate a single page, we put all already isolated pages back to their LRU and we bail out from the function. This is quite suboptimal, as this will force us to start over again because
scan_movable_pageswill give us the same range.
If there is no chance that we can isolate that page, we will loop here forever.This is true but reorganizing the code will not help the underlying issue. Because the permanently failing page will be still there for
scan_movable_pagesto encounter.
Well, it would only help in case the page is neither LRU nor non-movable page, then we would fail to isolate it in do_migrate_range and we will start over.
Letting do_migrate_range do some work, would mean that at some point the permanently failing page will not be within a range but the first one of a range, and so scan_movable_pages will skip it.
Quoted 7 lines
Quoted 3 lines
Issue debugged in
4d0c7db96("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") has proved that.I assume that
4d0c7db96is a sha1 from the linux-next. Please note that this is not going to be the case when merged upstream. So I would use a link.
I will replace the sha1 with the link in the next version.
Quoted 9 lines
Quoted 6 lines
Although this patch has proved to be useful when dealing with
4d0c7db96because it allows us to move forward as long as the page is not in LRU, we still need4d0c7db96
("hwpoison,memory_hotplug: allow hwpoisoned pages to be offlined") to handle the LRU case and the unmapping of the page if needed. So, this is just a follow-up cleanup.I suspect the above paragraph is adding more confusion than necessary. I would just drop it.
Fair enough, I will drop it.
Quoted 9 lines
The main question here is. Do we want to migrate as much as possible or do we want to be conservative and bail out early. The later could be an advantage if the next attempt could fail the whole operation because the impact of the failed operation would be somehow reduced. The former should be better for throughput because easily done stuff is done first.
I would go with the throuput because our failure mode is to bail out much earlier - even before we try to migrate. Even though the detection is not perfect it works reasonably well for most usecases.
I agree here.
I think it is better to do as much work as possible at once.
Quoted 4 lines
you really want to keep this branch. You just do not want to bail out. We want to know about pages which fail to isolate and you definitely do not want to keep the reference elevated behind.
not_managedstuff can go away.
Yeah, I just realized when I sent it.
I will fix it up in v2.
Thanks
Quoted 1 line · On Tue 11-12-18 13:22:27, [email protected] wrote:
On 2018-12-11 11:18, Michal Hocko wrote:
[...]
Quoted 6 lines
Quoted 6 lines
The main question here is. Do we want to migrate as much as possible or do we want to be conservative and bail out early. The later could be an advantage if the next attempt could fail the whole operation because the impact of the failed operation would be somehow reduced. The former should be better for throughput because easily done stuff is done first.
Quoted 6 lines
Quoted 3 lines
I would go with the throuput because our failure mode is to bail out much earlier - even before we try to migrate. Even though the detection is not perfect it works reasonably well for most usecases.
I agree here.
I think it is better to do as much work as possible at once.
This would be great to mention in the changelog. Because that is the real justification for the change IMHO.
Signature · 2 lines
Michal Hocko SUSE Labs