MADV_FREE support
Subsystems (14)
v17 cover MADV_FREE support
This patch enable MADV_FREE hint for madvise syscall, which have been supported by other OSes. [PATCH 1] includes the details.
[1] support MADVISE_FREE for !THP page so if VM encounter THP page in syscall context, it splits THP page.
[2-6] is to preparing to call madvise syscall without THP plitting
[7] enable THP page support for MADV_FREE.
* from v16
* Rebased on mmotm-2014-10-15-16-57
* from v15
* Add more Acked-by - Rik van Riel
* Rebased on mmotom-08-29-15-15
* from v14
* Add more Ackedy-by from arch people(sparc, arm64 and arm)
* Drop s390 since pmd_dirty/clean was merged
* from v13
* Add more Ackedy-by from arch people(arm, arm64 and ppc)
* Rebased on mmotm 2014-08-13-14-29
* from v12
* Fix - skip to mark free pte on try_to_free_swap failed page - Kirill
* Add more Acked-by from arch maintainers and Kirill
* From v11
* Fix arm build - Steve
* Separate patch for arm and arm64 - Steve
* Remove unnecessary check - Kirill
* Skip non-vm_normal page - Kirill
* Add Acked-by - Zhang
* Sparc64 build fix
* Pagetable walker THP handling fix
* From v10
* Add Acked-by from arch stuff(x86, s390)
* Pagewalker based pagetable working - Kirill
* Fix try_to_unmap_one broken with hwpoison - Kirill
* Use VM_BUG_ON_PAGE in madvise_free_pmd - Kirill
* Fix pgtable-3level.h for arm - Steve
* From v9
* Add Acked-by - Rik
* Add THP page support - Kirill
* From v8
* Rebased-on v3.16-rc2-mmotm-2014-06-25-16-44
* From v7
* Rebased-on next-20140613
* From v6
* Remove page from swapcache in syscal time
* Move utility functions from memory.c to madvise.c - Johannes
* Rename untilify functtions - Johannes
* Remove unnecessary checks from vmscan.c - Johannes
* Rebased-on v3.15-rc5-mmotm-2014-05-16-16-56
* Drop Reviewe-by because there was some changes since then.
* From v5
* Fix PPC problem which don't flush TLB - Rik
* Remove unnecessary lazyfree_range stub function - Rik
* Rebased on v3.15-rc5
* From v4
* Add Reviewed-by: Zhang Yanfei
* Rebase on v3.15-rc1-mmotm-2014-04-15-16-14
* From v3
* Add "how to work part" in description - Zhang
* Add page_discardable utility function - Zhang
* Clean up
* From v2
* Remove forceful dirty marking of swap-readed page - Johannes
* Remove deactivation logic of lazyfreed page
* Rebased on 3.14
* Remove RFC tag
* From v1
* Use custom page table walker for madvise_free - Johannes
* Remove PG_lazypage flag - Johannes
* Do madvise_dontneed instead of madvise_freein swapless system
Minchan Kim (7):
mm: support madvise(MADV_FREE)
x86: add pmd_[dirty|mkclean] for THP
sparc: add pmd_[dirty|mkclean] for THP
powerpc: add pmd_[dirty|mkclean] for THP
arm: add pmd_mkclean for THP
arm64: add pmd_[dirty|mkclean] for THP
mm: Don't split THP page when syscall is called
arch/arm/include/asm/pgtable-3level.h | 1 + arch/arm64/include/asm/pgtable.h | 2 + arch/powerpc/include/asm/pgtable-ppc64.h | 2 + arch/sparc/include/asm/pgtable_64.h | 16 ++++ arch/x86/include/asm/pgtable.h | 10 ++ include/linux/huge_mm.h | 4 + include/linux/rmap.h | 9 +- include/linux/vm_event_item.h | 1 + include/uapi/asm-generic/mman-common.h | 1 + mm/huge_memory.c | 35 +++++++ mm/madvise.c | 159 +++++++++++++++++++++++++++++++ mm/rmap.c | 46 ++++++++- mm/vmscan.c | 64 +++++++++---- mm/vmstat.c | 1 + 14 files changed, 331 insertions(+), 20 deletions(-)
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 1/7 mm: support madvise(MADV_FREE)
Linux doesn't have an ability to free pages lazy while other OS already have been supported that named by madvise(MADV_FREE).
The gain is clear that kernel can discard freed pages rather than swapping out or OOM if memory pressure happens.
Without memory pressure, freed pages would be reused by userspace without another additional overhead(ex, page fault + allocation
+ zeroing).
How to work is following as.
When madvise syscall is called, VM clears dirty bit of ptes of the range. If memory pressure happens, VM checks dirty bit of page table and if it found still "clean", it means it's a "lazyfree pages" so VM could discard the page instead of swapping out. Once there was store operation for the page before VM peek a page to reclaim, dirty bit is set so VM can swap out the page instead of discarding.
Firstly, heavy users would be general allocators(ex, jemalloc, tcmalloc and hope glibc supports it) and jemalloc/tcmalloc already have supported the feature for other OS(ex, FreeBSD)
barrios@blaptop:~/benchmark/ebizzy$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 12 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 2 Stepping: 3 CPU MHz: 3200.185 BogoMIPS: 6400.53 Virtualization: VT-x Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 4096K NUMA node0 CPU(s): 0-11 ebizzy benchmark(./ebizzy -S 10 -n 512)
Higher avg is better.
vanilla-jemalloc MADV_free-jemalloc
1 thread
records: 10 records: 10
avg: 2961.90 avg: 12069.70
std: 71.96(2.43%) std: 186.68(1.55%)
max: 3070.00 max: 12385.00 min: 2796.00 min: 11746.00
2 thread
records: 10 records: 10
avg: 5020.00 avg: 17827.00
std: 264.87(5.28%) std: 358.52(2.01%)
max: 5244.00 max: 18760.00 min: 4251.00 min: 17382.00
4 thread
records: 10 records: 10
avg: 8988.80 avg: 27930.80 std: 1175.33(13.08%) std: 3317.33(11.88%) max: 9508.00 max: 30879.00 min: 5477.00 min: 21024.00
8 thread
records: 10 records: 10
avg: 13036.50 avg: 33739.40
std: 170.67(1.31%) std: 5146.22(15.25%)
max: 13371.00 max: 40572.00 min: 12785.00 min: 24088.00
16 thread
records: 10 records: 10
avg: 11092.40 avg: 31424.20
std: 710.60(6.41%) std: 3763.89(11.98%)
max: 12446.00 max: 36635.00
min: 9949.00 min: 25669.00
32 thread
records: 10 records: 10
avg: 11067.00 avg: 34495.80
std: 971.06(8.77%) std: 2721.36(7.89%)
max: 12010.00 max: 38598.00
min: 9002.00 min: 30636.00
In summary, MADV_FREE is about much faster than MADV_DONTNEED.
* from v16
* Rebased on mmotm-2014-10-15-16-57
* from v15
* Add more Acked-by - Rik van Riel
* Rebased on mmotom-08-29-15-15
* from v14
* Add more Ackedy-by from arch people(sparc, arm64 and arm)
* Drop s390 since pmd_dirty/clean was merged
* from v13
* Add more Ackedy-by from arch people(arm, arm64 and ppc)
* Rebased on mmotm 2014-08-13-14-29
* from v12
* Fix - skip to mark free pte on try_to_free_swap failed page - Kirill
* Add more Acked-by from arch maintainers and Kirill
* From v11
* Fix arm build - Steve
* Separate patch for arm and arm64 - Steve
* Remove unnecessary check - Kirill
* Skip non-vm_normal page - Kirill
* Add Acked-by - Zhang
* Sparc64 build fix
* Pagetable walker THP handling fix
* From v10
* Add Acked-by from arch stuff(x86, s390)
* Pagewalker based pagetable working - Kirill
* Fix try_to_unmap_one broken with hwpoison - Kirill
* Use VM_BUG_ON_PAGE in madvise_free_pmd - Kirill
* Fix pgtable-3level.h for arm - Steve
* From v9
* Add Acked-by - Rik
* Add THP page support - Kirill
* From v8
* Rebased-on v3.16-rc2-mmotm-2014-06-25-16-44
* From v7
* Rebased-on next-20140613
* From v6
* Remove page from swapcache in syscal time
* Move utility functions from memory.c to madvise.c - Johannes
* Rename untilify functtions - Johannes
* Remove unnecessary checks from vmscan.c - Johannes
* Rebased-on v3.15-rc5-mmotm-2014-05-16-16-56
* Drop Reviewe-by because there was some changes since then.
* From v5
* Fix PPC problem which don't flush TLB - Rik
* Remove unnecessary lazyfree_range stub function - Rik
* Rebased on v3.15-rc5
* From v4
* Add Reviewed-by: Zhang Yanfei
* Rebase on v3.15-rc1-mmotm-2014-04-15-16-14
* From v3
* Add "how to work part" in description - Zhang
* Add page_discardable utility function - Zhang
* Clean up
* From v2
* Remove forceful dirty marking of swap-readed page - Johannes
* Remove deactivation logic of lazyfreed page
* Rebased on 3.14
* Remove RFC tag
* From v1
* Use custom page table walker for madvise_free - Johannes
* Remove PG_lazypage flag - Johannes
* Do madvise_dontneed instead of madvise_freein swapless system
--- include/linux/rmap.h | 9 ++- include/linux/vm_event_item.h | 1 + include/uapi/asm-generic/mman-common.h | 1 + mm/madvise.c | 140 +++++++++++++++++++++++++++++++++ mm/rmap.c | 42 +++++++++- mm/vmscan.c | 40 ++++++++-- mm/vmstat.c | 1 + 7 files changed, 222 insertions(+), 12 deletions(-)
include/linux/rmap.h +7 -2
@@ -75,6 +75,7 @@ enum ttu_flags {TTU_UNMAP =1 ,/* unmap mode */ TTU_MIGRATION =2 ,/* migration mode */ TTU_MUNLOCK =4 ,/* munlock mode */ +TTU_FREE =8 ,/* free mode */ TTU_IGNORE_MLOCK = (1 <<8 ),/* ignore mlock */ TTU_IGNORE_ACCESS = (1 << 9), /* don't age */
@@ -181,7 +182,8 @@ static inline void page_dup_rmap(struct page *page)* Called from mm/vmscan.c to handle paging out */ int page_referenced (struct page *,int is_locked, -struct mem_cgroup *memcg,unsigned long *vm_flags); +struct mem_cgroup *memcg,unsigned long *vm_flags, +int *is_pte_dirty);#define TTU_ACTION (x) ((x) & TTU_ACTION_MASK)
@@ -260,9 +262,12 @@ int rmap_walk(struct page *page, struct rmap_walk_control *rwc);static inline int page_referenced (struct page *page,int is_locked,struct mem_cgroup *memcg, -unsigned long *vm_flags) +unsigned long *vm_flags, +int *is_pte_dirty) { *vm_flags =0 ; +if (is_pte_dirty) + *is_pte_dirty =0 ;return 0 ; }
include/linux/vm_event_item.h +1 -0
@@ -25,6 +25,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,FOR_ALL_ZONES (PGALLOC ),PGFREE ,PGACTIVATE ,PGDEACTIVATE ,PGFAULT ,PGMAJFAULT , +PGLAZYFREED ,FOR_ALL_ZONES (PGREFILL ),FOR_ALL_ZONES (PGSTEAL_KSWAPD ), FOR_ALL_ZONES(PGSTEAL_DIRECT),
include/uapi/asm-generic/mman-common.h +1 -0
@@ -34,6 +34,7 @@#define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ #define MADV_DONTNEED 4/* don't need these pages */ +#define MADV_FREE 5/* free pages only if memory pressure */ /* common parameters: try to keep these consistent across architectures */ #define MADV_REMOVE 9/* remove these pages & resources */
mm/madvise.c +140 -0
170 lines not on this page · raw message
mm/rmap.c +40 -2
120 lines not on this page · raw message
mm/vmscan.c +32 -8
@@ -712,13 +712,17 @@ enum page_references { };static enum page_references page_check_references (struct page *page, -struct scan_control *sc) +struct scan_control *sc, +bool *freeable) {int referenced_ptes, referenced_page;unsigned long vm_flags; +int pte_dirty; + +VM_BUG_ON_PAGE (!PageLocked (page), page); referenced_ptes =page_referenced (page,1 , sc->target_mem_cgroup, - &vm_flags); + &vm_flags, &pte_dirty); referenced_page =TestClearPageReferenced (page);/*
@@ -759,6 +763,10 @@ static enum page_references page_check_references(struct page *page,return PAGEREF_KEEP ; } +if (PageAnon (page) && !pte_dirty && !PageSwapCache (page) && + !PageDirty (page)) + *freeable = true; +/* Reclaim if clean, defer dirty pages to writeback */ if (referenced_page && !PageSwapBacked (page))return PAGEREF_RECLAIM_CLEAN ;
@@ -827,6 +835,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,int may_enter_fs;enum page_references references =PAGEREF_RECLAIM_CLEAN ;bool dirty, writeback; +bool freeable = false;cond_resched ();
@@ -950,7 +959,8 @@ static unsigned long shrink_page_list(struct list_head *page_list, }if (!force_reclaim) - references =page_check_references (page, sc); + references =page_check_references (page, sc, + &freeable);switch (references) {case PAGEREF_ACTIVATE :
@@ -966,7 +976,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,* Anonymous process memory has backing store? * Try to allocate it some swap space here. */ -if (PageAnon (page) && !PageSwapCache (page)) { +if (PageAnon (page) && !PageSwapCache (page) && !freeable) {if (!(sc->gfp_mask & __GFP_IO)) goto keep_locked;if (!add_to_swap (page, page_list))
@@ -981,8 +991,9 @@ static unsigned long shrink_page_list(struct list_head *page_list,* The page is mapped into the page tables of one or more * processes. Try to unmap it here. */ -if (page_mapped (page) && mapping) { -switch (try_to_unmap (page, ttu_flags)) { +if (page_mapped (page) && (mapping || freeable)) { +switch (try_to_unmap (page, + freeable ?TTU_FREE : ttu_flags)) {case SWAP_FAIL : goto activate_locked;case SWAP_AGAIN :
@@ -990,7 +1001,20 @@ static unsigned long shrink_page_list(struct list_head *page_list,case SWAP_MLOCK : goto cull_mlocked;case SWAP_SUCCESS : - ;/* try to free the page below */ +/* try to free the page below */ +if (!freeable) +break ; +/* +* Freeable anon page doesn't have mapping +* due to skipping of swapcache so we free +* page in here rather than __remove_mapping. +*/ +VM_BUG_ON_PAGE (PageSwapCache (page), page); +if (!page_freeze_refs (page,1 )) + goto keep_locked; +__clear_page_locked (page); +count_vm_event (PGLAZYFREED ); + goto free_it; } }
@@ -1730,7 +1754,7 @@ static void shrink_active_list(unsigned long nr_to_scan, }if (page_referenced (page,0 , sc->target_mem_cgroup, - &vm_flags)) { + &vm_flags,NULL )) { nr_rotated +=hpage_nr_pages (page);/* * Identify referenced, file-backed active pages and
mm/vmstat.c +1 -0
@@ -814,6 +814,7 @@ const char * const vmstat_text[] = {"pgfault" ,"pgmajfault" , +"pglazyfreed" , TEXTS_FOR_ZONES("pgrefill")TEXTS_FOR_ZONES ("pgsteal_kswapd" )
Signature · 7 lines
2.0.0 -- 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
[Late but I didn't get to this soone - I hope this is still up-to-date version]
Quoted 12 lines · Minchan Kim
Linux doesn't have an ability to free pages lazy while other OS already have been supported that named by
madvise(MADV_FREE).The gain is clear that kernel can discard freed pages rather than swapping out or OOM if memory pressure happens.
Without memory pressure, freed pages would be reused by userspace without another additional overhead(ex, page fault + allocation
+ zeroing).How to work is following as.
Quoted 7 lines
When madvise syscall is called, VM clears dirty bit of ptes of the range. If memory pressure happens, VM checks dirty bit of page table and if it found still "clean", it means it's a "lazyfree pages" so VM could discard the page instead of swapping out. Once there was store operation for the page before VM peek a page to reclaim, dirty bit is set so VM can swap out the page instead of discarding.
Is there any patch for madvise man page? I guess the semantic will be same/similar to FreeBSD:
http://www.freebsd.org/cgi/man.cgi?query=madvise&sektion=2
I guess the changelog should be more specific that this is only for the private MAP_ANON mappings (same applies to the patch for man).
Quoted 4 lines
Firstly, heavy users would be general
allocators(ex, jemalloc, tcmalloc and hope glibc supports it)and jemalloc/tcmalloc already have supported the feature for otherOS(ex, FreeBSD)
[...]
Quoted 12 lines
Cc Michael Kerrisk <[email protected]>Cc Linux API <[email protected]>Cc Hugh Dickins <[email protected]>Cc Johannes Weiner <[email protected]>Cc KOSAKI Motohiro <[email protected]>Cc Mel Gorman <[email protected]>Cc Jason Evans <[email protected]>Acked-by Zhang Yanfei <[email protected]>Acked-by Rik van Riel <[email protected]>Signed-off-by Minchan Kim <[email protected]>
Signature · 8 lines
Michal Hocko 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hello Michal,
Quoted 24 lines · Michal Hocko
[Late but I didn't get to this soone - I hope this is still up-to-date version]
Quoted 12 lines · Minchan Kim
Linux doesn't have an ability to free pages lazy while other OS already have been supported that named by
madvise(MADV_FREE).The gain is clear that kernel can discard freed pages rather than swapping out or OOM if memory pressure happens.
Without memory pressure, freed pages would be reused by userspace without another additional overhead(ex, page fault + allocation
+ zeroing).How to work is following as.
Quoted 7 lines
When madvise syscall is called, VM clears dirty bit of ptes of the range. If memory pressure happens, VM checks dirty bit of page table and if it found still "clean", it means it's a "lazyfree pages" so VM could discard the page instead of swapping out. Once there was store operation for the page before VM peek a page to reclaim, dirty bit is set so VM can swap out the page instead of discarding.
Quoted 3 lines
Is there any patch for madvise man page? I guess the semantic will be same/similar to FreeBSD:
http://www.freebsd.org/cgi/man.cgi?query=madvise&sektion=2
I postponed because I didn't know when we release the feature into mainline but I should write down in man page ("MADV_FREE since Linux x.x.x"). However, early posting is not harmful.
Here it goes.
Most of content was copied from FreeBSD man page.
Re: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
On Mon 01-12-14 08:56:52, Minchan Kim wrote:
[...]
Quoted 15 lines
From
2edd6890f92fa4943ce3c452194479458582d88cMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>--- man2/madvise.2 | 13 +++++++++++++ 1 file changed, 13 insertions(+)man2/madvise.2 +0
-0
man2/madvise.2 file (see · line 273
Quoted 9 lines
man2/madvise.2 +6
-0@@ -265,6 +265,19 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Gives the VM system the freedom to free pages, and tells the system that +information in the specified page range is no longer important. +This is an efficient way of allowing +.BR malloc (3)
This might be rather misleading. Only some malloc implementations are using this feature (jemalloc, right?). So either be specific about which implementation or do not add it at all.
man2/madvise.2 file (see · line 278
Quoted 5 lines
man2/madvise.2 +5
-0+to free pages anywhere in the address space, while keeping the address space +valid. The next time that the page is referenced, the page might be demand +zeroed, or might contain the data that was there before the MADV_FREE call. +References made to that address space range will not make the VM system page the +information back in from backing store until the page is modified again.
I am not sure I understand the last sentence. So say I did MADV_FREE and the reclaim has dropped that page. I know that the file backed mappings are not supported yet but assume they were for a second... Now, I do read from that location again what is the result?
If we consider anon mappings then the backing store is misleading as well because memory was dropped and so always newly allocated. I would rather drop the whole sentence and rather see an explanation what is the difference between to MADV_DONT_NEED.
"
Unlike MADV_DONT_NEED the memory is freed lazily e.g. when the VM system is under memory pressure.
"
Quoted 5 lines
man2/madvise.2 +2
-0+It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()
Signature · 8 lines
Michal Hocko 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 22 lines · Michal Hocko
On Mon 01-12-14 08:56:52, Minchan Kim wrote:
[...]Quoted 20 lines
From
2edd6890f92fa4943ce3c452194479458582d88cMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>--- man2/madvise.2 | 13 +++++++++++++ 1 file changed, 13 insertions(+)man2/madvise.2 +2
-0@@ -265,6 +265,19 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)"
Quoted 8 lines
man2/madvise.2 file (see · line 273
Quoted 4 lines
man2/madvise.2 +4
-0+Gives the VM system the freedom to free pages, and tells the system that +information in the specified page range is no longer important. +This is an efficient way of allowing +.BR malloc (3)This might be rather misleading. Only some malloc implementations are using this feature (jemalloc, right?). So either be specific about which implementation or do not add it at all.
Make sense. I don't think it's a good idea to say specific example in man page, which is rather arguable and limit the idea.
Quoted 11 lines
man2/madvise.2 file (see · line 278
Quoted 6 lines
man2/madvise.2 +5
-0+to free pages anywhere in the address space, while keeping the address space +valid. The next time that the page is referenced, the page might be demand +zeroed, or might contain the data that was there before the MADV_FREE call. +References made to that address space range will not make the VM system page the +information back in from backing store until the page is modified again.I am not sure I understand the last sentence. So say I did
MADV_FREEand the reclaim has dropped that page. I know that the file backed mappings are not supported yet but assume they were for a second... Now, I do read from that location again what is the result?
Zero page.
Quoted 2 lines
If we consider anon mappings then the backing store is misleading as well because memory was dropped and so always newly allocated.
When I read the sentence at first, I thought backing store means swap so I don't have any trouble to understand it. But I agree your opinion. Target for man page is not a kernel developer but application developer.
Quoted 6 lines
I would rather drop the whole sentence and rather see an explanation what is the difference between to
MADV_DONT_NEED.
"
UnlikeMADV_DONT_NEEDthe memory is freed lazily e.g. when the VM system is under memory pressure.
"
It's a good idea but I don't think it's enough. At least we should explan cancel of delay free logic(ie, write). So, How about this?
MADV_FREE " (since Linux 3.19)"
Gives the VM system the freedom to free pages, and tells the system that it's okay to free pages if the VM system has reasons(e.g., memory pressure). So, it looks like delayed MADV_DONTNEED.
The next time that the page is referenced, the page might be demand zeroed if the VM system freed the page. Otherwise, it might contain the data that was there before the MADV_FREE call if the VM system didn't free the page. New write in the page after the MADV_FREE call makes the VM system not free the page any more.
It works only with private anonymous pages (see mmap(2)).
Quoted 15 lines
Quoted 6 lines
man2/madvise.2 +2
-0+It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()Signature · 8 lines
Michal Hocko 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>
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 47 lines · Minchan Kim
Quoted 22 lines · Michal Hocko
On Mon 01-12-14 08:56:52, Minchan Kim wrote:
[...]Quoted 20 lines
From
2edd6890f92fa4943ce3c452194479458582d88cMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>--- man2/madvise.2 | 13 +++++++++++++ 1 file changed, 13 insertions(+)man2/madvise.2 +2
-0@@ -265,6 +265,19 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)"Quoted 8 lines
man2/madvise.2 file (see · line 273
Quoted 4 lines
man2/madvise.2 +4
-0+Gives the VM system the freedom to free pages, and tells the system that +information in the specified page range is no longer important. +This is an efficient way of allowing +.BR malloc (3)This might be rather misleading. Only some malloc implementations are using this feature (jemalloc, right?). So either be specific about which implementation or do not add it at all.
Make sense. I don't think it's a good idea to say specific example in man page, which is rather arguable and limit the idea.
Quoted 11 lines
man2/madvise.2 file (see · line 278
Quoted 6 lines
man2/madvise.2 +5
-0+to free pages anywhere in the address space, while keeping the address space +valid. The next time that the page is referenced, the page might be demand +zeroed, or might contain the data that was there before the MADV_FREE call. +References made to that address space range will not make the VM system page the +information back in from backing store until the page is modified again.I am not sure I understand the last sentence. So say I did
MADV_FREEand the reclaim has dropped that page. I know that the file backed mappings are not supported yet but assume they were for a second... Now, I do read from that location again what is the result?
Quoted 1 line
Zero page.
OK, it felt strange at first but now that I am thinking about it some more it starts making sense. So the semantic is: Either zero page (disconnected from the backing store) or the original content after madvise(MADV_FREE). The page gets connected to the backing store after it gets modified again. If this is the case then the sentence in the man page makes perfect sense.
What made me confused was that I expected file backed pages would get a fresh page from the origin but this would be awkward I guess.
Quoted 19 lines
Quoted 2 lines
If we consider anon mappings then the backing store is misleading as well because memory was dropped and so always newly allocated.
When I read the sentence at first, I thought backing store means swap so I don't have any trouble to understand it. But I agree your opinion. Target for man page is not a kernel developer but application developer.
Quoted 6 lines
I would rather drop the whole sentence and rather see an explanation what is the difference between to
MADV_DONT_NEED.
"
UnlikeMADV_DONT_NEEDthe memory is freed lazily e.g. when the VM system is under memory pressure.
"It's a good idea but I don't think it's enough. At least we should explan cancel of delay free
logic(ie, write). So, How about this?
MADV_FREE" (since Linux 3.19)"
Quoted 8 lines
Gives the VM system the freedom to free pages, and tells the system that it's okay to free pages if the VM system has
reasons(e.g., memory pressure). So, it looks like delayedMADV_DONTNEED.
The next time that the page is referenced, the page might be demand zeroed if the VM system freed the page. Otherwise, it might contain the data that was there before theMADV_FREEcall if the VM system didn't free the page. New write in the page after theMADV_FREEcall makes the VM system not free the page any more.
Dunno, I guess the original content was slightly better. Or the following wording from UNIX man pages is even more descriptive
(http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3)
"
Tell the kernel that contents in the specified address range are no longer important and the range will be overwritten. When there is demand for memory, the system will free pages associated with the specified address range. In this instance, the next time a page in the address range is referenced, it will contain all zeroes. Otherwise, it will con- tain the data that was there prior to the MADV_FREE call. References made to the address range will not make the system read from backing store (swap space) until the page is modified again.
This value cannot be used on mappings that have underlying file objects. "
I would just clarify the last sentence with addition (MAP_PRIVATE|MAP_ANONYMOUS mappings in this implementation). The difference to MADV_DONTNEED is more complicated now so I wouldn't make the text even more confusing.
Anyway the confusion started on my end so feel free to stick with the BSD wording (modulo malloc note which is really confusing as the default glibc allocator doesn't do that AFAIK).
Quoted 1 line
It works only with private anonymous pages (see mmap(2)).
Signature · 8 lines
Michal Hocko 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 101 lines · Michal Hocko
Quoted 47 lines · Minchan Kim
Quoted 22 lines · Michal Hocko
On Mon 01-12-14 08:56:52, Minchan Kim wrote:
[...]Quoted 20 lines
From
2edd6890f92fa4943ce3c452194479458582d88cMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>--- man2/madvise.2 | 13 +++++++++++++ 1 file changed, 13 insertions(+)man2/madvise.2 +2
-0@@ -265,6 +265,19 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)"Quoted 8 lines
man2/madvise.2 file (see · line 273
Quoted 4 lines
man2/madvise.2 +4
-0+Gives the VM system the freedom to free pages, and tells the system that +information in the specified page range is no longer important. +This is an efficient way of allowing +.BR malloc (3)This might be rather misleading. Only some malloc implementations are using this feature (jemalloc, right?). So either be specific about which implementation or do not add it at all.
Make sense. I don't think it's a good idea to say specific example in man page, which is rather arguable and limit the idea.
Quoted 11 lines
man2/madvise.2 file (see · line 278
Quoted 6 lines
man2/madvise.2 +5
-0+to free pages anywhere in the address space, while keeping the address space +valid. The next time that the page is referenced, the page might be demand +zeroed, or might contain the data that was there before the MADV_FREE call. +References made to that address space range will not make the VM system page the +information back in from backing store until the page is modified again.I am not sure I understand the last sentence. So say I did
MADV_FREEand the reclaim has dropped that page. I know that the file backed mappings are not supported yet but assume they were for a second... Now, I do read from that location again what is the result?Quoted 1 line
Zero page.
OK, it felt strange at first but now that I am thinking about it some more it starts making sense. So the semantic is: Either zero page (disconnected from the backing store) or the original content after
madvise(MADV_FREE). The page gets connected to the backing store after it gets modified again. If this is the case then the sentence in the man page makes perfect sense.What made me confused was that I expected file backed pages would get a fresh page from the origin but this would be awkward I guess.
Quoted 19 lines
Quoted 2 lines
If we consider anon mappings then the backing store is misleading as well because memory was dropped and so always newly allocated.
When I read the sentence at first, I thought backing store means swap so I don't have any trouble to understand it. But I agree your opinion. Target for man page is not a kernel developer but application developer.
Quoted 6 lines
I would rather drop the whole sentence and rather see an explanation what is the difference between to
MADV_DONT_NEED.
"
UnlikeMADV_DONT_NEEDthe memory is freed lazily e.g. when the VM system is under memory pressure.
"It's a good idea but I don't think it's enough. At least we should explan cancel of delay free
logic(ie, write). So, How about this?
MADV_FREE" (since Linux 3.19)"Quoted 8 lines
Gives the VM system the freedom to free pages, and tells the system that it's okay to free pages if the VM system has
reasons(e.g., memory pressure). So, it looks like delayedMADV_DONTNEED.
The next time that the page is referenced, the page might be demand zeroed if the VM system freed the page. Otherwise, it might contain the data that was there before theMADV_FREEcall if the VM system didn't free the page. New write in the page after theMADV_FREEcall makes the VM system not free the page any more.Dunno, I guess the original content was slightly better. Or the following wording from UNIX man pages is even more descriptive
(http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3)
"
Tell the kernel that contents in the specified address range are no longer important and the range will be overwritten. When there is demand for memory, the system will free pages associated with the specified address range. In this instance, the next time a page in the address range is referenced, it will contain all zeroes. Otherwise, it will con- tain the data that was there prior to theMADV_FREEcall. References made to the address range will not make the system read from backing store (swap space) until the page is modified again.
Quoted 2 lines
This value cannot be used on mappings that have underlying file objects. "
For me, it would be better.
Thanks for the heads up.
Quoted 3 lines
I would just clarify the last sentence with addition (MAP_PRIVATE|MAP_ANONYMOUS mappings in this implementation). The
I want to be consistent with KSM/THP which used "private anonymous pages". So, I guess man page maintainer already acked the term so I want to use it, too.
Quoted 10 lines
difference to
MADV_DONTNEEDis more complicated now so I wouldn't make the text even more confusing.Anyway the confusion started on my end so feel free to stick with the BSD wording (modulo malloc note which is really confusing as the default glibc allocator doesn't do that AFAIK).
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: Document MADV_FREE
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)
man2/madvise.2 +12 -0
@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise, +it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()
Signature · 5 lines
2.0.0 -- Kind regards, Minchan Kim
Michal Hocko
Reviewed-byRe: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
On Fri 05-12-14 16:08:16, Minchan Kim wrote:
[...]
Quoted 6 lines
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>
Thanks!
Quoted 37 lines
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)man2/madvise.2 +12
-0@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise, +it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()Signature · 9 lines
2.0.0 -- Kind regards, Minchan Kim -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 8 lines
Michal Hocko 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hello Minchan (and Michal)
I did not see this patch until just now when Michael explicitly mentioned it in another discussion because
(a) it was buried in an LMKL thread that started a topic that was not about a man-pages patch.
(b) linux-man@ was not CCed.
When resubmitting this patch, could you please To:me and CC linux-man@ and give the mail a suitable subject line indicating a man-pages patch.
Quoted 32 lines · Michal Hocko
On Fri 05-12-14 16:08:16, Minchan Kim wrote:
[...]Quoted 6 lines
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>Reviewed-by Michal Hocko <[email protected]>Thanks!
Quoted 19 lines
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)man2/madvise.2 +7
-0@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise,
Quoted 8 lines
man2/madvise.2 file (see · line 282
Quoted 8 lines
man2/madvise.2 +5
-0+it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()
If I'm reading the conversation right, the initially proposed text was from the BSD man page (which would be okay), but most of the text above seems to have come straight from the page here:
http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3
Right?
Unfortunately, I don't think we can use that text. It's from the Solaris man page as far as I can tell, and I doubt that it's under a license that we can use.
If that's the case, we need to go back and come up with an original text. It might draw inspiration from the Solaris page, and take actual text from the BSD page (which is under a free license), and it might also draw inspiration from Jon Corbet's description at http://lwn.net/Articles/590991/.
Could you take another shot this please!
Thanks,
Michael
Signature · 9 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- 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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hello, Michael
Quoted 7 lines · Michael Kerrisk (man-pages)
Hello Minchan (and Michal)
I did not see this patch until just now when Michael explicitly mentioned it in another discussion because
(a) it was buried in an LMKL thread that started a topic that was not about a man-pages patch.
(b) linux-man@ was not CCed.
Sorry about that.
Quoted 3 lines
When resubmitting this patch, could you please To:me and CC linux-man@ and give the mail a suitable subject line indicating a man-pages patch.
Sure.
Quoted 48 lines · Michal Hocko
Quoted 32 lines · Minchan Kim
[...]
Quoted 6 lines
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>Reviewed-by Michal Hocko <[email protected]>Thanks!
Quoted 19 lines
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)man2/madvise.2 +7
-0@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise,Quoted 8 lines
man2/madvise.2 file (see · line 282
Quoted 8 lines
man2/madvise.2 +5
-0+it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()If I'm reading the conversation right, the initially proposed text was from the BSD man page (which would be okay), but most of the text above seems to have come straight from the page here:
http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3
Quoted 1 line
Right?
True. Solaris man page was really straightforward/clear rather than BSD.
Quoted 5 lines
Unfortunately, I don't think we can use that text. It's from the Solaris man page as far as I can tell, and I doubt that it's under a license that we can use.
Quoted 7 lines
If that's the case, we need to go back and come up with an original text. It might draw inspiration from the Solaris page, and take actual text from the BSD page (which is under a free license), and it might also draw inspiration from Jon Corbet's description at http://lwn.net/Articles/590991/.
Could you take another shot this please!
No problem. I will test my essay writing skill.
Thanks.
Quoted 11 lines
Thanks,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
In my test, jemalloc will map 61G vma, and use about 32G memory without MADV_FREE. If MADV_FREE is enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patch slightly to make it work without swap), I got oom. If swap is enabled, my system is totally stalled because of swap activity. Without the MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so sounds MADV_FREE will introduce big trouble here.
Did you think about move the MADV_FREE pages to the head of inactive LRU, so they can be reclaimed easily?
Thanks,
Shaohua
Quoted 90 lines · Minchan Kim
Hello, Michael
Quoted 7 lines · Michael Kerrisk (man-pages)
Hello Minchan (and Michal)
I did not see this patch until just now when Michael explicitly mentioned it in another discussion because
(a) it was buried in an LMKL thread that started a topic that was not about a man-pages patch.
(b) linux-man@ was not CCed.Sorry about that.
Quoted 3 lines
When resubmitting this patch, could you please To:me and CC linux-man@ and give the mail a suitable subject line indicating a man-pages patch.
Sure.
Quoted 48 lines · Michal Hocko
Quoted 32 lines · Minchan Kim
[...]
Quoted 6 lines
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>Reviewed-by Michal Hocko <[email protected]>Thanks!
Quoted 19 lines
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)man2/madvise.2 +7
-0@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise,Quoted 8 lines
man2/madvise.2 file (see · line 282
Quoted 8 lines
man2/madvise.2 +5
-0+it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()If I'm reading the conversation right, the initially proposed text was from the BSD man page (which would be okay), but most of the text above seems to have come straight from the page here:
http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3Quoted 1 line
Right?
True. Solaris man page was really straightforward/clear rather than BSD.
Quoted 5 lines
Unfortunately, I don't think we can use that text. It's from the Solaris man page as far as I can tell, and I doubt that it's under a license that we can use.
Quoted 7 lines
If that's the case, we need to go back and come up with an original text. It might draw inspiration from the Solaris page, and take actual text from the BSD page (which is under a free license), and it might also draw inspiration from Jon Corbet's description at http://lwn.net/Articles/590991/.
Could you take another shot this please!
No problem. I will test my essay writing skill.
Thanks.Quoted 3 lines
Thanks,
Quoted 18 lines
Quoted 8 lines
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/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>
--
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Quoted 4 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patch
Yes, IIUC, jemalloc replaces MADV_DONTNEED with MADV_FREE completely.
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with MADV_FREE with no swap, we should consider more things about anonymous aging.
Quoted 7 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?
I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion for MADV_FREE in my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.
However, MADV_FREE's main customer is allocators and afaik, they want to replace MADV_DONTNEED with MADV_FREE so I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.
In summary, I like your suggestion.
Thanks.
Quoted 113 lines
Thanks,
ShaohuaQuoted 108 lines · Minchan Kim
Hello, Michael
Quoted 7 lines · Michael Kerrisk (man-pages)
Hello Minchan (and Michal)
I did not see this patch until just now when Michael explicitly mentioned it in another discussion because
(a) it was buried in an LMKL thread that started a topic that was not about a man-pages patch.
(b) linux-man@ was not CCed.Sorry about that.
Quoted 3 lines
When resubmitting this patch, could you please To:me and CC linux-man@ and give the mail a suitable subject line indicating a man-pages patch.
Sure.
Quoted 48 lines · Michal Hocko
Quoted 32 lines · Minchan Kim
[...]
Quoted 6 lines
From
cfa212d4fb307ae772b08cf564cab7e6adb8f4fcMon Sep 17 00:00:00 2001
From: Minchan Kim <[email protected]>
Date: Mon, 1 Dec 2014 08:53:55 +0900
Subject: [PATCH] madvise.2: DocumentMADV_FREESigned-off-by Minchan Kim <[email protected]>Reviewed-by Michal Hocko <[email protected]>Thanks!
Quoted 19 lines
--- man2/madvise.2 | 12 ++++++++++++ 1 file changed, 12 insertions(+)man2/madvise.2 +7
-0@@ -265,6 +265,18 @@ file (see .BR MADV_DODUMP " (since Linux 3.4)" Undo the effect of an earlier .BR MADV_DONTDUMP . +.TP +.BR MADV_FREE " (since Linux 3.19)" +Tell the kernel that contents in the specified address range are no +longer important and the range will be overwritten. When there is +demand for memory, the system will free pages associated with the +specified address range. In this instance, the next time a page in the +address range is referenced, it will contain all zeroes. Otherwise,Quoted 8 lines
man2/madvise.2 file (see · line 282
Quoted 8 lines
man2/madvise.2 +5
-0+it will contain the data that was there prior to the MADV_FREE call. +References made to the address range will not make the system read +from backing store (swap space) until the page is modified again. +It works only with private anonymous pages (see +.BR mmap (2)). .SH RETURN VALUE On success .BR madvise ()If I'm reading the conversation right, the initially proposed text was from the BSD man page (which would be okay), but most of the text above seems to have come straight from the page here:
http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3Quoted 1 line
Right?
True. Solaris man page was really straightforward/clear rather than BSD.
Quoted 5 lines
Unfortunately, I don't think we can use that text. It's from the Solaris man page as far as I can tell, and I doubt that it's under a license that we can use.
Quoted 7 lines
If that's the case, we need to go back and come up with an original text. It might draw inspiration from the Solaris page, and take actual text from the BSD page (which is under a free license), and it might also draw inspiration from Jon Corbet's description at http://lwn.net/Articles/590991/.
Could you take another shot this please!
No problem. I will test my essay writing skill.
Thanks.Quoted 11 lines
Thanks,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/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>
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.
right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.
In the patch, MADV_FREE will be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and make MADV_FREE always enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.
Quoted 19 lines
Quoted 7 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.
Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.
Yes, they are definitely cold pages. I thought We should make sure the MADV_FREE pages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first or MADV_FREE pages first.
Thanks,
Shaohua
--
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 34 lines · Shaohua Li
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.
Quoted 6 lines
In the patch,
MADV_FREEwill be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and makeMADV_FREEalways enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.
In current VM implementation, it doesn't age anonymous LRU list if we have no swap. That's the reason to drop freeing pages instantly.
I think it could be enhanced later.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-December/311591.html
Quoted 30 lines
Quoted 20 lines
Quoted 8 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.
Quoted 4 lines
Yes, they are definitely cold pages. I thought We should make sure the
MADV_FREEpages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first orMADV_FREEpages first.
Frankly speaking, the issue with writeback page is just hurdle of implementation, not design so if we could fix it, we might move cold pages into tail of the inactive LRU. I tried it but don't have time slot to continue these days. Hope to get a time to look soon.
https://lkml.org/lkml/2014/7/1/628
Even, it wouldn't be critical problem although we couldn't fix the problem of writeback pages because they are already all cold pages so it might be not important to keep order in LRU so we could save working set and effort of VM to reclaim them at the cost of moving all of hinting pages into tail of the LRU whenever the syscall is called.
However, significant problem from my mind is we couldn't make sure they are really cold pages. It would be true for allocators but it's cache-friendly pages so it might be better to discard tail pages of inactive LRU, which are really cold.
In addition, we couldn't expect all of usecase for MADV_FREE so some of users might want to treat them as warm, not cold.
With moving them into inactive list's head, if we still see a lot stall, I think it's a sign to add other logic, for example, we could drop MADV_FREEed pages instantly if the zone is below low min watermark when the syscall is called. Because everybody doesn't like direct reclaim.
Quoted 3 lines
Thanks,
Shaohua
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 101 lines · Minchan Kim
Quoted 34 lines · Shaohua Li
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.Quoted 6 lines
In the patch,
MADV_FREEwill be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and makeMADV_FREEalways enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.In current VM implementation, it doesn't age anonymous LRU list if we have no swap. That's the reason to drop freeing pages instantly.
I think it could be enhanced later.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-December/311591.htmlQuoted 30 lines
Quoted 20 lines
Quoted 8 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.Quoted 4 lines
Yes, they are definitely cold pages. I thought We should make sure the
MADV_FREEpages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first orMADV_FREEpages first.Frankly speaking, the issue with writeback page is just hurdle of implementation, not design so if we could fix it, we might move cold pages into tail of the inactive LRU. I tried it but don't have time slot to continue these days. Hope to get a time to look soon.
https://lkml.org/lkml/2014/7/1/628
Even, it wouldn't be critical problem although we couldn't fix the problem of writeback pages because they are already all cold pages so it might be not important to keep order in LRU so we could save working set and effort of VM to reclaim them at the cost of moving all of hinting pages into tail of the LRU whenever the syscall is called.However, significant problem from my mind is we couldn't make sure they are really cold pages. It would be true for allocators but it's cache-friendly pages so it might be better to discard tail pages of inactive LRU, which are really cold.
In addition, we couldn't expect all of usecase forMADV_FREEso some of users might want to treat them as warm, not cold.
Quoted 5 lines
With moving them into inactive list's head, if we still see a lot stall, I think it's a sign to add other logic, for example, we could drop
MADV_FREEedpages instantly if the zone is below low min watermark when the syscall is called. Because everybody doesn't like direct reclaim.
So I tried move the MADV_FREE pages to inactive list head or tail. It helps a little. But there are still stalls/oom. kswapd isn't fast enough to free the pages, App enters direct reclaim frequently. In one machine, no swap trigger, but MADV_FREE is 5x slower than MADV_DONTNEED. In another machine, MADV_FREE trigers a lot of swap and sometimes even oom. app enters direct reclaim and has a lot of lock contention because of excessive direct reclaim, so there are a lot of stalls.
Thanks,
Shaohua
--
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hi Shaohua,
Quoted 108 lines · Shaohua Li
Quoted 101 lines · Minchan Kim
Quoted 34 lines · Shaohua Li
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.Quoted 6 lines
In the patch,
MADV_FREEwill be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and makeMADV_FREEalways enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.In current VM implementation, it doesn't age anonymous LRU list if we have no swap. That's the reason to drop freeing pages instantly.
I think it could be enhanced later.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-December/311591.htmlQuoted 30 lines
Quoted 20 lines
Quoted 8 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.Quoted 4 lines
Yes, they are definitely cold pages. I thought We should make sure the
MADV_FREEpages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first orMADV_FREEpages first.Frankly speaking, the issue with writeback page is just hurdle of implementation, not design so if we could fix it, we might move cold pages into tail of the inactive LRU. I tried it but don't have time slot to continue these days. Hope to get a time to look soon.
https://lkml.org/lkml/2014/7/1/628
Even, it wouldn't be critical problem although we couldn't fix the problem of writeback pages because they are already all cold pages so it might be not important to keep order in LRU so we could save working set and effort of VM to reclaim them at the cost of moving all of hinting pages into tail of the LRU whenever the syscall is called.However, significant problem from my mind is we couldn't make sure they are really cold pages. It would be true for allocators but it's cache-friendly pages so it might be better to discard tail pages of inactive LRU, which are really cold.
In addition, we couldn't expect all of usecase forMADV_FREEso some of users might want to treat them as warm, not cold.Quoted 5 lines
With moving them into inactive list's head, if we still see a lot stall, I think it's a sign to add other logic, for example, we could drop
MADV_FREEedpages instantly if the zone is below low min watermark when the syscall is called. Because everybody doesn't like direct reclaim.
Quoted 4 lines
So I tried move the
MADV_FREEpages to inactive list head or tail. It helps a little. But there are still stalls/oom. kswapd isn't fast enough to free the pages, App enters direct reclaim frequently. In one machine, no swap trigger, butMADV_FREEis 5x slower thanMADV_DONTNEED. In another machine,MADV_FREE
It's expected. MADV_DONTNEED and MADV_FREE is really different. MADV_DONTNEED is self-sacrificy for others in the system while MADV_FREE is greedy approach for itself because random process asking the memory could enter direct reclaim.
However, as I said earlier, we could mitigate the problem by checking min_free_kbytes. If memory in the system is under min_free_kbytes, it is pointless to impose reclaim overhead for hinted pages because we alreay know the hint is "please free when you are trouble with memory" and we got know it already.
When I test below patch on my 3G machine + 12 CPU + 8G swap with below test
test: 12 processes(each process does 5 iteration: mmap 512M + memset + madvise),
1. MADV_DONTNEED : 41.884sec, sys:3m4.552
2. MADV_FREE : 1m28sec, sys: 5m23
3. MADV_FREE + below patch : 37.188s, sys: 2m20
Could you test?
mm/madvise.c +1 -1
@@ -523,7 +523,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,* XXX: In this implementation, MADV_FREE works like * MADV_DONTNEED on swapless system or full swap. */ -if (get_nr_swap_pages () >0 ) +if (get_nr_swap_pages () >0 && min_free_kbytes <nr_free_pages ())return madvise_free (vma, prev, start, end);/* passthrough */ case MADV_DONTNEED :
Quoted 6 lines
trigers a lot of swap and sometimes even oom. app enters direct reclaim and has a lot of lock contention because of excessive direct reclaim, so there are a lot of stalls.
Thanks,
Shaohua
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 140 lines · Minchan Kim
Hi Shaohua,
Quoted 108 lines · Shaohua Li
Quoted 101 lines · Minchan Kim
Quoted 34 lines · Shaohua Li
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.Quoted 6 lines
In the patch,
MADV_FREEwill be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and makeMADV_FREEalways enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.In current VM implementation, it doesn't age anonymous LRU list if we have no swap. That's the reason to drop freeing pages instantly.
I think it could be enhanced later.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-December/311591.htmlQuoted 30 lines
Quoted 20 lines
Quoted 8 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.Quoted 4 lines
Yes, they are definitely cold pages. I thought We should make sure the
MADV_FREEpages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first orMADV_FREEpages first.Frankly speaking, the issue with writeback page is just hurdle of implementation, not design so if we could fix it, we might move cold pages into tail of the inactive LRU. I tried it but don't have time slot to continue these days. Hope to get a time to look soon.
https://lkml.org/lkml/2014/7/1/628
Even, it wouldn't be critical problem although we couldn't fix the problem of writeback pages because they are already all cold pages so it might be not important to keep order in LRU so we could save working set and effort of VM to reclaim them at the cost of moving all of hinting pages into tail of the LRU whenever the syscall is called.However, significant problem from my mind is we couldn't make sure they are really cold pages. It would be true for allocators but it's cache-friendly pages so it might be better to discard tail pages of inactive LRU, which are really cold.
In addition, we couldn't expect all of usecase forMADV_FREEso some of users might want to treat them as warm, not cold.Quoted 5 lines
With moving them into inactive list's head, if we still see a lot stall, I think it's a sign to add other logic, for example, we could drop
MADV_FREEedpages instantly if the zone is below low min watermark when the syscall is called. Because everybody doesn't like direct reclaim.Quoted 4 lines
So I tried move the
MADV_FREEpages to inactive list head or tail. It helps a little. But there are still stalls/oom. kswapd isn't fast enough to free the pages, App enters direct reclaim frequently. In one machine, no swap trigger, butMADV_FREEis 5x slower thanMADV_DONTNEED. In another machine,MADV_FREEIt's expected.
MADV_DONTNEEDandMADV_FREEis really different.MADV_DONTNEEDis self-sacrificy for others in the system whileMADV_FREEis greedy approach for itself because random process asking the memory could enter direct reclaim.
However, as I said earlier, we could mitigate the problem by checkingmin_free_kbytes. If memory in the system is undermin_free_kbytes, it is pointless to impose reclaim overhead for hinted pages because we alreay know the hint is "please free when you are trouble with memory" and we got know it already.When I test below patch on my 3G machine + 12 CPU + 8G swap with below test
test: 12 processes(each process does 5 iteration: mmap 512M + memset + madvise),1.
MADV_DONTNEED: 41.884sec, sys:3m4.552
2.MADV_FREE: 1m28sec, sys: 5m23
3.MADV_FREE+ below patch : 37.188s, sys: 2m20Could you test?
mm/madvise.c +0
-0
mm/madvise.c madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, · line 529
Quoted 8 lines
mm/madvise.c +1
-1@@ -523,7 +523,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,* XXX: In this implementation, MADV_FREE works like * MADV_DONTNEED on swapless system or full swap. */ -if (get_nr_swap_pages () >0 ) +if (get_nr_swap_pages () >0 && min_free_kbytes <nr_free_pages ())return madvise_free (vma, prev, start, end);/* passthrough */ case MADV_DONTNEED :
The throttling makes a lot of sense, definitely should be included in the patch. At least my jemalloc test has similar performance result with/without the patch in memory pressure case. So overall I'm pretty happy with it. However, this only solves half of the problem. pages which are MADV_FREE before watermark is hit are still hard to be reclaimed later if there are other allocations. I'm not sure how severe this issue is. My jemalloc test frequently does madvise (fallback to DONTNEED with above change), so itself can free a lot of memory in memory pressure. If application uses MADV_FREE before watermark is hit, but don't use it after watermark is hit, we will have trouble.
Thanks,
Shaohua
Re: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Hi Shaohua,
Quoted 136 lines · Shaohua Li
Quoted 135 lines · Minchan Kim
Hi Shaohua,
Quoted 108 lines · Shaohua Li
Quoted 101 lines · Minchan Kim
Quoted 34 lines · Shaohua Li
Quoted 9 lines · Minchan Kim
Hi Shaohua,
Quoted 5 lines · Shaohua Li
Hi Minchan,
Sorry to jump in this thread so later, and if some issues are discussed before. I'm interesting in this patch, so tried it here. I use a simple test with
Quoted 6 lines
No problem at all. Interest is always win over ignorance.
Quoted 2 lines
jemalloc. Obviously this can improve performance when there is no memory pressure. Did you try setup with memory pressure?
Sure but it was not a huge memory system like yours.
Yes, I'd like to check the symptom in memory pressure, so choose such test.
Quoted 5 lines
Quoted 3 lines
In my test, jemalloc will map 61G vma, and use about 32G memory without
MADV_FREE. IfMADV_FREEis enabled, jemalloc will use whole 61G memory because madvise doesn't reclaim the unused memory. If I disable swap (tweak your patchYes, IIUC, jemalloc replaces
MADV_DONTNEEDwithMADV_FREEcompletely.right.
Quoted 7 lines
Quoted 1 line
slightly to make it work without swap), I got oom. If swap is enabled, my
You mean you modified anon aging logic so it works although there is no swap? If so, I have no idea why OOM happens. I guess it should free all of freeable pages during the aging so although system stall happens more, I don't expect OOM. Anyway, with
MADV_FREEwith no swap, we should consider more things about anonymous aging.Quoted 6 lines
In the patch,
MADV_FREEwill be disabled and fallback to DONTNEED if no swap is enabled. Our production environment doesn't enable swap, so I tried to delete the 'no swap' check and makeMADV_FREEalways enabled regardless if swap is enabled. I didn't change anything else. With such change, I saw oom immediately. So definitely we have aging issue, the pages aren't reclaimed fast.In current VM implementation, it doesn't age anonymous LRU list if we have no swap. That's the reason to drop freeing pages instantly.
I think it could be enhanced later.
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-December/311591.htmlQuoted 30 lines
Quoted 20 lines
Quoted 8 lines
system is totally stalled because of swap activity. Without the
MADV_FREE, everything is ok. Considering we definitely don't want to waste too much memory, a system with memory pressure is normal, so soundsMADV_FREEwill introduce big trouble here.Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?I think it's desirable if the page lived in active LRU.
The reason I didn't that was caused by volatile ranges system call which was motivaion forMADV_FREEin my mind.
In last LSF/MM, there was concern about data's hotness.
Some of users want to keep that as it is in LRU position, others want to handle that as cold(tail of inactive list)/warm(head of inactive list)/ hot(head of active list), for example.
The vrange syscall was just about volatiltiy, not depends on page hotness so the decision on my head was not to change LRU order and let's make new hotness advise if we need it later.Quoted 9 lines
However, MADV_FREE's main customer is allocators and afaik, they want to replace
MADV_DONTNEEDwithMADV_FREEso I think it is really cold, but we couldn't make sure so head of inactive is good compromise. Another concern about tail of inactive list is that there could be plenty of pages in there, which was asynchromos write-backed in previous reclaim path, not-yet reclaimed because of not being able to free the in softirq context of writeback. It means we ends up freeing more potential pages to become workingset in advance than pages VM already decided to evict.Quoted 4 lines
Yes, they are definitely cold pages. I thought We should make sure the
MADV_FREEpages are reclaimed first before other pages, at least in the anon LRU list, though there might be difficult to determine if we should reclaim writeback pages first orMADV_FREEpages first.Frankly speaking, the issue with writeback page is just hurdle of implementation, not design so if we could fix it, we might move cold pages into tail of the inactive LRU. I tried it but don't have time slot to continue these days. Hope to get a time to look soon.
https://lkml.org/lkml/2014/7/1/628
Even, it wouldn't be critical problem although we couldn't fix the problem of writeback pages because they are already all cold pages so it might be not important to keep order in LRU so we could save working set and effort of VM to reclaim them at the cost of moving all of hinting pages into tail of the LRU whenever the syscall is called.However, significant problem from my mind is we couldn't make sure they are really cold pages. It would be true for allocators but it's cache-friendly pages so it might be better to discard tail pages of inactive LRU, which are really cold.
In addition, we couldn't expect all of usecase forMADV_FREEso some of users might want to treat them as warm, not cold.Quoted 5 lines
With moving them into inactive list's head, if we still see a lot stall, I think it's a sign to add other logic, for example, we could drop
MADV_FREEedpages instantly if the zone is below low min watermark when the syscall is called. Because everybody doesn't like direct reclaim.Quoted 4 lines
So I tried move the
MADV_FREEpages to inactive list head or tail. It helps a little. But there are still stalls/oom. kswapd isn't fast enough to free the pages, App enters direct reclaim frequently. In one machine, no swap trigger, butMADV_FREEis 5x slower thanMADV_DONTNEED. In another machine,MADV_FREEIt's expected.
MADV_DONTNEEDandMADV_FREEis really different.MADV_DONTNEEDis self-sacrificy for others in the system whileMADV_FREEis greedy approach for itself because random process asking the memory could enter direct reclaim.
However, as I said earlier, we could mitigate the problem by checkingmin_free_kbytes. If memory in the system is undermin_free_kbytes, it is pointless to impose reclaim overhead for hinted pages because we alreay know the hint is "please free when you are trouble with memory" and we got know it already.When I test below patch on my 3G machine + 12 CPU + 8G swap with below test
test: 12 processes(each process does 5 iteration: mmap 512M + memset + madvise),1.
MADV_DONTNEED: 41.884sec, sys:3m4.552
2.MADV_FREE: 1m28sec, sys: 5m23
3.MADV_FREE+ below patch : 37.188s, sys: 2m20Could you test?
Quoted 16 lines
mm/madvise.c madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, · line 529
Quoted 13 lines
mm/madvise.c +1
-1@@ -523,7 +523,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,* XXX: In this implementation, MADV_FREE works like * MADV_DONTNEED on swapless system or full swap. */ -if (get_nr_swap_pages () >0 ) +if (get_nr_swap_pages () >0 && min_free_kbytes <nr_free_pages ())return madvise_free (vma, prev, start, end);/* passthrough */ case MADV_DONTNEED :The throttling makes a lot of sense, definitely should be included in the patch. At least my jemalloc test has similar performance result with/without
Yeb, I will post it with a little modification after long vacation.
Quoted 1 line
the patch in memory pressure case. So overall I'm pretty happy with it.
Thanks for the testing.
Quoted 6 lines
However, this only solves half of the problem. pages which are
MADV_FREEbefore watermark is hit are still hard to be reclaimed later if there are other allocations. I'm not sure how severe this issue is. My jemalloc test frequently does madvise (fallback to DONTNEED with above change), so itself can free a lot of memory in memory pressure. If application usesMADV_FREEbefore watermark is hit, but don't use it after watermark is hit, we will have trouble.
Fair enough. It might make those pages close to inactive LRU's tail be unlikely to free, instead rotate back to active LRU.
Hmm, I don't know how such anonymous LRU scanning without freeing makes trobule in huge system.
Anyway, one of the idea is we could use COW so that it could move recent dirtied pages into active LRU's head. Although it adds more overhead for MADV_FREE than now, it could solve above issue.
As well, I think we could make MADV_FREE support on swapless system easier. On swapless system, we don't move pages in active LRU to inactive so when MADV_FREE is called on, we could move those pages in inactive's LRU and if recent access happens on those pages before discarding by VM, we could move them from inactive to active list. So, inactive LRU list could have mostly freeable pages(if swapoff race happens, some of non-freeable pages remains inactive list) so it's not a performan problem only if VM does aging if there are anonymous pages
in inactive LRU list on swapless system.
Quoted 3 lines
Thanks,
Shaohua
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
In reply to Shaohua LiOn Thu 05-02-15 16:33:11, Shaohua Li wrote:
[...]
Quoted 2 lines
Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?
Yes this makes sense for pages living on the active LRU list. I would preserve LRU ordering on the inactive list because there is no good reason to make the operation more costly for inactive pages. On the other hand having tons of to-be-freed pages on the active list clearly sucks. Care to send a patch?
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
Quoted 10 lines · Michal Hocko
On Thu 05-02-15 16:33:11, Shaohua Li wrote:
[...]Quoted 2 lines
Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?Yes this makes sense for pages living on the active LRU list. I would preserve LRU ordering on the inactive list because there is no good reason to make the operation more costly for inactive pages. On the other hand having tons of to-be-freed pages on the active list clearly sucks. Care to send a patch?
Considering anon pages are in active LRU first, it's likely MADV_FREE pages are in active list. I'm curious why preserves the order of inactive list. App knows which pages are cold, why don't take the advantages? I'll play the patch more to see what I can do for it.
Thanks,
Shaohua
--
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 11 lines · Shaohua Li
Quoted 9 lines · Michal Hocko
On Thu 05-02-15 16:33:11, Shaohua Li wrote: [...]
Quoted 2 lines
Did you think about move the
MADV_FREEpages to the head of inactive LRU, so they can be reclaimed easily?Yes this makes sense for pages living on the active LRU list. I would preserve LRU ordering on the inactive list because there is no good reason to make the operation more costly for inactive pages. On the other hand having tons of to-be-freed pages on the active list clearly sucks. Care to send a patch?
Quoted 3 lines
Considering anon pages are in active LRU first, it's likely
MADV_FREEpages are in active list. I'm curious why preserves the order of inactive list.
Only before the first time MADV_FREE is called on those pages.
If a program repeatedly allocates and frees the same memory region, not moving the MADV_FREE pages around in the LRU several times can save some overhead.
- --
All rights reversed
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJU1QqHAAoJEM553pKExN6DTXoH/3bS+VhdIm1EpOc8OOFtBHvd T63DHObtOY1FOog48CtgvUCfo7Q+g1aG/9hz7lJNP1G26B3+LNszM9OtE/9QrYUH uzmuWvFL7l0W0qen/WsyO0RcyqN+0mEXvNVqynTmJJu8qAG0p5WsjA6L5Penzj// tnBmn5xb1h3COjDZkHsxBfkpfCpNq5dm88K6B3nApHz4QhfcviKefczsrWdZ/bBc 2uMnlIebKY1Oq9MDHsg8p/b3lIHzwAf0xGSvGLN0YfzDPzlqBMbxSbVubYEA9EaU OiS1XqRp8okeGgrxsRAb/F8wPgClpce+h0E5xpyUuew2rlD1OmciX6iIDcE5Zrk= =KUng
-----END PGP SIGNATURE-----
--
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: [PATCH v17 1/7] mm: support madvise(MADV_FREE)
In reply to Michael Kerrisk (man-pages)On Tue 03-02-15 17:39:24, Michael Kerrisk wrote:
[...]
Quoted 10 lines
If I'm reading the conversation right, the initially proposed text was from the BSD man page (which would be okay), but most of the text above seems to have come straight from the page here:
http://www.lehman.cuny.edu/cgi-bin/man-cgi?madvise+3Right?
Unfortunately, I don't think we can use that text. It's from the Solaris man page as far as I can tell, and I doubt that it's under a license that we can use.
Ohh, I wasn't aware of that restriction and didn't notice anything at the man page nor http://www.lehman.cuny.edu/cgi-bin/man-cgi.
But you are definitely right that it would be better to not use this source. Sorry about that, I should have noticed that myself.
Quoted 7 lines
If that's the case, we need to go back and come up with an original text. It might draw inspiration from the Solaris page, and take actual text from the BSD page (which is under a free license), and it might also draw inspiration from Jon Corbet's description at http://lwn.net/Articles/590991/.
Could you take another shot this please!
Minchan is obviously working on one and I will review it once he is done with it.
Signature · 2 lines
Michal Hocko SUSE Labs
PATCH v17 2/7 x86: add pmd_[dirty|mkclean] for THP
In reply to Minchan KimMADV_FREE needs pmd_dirty and pmd_mkclean for detecting recent overwrite of the contents since MADV_FREE syscall is called for THP page.
This patch adds pmd_dirty and pmd_mkclean for THP page MADV_FREE support.
--- arch/x86/include/asm/pgtable.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/include/asm/pgtable.h +10 -0
@@ -104,6 +104,11 @@ static inline int pmd_young(pmd_t pmd)return pmd_flags (pmd) & _PAGE_ACCESSED; } +static inline int pmd_dirty (pmd_t pmd) +{ +return pmd_flags (pmd) & _PAGE_DIRTY; +} +static inline int pte_write (pte_t pte) {return pte_flags (pte) & _PAGE_RW;
@@ -272,6 +277,11 @@ static inline pmd_t pmd_mkold(pmd_t pmd)return pmd_clear_flags (pmd, _PAGE_ACCESSED); } +static inline pmd_t pmd_mkclean (pmd_t pmd) +{ +return pmd_clear_flags (pmd, _PAGE_DIRTY); +} +static inline pmd_t pmd_wrprotect (pmd_t pmd) {return pmd_clear_flags (pmd, _PAGE_RW);
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 3/7 sparc: add pmd_[dirty|mkclean] for THP
In reply to Minchan KimMADV_FREE needs pmd_dirty and pmd_mkclean for detecting recent overwrite of the contents since MADV_FREE syscall is called for THP page.
This patch adds pmd_dirty and pmd_mkclean for THP page MADV_FREE support.
--- arch/sparc/include/asm/pgtable_64.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/sparc/include/asm/pgtable_64.h +16 -0
@@ -666,6 +666,13 @@ static inline unsigned long pmd_young(pmd_t pmd)return pte_young (pte); } +static inline int pmd_dirty (pmd_t pmd) +{ +pte_t pte =__pte (pmd_val (pmd)); + +return pte_dirty (pte); +} +static inline unsigned long pmd_write (pmd_t pmd) {pte_t pte =__pte (pmd_val (pmd));
@@ -723,6 +730,15 @@ static inline pmd_t pmd_mkdirty(pmd_t pmd)return __pmd (pte_val (pte)); } +static inline pmd_t pmd_mkclean (pmd_t pmd) +{ +pte_t pte =__pte (pmd_val (pmd)); + + pte =pte_mkclean (pte); + +return __pmd (pte_val (pte)); +} +static inline pmd_t pmd_mkyoung (pmd_t pmd) {pte_t pte =__pte (pmd_val (pmd));
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 4/7 powerpc: add pmd_[dirty|mkclean] for THP
In reply to Minchan KimMADV_FREE needs pmd_dirty and pmd_mkclean for detecting recent overwrite of the contents since MADV_FREE syscall is called for THP page.
This patch adds pmd_dirty and pmd_mkclean for THP page MADV_FREE support.
--- arch/powerpc/include/asm/pgtable-ppc64.h | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/include/asm/pgtable-ppc64.h +2 -0
@@ -468,9 +468,11 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd)#define pmd_pfn (pmd) pte_pfn(pmd_pte(pmd))#define pmd_young (pmd) pte_young(pmd_pte(pmd)) +#define pmd_dirty (pmd) pte_dirty(pmd_pte(pmd))#define pmd_mkold (pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))#define pmd_wrprotect (pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))#define pmd_mkdirty (pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd))) +#define pmd_mkclean (pmd) pte_pmd(pte_mkclean(pmd_pte(pmd)))#define pmd_mkyoung (pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))#define pmd_mkwrite (pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 5/7 arm: add pmd_mkclean for THP
In reply to Minchan KimMADV_FREE needs pmd_dirty and pmd_mkclean for detecting recent overwrite of the contents since MADV_FREE syscall is called for THP page.
This patch adds pmd_mkclean for THP page MADV_FREE support.
--- arch/arm/include/asm/pgtable-3level.h | 1 + 1 file changed, 1 insertion(+)
arch/arm/include/asm/pgtable-3level.h +1 -0
@@ -249,6 +249,7 @@ PMD_BIT_FUNC(mkold, &= ~PMD_SECT_AF); PMD_BIT_FUNC(mksplitting, |= L_PMD_SECT_SPLITTING); PMD_BIT_FUNC(mkwrite, &= ~L_PMD_SECT_RDONLY); PMD_BIT_FUNC(mkdirty, |= L_PMD_SECT_DIRTY); +PMD_BIT_FUNC(mkclean, &= ~L_PMD_SECT_DIRTY); PMD_BIT_FUNC(mkyoung, |= PMD_SECT_AF);#define pmd_mkhuge (pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT))
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 6/7 arm64: add pmd_[dirty|mkclean] for THP
In reply to Minchan KimMADV_FREE needs pmd_dirty and pmd_mkclean for detecting recent overwrite of the contents since MADV_FREE syscall is called for THP page.
This patch adds pmd_dirty and pmd_mkclean for THP page MADV_FREE support.
--- arch/arm64/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/include/asm/pgtable.h +2 -0
@@ -275,10 +275,12 @@ void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #define pmd_young (pmd) pte_young(pmd_pte(pmd)) +#define pmd_dirty (pmd) pte_dirty(pmd_pte(pmd))#define pmd_wrprotect (pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))#define pmd_mksplitting (pmd) pte_pmd(pte_mkspecial(pmd_pte(pmd)))#define pmd_mkold (pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))#define pmd_mkwrite (pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd))) +#define pmd_mkclean (pmd) pte_pmd(pte_mkclean(pmd_pte(pmd)))#define pmd_mkdirty (pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))#define pmd_mkyoung (pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))#define pmd_mknotpresent (pmd) (__pmd(pmd_val(pmd) & ~PMD_TYPE_MASK))
Signature · 7 lines
2.0.0 -- 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>
PATCH v17 7/7 mm: Don't split THP page when syscall is called
In reply to Minchan KimWe don't need to split THP page when MADV_FREE syscall is called. It could be done when VM decide really frees it so we could avoid unnecessary THP split.
--- include/linux/huge_mm.h | 4 ++++ mm/huge_memory.c | 35 +++++++++++++++++++++++++++++++++++ mm/madvise.c | 21 ++++++++++++++++++++- mm/rmap.c | 8 ++++++-- mm/vmscan.c | 28 ++++++++++++++++++---------- 5 files changed, 83 insertions(+), 13 deletions(-)
include/linux/huge_mm.h +4 -0
@@ -19,6 +19,9 @@ extern struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,unsigned long addr, pmd_t *pmd, unsigned int flags); +extern int madvise_free_huge_pmd (struct mmu_gather *tlb, +struct vm_area_struct *vma, +pmd_t *pmd,unsigned long addr);extern int zap_huge_pmd (struct mmu_gather *tlb,struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr);
@@ -56,6 +59,7 @@ extern pmd_t *page_check_address_pmd(struct page *page,unsigned long address, enum page_check_address_pmd_flag flag, spinlock_t **ptl); +extern int pmd_freeable (pmd_t pmd);#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
mm/huge_memory.c +35 -0
@@ -1384,6 +1384,36 @@ out:return 0 ; } +int madvise_free_huge_pmd (struct mmu_gather *tlb,struct vm_area_struct *vma, +pmd_t *pmd,unsigned long addr) + +{ +spinlock_t *ptl; +struct mm_struct *mm = tlb->mm; +int ret =1 ; + +if (pmd_trans_huge_lock (pmd, vma, &ptl) ==1 ) { +struct page *page; +pmd_t orig_pmd; + + orig_pmd =pmdp_get_and_clear (mm, addr, pmd); + +/* No hugepage in swapcache */ + page =pmd_page (orig_pmd); +VM_BUG_ON_PAGE (PageSwapCache (page), page); + + orig_pmd =pmd_mkold (orig_pmd); + orig_pmd =pmd_mkclean (orig_pmd); + +set_pmd_at (mm, addr, pmd, orig_pmd); +tlb_remove_pmd_tlb_entry (tlb, pmd, addr); +spin_unlock (ptl); + ret =0 ; + } + +return ret; +} +int zap_huge_pmd (struct mmu_gather *tlb,struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr) {
@@ -1620,6 +1650,11 @@ unlock:return NULL ; } +int pmd_freeable (pmd_t pmd) +{ +return !pmd_dirty (pmd); +} +static int __split_huge_page_splitting (struct page *page,struct vm_area_struct *vma,unsigned long address)
mm/madvise.c +20 -1
@@ -271,8 +271,26 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,spinlock_t *ptl;pte_t *pte, ptent;struct page *page; +unsigned long next; + + next =pmd_addr_end (addr, end); +if (pmd_trans_huge (*pmd)) { +if (next - addr !=HPAGE_PMD_SIZE ) { +#ifdef CONFIG_DEBUG_VM +if (!rwsem_is_locked (&mm->mmap_sem)) { +pr_err ("%s: mmap_sem is unlocked! addr=0x%lx end=0x%lx vma->vm_start=0x%lx vma->vm_end=0x%lx\n" , + __func__, addr, end, + vma->vm_start, + vma->vm_end); +BUG (); + } +#endif +split_huge_page_pmd (vma, addr, pmd); + }else if (!madvise_free_huge_pmd (tlb, vma, pmd, addr)) + goto next; +/* fall through */ + } -split_huge_page_pmd (vma, addr, pmd);if (pmd_trans_unstable (pmd))return 0 ;
@@ -316,6 +334,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, }arch_leave_lazy_mmu_mode ();pte_unmap_unlock (pte -1 , ptl); +next:cond_resched ();return 0 ; }
mm/rmap.c +6 -2
@@ -704,9 +704,13 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma, referenced++;/* -* In this implmentation, MADV_FREE doesn't support THP free +* Use pmd_freeable instead of raw pmd_dirty because in some +* of architecture, pmd_dirty is not defined unless +* CONFIG_TRANSPARNTE_HUGE is enabled */ - dirty++; +if (!pmd_freeable (*pmd)) + dirty++; +spin_unlock (ptl); }else {pte_t *pte;
mm/vmscan.c +18 -10
@@ -976,17 +976,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,* Anonymous process memory has backing store? * Try to allocate it some swap space here. */ -if (PageAnon (page) && !PageSwapCache (page) && !freeable) { -if (!(sc->gfp_mask & __GFP_IO)) - goto keep_locked; -if (!add_to_swap (page, page_list)) - goto activate_locked; - may_enter_fs =1 ; - -/* Adding to swap updated mapping */ - mapping =page_mapping (page); +if (PageAnon (page) && !PageSwapCache (page)) { +if (!freeable) { +if (!(sc->gfp_mask & __GFP_IO)) + goto keep_locked; +if (!add_to_swap (page, page_list)) + goto activate_locked; + may_enter_fs =1 ; +/* Adding to swap updated mapping */ + mapping =page_mapping (page); + }else { +if (likely (!PageTransHuge (page))) + goto unmap; +/* try_to_unmap isn't aware of THP page */ +if (unlikely (split_huge_page_to_list (page, + page_list))) + goto keep_locked; + } } - +unmap:/* * The page is mapped into the page tables of one or more * processes. Try to unmap it here.
Signature · 7 lines
2.0.0 -- 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: [PATCH v17 7/7] mm: Don't split THP page when syscall is called
Quoted 8 lines · Minchan Kim
We don't need to split THP page when
MADV_FREEsyscall is called. It could be done when VM decide really frees it so we could avoid unnecessary THP split.Cc Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>Signed-off-by Minchan Kim <[email protected]>
Other than a minor comment below
Quoted 8 lines
--- include/linux/huge_mm.h | 4 ++++ mm/huge_memory.c | 35 +++++++++++++++++++++++++++++++++++ mm/madvise.c | 21 ++++++++++++++++++++- mm/rmap.c | 8 ++++++-- mm/vmscan.c | 28 ++++++++++++++++++---------- 5 files changed, 83 insertions(+), 13 deletions(-)
[...]
Quoted 12 lines
mm/madvise.c +4
-0@@ -271,8 +271,26 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,spinlock_t *ptl;pte_t *pte, ptent;struct page *page; +unsigned long next; + + next =pmd_addr_end (addr, end); +if (pmd_trans_huge (*pmd)) {
mm/madvise.c static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, · line 287
Quoted 10 lines
mm/madvise.c +10
-0+if (next - addr !=HPAGE_PMD_SIZE ) { +#ifdef CONFIG_DEBUG_VM +if (!rwsem_is_locked (&mm->mmap_sem)) { +pr_err ("%s: mmap_sem is unlocked! addr=0x%lx end=0x%lx vma->vm_start=0x%lx vma->vm_end=0x%lx\n" , + __func__, addr, end, + vma->vm_start, + vma->vm_end); +BUG (); + } +#endif
Why is this code here? madvise_free_pte_range is called only from the madvise path and we are holding mmap_sem and relying on that for regular pages as well.
Quoted 18 lines
mm/madvise.c +6
-1+split_huge_page_pmd (vma, addr, pmd); + }else if (!madvise_free_huge_pmd (tlb, vma, pmd, addr)) + goto next; +/* fall through */ + } -split_huge_page_pmd (vma, addr, pmd);if (pmd_trans_unstable (pmd))return 0 ;@@ -316,6 +334,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, }arch_leave_lazy_mmu_mode ();pte_unmap_unlock (pte -1 , ptl); +next:cond_resched ();return 0 ; }
[...]
Signature · 8 lines
Michal Hocko 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: [PATCH v17 7/7] mm: Don't split THP page when syscall is called
Quoted 5 lines · Michal Hocko
Quoted 4 lines · Minchan Kim
We don't need to split THP page when
MADV_FREEsyscall is called. It could be done when VM decide really frees it so we could avoid unnecessary THP split.
Quoted 7 lines
Quoted 4 lines
Cc Andrea Arcangeli <[email protected]>Acked-by Rik van Riel <[email protected]>Signed-off-by Minchan Kim <[email protected]>Other than a minor comment below
Reviewed-by Michal Hocko <[email protected]>
Thanks!
Quoted 28 lines
Quoted 9 lines
--- include/linux/huge_mm.h | 4 ++++ mm/huge_memory.c | 35 +++++++++++++++++++++++++++++++++++ mm/madvise.c | 21 ++++++++++++++++++++- mm/rmap.c | 8 ++++++-- mm/vmscan.c | 28 ++++++++++++++++++---------- 5 files changed, 83 insertions(+), 13 deletions(-)[...]
Quoted 18 lines
mm/madvise.c +10
-0@@ -271,8 +271,26 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,spinlock_t *ptl;pte_t *pte, ptent;struct page *page; +unsigned long next; + + next =pmd_addr_end (addr, end); + if (pmd_trans_huge(*pmd)) { + if (next - addr != HPAGE_PMD_SIZE) { +#ifdef CONFIG_DEBUG_VM + if (!rwsem_is_locked(&mm->mmap_sem)) { + pr_err("%s: mmap_sem is unlocked! addr=0x%lx end=0x%lx vma->vm_start=0x%lx vma->vm_end=0x%lx\n", + __func__, addr, end, + vma->vm_start,
Quoted 8 lines
mm/madvise.c static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, · line 287
Quoted 4 lines
mm/madvise.c +4
-0+ vma->vm_end); + BUG(); + } +#endif Why is this code here?
madvise_free_pte_rangeis called only from the madvise path and we are holdingmmap_semand relying on that for regular pages as well.
Make sense.
Hello Andrew,
It seems I have waited your review for a long time. What should I do to take your time slot?
Quoted 121 lines · Minchan Kim
This patch enable
MADV_FREEhint for madvise syscall, which have been supported by other OSes. [PATCH 1] includes the details.[1] support
MADVISE_FREEfor !THP page so if VM encounter THP page in syscall context, it splits THP page.
[2-6] is to preparing to call madvise syscall without THP plitting
[7] enable THP page support forMADV_FREE.* from v16
* Rebased on mmotm-2014-10-15-16-57* from v15
* Add more Acked-by - Rik van Riel
* Rebased on mmotom-08-29-15-15* from v14
* Add more Ackedy-by from archpeople(sparc, arm64 and arm)
* Drop s390 since pmd_dirty/clean was merged* from v13
* Add more Ackedy-by from archpeople(arm, arm64 and ppc)
* Rebased on mmotm 2014-08-13-14-29* from v12
* Fix - skip to mark free pte ontry_to_free_swapfailed page - Kirill
* Add more Acked-by from arch maintainers and Kirill* From v11
* Fix arm build - Steve
* Separate patch for arm and arm64 - Steve
* Remove unnecessary check - Kirill
* Skip non-vm_normal page - Kirill
* Add Acked-by - Zhang
* Sparc64 build fix
* Pagetable walker THP handling fix* From v10
* Add Acked-by from archstuff(x86, s390)
* Pagewalker based pagetable working - Kirill
* Fixtry_to_unmap_onebroken with hwpoison - Kirill
* UseVM_BUG_ON_PAGEinmadvise_free_pmd- Kirill
* Fixpgtable-3level.hfor arm - Steve* From v9
* Add Acked-by - Rik
* Add THP page support - Kirill* From v8
* Rebased-on v3.16-rc2-mmotm-2014-06-25-16-44* From v7
* Rebased-on next-20140613* From v6
* Remove page from swapcache in syscal time
* Move utility functions frommemory.ctomadvise.c- Johannes
* Rename untilify functtions - Johannes
* Remove unnecessary checks fromvmscan.c- Johannes
* Rebased-on v3.15-rc5-mmotm-2014-05-16-16-56
* Drop Reviewe-by because there was some changes since then.* From v5
* Fix PPC problem which don't flush TLB - Rik
* Remove unnecessarylazyfree_rangestub function - Rik
* Rebased on v3.15-rc5* From v4
* Add Reviewed-by: Zhang Yanfei
* Rebase on v3.15-rc1-mmotm-2014-04-15-16-14* From v3
* Add "how to work part" in description - Zhang
* Addpage_discardableutility function - Zhang
* Clean up* From v2
* Remove forceful dirty marking of swap-readed page - Johannes
* Remove deactivation logic of lazyfreed page
* Rebased on 3.14
* Remove RFC tag* From v1
* Use custom page table walker formadvise_free- Johannes
* RemovePG_lazypageflag - Johannes
* Domadvise_dontneedinstead ofmadvise_freeinswapless systemMinchan Kim (7):
mm: supportmadvise(MADV_FREE)
x86: add pmd_[dirty|mkclean] for THP
sparc: add pmd_[dirty|mkclean] for THP
powerpc: add pmd_[dirty|mkclean] for THP
arm: addpmd_mkcleanfor THP
arm64: add pmd_[dirty|mkclean] for THP
mm: Don't split THP page when syscall is calledarch/arm/include/asm/pgtable-3level.h | 1 + arch/arm64/include/asm/pgtable.h | 2 + arch/powerpc/include/asm/pgtable-ppc64.h | 2 + arch/sparc/include/asm/pgtable_64.h | 16 ++++ arch/x86/include/asm/pgtable.h | 10 ++ include/linux/huge_mm.h | 4 + include/linux/rmap.h | 9 +- include/linux/vm_event_item.h | 1 + include/uapi/asm-generic/mman-common.h | 1 + mm/huge_memory.c | 35 +++++++ mm/madvise.c | 159 +++++++++++++++++++++++++++++++ mm/rmap.c | 46 ++++++++- mm/vmscan.c | 64 +++++++++---- mm/vmstat.c | 1 + 14 files changed, 331 insertions(+), 20 deletions(-)Signature · 7 lines
2.0.0 -- 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>
Andrew Morton
maintainerQuoted 2 lines · On Fri, 14 Nov 2014 07:58:09 +0900 Minchan Kim <[email protected]> wrote:
It seems I have waited your review for a long time. What should I do to take your time slot?
I'm being terrible, sorry.
I'll merge the patches into -mm next week so at least they get some external testing while I get my ass into gear.