mm: make swapin readahead to gain more thp performance
Subsystems (4)
v4 cover mm: make swapin readahead to gain more thp performance
This patch series makes swapin readahead up to a certain number to gain more thp performance and adds tracepoint for khugepaged_scan_pmd, collapse_huge_page, __collapse_huge_page_isolate.
This patch series was written to deal with programs that access most, but not all, of their memory after they get swapped out. Currently these programs do not get their memory collapsed into THPs after the system swapped their memory out, while they would get THPs before swapping happened.
This patch series was tested with a test program, it allocates 800MB of memory, writes to it, and then sleeps. I force the system to swap out all. Afterwards, the test program touches the area by writing and leaves a piece of it without writing. This shows how much swap in readahead made by the patch.
Test results:
After swapped out
-------------------------------------------------------------------
| Anonymous | AnonHugePages | Swap | Fraction |
-------------------------------------------------------------------
With patch | 253720 kB | 251904 kB | 546284 kB | %99 |
-------------------------------------------------------------------
Without patch | 238160 kB | 235520 kB | 561844 kB | %98 |
-------------------------------------------------------------------
After swapped in
-------------------------------------------------------------------
| Anonymous | AnonHugePages | Swap | Fraction |
-------------------------------------------------------------------
With patch | 533532 kB | 528384 kB | 266472 kB | %90 |
-------------------------------------------------------------------
Without patch | 499956 kB | 235520 kB | 300048 kB | %47 |
-------------------------------------------------------------------
Ebru Akagunduz (3):
mm: add tracepoint for scanning pages
mm: make optimistic check for swapin readahead
mm: make swapin readahead to improve thp collapse rate
include/linux/mm.h | 4 + include/trace/events/huge_memory.h | 126 +++++++++++++++++ mm/huge_memory.c | 274 ++++++++++++++++++++++++++++++++----- mm/memory.c | 2 +- 4 files changed, 373 insertions(+), 33 deletions(-) create mode 100644 include/trace/events/huge_memory.h
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RFC v4 1/3 mm: add tracepoint for scanning pages
Using static tracepoints, data of functions is recorded. It is good to automatize debugging without doing a lot of changes in the source code.
This patch adds tracepoint for khugepaged_scan_pmd, collapse_huge_page and __collapse_huge_page_isolate.
---
Changes in v2:
- Nothing changed
Changes in v3:
- Print page address instead of vm_start (Vlastimil Babka)
- Define constants to specify exact tracepoint result (Vlastimil Babka)
Changes in v4:
- Change the constant prefix with SCAN_ instead of MM_ (Vlastimil Babka)
- Move the constants into the enum (Vlastimil Babka)
- Move the constants from mm.h to huge_memory.c
(because only will be used in huge_memory.c) (Vlastimil Babka)
- Print pfn in tracepoints (Vlastimil Babka)
- Print scan result as string in tracepoint (Vlastimil Babka) (I tried to make same things to print string like mm/compaction.c. My patch does not print string, I skip something but could not see why)
- Do not change function return values for success and failure, leave them original agreed with Doc/CodingStyle (Vlastimil Babka)
- Define scan_result to specify tracepoint result (Ebru Akagunduz)
- Add out_nolock label to avoid multiple tracepoints (Vlastimil Babka)
include/trace/events/huge_memory.h | 100 ++++++++++++++++++++ mm/huge_memory.c | 189 +++++++++++++++++++++++++++++++------ 2 files changed, 258 insertions(+), 31 deletions(-) create mode 100644 include/trace/events/huge_memory.h
include/trace/events/huge_memory.h new file +100 -0
@@ -0,0 +1,100 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM huge_memory + +#if !defined(__HUGE_MEMORY_H) || defined(TRACE_HEADER_MULTI_READ ) +#define __HUGE_MEMORY_H + +#include <linux/tracepoint.h> + +TRACE_EVENT (mm_khugepaged_scan_pmd, + + TP_PROTO(struct mm_struct *mm, unsigned long pfn, bool writable, + bool referenced, int none_or_zero, int status), + +TP_ARGS (mm, pfn, writable, referenced, none_or_zero, status), + +TP_STRUCT__entry ( + __field(struct mm_struct *, mm) + __field(unsigned long, pfn) + __field(bool, writable) + __field(bool, referenced) + __field(int, none_or_zero) +__field (int, status) + ), + +TP_fast_assign ( + __entry->mm = mm; + __entry->pfn = pfn; + __entry->writable = writable; + __entry->referenced = referenced; + __entry->none_or_zero = none_or_zero; + __entry->status = status; + ), + +TP_printk ("mm=%p, scan_pfn=0x%lx, writable=%d, referenced=%d, none_or_zero=%d, status=%s" , + __entry->mm, + __entry->pfn, + __entry->writable, + __entry->referenced, + __entry->none_or_zero, + khugepaged_status_string[__entry->status]) +); + +TRACE_EVENT (mm_collapse_huge_page, + + TP_PROTO(struct mm_struct *mm, int isolated, int status), + +TP_ARGS (mm, isolated, status), + +TP_STRUCT__entry ( + __field(struct mm_struct *, mm) + __field(int, isolated) +__field (int, status) + ), + +TP_fast_assign ( + __entry->mm = mm; + __entry->isolated = isolated; + __entry->status = status; + ), + +TP_printk ("mm=%p, isolated=%d, status=%s" , + __entry->mm, + __entry->isolated, + khugepaged_status_string[__entry->status]) +); + +TRACE_EVENT (mm_collapse_huge_page_isolate, + + TP_PROTO(unsigned long pfn, int none_or_zero, + bool referenced, bool writable, int status), + +TP_ARGS (pfn, none_or_zero, referenced, writable, status), + +TP_STRUCT__entry ( + __field(unsigned long, pfn) + __field(int, none_or_zero) + __field(bool, referenced) + __field(bool, writable) +__field (int, status) + ), + +TP_fast_assign ( + __entry->pfn = pfn; + __entry->none_or_zero = none_or_zero; + __entry->referenced = referenced; + __entry->writable = writable; + __entry->status = status; + ), + +TP_printk ("scan_pfn=0x%lx, none_or_zero=%d, referenced=%d, writable=%d, status=%s" , + __entry->pfn, + __entry->none_or_zero, + __entry->referenced, + __entry->writable, + khugepaged_status_string[__entry->status]) +); + +#endif /* __HUGE_MEMORY_H */ +#include <trace/define_trace.h> +
mm/huge_memory.c +158 -31
348 lines not on this page · raw message
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RFC v4 2/3 mm: make optimistic check for swapin readahead
In reply to Ebru AkagunduzThis patch introduces new sysfs integer knob /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_swap which makes optimistic check for swapin readahead to increase thp collapse rate. Before getting swapped out pages to memory, checks them and allows up to a certain number. It also prints out using tracepoints amount of unmapped ptes.
---
Changes in v2:
- Nothing changed
Changes in v3:
- Define constant for exact tracepoint result (Vlastimil Babka)
Changes in v4:
- Add sysfs knob request (Kirill A. Shutemov)
include/trace/events/huge_memory.h | 10 ++++---- mm/huge_memory.c | 48 ++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-)
include/trace/events/huge_memory.h +6 -4
@@ -9,9 +9,9 @@ TRACE_EVENT(mm_khugepaged_scan_pmd, TP_PROTO(struct mm_struct *mm, unsigned long pfn, bool writable, - bool referenced, int none_or_zero, int status), + bool referenced, int none_or_zero, int status, int unmapped), - TP_ARGS(mm, pfn, writable, referenced, none_or_zero, status), + TP_ARGS(mm, pfn, writable, referenced, none_or_zero, status, unmapped), TP_STRUCT__entry( __field(struct mm_struct *, mm)
@@ -20,6 +20,7 @@ TRACE_EVENT(mm_khugepaged_scan_pmd, __field(bool, referenced) __field(int, none_or_zero) __field(int, status) +__field (int, unmapped) ), TP_fast_assign(
@@ -31,13 +32,14 @@ TRACE_EVENT(mm_khugepaged_scan_pmd, __entry->status = status; ), -TP_printk ("mm=%p, scan_pfn=0x%lx, writable=%d, referenced=%d, none_or_zero=%d, status=%s" , +TP_printk ("mm=%p, scan_pfn=0x%lx, writable=%d, referenced=%d, none_or_zero=%d, status=%s, unmapped=%d" , __entry->mm, __entry->pfn, __entry->writable, __entry->referenced, __entry->none_or_zero, - khugepaged_status_string[__entry->status]) + khugepaged_status_string[__entry->status], + __entry->unmapped) ); TRACE_EVENT(mm_collapse_huge_page,
mm/huge_memory.c +44 -4
102 lines not on this page · raw message
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RFC v4 3/3 mm: make swapin readahead to improve thp collapse rate
In reply to Ebru AkagunduzThis patch makes swapin readahead to improve thp collapse rate. When khugepaged scanned pages, there can be a few of the pages in swap area.
With the patch THP can collapse 4kB pages into a THP when there are up to max_ptes_swap swap ptes in a 2MB range.
The patch was tested with a test program that allocates 800MB of memory, writes to it, and then sleeps. I force the system to swap out all. Afterwards, the test program touches the area by writing, it skips a page in each 20 pages of the area.
Without the patch, system did not swap in readahead. THP rate was %47 of the program of the memory, it did not change over time.
With this patch, after 10 minutes of waiting khugepaged had collapsed %90 of the program's memory.
---
Changes in v2:
- Use FAULT_FLAG_ALLOW_RETRY|FAULT_FLAG_RETRY_NOWAIT flag instead of 0x0 when called do_swap_page from __collapse_huge_page_swapin (Rik van Riel)
Changes in v3:
- Catch VM_FAULT_HWPOISON and VM_FAULT_OOM return cases in __collapse_huge_page_swapin (Kirill A. Shutemov)
Changes in v4:
- Fix broken indentation reverting if (...) statement in __collapse_huge_page_swapin (Kirill A. Shutemov)
- Fix check statement of ret (Kirill A. Shutemov)
- Use swapped_in name instead of swap_pte
After swapped out
-------------------------------------------------------------------
| Anonymous | AnonHugePages | Swap | Fraction |
-------------------------------------------------------------------
With patch | 253720 kB | 251904 kB | 546284 kB | %99 |
-------------------------------------------------------------------
Without patch | 238160 kB | 235520 kB | 561844 kB | %98 |
-------------------------------------------------------------------
After swapped in
-------------------------------------------------------------------
| Anonymous | AnonHugePages | Swap | Fraction |
-------------------------------------------------------------------
With patch | 533532 kB | 528384 kB | 266472 kB | %90 |
-------------------------------------------------------------------
Without patch | 499956 kB | 235520 kB | 300048 kB | %47 |
-------------------------------------------------------------------
include/linux/mm.h | 4 ++++ include/trace/events/huge_memory.h | 24 +++++++++++++++++++++ mm/huge_memory.c | 43 ++++++++++++++++++++++++++++++++++++++ mm/memory.c | 2 +- 4 files changed, 72 insertions(+), 1 deletion(-)
include/linux/mm.h +4 -0
@@ -29,6 +29,10 @@ struct user_struct;struct writeback_control ;struct bdi_writeback ; +extern int do_swap_page (struct mm_struct *mm,struct vm_area_struct *vma, +unsigned long address,pte_t *page_table,pmd_t *pmd, +unsigned int flags,pte_t orig_pte); +#ifndef CONFIG_NEED_MULTIPLE_NODES /* Don't use mapnrs, do it properly */ extern unsigned long max_mapnr;
include/trace/events/huge_memory.h +24 -0
@@ -97,6 +97,30 @@ TRACE_EVENT(mm_collapse_huge_page_isolate, khugepaged_status_string[__entry->status]) ); +TRACE_EVENT (mm_collapse_huge_page_swapin, + + TP_PROTO(struct mm_struct *mm, int swapped_in, int ret), + +TP_ARGS (mm, swapped_in, ret), + +TP_STRUCT__entry ( + __field(struct mm_struct *, mm) + __field(int, swapped_in) +__field (int, ret) + ), + +TP_fast_assign ( + __entry->mm = mm; + __entry->swapped_in = swapped_in; + __entry->ret = ret; + ), + +TP_printk ("mm=%p, swapped_in=%d, ret=%d" , + __entry->mm, + __entry->swapped_in, + __entry->ret) +); +#endif /* __HUGE_MEMORY_H */ #include <trace/define_trace.h>
mm/huge_memory.c +43 -0
55 lines not on this page · raw message
mm/memory.c +1 -1
@@ -2443,7 +2443,7 @@ EXPORT_SYMBOL(unmap_mapping_range);* We return with the mmap_sem locked or unlocked in the same cases * as does filemap_fault(). */ -static int do_swap_page (struct mm_struct *mm,struct vm_area_struct *vma, +int do_swap_page (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long address,pte_t *page_table,pmd_t *pmd,unsigned int flags,pte_t orig_pte) {
Signature · 7 lines
1.9.1 -- 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>