TLB flush multiple pages per IPI v7
Subsystems (12)
Mel Gorman
reviewercover TLB flush multiple pages per IPI v7
This is hopefully the final version that was agreed on. Ingo, you had sent an ack but I had to add a new arch helper after that for accounting purposes and there was a new patch added for the swap cluster suggestion. With the changes I did not include the ack just in case it was no longer valid.
Changelog since V6
o Rebase to v4.2-rc1
o Fix TLB flush counter accounting
o Drop dynamic allocation patch, no benefit and very messy
o Drop targetting flushing, expected to be of dubious merit
o Increase swap cluster max
Changelog since V5
o Split series to first do a full TLB flush and then targetting flushing
Changelog since V4
o Rebase to 4.1-rc6
Changelog since V3
o Drop batching of TLB flush from migration
o Redo how larger batching is managed
o Batch TLB flushes when writable entries exist
When unmapping pages it is necessary to flush the TLB. If that page was accessed by another CPU then an IPI is used to flush the remote CPU. That is a lot of IPIs if kswapd is scanning and unmapping >100K pages per second.
There already is a window between when a page is unmapped and when it is TLB flushed. This series ses the window so multiple pages can be flushed using a single IPI. This should be safe or the kernel is hosed already.
Patch 1 simply made the rest of the series easier to write as ftrace
could identify all the senders of TLB flush IPIS.
Patch 2 tracks what CPUs potentially map a PFN and then sends an IPI
to flush the entire TLB.
Patch 3 tracks when there potentially are writable TLB entries that
need to be batched differently
Patch 4 increases SWAP_CLUSTER_MAX to further batch flushes
The performance impact is documented in the changelogs but in the optimistic case on a 4-socket machine the full series reduces interrupts from 900K interrupts/second to 60K interrupts/second.
arch/x86/Kconfig | 1 + arch/x86/include/asm/tlbflush.h | 6 +++ arch/x86/mm/tlb.c | 1 + include/linux/mm_types.h | 1 + include/linux/rmap.h | 3 ++ include/linux/sched.h | 23 ++++++++ include/linux/swap.h | 2 +- include/trace/events/tlb.h | 3 +- init/Kconfig | 10 ++++ mm/internal.h | 15 ++++++ mm/rmap.c | 117 +++++++++++++++++++++++++++++++++++++++- mm/vmscan.c | 30 ++++++++++- 12 files changed, 207 insertions(+), 5 deletions(-)
Signature · 7 lines
2.3.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 1/4 x86, mm: Trace when an IPI is about to be sent
It is easy to trace when an IPI is received to flush a TLB but harder to detect what event sent it. This patch makes it easy to identify the source of IPIs being transmitted for TLB flushes on x86.
--- arch/x86/mm/tlb.c | 1 + include/linux/mm_types.h | 1 + include/trace/events/tlb.h | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/mm/tlb.c +1 -0
@@ -140,6 +140,7 @@ void native_flush_tlb_others(const struct cpumask *cpumask, info.flush_end = end;count_vm_tlb_event (NR_TLB_REMOTE_FLUSH ); +trace_tlb_flush (TLB_REMOTE_SEND_IPI , end - start);if (is_uv_system ()) {unsigned int cpu;
include/linux/mm_types.h +1 -0
@@ -552,6 +552,7 @@ enum tlb_flush_reason {TLB_REMOTE_SHOOTDOWN ,TLB_LOCAL_SHOOTDOWN ,TLB_LOCAL_MM_SHOOTDOWN , +TLB_REMOTE_SEND_IPI , NR_TLB_FLUSH_REASONS, };
include/trace/events/tlb.h +2 -1
@@ -11,7 +11,8 @@ EM( TLB_FLUSH_ON_TASK_SWITCH, "flush on task switch" ) \ EM( TLB_REMOTE_SHOOTDOWN, "remote shootdown" ) \ EM( TLB_LOCAL_SHOOTDOWN, "local shootdown" ) \ -EMe (TLB_LOCAL_MM_SHOOTDOWN ,"local mm shootdown" ) + EM( TLB_LOCAL_MM_SHOOTDOWN, "local mm shootdown" ) \ +EMe (TLB_REMOTE_SEND_IPI ,"remote ipi send" )/* * First define the enums in TLB_FLUSH_REASON to be exported to userspace
Signature · 7 lines
2.3.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 2/4 mm: Send one IPI per CPU to TLB flush all entries after unmapping pages
In reply to Mel GormanAn IPI is sent to flush remote TLBs when a page is unmapped that was potentially accesssed by other CPUs. There are many circumstances where this happens but the obvious one is kswapd reclaiming pages belonging to a running process as kswapd and the task are likely running on separate CPUs.
On small machines, this is not a significant problem but as machine gets larger with more cores and more memory, the cost of these IPIs can be high. This patch uses a simple structure that tracks CPUs that potentially have TLB entries for pages being unmapped. When the unmapping is complete, the full TLB is flushed on the assumption that a refill cost is lower than flushing individual entries.
Architectures wishing to do this must give the following guarantee.
If a clean page is unmapped and not immediately flushed, the architecture must guarantee that a write to that linear address from a CPU with a cached TLB entry will trap a page fault.
This is essentially what the kernel already depends on but the window is much larger with this patch applied and is worth highlighting. The architecture should consider whether the cost of the full TLB flush is higher than sending an IPI to flush each individual entry. An additional architecture helper called flush_tlb_local is required. It's a trivial wrapper with some accounting in the x86 case.
The impact of this patch depends on the workload as measuring any benefit requires both mapped pages co-located on the LRU and memory pressure. The case with the biggest impact is multiple processes reading mapped pages taken from the vm-scalability test suite. The test case uses NR_CPU readers of mapped files that consume 10*RAM.
Linear mapped reader on a 4-node machine with 64G RAM and 48 CPUs
4.2.0-rc1 4.2.0-rc1
vanilla flushfull-v7
Ops lru-file-mmap-read-elapsed 159.62 ( 0.00%) 120.68 ( 24.40%)
Ops lru-file-mmap-read-time_range 30.59 ( 0.00%) 2.80 ( 90.85%)
Ops lru-file-mmap-read-time_stddv 6.70 ( 0.00%) 0.64 ( 90.38%) 4.2.0-rc1 4.2.0-rc1
vanilla flushfull-v7User 581.00 611.43
System 5804.93 4111.76
Elapsed 161.03 122.12
This is showing that the readers completed 24.40% faster with 29% less system CPU time. From vmstats, it is known that the vanilla kernel was interrupted roughly 900K times per second during the steady phase of the test and the patched kernel was interrupts 180K times per second.
The impact is lower on a single socket machine.
4.2.0-rc1 4.2.0-rc1
vanilla flushfull-v7
Ops lru-file-mmap-read-elapsed 25.33 ( 0.00%) 20.38 ( 19.54%)
Ops lru-file-mmap-read-time_range 0.91 ( 0.00%) 1.44 (-58.24%)
Ops lru-file-mmap-read-time_stddv 0.28 ( 0.00%) 0.47 (-65.34%) 4.2.0-rc1 4.2.0-rc1
vanilla flushfull-v7
User 58.09 57.64
System 111.82 76.56
Elapsed 27.29 22.55It's still a noticeable improvement with vmstat showing interrupts went from roughly 500K per second to 45K per second.
The patch will have no impact on workloads with no memory pressure or have relatively few mapped pages. It will have an unpredictable impact on the workload running on the CPU being flushed as it'll depend on how many TLB entries need to be refilled and how long that takes. Worst case, the TLB will be completely cleared of active entries when the target PFNs were not resident at all.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/tlbflush.h | 6 +++ include/linux/rmap.h | 3 ++ include/linux/sched.h | 16 +++++++ init/Kconfig | 10 ++++ mm/internal.h | 11 +++++ mm/rmap.c | 103 +++++++++++++++++++++++++++++++++++++++- mm/vmscan.c | 23 ++++++++- 8 files changed, 171 insertions(+), 2 deletions(-)
arch/x86/Kconfig +1 -0
@@ -41,6 +41,7 @@ config X86 select ARCH_USE_CMPXCHG_LOCKREF if X86_64 select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS + select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if SMP select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_IPC_PARSE_VERSION if X86_32 select ARCH_WANT_OPTIONAL_GPIOLIB
arch/x86/include/asm/tlbflush.h +6 -0
@@ -261,6 +261,12 @@ static inline void reset_lazy_tlbstate(void)#endif /* SMP */ +/* Not inlined due to inc_irq_stat not being defined yet */ +#define flush_tlb_local () { \ + inc_irq_stat(irq_tlb_count); \ + local_flush_tlb(); \ +} +#ifndef CONFIG_PARAVIRT #define flush_tlb_others (mask, mm, start, end) \ native_flush_tlb_others(mask, mm, start, end)
include/linux/rmap.h +3 -0
@@ -89,6 +89,9 @@ enum ttu_flags {TTU_IGNORE_MLOCK = (1 <<8 ),/* ignore mlock */ TTU_IGNORE_ACCESS = (1 <<9 ),/* don't age */ TTU_IGNORE_HWPOISON = (1 <<10 ),/* corrupted page is recoverable */ +TTU_BATCH_FLUSH = (1 <<11 ),/* Batch TLB flushes where possible +* and caller guarantees they will +* do a final flush if necessary */ }; #ifdef CONFIG_MMU
include/linux/sched.h +16 -0
@@ -1341,6 +1341,18 @@ enum perf_event_task_context { perf_nr_task_contexts, }; +/* Track pages that require TLB flushes */ +struct tlbflush_unmap_batch { +/* +* Each bit set is a CPU that potentially has a TLB entry for one of +* the PFNs being flushed. See set_tlb_ubc_flush_pending(). +*/ +struct cpumask cpumask; + +/* True if any bit in cpumask is set */ +bool flush_required; +}; +struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */ void *stack;
@@ -1701,6 +1713,10 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH +struct tlbflush_unmap_batch tlb_ubc; +#endif +struct rcu_head rcu;/*
init/Kconfig +10 -0
@@ -891,6 +891,16 @@ config ARCH_SUPPORTS_NUMA_BALANCING bool # +# For architectures that prefer to flush all TLBs after a number of pages +# are unmapped instead of sending one IPI per page to flush. The architecture +# must provide guarantees on what happens if a clean TLB cache entry is +# written after the unmap. Details are in mm/rmap.c near the check for +# should_defer_flush. The architecture should also consider if the full flush +# and the refill costs are offset by the savings of sending fewer IPIs. +config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH + bool + +# # For architectures that know their GCC __int128 support is sound # config ARCH_SUPPORTS_INT128
mm/internal.h +11 -0
@@ -426,4 +426,15 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_CMA 0x80/* allow allocations from CMA areas */ #define ALLOC_FAIR 0x100/* fair zone allocation */ +enum ttu_flags ; +struct tlbflush_unmap_batch ; + +#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH +void try_to_unmap_flush (void ); +#else +static inline void try_to_unmap_flush (void ) +{ +} + +#endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ #endif /* __MM_INTERNAL_H */
mm/rmap.c +102 -1
121 lines not on this page · raw message
mm/vmscan.c +22 -1
@@ -1061,7 +1061,8 @@ static unsigned long shrink_page_list(struct list_head *page_list,* processes. Try to unmap it here. */ if (page_mapped (page) && mapping) { -switch (try_to_unmap (page, ttu_flags)) { +switch (try_to_unmap (page, + ttu_flags|TTU_BATCH_FLUSH )) {case SWAP_FAIL : goto activate_locked;case SWAP_AGAIN :
@@ -1212,6 +1213,7 @@ keep: }mem_cgroup_uncharge_list (&free_pages); +try_to_unmap_flush ();free_hot_cold_page_list (&free_pages, true);list_splice (&ret_pages, page_list);
@@ -2155,6 +2157,23 @@ out: } } +#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH +static void init_tlb_ubc (void ) +{ +/* +* This deliberately does not clear the cpumask as it's expensive +* and unnecessary. If there happens to be data in there then the +* first SWAP_CLUSTER_MAX pages will send an unnecessary IPI and +* then will be cleared. +*/ + current->tlb_ubc.flush_required = false; +} +#else +static inline void init_tlb_ubc (void ) +{ +} +#endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ +/* * This is a basic per-zone page freer. Used by both kswapd and direct reclaim. */
@@ -2189,6 +2208,8 @@ static void shrink_lruvec(struct lruvec *lruvec, int swappiness, scan_adjusted = (global_reclaim (sc) && !current_is_kswapd () && sc->priority ==DEF_PRIORITY ); +init_tlb_ubc (); +blk_start_plug (&plug);while (nr[LRU_INACTIVE_ANON ] || nr[LRU_ACTIVE_FILE ] || nr[LRU_INACTIVE_FILE ]) {
Signature · 7 lines
2.3.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 3/4 mm: Defer flush of writable TLB entries
In reply to Mel GormanIf a PTE is unmapped and it's dirty then it was writable recently. Due to deferred TLB flushing, it's best to assume a writable TLB cache entry exists. With that assumption, the TLB must be flushed before any IO can start or the page is freed to avoid lost writes or data corruption. This patch defers flushing of potentially writable TLBs as long as possible.
--- include/linux/sched.h | 7 +++++++ mm/internal.h | 4 ++++ mm/rmap.c | 28 +++++++++++++++++++++------- mm/vmscan.c | 7 ++++++- 4 files changed, 38 insertions(+), 8 deletions(-)
include/linux/sched.h +7 -0
@@ -1351,6 +1351,13 @@ struct tlbflush_unmap_batch {/* True if any bit in cpumask is set */ bool flush_required; + +/* +* If true then the PTE was dirty when unmapped. The entry must be +* flushed before IO is initiated or a stale TLB entry potentially +* allows an update without redirtying the page. +*/ +bool writable; };struct task_struct {
mm/internal.h +4 -0
@@ -431,10 +431,14 @@ struct tlbflush_unmap_batch;#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH void try_to_unmap_flush (void ); +void try_to_unmap_flush_dirty (void );#else static inline void try_to_unmap_flush (void ) { } +static inline void try_to_unmap_flush_dirty (void ) +{ +}#endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */ #endif /* __MM_INTERNAL_H */
mm/rmap.c +21 -7
@@ -625,16 +625,34 @@ void try_to_unmap_flush(void) }cpumask_clear (&tlb_ubc->cpumask); tlb_ubc->flush_required = false; + tlb_ubc->writable = false;put_cpu (); } +/* Flush iff there are potentially writable TLB entries that can race with IO */ +void try_to_unmap_flush_dirty (void ) +{ +struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; + +if (tlb_ubc->writable) +try_to_unmap_flush (); +} +static void set_tlb_ubc_flush_pending (struct mm_struct *mm, -struct page *page) +struct page *page,bool writable) {struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc;cpumask_or (&tlb_ubc->cpumask, &tlb_ubc->cpumask,mm_cpumask (mm)); tlb_ubc->flush_required = true; + +/* +* If the PTE was dirty then it's best to assume it's writable. The +* caller must use try_to_unmap_flush_dirty() or try_to_unmap_flush() +* before the page is queued for IO. +*/ +if (writable) + tlb_ubc->writable = true; }/*
@@ -657,7 +675,7 @@ static bool should_defer_flush(struct mm_struct *mm, enum ttu_flags flags) }#else static void set_tlb_ubc_flush_pending (struct mm_struct *mm, -struct page *page) +struct page *page,bool writable) { }
@@ -1314,11 +1332,7 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,*/ pteval =ptep_get_and_clear (mm, address, pte); -/* Potentially writable TLBs must be flushed before IO */ -if (pte_dirty (pteval)) -flush_tlb_page (vma, address); -else -set_tlb_ubc_flush_pending (mm, page); +set_tlb_ubc_flush_pending (mm, page,pte_dirty (pteval)); }else { pteval =ptep_clear_flush (vma, address, pte); }
mm/vmscan.c +6 -1
@@ -1102,7 +1102,12 @@ static unsigned long shrink_page_list(struct list_head *page_list,if (!sc->may_writepage) goto keep_locked; -/* Page is dirty, try to write it out here */ +/* +* Page is dirty. Flush the TLB if a writable entry +* potentially exists to avoid CPU writes after IO +* starts and then write it out here. +*/ +try_to_unmap_flush_dirty ();switch (pageout (page, mapping, sc)) {case PAGE_KEEP : goto keep_locked;
Signature · 7 lines
2.3.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 4/4 mm: Increase SWAP_CLUSTER_MAX to batch TLB flushes
In reply to Mel GormanPages that are unmapped for reclaim must be flushed before being freed to avoid corruption due to a page being freed and reallocated while a stale TLB entry exists. When reclaiming mapped pages, the requires one IPI per SWAP_CLUSTER_MAX. This patch increases SWAP_CLUSTER_MAX to 256 so more pages can be flushed with a single IPI. This number was selected because it reduced IPIs for TLB shootdowns by 40% on a workload that is dominated by mapped pages.
Note that it is expected that doubling SWAP_CLUSTER_MAX would not always halve the IPIs as it is workload dependent. Reclaim efficiency was not 100% on this workload which was picked for being IPI-intensive and was closer to 35%. More importantly, reclaim does not always isolate in SWAP_CLUSTER_MAX pages. The LRU lists for a zone may be small, the priority can be low and even when reclaiming a lot of pages, the last isolation may not be exactly SWAP_CLUSTER_MAX.
There are a few potential issues with increasing SWAP_CLUSTER_MAX.
1. LRU lock hold times increase slightly because more pages are being isolated.
2. There are slight timing changes due to more pages having to be processed before they are freed. There is a slight risk that more pages than are necessary get reclaimed.
3. There is a risk that too_many_isolated checks will be easier to trigger resulting in a HZ/10 stall.
4. The rotation rate of active->inactive is slightly faster but there should be fewer rotations before the lists get balanced so it shouldn't matter.
5. More pages are reclaimed in a single pass if zone_reclaim_mode is active but that thing sucks hard when it's enabled no matter what
6. More pages are isolated for compaction so page hold times there are longer while they are being copied
It's unlikely any of these will be problems but worth keeping in mind if there are any reclaim-related bug reports in the near future.
--- include/linux/swap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/swap.h +1 -1
@@ -154,7 +154,7 @@ enum { SWP_SCANNING = (1 << 10), /* refcount in scan_swap_map */ }; -#define SWAP_CLUSTER_MAX 32UL +#define SWAP_CLUSTER_MAX 256UL#define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX/*
Signature · 7 lines
2.3.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 4/4] mm: Increase SWAP_CLUSTER_MAX to batch TLB flushes
Quoted 33 lines · On Mon, 6 Jul 2015 14:39:56 +0100 Mel Gorman <[email protected]> wrote:
Pages that are unmapped for reclaim must be flushed before being freed to avoid corruption due to a page being freed and reallocated while a stale TLB entry exists. When reclaiming mapped pages, the requires one IPI per
SWAP_CLUSTER_MAX. This patch increasesSWAP_CLUSTER_MAXto 256 so more pages can be flushed with a single IPI. This number was selected because it reduced IPIs for TLB shootdowns by 40% on a workload that is dominated by mapped pages.Note that it is expected that doubling
SWAP_CLUSTER_MAXwould not always halve the IPIs as it is workload dependent. Reclaim efficiency was not 100% on this workload which was picked for being IPI-intensive and was closer to 35%. More importantly, reclaim does not always isolate inSWAP_CLUSTER_MAXpages. The LRU lists for a zone may be small, the priority can be low and even when reclaiming a lot of pages, the last isolation may not be exactlySWAP_CLUSTER_MAX.There are a few potential issues with increasing
SWAP_CLUSTER_MAX.1. LRU lock hold times increase slightly because more pages are being isolated.
2. There are slight timing changes due to more pages having to be processed before they are freed. There is a slight risk that more pages than are necessary get reclaimed.
3. There is a risk thattoo_many_isolatedchecks will be easier to trigger resulting in a HZ/10 stall.
4. The rotation rate ofactive->inactiveis slightly faster but there should be fewer rotations before the lists get balanced so it shouldn't matter.
5. More pages are reclaimed in a single pass ifzone_reclaim_modeis active but that thing sucks hard when it's enabled no matter what
6. More pages are isolated for compaction so page hold times there are longer while they are being copied
Quoted 2 lines
It's unlikely any of these will be problems but worth keeping in mind if there are any reclaim-related bug reports in the near future.
Yes, this may well cause small&subtle changes which will take some time to be noticed.
What is the overall effect on the performance improvement if this patch is omitted?
I wonder if we should leave small systems or !SMP systems or CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH=n systems with SWAP_CLUSTER_MAX=32. If not, why didn't we change this years ago ;)
--
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>
Mel Gorman
reviewerRe: [PATCH 4/4] mm: Increase SWAP_CLUSTER_MAX to batch TLB flushes
Quoted 35 lines · Andrew Morton
Quoted 33 lines · On Mon, 6 Jul 2015 14:39:56 +0100 Mel Gorman <[email protected]> wrote:
Pages that are unmapped for reclaim must be flushed before being freed to avoid corruption due to a page being freed and reallocated while a stale TLB entry exists. When reclaiming mapped pages, the requires one IPI per
SWAP_CLUSTER_MAX. This patch increasesSWAP_CLUSTER_MAXto 256 so more pages can be flushed with a single IPI. This number was selected because it reduced IPIs for TLB shootdowns by 40% on a workload that is dominated by mapped pages.Note that it is expected that doubling
SWAP_CLUSTER_MAXwould not always halve the IPIs as it is workload dependent. Reclaim efficiency was not 100% on this workload which was picked for being IPI-intensive and was closer to 35%. More importantly, reclaim does not always isolate inSWAP_CLUSTER_MAXpages. The LRU lists for a zone may be small, the priority can be low and even when reclaiming a lot of pages, the last isolation may not be exactlySWAP_CLUSTER_MAX.There are a few potential issues with increasing
SWAP_CLUSTER_MAX.1. LRU lock hold times increase slightly because more pages are being isolated.
2. There are slight timing changes due to more pages having to be processed before they are freed. There is a slight risk that more pages than are necessary get reclaimed.
3. There is a risk thattoo_many_isolatedchecks will be easier to trigger resulting in a HZ/10 stall.
4. The rotation rate ofactive->inactiveis slightly faster but there should be fewer rotations before the lists get balanced so it shouldn't matter.
5. More pages are reclaimed in a single pass ifzone_reclaim_modeis active but that thing sucks hard when it's enabled no matter what
6. More pages are isolated for compaction so page hold times there are longer while they are being copied
Quoted 9 lines
Quoted 2 lines
It's unlikely any of these will be problems but worth keeping in mind if there are any reclaim-related bug reports in the near future.
Yes, this may well cause small&subtle changes which will take some time to be noticed.
What is the overall effect on the performance improvement if this patch is omitted?
For the workload that maps a lot of memory and is reclaim-intensive, the headline performance difference is marginal, in the noise and inconclusive as to whether it's a win -- at least on the workloads and machines I tried. This is a representative example;
vmscale
4.2.0-rc1 4.2.0-rc1
batchdirty-v7r17 swapcluster-v7r17
Ops lru-file-mmap-read-elapsed 20.47 ( 0.00%) 20.36 ( 0.54%)
Ops lru-file-mmap-read-time_range 0.59 ( 0.00%) 0.72 (-22.03%)
Ops lru-file-mmap-read-time_stddv 0.19 ( 0.00%) 0.22 (-16.26%) 4.2.0-rc1 4.2.0-rc1
batchdirty-v7r17swapcluster-v7r17
User 58.20 57.13
System 76.97 78.09
Elapsed 22.50 22.45There is a slight gain in elapsed time but well within standard deviation and an increase in system CPUI usage. The number of IPIs sent is halved but other factors dominate such as LRU processing, rmap walks, page reference counting, IO etc.
A workload that force fragments memory and then attempts to allocate THP reported no significant difference as a result of this patch.
Other reclaim workloads were inconclusive on whether it was a gain or a loss. lmbench for mappings of different sizes showed little difference but it was nice to note that reclaim activity is approximately the same.
The "stutter" workload that measures the latency of mmap in the presense of intensive reclaim was odd for two reasons. This workload used to be a reliable indicator if a desktop interactivity would stall during heavy IO. First, it showed that mapping latency was higher -- 63ns stall on average with patch applied vs 30ns without patch. Second, it showed that compaction activity was high with many more migration attempts and failures. It follows that COMPACT_CLUSTER_MAX should have been divorced from SWAP_CLUSTER_MAX and separately considered.
A workload that runs a in-memory database while doing a lot of IO in the background showed no difference.
Overall, I would say that none of these workloads justify the patch on its own. Reducing IPIs further is nice but we got the bulk of the benefit from the two batching patches and after that other factors dominate. Based on the results I have, I'd be ok with the patch being dropped. It can be reconsidered for evaluation if someone complains about excessive IPIs again on reclaim intensive workloads.
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 4/4] mm: Increase SWAP_CLUSTER_MAX to batch TLB flushes
Quoted 6 lines · On Thu, 9 Jul 2015 09:14:25 +0100 Mel Gorman <[email protected]> wrote:
Overall, I would say that none of these workloads justify the patch on its own. Reducing IPIs further is nice but we got the bulk of the benefit from the two batching patches and after that other factors dominate. Based on the results I have, I'd be ok with the patch being dropped. It can be reconsidered for evaluation if someone complains about excessive IPIs again on reclaim intensive workloads.
OK, thanks. The benefit is small and there is some risk of unanticipated problems. I think I'll park the patch in -mm for now and will wait to see if something happens.
--
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>
Quoted 4 lines · Mel Gorman
This is hopefully the final version that was agreed on. Ingo, you had sent an ack but I had to add a new arch helper after that for accounting purposes and there was a new patch added for the swap cluster suggestion. With the changes I did not include the ack just in case it was no longer valid.
The series still looks very good to me:
Thanks Mel!
Ingo
--
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>
Mel Gorman
reviewer[PATCH 5/4] Documentation/features/vm: Add feature description and arch support status for batched TLB flush after unmap
In reply to Mel Gorman--- Documentation/features/vm/TLB/arch-support.txt | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
Documentation/features/vm/TLB/arch-support.txt new file +40 -0
@@ -0,0 +1,40 @@ +# +# Feature name: batch-unmap-tlb-flush +# Kconfig: ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH +# description: arch supports deferral of TLB flush until multiple pages are unmapped +# + ----------------------- + | arch |status| + ----------------------- + | alpha: | TODO | + | arc: | TODO | + | arm: | TODO | + | arm64: | TODO | + | avr32: | .. | + | blackfin: | TODO | + | c6x: | .. | + | cris: | .. | + | frv: | .. | + | h8300: | .. | + | hexagon: | TODO | + | ia64: | TODO | + | m32r: | TODO | + | m68k: | .. | + | metag: | TODO | + | microblaze: | .. | + | mips: | TODO | + | mn10300: | TODO | + | nios2: | .. | + | openrisc: | .. | + | parisc: | TODO | + | powerpc: | TODO | + | s390: | TODO | + | score: | .. | + | sh: | TODO | + | sparc: | TODO | + | tile: | TODO | + | um: | .. | + | unicore32: | .. | + | x86: | ok | + | xtensa: | TODO | + -----------------------
--
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>