Reduce alloc_contig_range latency
Subsystems (6)
cover Reduce alloc_contig_range latency
Hi All,
I played with CMA's core function alloc_contig_range and found it's very very slow so I suspect we can use it in real practice.
I tested it with a bit tweak for working CMA in x86 on qemu. Test environment is following as.
1. x86_64 machince, 2G RAM, 4 core, movable zone 40M with
try alloc_contig_range(movable_zone->middle_pfn, movable_zone->middle_pfn + 10M) per 5sec until background stress test program is terminated.
2. There is background stress program which can make lots of clean cache page. It mimics movie player.
alloc_contig_range's latency unit: usec
before:
min 204000 max 8156000 mean 3109310.34482759 success count 58
after:
min 8000 max 112000 mean 45788.2352941177 success count 85
So this patch reduces 8 sec as worst case, 3 sec as mean case. I'm off from now on until the day of tomorrow so please understand if I can't reply instantly.
Minchan Kim (2):
cma: remove __reclaim_pages
cma: support MIGRATE_DISCARD
include/linux/migrate_mode.h | 11 +++++-- include/linux/mm.h | 2 +- include/linux/mmzone.h | 9 ------ mm/compaction.c | 2 +- mm/migrate.c | 50 +++++++++++++++++++++++------ mm/page_alloc.c | 73 +++++------------------------------------- 6 files changed, 58 insertions(+), 89 deletions(-)
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RFC 1/2 cma: remove __reclaim_pages
Now cma reclaims too many pages by __reclaim_pages which says following as
* Reclaim enough pages to make sure that contiguous allocation
* will not starve the system.
Starve? What does it starve the system? The function which allocate free page for migration target would wake up kswapd and do direct reclaim if needed during migration so system doesn't starve.
Let remove __reclaim_pages and related function and fields.
I modified split_free_page slightly because I removed __reclaim_pages, isolate_freepages_range can fail by split_free_page's watermark check. It's very critical in CMA because it ends up failing alloc_contig_range.
I think we don't need the check in case of CMA because CMA allocates free pages by alloc_pages, not isolate_freepages_block in migrate_pages so watermark is already checked in alloc_pages.
If the condition isn't meet, kswapd/direct-reclaim could reclaim pages. There is no reason to check it in split_free_page.
--- include/linux/mm.h | 2 +- include/linux/mmzone.h | 9 ------ mm/compaction.c | 2 +- mm/page_alloc.c | 71 +++++------------------------------------------- 4 files changed, 9 insertions(+), 75 deletions(-)
include/linux/mm.h +1 -1
@@ -441,7 +441,7 @@ void put_page(struct page *page);void put_pages_list (struct list_head *pages);void split_page (struct page *page,unsigned int order); -int split_free_page (struct page *page); +int split_free_page (struct page *page,bool check_wmark);/* * Compound pages have a destructor function. Provide a
include/linux/mmzone.h +0 -9
@@ -63,10 +63,8 @@ enum {#ifdef CONFIG_CMA # define is_migrate_cma (migratetype) unlikely((migratetype) == MIGRATE_CMA) -# define cma_wmark_pages (zone) zone->min_cma_pages#else # define is_migrate_cma (migratetype) false -# define cma_wmark_pages (zone) 0#endif #define for_each_migratetype_order (order, type) \
@@ -376,13 +374,6 @@ struct zone {/* see spanned/present_pages for more description */ seqlock_t span_seqlock;#endif -#ifdef CONFIG_CMA -/* -* CMA needs to increase watermark levels during the allocation -* process to make sure that the system is not starved. -*/ -unsigned long min_cma_pages; -#endif struct free_area free_area[MAX_ORDER ];#ifndef CONFIG_SPARSEMEM
mm/compaction.c +1 -1
@@ -85,7 +85,7 @@ static unsigned long isolate_freepages_block(unsigned long blockpfn, }/* Found a free page, break it into order-0 pages */ - isolated =split_free_page (page); + isolated =split_free_page (page, !strict);if (!isolated && strict)return 0 ; total_isolated += isolated;
mm/page_alloc.c +7 -64
107 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 1/2] cma: remove __reclaim_pages
Quoted 11 lines · Minchan Kim
Now cma reclaims too many pages by
__reclaim_pageswhich says following as* Reclaim enough pages to make sure that contiguous allocation
* will not starve the system.Starve? What does it starve the system? The function which allocate free page for migration target would wake up kswapd and do direct reclaim if needed during migration so system doesn't starve.
Let remove
__reclaim_pagesand related function and fields.
Fair enough.
Quoted 1 line
Signed-off-by Minchan Kim <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 1/2] cma: remove __reclaim_pages
In reply to Minchan KimQuoted 10 lines · Minchan Kim
Now cma reclaims too many pages by
__reclaim_pageswhich says following as* Reclaim enough pages to make sure that contiguous allocation
* will not starve the system.Starve? What does it starve the system? The function which allocate free page for migration target would wake up kswapd and do direct reclaim if needed during migration so system doesn't starve.
I thought this patch was overkill at the time it was introduced but didn't have a concrete reason to reject it when I commented on it
https://lkml.org/lkml/2012/1/30/136 . Marek did want this and followed up with "contiguous allocations should have higher priority than others" which I took to mean that he was also ok with excessive reclaim.
Quoted 2 lines
Let remove
__reclaim_pagesand related function and fields.
That should be one patch and I don't object to it being removed as such but it's Marek's call.
Quoted 4 lines
I modified
split_free_pageslightly because I removed__reclaim_pages,isolate_freepages_rangecan fail by split_free_page's watermark check. It's very critical in CMA because it ends up failingalloc_contig_range.
This is a big change and should have been in a patch on its own. split_free_page checks watermarks because if the watermarks are not obeyed a zone can become fully allocated. This can cause a system to livelock under certain circumstances if a page cannot be allocated and a free page is required before other pages can be freed.
Quoted 3 lines
I think we don't need the check in case of CMA because CMA allocates free pages by
alloc_pages, notisolate_freepages_blockinmigrate_pagesso watermark is already checked inalloc_pages.
It uses alloc_pages when migrating pages out of the CMA area but note that it uses isolate_freepages_block when allocating the CMA buffer when alloc_contig_range calls isolate_freepages_range
isolate_freepages_range(unsigned long start_pfn, unsigned long end_pfn)
{
for (pfn = start_pfn; pfn < end_pfn; pfn += isolated) {
isolated = isolate_freepages_block(pfn, block_end_pfn,
&freelist, true);
}
map_pages(&freelist);
}so the actual CMA allocation itself is not using alloc_pages. By removing the watermark check you allow the CMA to breach watermarks and puts the system at risk of livelock.
I'm not keen on the split_free_page() change at all.
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 1/2] cma: remove __reclaim_pages
Hi Mel,
Quoted 12 lines · Mel Gorman
Quoted 10 lines · Minchan Kim
Now cma reclaims too many pages by
__reclaim_pageswhich says following as* Reclaim enough pages to make sure that contiguous allocation
* will not starve the system.Starve? What does it starve the system? The function which allocate free page for migration target would wake up kswapd and do direct reclaim if needed during migration so system doesn't starve.
Quoted 5 lines
I thought this patch was overkill at the time it was introduced but didn't have a concrete reason to reject it when I commented on it
https://lkml.org/lkml/2012/1/30/136 . Marek did want this and followed up with "contiguous allocations should have higher priority than others" which I took to mean that he was also ok with excessive reclaim.
I think OOM kill to background applications is more appropriate than big latency of foreground(ex, Camera app) application in your mobile phone. In other words, excessive reclaim is *really* bad which elapsed 8sec in my test as worst case. :(
Quoted 6 lines
Quoted 3 lines
Let remove
__reclaim_pagesand related function and fields.That should be one patch and I don't object to it being removed as such but it's Marek's call.
Marek. Any thought?
Quoted 29 lines
Quoted 5 lines
I modified
split_free_pageslightly because I removed__reclaim_pages,isolate_freepages_rangecan fail by split_free_page's watermark check. It's very critical in CMA because it ends up failingalloc_contig_range.This is a big change and should have been in a patch on its own.
split_free_pagechecks watermarks because if the watermarks are not obeyed a zone can become fully allocated. This can cause a system to livelock under certain circumstances if a page cannot be allocated and a free page is required before other pages can be freed.Quoted 3 lines
I think we don't need the check in case of CMA because CMA allocates free pages by
alloc_pages, notisolate_freepages_blockinmigrate_pagesso watermark is already checked inalloc_pages.It uses
alloc_pageswhen migrating pages out of the CMA area but note that it usesisolate_freepages_blockwhen allocating the CMA buffer whenalloc_contig_rangecallsisolate_freepages_range
isolate_freepages_range(unsigned long start_pfn, unsigned long end_pfn){ for (pfn = start_pfn; pfn < end_pfn; pfn += isolated) { isolated = isolate_freepages_block(pfn, block_end_pfn, &freelist, true); } map_pages(&freelist); }
Quoted 3 lines
so the actual CMA allocation itself is not using
alloc_pages. By removing the watermark check you allow the CMA to breach watermarks and puts the system at risk of livelock.
Fair enough. I will look into that.
Thanks, Mel.
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RE: [RFC 1/2] cma: remove __reclaim_pages
Hi Minchan,
Quoted 25 lines · Minchan Kim
Quoted 12 lines · Mel Gorman
Quoted 10 lines · Minchan Kim
Now cma reclaims too many pages by
__reclaim_pageswhich says following as* Reclaim enough pages to make sure that contiguous allocation
* will not starve the system.Starve? What does it starve the system? The function which allocate free page for migration target would wake up kswapd and do direct reclaim if needed during migration so system doesn't starve.
Quoted 5 lines
I thought this patch was overkill at the time it was introduced but didn't have a concrete reason to reject it when I commented on it
https://lkml.org/lkml/2012/1/30/136 . Marek did want this and followed up with "contiguous allocations should have higher priority than others" which I took to mean that he was also ok with excessive reclaim.I think OOM kill to background applications is more appropriate than big latency of
foreground(ex, Camera app)application in your mobile phone. In other words, excessive reclaim is *really* bad which elapsed 8sec in my test as worst case. :(Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Let remove
__reclaim_pagesand related function and fields.That should be one patch and I don't object to it being removed as such but it's Marek's call.
Marek. Any thought?
Well, I've introduced this function as a result of solving Mel's request:
http://www.spinics.net/lists/linux-mm/msg28485.html
Before that I solved it almost the same as in your current patch. I'm aware of the fact that __reclaim_pages() approach might be a little overkill, but I didn't find anything better yet.
Quoted 28 lines
Quoted 28 lines
Quoted 4 lines
I modified
split_free_pageslightly because I removed__reclaim_pages,isolate_freepages_rangecan fail by split_free_page's watermark check. It's very critical in CMA because it ends up failingalloc_contig_range.This is a big change and should have been in a patch on its own.
split_free_pagechecks watermarks because if the watermarks are not obeyed a zone can become fully allocated. This can cause a system to livelock under certain circumstances if a page cannot be allocated and a free page is required before other pages can be freed.Quoted 3 lines
I think we don't need the check in case of CMA because CMA allocates free pages by
alloc_pages, notisolate_freepages_blockinmigrate_pagesso watermark is already checked inalloc_pages.It uses
alloc_pageswhen migrating pages out of the CMA area but note that it usesisolate_freepages_blockwhen allocating the CMA buffer whenalloc_contig_rangecallsisolate_freepages_range
isolate_freepages_range(unsigned long start_pfn, unsigned long end_pfn){ for (pfn = start_pfn; pfn < end_pfn; pfn += isolated) { isolated = isolate_freepages_block(pfn, block_end_pfn, &freelist, true); } map_pages(&freelist); }
Quoted 5 lines
Quoted 3 lines
so the actual CMA allocation itself is not using
alloc_pages. By removing the watermark check you allow the CMA to breach watermarks and puts the system at risk of livelock.Fair enough. I will look into that.
We will also looks into this issue.
Best regards
Signature · 9 lines
Marek Szyprowski Samsung Poland R&D Center -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RFC 2/2 cma: support MIGRATE_DISCARD
In reply to Minchan KimThis patch introudes MIGRATE_DISCARD mode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.
--- include/linux/migrate_mode.h | 11 +++++++--- mm/migrate.c | 50 +++++++++++++++++++++++++++++++++--------- mm/page_alloc.c | 2 +- 3 files changed, 49 insertions(+), 14 deletions(-)
include/linux/migrate_mode.h +8 -3
@@ -6,11 +6,16 @@* on most operations but not ->writepage as the potential stall time * is too significant * MIGRATE_SYNC will block when migrating pages +* MIGRTATE_DISCARD will discard clean cache page instead of migration +* +* MIGRATE_ASYNC, MIGRATE_SYNC_LIGHT, MIGRATE_SYNC shouldn't be used +* together as OR flag. */ enum migrate_mode { -MIGRATE_ASYNC , -MIGRATE_SYNC_LIGHT , -MIGRATE_SYNC , +MIGRATE_ASYNC =1 <<0 , +MIGRATE_SYNC_LIGHT =1 <<1 , +MIGRATE_SYNC =1 <<2 , +MIGRATE_DISCARD =1 <<3 , };#endif /* MIGRATE_MODE_H_INCLUDED */
mm/migrate.c +40 -10
103 lines not on this page · raw message
mm/page_alloc.c +1 -1
@@ -5662,7 +5662,7 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end) ret =migrate_pages (&cc.migratepages, __alloc_contig_migrate_alloc, -0 , false,MIGRATE_SYNC ); +0 , false,MIGRATE_SYNC |MIGRATE_DISCARD ); }putback_lru_pages (&cc.migratepages);
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
Quoted 8 lines · Minchan Kim
This patch introudes
MIGRATE_DISCARDmode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.Signed-off-by Minchan Kim <[email protected]>
This looks good to me.
Quoted 18 lines
--- include/linux/migrate_mode.h | 11 +++++++--- mm/migrate.c | 50 +++++++++++++++++++++++++++++++++--------- mm/page_alloc.c | 2 +- 3 files changed, 49 insertions(+), 14 deletions(-)include/linux/migrate_mode.h +4
-0@@ -6,11 +6,16 @@* on most operations but not ->writepage as the potential stall time * is too significant * MIGRATE_SYNC will block when migrating pages +* MIGRTATE_DISCARD will discard clean cache page instead of migration +* +* MIGRATE_ASYNC, MIGRATE_SYNC_LIGHT, MIGRATE_SYNC shouldn't be used +* together as OR flag.
include/linux/migrate_mode.h line 19
Quoted 10 lines
include/linux/migrate_mode.h +4
-3*/ enum migrate_mode { -MIGRATE_ASYNC , -MIGRATE_SYNC_LIGHT , -MIGRATE_SYNC , +MIGRATE_ASYNC =1 <<0 , +MIGRATE_SYNC_LIGHT =1 <<1 , +MIGRATE_SYNC =1 <<2 , +MIGRATE_DISCARD =1 <<3 , };
Since CMA is the only user of MIGRATE_DISCARD it may be worth it to guard it inside an #ifdef, eg:
#ifdef CONFIG_CMA MIGRATE_DISCARD = 1 << 3,
#define is_migrate_discard(mode) (((mode) & MIGRATE_DISCARD) == MIGRATE_DISCARD) #endif
Quoted 6 lines
include/linux/migrate_mode.h +0
-0#endif /* MIGRATE_MODE_H_INCLUDED */ mm/migrate.c +0
-0
mm/migrate.c static int __unmap_and_move(struct page *page, struct page *newpage, · line 693
Quoted 10 lines
mm/migrate.c +4
-1@@ -685,9 +685,12 @@ static int __unmap_and_move(struct page *page, struct page *newpage,int remap_swapcache =1 ;struct mem_cgroup *mem;struct anon_vma *anon_vma =NULL ; +enum ttu_flags ttu_flags; +bool discard_mode = false; +bool file = false;if (!trylock_page (page)) { -if (!force || mode ==MIGRATE_ASYNC ) +if (!force || mode &MIGRATE_ASYNC )
+ if (!force || (mode & MIGRATE_ASYNC))
Quoted 3 lines
mm/migrate.c +0
-0goto out;/*
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
Hi Michal,
Quoted 44 lines · Michal Nazarewicz
Quoted 8 lines · Minchan Kim
This patch introudes
MIGRATE_DISCARDmode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.Signed-off-by Minchan Kim <[email protected]>This looks good to me.
Quoted 18 lines
--- include/linux/migrate_mode.h | 11 +++++++--- mm/migrate.c | 50 +++++++++++++++++++++++++++++++++--------- mm/page_alloc.c | 2 +- 3 files changed, 49 insertions(+), 14 deletions(-)include/linux/migrate_mode.h +4
-0@@ -6,11 +6,16 @@* on most operations but not ->writepage as the potential stall time * is too significant * MIGRATE_SYNC will block when migrating pages +* MIGRTATE_DISCARD will discard clean cache page instead of migration +* +* MIGRATE_ASYNC, MIGRATE_SYNC_LIGHT, MIGRATE_SYNC shouldn't be used +* together as OR flag. include/linux/migrate_mode.h line 19
Quoted 10 lines
include/linux/migrate_mode.h +4
-3*/ enum migrate_mode { -MIGRATE_ASYNC , -MIGRATE_SYNC_LIGHT , -MIGRATE_SYNC , +MIGRATE_ASYNC =1 <<0 , +MIGRATE_SYNC_LIGHT =1 <<1 , +MIGRATE_SYNC =1 <<2 , +MIGRATE_DISCARD =1 <<3 , };Since CMA is the only user of
MIGRATE_DISCARDit may be worth it to guard it inside an #ifdef, eg:
Quoted 3 lines
#ifdef CONFIG_CMA MIGRATE_DISCARD = 1 << 3,#define
is_migrate_discard(mode)(((mode) &MIGRATE_DISCARD) ==MIGRATE_DISCARD)
The mode bit can be used with other bits like MIGRATE_SYNC|MIGRATE_DISCARD. So it is correct that (mode & MIGRATE_DISCARD).
Anyway, I don't want to fold it into only CMA because I think we can have a pontential users in mm.
For example, memory-hotplug case. No enough free memory in the system but lots of page cache page as a migration source, then we can remove page cache page instead of migration and it might be better than failing memory-hotremove.
In summary, I want to open it for potential usecases in future if anyone doesn't oppose strongly.
Quoted 16 lines
#endif
Quoted 13 lines
include/linux/migrate_mode.h +0
-0#endif /* MIGRATE_MODE_H_INCLUDED */ mm/migrate.c +3
-0@@ -685,9 +685,12 @@ static int __unmap_and_move(struct page *page, struct page *newpage,int remap_swapcache =1 ;struct mem_cgroup *mem;struct anon_vma *anon_vma =NULL ; +enum ttu_flags ttu_flags; +bool discard_mode = false; +bool file = false;
Quoted 3 lines
mm/migrate.c static int __unmap_and_move(struct page *page, struct page *newpage, · line 693
Quoted 3 lines
mm/migrate.c +1
-1if (!trylock_page (page)) { -if (!force || mode ==MIGRATE_ASYNC ) +if (!force || mode &MIGRATE_ASYNC )
It's not wrong technically but for readability, NP.
Quoted 13 lines
(quoted diff) +1
-0+ if (!force || (mode & MIGRATE_ASYNC))Quoted 4 lines
mm/migrate.c +0
-0goto out;/* Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, MichaA? a??mina86a?? Nazarewicz (o o) ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
Quoted 3 lines · Michal Nazarewicz
Quoted 2 lines
Since CMA is the only user of
MIGRATE_DISCARDit may be worth it to guard it inside an #ifdef, eg:
Quoted 2 lines · Minchan Kim
In summary, I want to open it for potential usecases in future if anyone doesn't oppose strongly.
Fair enough.
Quoted 5 lines
Quoted 3 lines
mm/migrate.c static int __unmap_and_move(struct page *page, struct page *newpage, · line 693
Quoted 3 lines
mm/migrate.c +1
-1if (!trylock_page (page)) { -if (!force || mode ==MIGRATE_ASYNC ) +if (!force || mode &MIGRATE_ASYNC )It's not wrong technically but for readability, NP.
Yep, that was my point, thanks. :)
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
In reply to Minchan KimQuoted 6 lines · Minchan Kim
This patch introudes
MIGRATE_DISCARDmode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.
Would it be an idea to only drop clean UNMAPPED
page cache pages?
Quoted 7 lines
Signed-off-by Minchan Kim <[email protected]>mm/migrate.c +1
-0@@ -799,12 +802,39 @@ static int __unmap_and_move(struct page *page, struct page *newpage, goto skip_unmap; } + file =page_is_file_cache (page);
mm/migrate.c static int __unmap_and_move(struct page *page, struct page *newpage, · line 814
Quoted 10 lines
mm/migrate.c +8
-1+ ttu_flags =TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ; + +if (!(mode &MIGRATE_DISCARD ) || !file ||PageDirty (page)) + ttu_flags |=TTU_MIGRATION ; +else + discard_mode = true; +/* Establish migration ptes or remove ptes */ -try_to_unmap (page,TTU_MIGRATION |TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ); +try_to_unmap (page, ttu_flags);
This bit looks wrong, because you end up ignoring mlock and then discarding the page.
Only dropping clean page cache pages that are not mapped would avoid that problem, without introducing much complexity in the code.
That would turn the test above into:
if (!page_mapped(page)) discard_mode = true;
Quoted 14 lines
mm/migrate.c +11
-2skip_unmap: -if (!page_mapped (page)) - rc =move_to_new_page (newpage, page, remap_swapcache, mode); +if (!page_mapped (page)) { +if (!discard_mode) + rc =move_to_new_page (newpage, page, remap_swapcache, mode); +else { +struct address_space *mapping; + mapping =page_mapping (page); + +if (page_has_private (page)) { +if (!try_to_release_page (page,GFP_KERNEL )) { + rc = -EAGAIN ; + goto uncharge;
mm/migrate.c static int __unmap_and_move(struct page *page, struct page *newpage, · line 837
Quoted 10 lines
mm/migrate.c +10
-0+ } + } + +if (remove_mapping (mapping, page)) + rc =0 ; +else + rc = -EAGAIN ; + goto uncharge; + } + }
This big piece of code could probably be split out into its own function.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
Hi Rik,
Quoted 10 lines · Rik van Riel
Quoted 6 lines · Minchan Kim
This patch introudes
MIGRATE_DISCARDmode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.Would it be an idea to only drop clean UNMAPPED
page cache pages?
Firstly I thougt about that but I chose more agressive thing. Namely, even drop mapped page cache.
Because it can reduce latency more(ex, memcpy + remapping cost during migration) and it could not trivial if migration range is big.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Minchan Kim <[email protected]>(quoted diff) +0
-0@@ -799,12 +802,39 @@ static int __unmap_and_move(struct page *page, struct page *newpage, goto skip_unmap; }
Quoted 14 lines
Review static int __unmap_and_move(struct page *page, struct page *newpage, · line 814
Quoted 11 lines
(quoted diff) +9
-1+ file = page_is_file_cache(page); + ttu_flags = TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS; + + if (!(mode & MIGRATE_DISCARD) || !file || PageDirty(page)) + ttu_flags |= TTU_MIGRATION; + else + discard_mode = true; + /* Establish migration ptes or remove ptes */ - try_to_unmap(page, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS); + try_to_unmap(page, ttu_flags);This bit looks wrong, because you end up ignoring mlock and then discarding the page.
Argh, Thanks!
I will fix it in next spin.
Quoted 4 lines
Only dropping clean page cache pages that are not mapped would avoid that problem, without introducing much complexity in the code.
Hmm, I don't think it makes code much complex.
How about this?
mm/rmap.c +4 -2
@@ -1223,7 +1223,8 @@ out:* repeatedly from try_to_unmap_ksm, try_to_unmap_anon or try_to_unmap_file. */ int try_to_unmap_one (struct page *page,struct vm_area_struct *vma, -unsigned long address,enum ttu_flags flags) +unsigned long address,enum ttu_flags flags, +unsigned long *vm_flags) {struct mm_struct *mm = vma->vm_mm;pte_t *pte;
@@ -1235,6 +1236,7 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,if (!pte) goto out; + vm_flags |= vma->vm_flags;/* * If the page is mlock()d, we cannot swap it out. * If it's recently referenced (perhaps page_referenced
@@ -1652,7 +1654,7 @@ out:* SWAP_FAIL - the page is unswappable * SWAP_MLOCK - page is mlocked. */ -int try_to_unmap (struct page *page,enum ttu_flags flags) +int try_to_unmap (struct page *page,enum ttu_flags flags,unsigned long *vm_flags) {int ret;
<snip>
+ file = page_is_file_cache(page);
+ ttu_flags = TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS;
+
+ if (!(mode & MIGRATE_DISCARD) || !file || PageDirty(page) ||
+ vm_flags & VM_LOCKED)
+ ttu_flags |= TTU_MIGRATION;
+ else
+ discard_mode = true;
+
Quoted 41 lines
That would turn the test above into:
if (!page_mapped(page)) discard_mode = true;Quoted 14 lines
(quoted diff) +11
-2skip_unmap: - if (!page_mapped(page)) - rc = move_to_new_page(newpage, page, remap_swapcache, mode); + if (!page_mapped(page)) { + if (!discard_mode) + rc = move_to_new_page(newpage, page, remap_swapcache, mode); + else { + struct address_space *mapping; + mapping = page_mapping(page); + + if (page_has_private(page)) { + if (!try_to_release_page(page, GFP_KERNEL)) { + rc = -EAGAIN; + goto uncharge;Review static int __unmap_and_move(struct page *page, struct page *newpage, · line 836
Quoted 10 lines
(quoted diff) +10
-0+ } + } + + if (remove_mapping(mapping, page)) + rc = 0; + else + rc = -EAGAIN; + goto uncharge; + } + }This big piece of code could probably be split out into its own function.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RFC 2/2] cma: support MIGRATE_DISCARD
Quoted 80 lines · Minchan Kim
Hi Rik,
Quoted 10 lines · Rik van Riel
Quoted 6 lines · Minchan Kim
This patch introudes
MIGRATE_DISCARDmode in migration. It drop clean cache pages instead of migration so that migration latency could be reduced. Of course, it could evict code pages but latency of big contiguous memory is more important than some background application's slow down in mobile embedded enviroment.Would it be an idea to only drop clean UNMAPPED page cache pages?
Firstly I thougt about that but I chose more agressive thing. Namely, even drop mapped page cache.
Because it can reduce latencymore(ex, memcpy + remapping cost during migration)and it could not trivial if migration range is big.Quoted 7 lines
Quoted 7 lines
Signed-off-by Minchan Kim <[email protected]>(quoted diff) +0
-0@@ -799,12 +802,39 @@ static int __unmap_and_move(struct page *page, struct page *newpage, goto skip_unmap; }Quoted 14 lines
Review static int __unmap_and_move(struct page *page, struct page *newpage, · line 814
Quoted 11 lines
(quoted diff) +9
-1+ file = page_is_file_cache(page); + ttu_flags = TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS; + + if (!(mode & MIGRATE_DISCARD) || !file || PageDirty(page)) + ttu_flags |= TTU_MIGRATION; + else + discard_mode = true; + /* Establish migration ptes or remove ptes */ - try_to_unmap(page, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS); + try_to_unmap(page, ttu_flags);This bit looks wrong, because you end up ignoring mlock and then discarding the page.
Argh, Thanks!
I will fix it in next spin.Quoted 4 lines
Only dropping clean page cache pages that are not mapped would avoid that problem, without introducing much complexity in the code.
Hmm, I don't think it makes code much complex.
How about this?mm/rmap.c +4
-2@@ -1223,7 +1223,8 @@ out:* repeatedly from try_to_unmap_ksm, try_to_unmap_anon or try_to_unmap_file. */ int try_to_unmap_one (struct page *page,struct vm_area_struct *vma, -unsigned long address,enum ttu_flags flags) +unsigned long address,enum ttu_flags flags, +unsigned long *vm_flags) {struct mm_struct *mm = vma->vm_mm;pte_t *pte;@@ -1235,6 +1236,7 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,if (!pte) goto out; + vm_flags |= vma->vm_flags;/* * If the page is mlock()d, we cannot swap it out. * If it's recently referenced (perhaps page_referenced @@ -1652,7 +1654,7 @@ out:* SWAP_FAIL - the page is unswappable * SWAP_MLOCK - page is mlocked. */ -int try_to_unmap (struct page *page,enum ttu_flags flags) +int try_to_unmap (struct page *page,enum ttu_flags flags,unsigned long *vm_flags)
mm/rmap.c out:
Quoted 10 lines
mm/rmap.c +5
-0{int ret; + file =page_is_file_cache (page); + ttu_flags =TTU_IGNORE_MLOCK |TTU_IGNORE_ACCESS ; + +if (!(mode &MIGRATE_DISCARD ) || !file ||PageDirty (page) || + vm_flags &VM_LOCKED )
We do try_to_unmap after this piece so we can't get the information in advance. :( I don't have better idea which doesn't have a drawback so I will accept your idea. Thanks, Rik.
Quoted 6 lines
mm/rmap.c +4
-0+ ttu_flags |=TTU_MIGRATION ; + else + discard_mode = true; +
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>