RFC: Unified NUMA balancing tree, v1
Subsystems (21)
cover RFC: Unified NUMA balancing tree, v1
Now that the code in numa/core is settling down nicely, I thought I'd address a growing testing/contribution problem that has become a problem over the last two weeks: the 'balacenuma' tree by Mel Gorman was drifting away from numa/core (or, numa/core was drifting away from Mel's tree, depending on your perspective), and there was a lot of partly duplicated, partly obsolete and partly objected to content making any upstream merge both contentious and technically more difficult to judge.
This growing split between the NUMA projects makes little technical sense IMO, so here's an attempt at a unified tree that hopefully has an increased chance of being upstreamed.
Most of the outstanding objections against numa/core centered around Mel and Rik objecting to the PROT_NONE approach Peter implemented in numa/core. To settle that question objectively I've performed performance testing of those differences, by picking up the minimum number of essentials needed to be able to remove the PROT_NONE approach and use the PTE_NUMA approach Mel took from the AutoNUMA tree and elsewhere.
The result for today's numa/core tree is that there's no measurable performance difference between the PROT_NONE and PTE_NUMA approaches
- except the 'migration rate limit' patches that are present in the
'balancenuma' tree.
Those migration rate-limits IMO hide scalability problems, and they also slow down workloads where migration is beneficial:
numa/core-v18 + Mel's PTE_NUMA bits, with migration ratelimit:
======================
numa01: 196.692 secs elapsed (max) thread time [ spread: -11.3% ]
numa01-TA: 110.299 secs elapsed (max) thread time [ spread: -1.0% ]
numa02: 15.471 secs elapsed (max) thread time [ spread: -2.0% ]
numa/core-v18 + Mel's PTE_NUMA bits, without migration ratelimit:
======================
numa01: 188.093 secs elapsed (max) thread time [ spread: -9.2% ]
numa01-TA: 107.385 secs elapsed (max) thread time [ spread: -0.8% ]
numa02: 15.480 secs elapsed (max) thread time [ spread: -1.6% ]
The migration rate limits decreased performance and increased the execution runtime 'spread' between threads.
So based on these numbers I left out the migration rate-limiting bits for the time being - with the goal to be minimal and all that.
So in the end I picked up (a ported) version of these ~12 AutoNUMA/Mel patches:
Andrea Arcangeli (4):
mm/numa: define _PAGE_NUMA
mm/numa: Add pte_numa() and pmd_numa()
mm/numa: Support NUMA hinting page faults from gup/gup_fast mm/numa: split_huge_page: transfer the NUMA type from the pmd to the pte
Mel Gorman (8):
mm/compaction: Move migration fail/success stats to migrate.c mm/compaction: Add scanned and isolated counters for compaction mm/migrate: Add a tracepoint for migrate_pages
mm/numa: Create basic numa page hinting infrastructure mm/mempolicy: Use _PAGE_NUMA to migrate pages mm/mempolicy: Hide MPOL_NOOP and MPOL_MF_LAZY from userspace for now mm/numa: Add pte updates, hinting and migration stats mm/numa: Migrate on reference policy
and created a unified tree - which consists of 52 patches in total.
I have done some more testing today, and the original numa/core-v18 tree seems identical in performance to v18-unified, within noise.
So, because it does not look like that the objecting MM folks will lift their objections to Peter's PROT_NONE code, I hope there will be no objections to this compromise tree that offers a unified, minimalistic base - and we can move the NUMA project forward with less divergence.
The unified tree too is bisectable at every point and builds up the NUMA feature from scratch, with the latest policy changes left at the end as incremental patches.
So this tree is roughly the minimum set of mm/ patches we need to be able to implement the policy code in numa/core. These patches from Andrea Arcangeli (4), Lee Schermerhorn (4), Mel Gorman (8), Peter Zijlstra (10) and myself are partly present in Mel's tree but it's also partly our own implementation where Mel's tree diverged from ours incompatibly - see the specific patches for details.
Thanks to everyone for their contributions!
Quoted 1 line
From my perspective I see no reason not to merge the
mm/basis present
in this unified tree in v3.8 (roughly a third of the patches) - it's shaped in a way that everyone can work based on it, even if we might disagree about some of the add-on approaches. That should address most if not all of the items that were contentious in the past.
I'd really love to see some progress here and I'm ready to put as much work and effort into this unified approach as possible. I'll post updated versions based on review feedback and testing.
Thanks,
Ingo
---------------->
Andrea Arcangeli (4):
mm/numa: define _PAGE_NUMA
mm/numa: Add pte_numa() and pmd_numa()
mm/numa: Support NUMA hinting page faults from gup/gup_fast mm/numa: split_huge_page: transfer the NUMA type from the pmd to the pte
Ingo Molnar (25):
sched, numa: Improve the CONFIG_NUMA_BALANCING help text
sched: Implement NUMA scanning backoff
sched: Improve convergence
sched: Introduce staged average NUMA faults
sched: Track groups of shared tasks
sched: Use the best-buddy 'ideal cpu' in balancing decisions
sched: Average the fault stats longer
sched: Use the ideal CPU to drive active balancing
sched: Add hysteresis to p->numa_shared
sched, numa, mm: Interleave shared tasks
sched, mm, mempolicy: Add per task mempolicy
sched: Track shared task's node groups and interleave their memory allocations
sched: Add "task flipping" support
sched: Move the NUMA placement logic to a worklet
numa, mempolicy: Improve CONFIG_NUMA_BALANCING=y OOM behavior
sched: Introduce directed NUMA convergence
sched: Remove statistical NUMA scheduling
sched: Track quality and strength of convergence
sched: Converge NUMA migrations
sched: Add convergence strength based adaptive NUMA page fault rate
sched: Refine the 'shared tasks' memory interleaving logic mm/rmap: Convert the struct anon_vma::mutex to an rwsem
mm/rmap, migration: Make rmap_walk_anon() and try_to_unmap_anon() more scalable
sched: Exclude pinned tasks from the NUMA-balancing logic
sched: Add RSS filter to NUMA-balancing
Lee Schermerhorn (4):
mm/mempolicy: Add MPOL_MF_NOOP
mm/mempolicy: Check for misplaced page
mm/mempolicy: Add MPOL_MF_LAZY
mm/mempolicy: Implement change_prot_numa() in terms of change_protection()
Mel Gorman (8):
mm/compaction: Move migration fail/success stats to migrate.c mm/compaction: Add scanned and isolated counters for compaction mm/migrate: Add a tracepoint for migrate_pages
mm/numa: Create basic numa page hinting infrastructure mm/mempolicy: Use _PAGE_NUMA to migrate pages mm/mempolicy: Hide MPOL_NOOP and MPOL_MF_LAZY from userspace for now mm/numa: Add pte updates, hinting and migration stats mm/numa: Migrate on reference policy
Peter Zijlstra (10):
mm/mempolicy: Make MPOL_LOCAL a real policy
mm/migrate: Introduce migrate_misplaced_page()
sched, numa, mm: Add last_cpu to page flags
mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages
sched: Make find_busiest_queue() a method
sched, numa, mm: Describe the NUMA scheduling problem formally
sched: Add adaptive NUMA affinity support
sched: Implement constant, per task Working Set Sampling (WSS) rate sched, numa, mm: Count WS scanning against present PTEs, not virtual memory ranges
sched: Implement slow start for working set sampling
Rik van Riel (1):
sched, numa, mm: Add credits for NUMA placement
CREDITS | 1 + Documentation/scheduler/numa-problem.txt | 236 +++ arch/sh/mm/Kconfig | 1 + arch/x86/Kconfig | 2 + arch/x86/include/asm/paravirt.h | 2 - arch/x86/include/asm/pgtable.h | 11 +- arch/x86/include/asm/pgtable_types.h | 20 + include/asm-generic/pgtable.h | 74 + include/linux/huge_mm.h | 16 +- include/linux/init_task.h | 8 + include/linux/mempolicy.h | 47 +- include/linux/migrate.h | 58 +- include/linux/mm.h | 113 +- include/linux/mm_types.h | 50 + include/linux/mmzone.h | 14 +- include/linux/page-flags-layout.h | 83 ++ include/linux/rmap.h | 33 +- include/linux/sched.h | 57 +- include/linux/vm_event_item.h | 12 +- include/linux/vmstat.h | 8 + include/trace/events/migrate.h | 51 + include/uapi/linux/mempolicy.h | 15 +- init/Kconfig | 63 + kernel/bounds.c | 4 + kernel/sched/core.c | 174 ++- kernel/sched/debug.c | 1 + kernel/sched/fair.c | 2346 +++++++++++++++++++++++++++--- kernel/sched/features.h | 30 +- kernel/sched/sched.h | 51 +- kernel/sysctl.c | 59 +- mm/compaction.c | 15 +- mm/huge_memory.c | 197 ++- mm/internal.h | 7 +- mm/ksm.c | 6 +- mm/memcontrol.c | 7 +- mm/memory-failure.c | 7 +- mm/memory.c | 205 ++- mm/memory_hotplug.c | 3 +- mm/mempolicy.c | 360 ++++- mm/migrate.c | 240 ++- mm/mmap.c | 10 +- mm/mprotect.c | 76 +- mm/mremap.c | 2 +- mm/page_alloc.c | 5 +- mm/rmap.c | 66 +- mm/vmstat.c | 16 +- 46 files changed, 4341 insertions(+), 521 deletions(-) create mode 100644 Documentation/scheduler/numa-problem.txt create mode 100644 include/linux/page-flags-layout.h create mode 100644 include/trace/events/migrate.h
Signature · 7 lines
1.7.11.7 -- 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 1/52 mm/compaction: Move migration fail/success stats to migrate.c
From: Mel Gorman <[email protected]>
The compact_pages_moved and compact_pagemigrate_failed events are convenient for determining if compaction is active and to what degree migration is succeeding but it's at the wrong level. Other users of migration may also want to know if migration is working properly and this will be particularly true for any automated NUMA migration. This patch moves the counters down to migration with the new events called pgmigrate_success and pgmigrate_fail. The compact_blocks_moved counter is removed because while it was useful for debugging initially, it's worthless now as no meaningful conclusions can be drawn from its value.
--- include/linux/vm_event_item.h | 4 +++- mm/compaction.c | 4 ---- mm/migrate.c | 6 ++++++ mm/vmstat.c | 7 ++++--- 4 files changed, 13 insertions(+), 8 deletions(-)
include/linux/vm_event_item.h +3 -1
@@ -38,8 +38,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,KSWAPD_LOW_WMARK_HIT_QUICKLY ,KSWAPD_HIGH_WMARK_HIT_QUICKLY ,KSWAPD_SKIP_CONGESTION_WAIT ,PAGEOUTRUN ,ALLOCSTALL ,PGROTATED , +#ifdef CONFIG_MIGRATION +PGMIGRATE_SUCCESS ,PGMIGRATE_FAIL , +#endif #ifdef CONFIG_COMPACTION -COMPACTBLOCKS ,COMPACTPAGES ,COMPACTPAGEFAILED ,COMPACTSTALL ,COMPACTFAIL ,COMPACTSUCCESS , #endif #ifdef CONFIG_HUGETLB_PAGE
mm/compaction.c +0 -4
@@ -994,10 +994,6 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)update_nr_listpages (cc); nr_remaining = cc->nr_migratepages; -count_vm_event (COMPACTBLOCKS ); -count_vm_events (COMPACTPAGES , nr_migrate - nr_remaining); -if (nr_remaining) -count_vm_events (COMPACTPAGEFAILED , nr_remaining);trace_mm_compaction_migratepages (nr_migrate - nr_remaining, nr_remaining);
mm/migrate.c +6 -0
@@ -962,6 +962,7 @@ int migrate_pages(struct list_head *from, {int retry =1 ;int nr_failed =0 ; +int nr_succeeded =0 ;int pass =0 ;struct page *page;struct page *page2;
@@ -988,6 +989,7 @@ int migrate_pages(struct list_head *from, retry++;break ;case 0 : + nr_succeeded++;break ;default :/* Permanent failure */
@@ -998,6 +1000,10 @@ int migrate_pages(struct list_head *from, } rc =0 ; out: +if (nr_succeeded) +count_vm_events (PGMIGRATE_SUCCESS , nr_succeeded); +if (nr_failed) +count_vm_events (PGMIGRATE_FAIL , nr_failed);if (!swapwrite) current->flags &= ~PF_SWAPWRITE ;
mm/vmstat.c +4 -3
@@ -774,10 +774,11 @@ const char * const vmstat_text[] = {"pgrotated" , +#ifdef CONFIG_MIGRATION +"pgmigrate_success" , +"pgmigrate_fail" , +#endif #ifdef CONFIG_COMPACTION -"compact_blocks_moved" , -"compact_pages_moved" , -"compact_pagemigrate_failed" ,"compact_stall" ,"compact_fail" , "compact_success",
Signature · 7 lines
1.7.11.7 -- 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 2/52 mm/compaction: Add scanned and isolated counters for compaction
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
Compaction already has tracepoints to count scanned and isolated pages but it requires that ftrace be enabled and if that information has to be written to disk then it can be disruptive. This patch adds vmstat counters for compaction called compact_migrate_scanned, compact_free_scanned and compact_isolated.
With these counters, it is possible to define a basic cost model for compaction. This approximates of how much work compaction is doing and can be compared that with an oprofile showing TLB misses and see if the cost of compaction is being offset by THP for example. Minimally a compaction patch can be evaluated in terms of whether it increases or decreases cost. The basic cost model looks like this
Fundamental unit u: a word sizeof(void *)
Ca = cost of struct page access = sizeof(struct page) / u
Cmc = Cost migrate page copy = (Ca + PAGE_SIZE/u) * 2
Cmf = Cost migrate failure = Ca * 2
Ci = Cost page isolation = (Ca + Wi)
where Wi is a constant that should reflect the approximate cost of the locking operation.
Csm = Cost migrate scanning = Ca
Csf = Cost free scanning = Ca
Overall cost = (Csm * compact_migrate_scanned) +
(Csf * compact_free_scanned) +
(Ci * compact_isolated) +
(Cmc * pgmigrate_success) +
(Cmf * pgmigrate_failed)
Where the values are read from /proc/vmstat.
This is very basic and ignores certain costs such as the allocation cost to do a migrate page copy but any improvement to the model would still use the same vmstat counters.
--- include/linux/vm_event_item.h | 2 ++ mm/compaction.c | 8 ++++++++ mm/vmstat.c | 3 +++ 3 files changed, 13 insertions(+)
include/linux/vm_event_item.h +2 -0
@@ -41,6 +41,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,#ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS ,PGMIGRATE_FAIL , #endif +COMPACTMIGRATE_SCANNED ,COMPACTFREE_SCANNED , +COMPACTISOLATED , #ifdef CONFIG_COMPACTION COMPACTSTALL, COMPACTFAIL, COMPACTSUCCESS, #endif
mm/compaction.c +8 -0
@@ -356,6 +356,10 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,if (blockpfn == end_pfn)update_pageblock_skip (cc, valid_page, total_isolated, false); +count_vm_events (COMPACTFREE_SCANNED , nr_scanned); +if (total_isolated) +count_vm_events (COMPACTISOLATED , total_isolated); +return total_isolated; }
@@ -646,6 +650,10 @@ next_pageblock:trace_mm_compaction_isolate_migratepages (nr_scanned, nr_isolated); +count_vm_events (COMPACTMIGRATE_SCANNED , nr_scanned); +if (nr_isolated) +count_vm_events (COMPACTISOLATED , nr_isolated); +return low_pfn; }
mm/vmstat.c +3 -0
@@ -779,6 +779,9 @@ const char * const vmstat_text[] = { "pgmigrate_fail",#endif #ifdef CONFIG_COMPACTION +"compact_migrate_scanned" , +"compact_free_scanned" , +"compact_isolated" ,"compact_stall" ,"compact_fail" , "compact_success",
Signature · 7 lines
1.7.11.7 -- 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 3/52 mm/migrate: Add a tracepoint for migrate_pages
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
The pgmigrate_success and pgmigrate_fail vmstat counters tells the user about migration activity but not the type or the reason. This patch adds a tracepoint to identify the type of page migration and why the page is being migrated.
--- include/linux/migrate.h | 13 +++++++++-- include/trace/events/migrate.h | 51 ++++++++++++++++++++++++++++++++++++++++++ mm/compaction.c | 3 ++- mm/memory-failure.c | 3 ++- mm/memory_hotplug.c | 3 ++- mm/mempolicy.c | 6 +++-- mm/migrate.c | 10 +++++++-- mm/page_alloc.c | 3 ++- 8 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 include/trace/events/migrate.h
include/linux/migrate.h +11 -2
@@ -7,6 +7,15 @@typedef struct page *new_page_t (struct page *,unsigned long private,int **); +enum migrate_reason { +MR_COMPACTION , +MR_MEMORY_FAILURE , +MR_MEMORY_HOTPLUG , +MR_SYSCALL ,/* also applies to cpusets */ +MR_MEMPOLICY_MBIND , +MR_CMA +}; +#ifdef CONFIG_MIGRATION extern void putback_lru_pages (struct list_head *l);
@@ -14,7 +23,7 @@ extern int migrate_page(struct address_space *, struct page *, struct page *, enum migrate_mode);extern int migrate_pages (struct list_head *l,new_page_t x,unsigned long private,bool offlining, -enum migrate_mode mode); +enum migrate_mode mode,int reason);extern int migrate_huge_page (struct page *,new_page_t x,unsigned long private,bool offlining,enum migrate_mode mode);
@@ -35,7 +44,7 @@ extern int migrate_huge_page_move_mapping(struct address_space *mapping,static inline void putback_lru_pages (struct list_head *l) {}static inline int migrate_pages (struct list_head *l,new_page_t x,unsigned long private,bool offlining, -enum migrate_mode mode) {return -ENOSYS ; } +enum migrate_mode mode,int reason) {return -ENOSYS ; }static inline int migrate_huge_page (struct page *page,new_page_t x,unsigned long private,bool offlining,enum migrate_mode mode) {return -ENOSYS ; }
include/trace/events/migrate.h new file +51 -0
51 lines not on this page · raw message
mm/compaction.c +2 -1
@@ -998,7 +998,8 @@ static int compact_zone(struct zone *zone, struct compact_control *cc) nr_migrate = cc->nr_migratepages; err =migrate_pages (&cc->migratepages, compaction_alloc, (unsigned long )cc, false, - cc->sync ?MIGRATE_SYNC_LIGHT :MIGRATE_ASYNC ); + cc->sync ?MIGRATE_SYNC_LIGHT :MIGRATE_ASYNC , +MR_COMPACTION );update_nr_listpages (cc); nr_remaining = cc->nr_migratepages;
mm/memory-failure.c +2 -1
@@ -1558,7 +1558,8 @@ int soft_offline_page(struct page *page, int flags) page_is_file_cache(page));list_add (&page->lru, &pagelist); ret =migrate_pages (&pagelist, new_page,MPOL_MF_MOVE_ALL , - false,MIGRATE_SYNC ); + false,MIGRATE_SYNC , +MR_MEMORY_FAILURE );if (ret) {putback_lru_pages (&pagelist); pr_info("soft offline: %#lx: migration failed %d, type %lx\n",
mm/memory_hotplug.c +2 -1
@@ -812,7 +812,8 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)* migrate_pages returns # of failed pages. */ ret =migrate_pages (&source, alloc_migrate_target,0 , - true,MIGRATE_SYNC ); + true,MIGRATE_SYNC , +MR_MEMORY_HOTPLUG );if (ret)putback_lru_pages (&source); }
mm/mempolicy.c +4 -2
@@ -961,7 +961,8 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,if (!list_empty (&pagelist)) { err =migrate_pages (&pagelist, new_node_page, dest, - false,MIGRATE_SYNC ); + false,MIGRATE_SYNC , +MR_SYSCALL );if (err)putback_lru_pages (&pagelist); }
@@ -1202,7 +1203,8 @@ static long do_mbind(unsigned long start, unsigned long len,if (!list_empty (&pagelist)) { nr_failed =migrate_pages (&pagelist, new_vma_page, (unsigned long )vma, - false,MIGRATE_SYNC ); + false,MIGRATE_SYNC , +MR_MEMPOLICY_MBIND );if (nr_failed)putback_lru_pages (&pagelist); }
mm/migrate.c +8 -2
@@ -38,6 +38,9 @@#include <asm/tlbflush.h> +#define CREATE_TRACE_POINTS +#include <trace/events/migrate.h> +#include "internal.h" /*
@@ -958,7 +961,7 @@ out:*/ int migrate_pages (struct list_head *from,new_page_t get_new_page,unsigned long private,bool offlining, -enum migrate_mode mode) +enum migrate_mode mode,int reason) {int retry =1 ;int nr_failed =0 ;
@@ -1004,6 +1007,8 @@ out:count_vm_events (PGMIGRATE_SUCCESS , nr_succeeded);if (nr_failed)count_vm_events (PGMIGRATE_FAIL , nr_failed); +trace_mm_migrate_pages (nr_succeeded, nr_failed, mode, reason); +if (!swapwrite) current->flags &= ~PF_SWAPWRITE ;
@@ -1145,7 +1150,8 @@ set_status: err =0 ;if (!list_empty (&pagelist)) { err =migrate_pages (&pagelist, new_page_node, - (unsigned long )pm,0 ,MIGRATE_SYNC ); + (unsigned long )pm,0 ,MIGRATE_SYNC , +MR_SYSCALL );if (err)putback_lru_pages (&pagelist); }
mm/page_alloc.c +2 -1
@@ -5707,7 +5707,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, ret =migrate_pages (&cc->migratepages, alloc_migrate_target, -0 , false,MIGRATE_SYNC ); +0 , false,MIGRATE_SYNC , +MR_CMA ); }putback_lru_pages (&cc->migratepages);
Signature · 7 lines
1.7.11.7 -- 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 4/52 mm/numa: define _PAGE_NUMA
In reply to Ingo MolnarFrom: Andrea Arcangeli <[email protected]>
The objective of _PAGE_NUMA is to be able to trigger NUMA hinting page faults to identify the per NUMA node working set of the thread at runtime.
Arming the NUMA hinting page fault mechanism works similarly to setting up a mprotect(PROT_NONE) virtual range: the present bit is cleared at the same time that _PAGE_NUMA is set, so when the fault triggers we can identify it as a NUMA hinting page fault.
_PAGE_NUMA on x86 shares the same bit number of _PAGE_PROTNONE (but it could also use a different bitflag, it's up to the architecture to decide).
It would be confusing to call the "NUMA hinting page faults" as "do_prot_none faults". They're different events and _PAGE_NUMA doesn't alter the semantics of mprotect(PROT_NONE) in any way.
Sharing the same bitflag with _PAGE_PROTNONE in fact complicates
things: it requires us to ensure the code paths executed by _PAGE_PROTNONE remains mutually exclusive to the code paths executed by _PAGE_NUMA at all times, to avoid _PAGE_NUMA and _PAGE_PROTNONE to step into each other toes.
Because we want to be able to set this bitflag in any established pte or pmd (while clearing the present bit at the same time) without losing information, this bitflag must never be set when the pte and pmd are present, so the bitflag picked for _PAGE_NUMA usage, must not be used by the swap entry format.
--- arch/x86/include/asm/pgtable_types.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
arch/x86/include/asm/pgtable_types.h +20 -0
@@ -64,6 +64,26 @@#define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)#define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE) +/* +* _PAGE_NUMA indicates that this page will trigger a numa hinting +* minor page fault to gather numa placement statistics (see +* pte_numa()). The bit picked (8) is within the range between +* _PAGE_FILE (6) and _PAGE_PROTNONE (8) bits. Therefore, it doesn't +* require changes to the swp entry format because that bit is always +* zero when the pte is not present. +* +* The bit picked must be always zero when the pmd is present and not +* present, so that we don't lose information when we set it while +* atomically clearing the present bit. +* +* Because we shared the same bit (8) with _PAGE_PROTNONE this can be +* interpreted as _PAGE_NUMA only in places that _PAGE_PROTNONE +* couldn't reach, like handle_mm_fault() (see access_error in +* arch/x86/mm/fault.c, the vma protection must not be PROT_NONE for +* handle_mm_fault() to be invoked). +*/ +#define _PAGE_NUMA _PAGE_PROTNONE +#define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ _PAGE_ACCESSED | _PAGE_DIRTY)#define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | \
Signature · 7 lines
1.7.11.7 -- 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 5/52 mm/numa: Add pte_numa() and pmd_numa()
In reply to Ingo MolnarFrom: Andrea Arcangeli <[email protected]>
Implement pte_numa and pmd_numa.
We must atomically set the numa bit and clear the present bit to define a pte_numa or pmd_numa.
Once a pte or pmd has been set as pte_numa or pmd_numa, the next time a thread touches a virtual address in the corresponding virtual range, a NUMA hinting page fault will trigger. The NUMA hinting page fault will clear the NUMA bit and set the present bit again to resolve the page fault.
The expectation is that a NUMA hinting page fault is used as part of a placement policy that decides if a page should remain on the current node or migrated to a different node.
[ Also add the Kconfig machinery that will be filled with
more details of the NUMA balancing feature in later patches. ]
--- arch/sh/mm/Kconfig | 1 + arch/x86/include/asm/pgtable.h | 11 +++++-- include/asm-generic/pgtable.h | 74 ++++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 33 +++++++++++++++++++ 4 files changed, 117 insertions(+), 2 deletions(-)
arch/sh/mm/Kconfig +1 -0
@@ -111,6 +111,7 @@ config VSYSCALL config NUMA bool "Non Uniform Memory Access (NUMA) Support" depends on MMU && SYS_SUPPORTS_NUMA && EXPERIMENTAL + select ARCH_WANT_NUMA_VARIABLE_LOCALITY default n help Some SH systems have many various memories scattered around
arch/x86/include/asm/pgtable.h +9 -2
@@ -404,7 +404,8 @@ static inline int pte_same(pte_t a, pte_t b)static inline int pte_present (pte_t a) { -return pte_flags (a) & (_PAGE_PRESENT | _PAGE_PROTNONE); +return pte_flags (a) & (_PAGE_PRESENT | _PAGE_PROTNONE | + _PAGE_NUMA); }#define pte_accessible pte_accessible
@@ -426,7 +427,8 @@ static inline int pmd_present(pmd_t pmd)* the _PAGE_PSE flag will remain set at all times while the * _PAGE_PRESENT bit is clear). */ -return pmd_flags (pmd) & (_PAGE_PRESENT | _PAGE_PROTNONE | _PAGE_PSE); +return pmd_flags (pmd) & (_PAGE_PRESENT | _PAGE_PROTNONE | _PAGE_PSE | + _PAGE_NUMA); }static inline int pmd_none (pmd_t pmd)
@@ -485,6 +487,11 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)static inline int pmd_bad (pmd_t pmd) { +#ifdef CONFIG_NUMA_BALANCING +/* pmd_numa check */ +if ((pmd_flags (pmd) & (_PAGE_NUMA|_PAGE_PRESENT)) == _PAGE_NUMA) +return 0 ; +#endif return (pmd_flags (pmd) & ~_PAGE_USER) != _KERNPG_TABLE; }
include/asm-generic/pgtable.h +74 -0
80 lines not on this page · raw message
init/Kconfig +33 -0
@@ -696,6 +696,39 @@ config LOG_BUF_SHIFT config HAVE_UNSTABLE_SCHED_CLOCK bool +# +# For architectures that want to enable the support for NUMA-affine scheduler +# balancing logic: +# +config ARCH_SUPPORTS_NUMA_BALANCING + bool + +# For architectures that (ab)use NUMA to represent different memory regions +# all cpu-local but of different latencies, such as SuperH. +# +config ARCH_WANT_NUMA_VARIABLE_LOCALITY + bool + +# +# For architectures that are willing to define _PAGE_NUMA as _PAGE_PROTNONE +config ARCH_WANT_PROT_NUMA_PROT_NONE + bool + +config ARCH_USES_NUMA_PROT_NONE + bool + default y + depends on ARCH_WANT_PROT_NUMA_PROT_NONE + depends on NUMA_BALANCING + +config NUMA_BALANCING + bool "Memory placement aware NUMA scheduler" + default n + depends on ARCH_SUPPORTS_NUMA_BALANCING + depends on !ARCH_WANT_NUMA_VARIABLE_LOCALITY + depends on SMP && NUMA && MIGRATION + help + This option adds support for automatic NUMA aware memory/task placement. + menuconfig CGROUPS boolean "Control Group support" depends on EVENTFD
Signature · 7 lines
1.7.11.7 -- 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 6/52 mm/numa: Support NUMA hinting page faults from gup/gup_fast
In reply to Ingo MolnarFrom: Andrea Arcangeli <[email protected]>
Introduce FOLL_NUMA to tell follow_page to check pte/pmd_numa. get_user_pages must use FOLL_NUMA, and it's safe to do so because it always invokes handle_mm_fault and retries the follow_page later.
KVM secondary MMU page faults will trigger the NUMA hinting page faults through gup_fast -> get_user_pages -> follow_page -> handle_mm_fault.
Other follow_page callers like KSM should not use FOLL_NUMA, or they would fail to get the pages if they use follow_page instead of get_user_pages.
[ This patch was picked up from the AutoNUMA tree. ]
--- include/linux/mm.h | 1 + mm/memory.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/linux/mm.h +1 -0
@@ -1572,6 +1572,7 @@ struct page *follow_page(struct vm_area_struct *, unsigned long address,#define FOLL_MLOCK 0x40/* mark page as mlocked */ #define FOLL_SPLIT 0x80/* don't return transhuge pages, split them */ #define FOLL_HWPOISON 0x100/* check page is hwpoisoned */ +#define FOLL_NUMA 0x200/* force NUMA hinting page fault */ typedef int (*pte_fn_t )(pte_t *pte,pgtable_t token,unsigned long addr,void *data);
mm/memory.c +17 -0
@@ -1517,6 +1517,8 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, page =follow_huge_pmd (mm, address, pmd, flags &FOLL_WRITE ); goto out; } +if ((flags &FOLL_NUMA ) &&pmd_numa (*pmd)) + goto no_page_table;if (pmd_trans_huge (*pmd)) {if (flags &FOLL_SPLIT ) {split_huge_page_pmd (mm, pmd);
@@ -1546,6 +1548,8 @@ split_fallthrough: pte = *ptep;if (!pte_present (pte)) goto no_page; +if ((flags &FOLL_NUMA ) &&pte_numa (pte)) + goto no_page;if ((flags &FOLL_WRITE ) && !pte_write (pte)) goto unlock;
@@ -1697,6 +1701,19 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD); vm_flags &= (gup_flags &FOLL_FORCE ) ? (VM_MAYREAD |VM_MAYWRITE ) : (VM_READ |VM_WRITE ); + +/* +* If FOLL_FORCE and FOLL_NUMA are both set, handle_mm_fault +* would be called on PROT_NONE ranges. We must never invoke +* handle_mm_fault on PROT_NONE ranges or the NUMA hinting +* page faults would unprotect the PROT_NONE ranges if +* _PAGE_NUMA and _PAGE_PROTNONE are sharing the same pte/pmd +* bitflag. So to avoid that, don't set FOLL_NUMA if +* FOLL_FORCE is set. +*/ +if (!(gup_flags &FOLL_FORCE )) + gup_flags |=FOLL_NUMA ; + i =0 ; do {
Signature · 7 lines
1.7.11.7 -- 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 7/52 mm/numa: split_huge_page: transfer the NUMA type from the pmd to the pte
In reply to Ingo MolnarFrom: Andrea Arcangeli <[email protected]>
When we split a transparent hugepage, transfer the NUMA type from the pmd to the pte if needed.
--- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+)
mm/huge_memory.c +2 -0
@@ -1364,6 +1364,8 @@ static int __split_huge_page_map(struct page *page,BUG_ON (page_mapcount (page) !=1 );if (!pmd_young (*pmd)) entry =pte_mkold (entry); +if (pmd_numa (*pmd)) + entry =pte_mknuma (entry); pte =pte_offset_map (&_pmd, haddr);BUG_ON (!pte_none (*pte));set_pte_at (mm, haddr, pte, entry);
Signature · 7 lines
1.7.11.7 -- 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 8/52 mm/numa: Create basic numa page hinting infrastructure
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
Note: This patch started as "mm/mpol: Create special PROT_NONE
infrastructure" and preserves the basic idea but steals *very* heavily from "autonuma: numa hinting page faults entry points" for
the actual fault handlers without the migration parts. The end
result is barely recognisable as either patch so all Signed-off and Reviewed-bys are dropped. If Peter, Ingo and Andrea are ok with this version, I will re-add the signed-offs-by to reflect the history.
In order to facilitate a lazy -- fault driven -- migration of pages, create a special transient PAGE_NUMA variant, we can then use the 'spurious' protection faults to drive our migrations from.
The meaning of PAGE_NUMA depends on the architecture but on x86 it is effectively PROT_NONE. Actual PROT_NONE mappings will not generate these NUMA faults for the reason that the page fault code checks the permission on the VMA (and will throw a segmentation fault on actual PROT_NONE mappings), before it ever calls handle_mm_fault.
--- arch/x86/include/asm/paravirt.h | 2 - include/linux/huge_mm.h | 11 +++++ mm/huge_memory.c | 22 +++++++++ mm/memory.c | 104 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 134 insertions(+), 5 deletions(-)
arch/x86/include/asm/paravirt.h +0 -2
@@ -528,7 +528,6 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,PVOP_VCALL4 (pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte); } -#ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline void set_pmd_at (struct mm_struct *mm,unsigned long addr,pmd_t *pmdp,pmd_t pmd) {
@@ -539,7 +538,6 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,PVOP_VCALL4 (pv_mmu_ops.set_pmd_at, mm, addr, pmdp,native_pmd_val (pmd)); } -#endif static inline void set_pmd (pmd_t *pmdp,pmd_t pmd) {
include/linux/huge_mm.h +11 -0
@@ -159,6 +159,10 @@ static inline struct page *compound_trans_head(struct page *page) }return page; } + +extern int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, +pmd_t pmd,pmd_t *pmdp); +#else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -195,6 +199,13 @@ static inline int pmd_trans_huge_lock(pmd_t *pmd, {return 0 ; } + +static inline int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, +pmd_t pmd,pmd_t *pmdp) +{ +return 0 ; +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_HUGE_MM_H */
mm/huge_memory.c +22 -0
@@ -1018,6 +1018,28 @@ out:return page; } +/* NUMA hinting page fault entry point for trans huge pmds */ +int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, +pmd_t pmd,pmd_t *pmdp) +{ +unsigned long haddr = addr &HPAGE_PMD_MASK ; +struct page *page; + +spin_lock (&mm->page_table_lock); +if (unlikely (!pmd_same (pmd, *pmdp))) + goto out_unlock; + + page =pmd_page (pmd); + pmd =pmd_mknonnuma (pmd); +set_pmd_at (mm, haddr, pmdp, pmd); +VM_BUG_ON (pmd_numa (*pmdp)); +update_mmu_cache_pmd (vma, addr, pmdp); + +out_unlock: +spin_unlock (&mm->page_table_lock); +return 0 ; +} +int zap_huge_pmd (struct mmu_gather *tlb,struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr) {
mm/memory.c +101 -3
132 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 9/52 mm/mempolicy: Make MPOL_LOCAL a real policy
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Make MPOL_LOCAL a real and exposed policy such that applications that relied on the previous default behaviour can explicitly request it.
--- include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
include/uapi/linux/mempolicy.h +1 -0
@@ -20,6 +20,7 @@ enum {MPOL_PREFERRED ,MPOL_BIND ,MPOL_INTERLEAVE , +MPOL_LOCAL , MPOL_MAX, /* always last member of enum */ };
mm/mempolicy.c +6 -3
@@ -269,6 +269,10 @@ static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags, (flags & MPOL_F_RELATIVE_NODES)))return ERR_PTR (-EINVAL ); } + }else if (mode ==MPOL_LOCAL ) { +if (!nodes_empty (*nodes)) +return ERR_PTR (-EINVAL ); + mode =MPOL_PREFERRED ; }else if (nodes_empty (*nodes))return ERR_PTR (-EINVAL ); policy =kmem_cache_alloc (policy_cache,GFP_KERNEL );
@@ -2399,7 +2403,6 @@ void numa_default_policy(void)* "local" is pseudo-policy: MPOL_PREFERRED with MPOL_F_LOCAL flag * Used only for mpol_parse_str() and mpol_to_str() */ -#define MPOL_LOCAL MPOL_MAXstatic const char *const policy_modes[] = { [MPOL_DEFAULT ] ="default" ,
@@ -2452,12 +2455,12 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)if (flags) *flags++ ='\0' ;/* terminate mode string */ -for (mode =0 ; mode <=MPOL_LOCAL ; mode++) { +for (mode =0 ; mode <MPOL_MAX ; mode++) {if (!strcmp (str, policy_modes[mode])) {break ; } } -if (mode >MPOL_LOCAL ) +if (mode >=MPOL_MAX ) goto out;switch (mode) {
Signature · 7 lines
1.7.11.7 -- 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 10/52 mm/mempolicy: Add MPOL_MF_NOOP
In reply to Ingo MolnarFrom: Lee Schermerhorn <[email protected]>
NOTE: I have not yet addressed by own review feedback of this
patch. At this point I'm trying to construct a baseline tree and will apply
my own review feedback later and then fold it in.
This patch augments the MPOL_MF_LAZY feature by adding a "NOOP" policy to mbind(). When the NOOP policy is used with the 'MOVE and 'LAZY flags, mbind() will map the pages PROT_NONE so that they will be migrated on the next touch.
This allows an application to prepare for a new phase of operation where different regions of shared storage will be assigned to worker threads, w/o changing policy. Note that we could just use "default" policy in this case. However, this also allows an application to request that pages be migrated, only if necessary, to follow any arbitrary policy that might currently apply to a range of pages, without knowing the policy, or without specifying multiple mbind()s for ranges with different policies.
[ Bug in early version of mpol_parse_str() reported by Fengguang Wu. ]
--- include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-)
include/uapi/linux/mempolicy.h +1 -0
@@ -21,6 +21,7 @@ enum {MPOL_BIND ,MPOL_INTERLEAVE ,MPOL_LOCAL , +MPOL_NOOP ,/* retain existing policy for range */ MPOL_MAX, /* always last member of enum */ };
mm/mempolicy.c +6 -5
@@ -251,10 +251,10 @@ static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,pr_debug ("setting mode %d flags %d nodes[0] %lx\n" , mode, flags, nodes ?nodes_addr (*nodes)[0 ] :-1 ); -if (mode ==MPOL_DEFAULT ) { +if (mode ==MPOL_DEFAULT || mode ==MPOL_NOOP ) {if (nodes && !nodes_empty (*nodes))return ERR_PTR (-EINVAL ); -return NULL ;/* simply delete any existing policy */ +return NULL ; }VM_BUG_ON (!nodes);
@@ -1147,7 +1147,7 @@ static long do_mbind(unsigned long start, unsigned long len,if (start & ~PAGE_MASK )return -EINVAL ; -if (mode ==MPOL_DEFAULT ) +if (mode ==MPOL_DEFAULT || mode ==MPOL_NOOP ) flags &= ~MPOL_MF_STRICT ; len = (len +PAGE_SIZE -1 ) &PAGE_MASK ;
@@ -2409,7 +2409,8 @@ static const char * const policy_modes[] = [MPOL_PREFERRED] = "prefer", [MPOL_BIND] = "bind", [MPOL_INTERLEAVE] = "interleave", - [MPOL_LOCAL] = "local" + [MPOL_LOCAL] = "local", + [MPOL_NOOP] = "noop", /* should not actually be used */ };
@@ -2460,7 +2461,7 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)break ; } } -if (mode >=MPOL_MAX ) +if (mode >=MPOL_MAX || mode ==MPOL_NOOP ) goto out;switch (mode) {
Signature · 7 lines
1.7.11.7 -- 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 11/52 mm/mempolicy: Check for misplaced page
In reply to Ingo MolnarFrom: Lee Schermerhorn <[email protected]>
This patch provides a new function to test whether a page resides on a node that is appropriate for the mempolicy for the vma and address where the page is supposed to be mapped. This involves looking up the node where the page belongs. So, the function returns that node so that it may be used to allocated the page without consulting the policy again.
A subsequent patch will call this function from the fault path. Because of this, I don't want to go ahead and allocate the page, e.g., via alloc_page_vma() only to have to free it if it has the correct policy. So, I just mimic the alloc_page_vma() node computation logic--sort of.
Note: we could use this function to implement a MPOL_MF_STRICT behavior when migrating pages to match mbind() mempolicy--e.g., to ensure that pages in an interleaved range are reinterleaved rather than left where they are when they reside on any page in the interleave nodemask.
[ Added MPOL_F_LAZY to trigger migrate-on-fault;
simplified code now that we don't have to bother with special crap for interleaved ]
--- include/linux/mempolicy.h | 8 +++++ include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)
include/linux/mempolicy.h +8 -0
@@ -198,6 +198,8 @@ static inline int vma_migratable(struct vm_area_struct *vma) return 1; } +extern int mpol_misplaced (struct page *,struct vm_area_struct *,unsigned long ); +#else struct mempolicy {};
@@ -323,5 +325,11 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol,return 0 ; } +static inline int mpol_misplaced (struct page *page,struct vm_area_struct *vma, +unsigned long address) +{ +return -1 ;/* no node preference */ +} +#endif /* CONFIG_NUMA */ #endif
include/uapi/linux/mempolicy.h +1 -0
@@ -61,6 +61,7 @@ enum mpol_rebind_step {#define MPOL_F_SHARED (1 << 0)/* identify shared policies */ #define MPOL_F_LOCAL (1 << 1)/* preferred local allocation */ #define MPOL_F_REBINDING (1 << 2)/* identify policies in rebinding */ +#define MPOL_F_MOF (1 << 3)/* this policy wants migrate on fault */ #endif /* _UAPI_LINUX_MEMPOLICY_H */
mm/mempolicy.c +76 -0
82 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 12/52 mm/migrate: Introduce migrate_misplaced_page()
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Note: This was originally based on Peter's patch "mm/migrate:
Introduce migrate_misplaced_page()" but borrows extremely heavily from Andrea's
"autonuma: memory follows CPU algorithm and task/mm_autonuma stats collection". The end result is barely recognisable so signed-offs had to be dropped. If original authors are ok with it, I'll re-add the signed-off-bys.
Add migrate_misplaced_page() which deals with migrating pages from faults.
--- include/linux/migrate.h | 16 +++++++ mm/migrate.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-)
include/linux/migrate.h +16 -0
@@ -13,6 +13,7 @@ enum migrate_reason {MR_MEMORY_HOTPLUG ,MR_SYSCALL ,/* also applies to cpusets */ MR_MEMPOLICY_MBIND , +MR_NUMA_MISPLACED , MR_CMA };
@@ -39,6 +40,15 @@ extern int migrate_vmas(struct mm_struct *mm,extern void migrate_page_copy (struct page *newpage,struct page *page);extern int migrate_huge_page_move_mapping (struct address_space *mapping,struct page *newpage,struct page *page); +#ifdef CONFIG_NUMA_BALANCING +extern int migrate_misplaced_page (struct page *page,int node); +#else +static inline +int migrate_misplaced_page (struct page *page,int node) +{ +return -EAGAIN ;/* can't migrate now */ +} +#endif #else static inline void putback_lru_pages (struct list_head *l) {}
@@ -72,5 +82,11 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,#define migrate_page NULL#define fail_migrate_page NULL +static inline +int migrate_misplaced_page (struct page *page,int node) +{ +return -EAGAIN ;/* can't migrate now */ +}#endif /* CONFIG_MIGRATION */ +#endif /* _LINUX_MIGRATE_H */
mm/migrate.c +106 -2
117 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 13/52 mm/mempolicy: Use _PAGE_NUMA to migrate pages
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
Note: Based on "mm/mpol: Use special PROT_NONE to migrate pages"
but sufficiently different that the signed-off-bys were dropped
Combine our previous _PAGE_NUMA, mpol_misplaced and migrate_misplaced_page() pieces into an effective migrate on fault scheme.
Note that (on x86) we rely on PROT_NONE pages being !present and avoid the TLB flush from try_to_unmap(TTU_MIGRATION). This greatly improves the page-migration performance.
--- include/linux/huge_mm.h | 8 ++++---- mm/huge_memory.c | 31 ++++++++++++++++++++++++++++--- mm/memory.c | 32 +++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 12 deletions(-)
include/linux/huge_mm.h +4 -4
@@ -160,8 +160,8 @@ static inline struct page *compound_trans_head(struct page *page) return page; } -extern int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, -pmd_t pmd,pmd_t *pmdp); +extern int do_huge_pmd_numa_page (struct mm_struct *mm,struct vm_area_struct *vma, +unsigned long addr,pmd_t pmd,pmd_t *pmdp);#else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
@@ -200,8 +200,8 @@ static inline int pmd_trans_huge_lock(pmd_t *pmd,return 0 ; } -static inline int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, -pmd_t pmd,pmd_t *pmdp) +static inline int do_huge_pmd_numa_page (struct mm_struct *mm,struct vm_area_struct *vma, +unsigned long addr,pmd_t pmd,pmd_t *pmdp) {return 0 ; }
mm/huge_memory.c +28 -3
@@ -18,6 +18,7 @@#include <linux/freezer.h> #include <linux/mman.h> #include <linux/pagemap.h> +#include <linux/migrate.h> #include <asm/tlb.h> #include <asm/pgalloc.h> #include "internal.h"
@@ -1019,17 +1020,39 @@ out: }/* NUMA hinting page fault entry point for trans huge pmds */ -int do_huge_pmd_numa_page (struct mm_struct *mm,unsigned long addr, -pmd_t pmd,pmd_t *pmdp) +int do_huge_pmd_numa_page (struct mm_struct *mm,struct vm_area_struct *vma, +unsigned long addr,pmd_t pmd,pmd_t *pmdp) { +struct page *page =NULL ;unsigned long haddr = addr &HPAGE_PMD_MASK ; -struct page *page; +int target_nid;spin_lock (&mm->page_table_lock);if (unlikely (!pmd_same (pmd, *pmdp))) goto out_unlock; page =pmd_page (pmd); +get_page (page); +spin_unlock (&mm->page_table_lock); + + target_nid =mpol_misplaced (page, vma, haddr); +if (target_nid ==-1 ) + goto clear_pmdnuma; + +/* +* Due to lacking code to migrate thp pages, we'll split +* (which preserves the special PROT_NONE) and re-take the +* fault on the normal pages. +*/ +split_huge_page (page); +put_page (page); +return 0 ; + +clear_pmdnuma: +spin_lock (&mm->page_table_lock); +if (unlikely (!pmd_same (pmd, *pmdp))) + goto out_unlock; + pmd =pmd_mknonnuma (pmd);set_pmd_at (mm, haddr, pmdp, pmd);VM_BUG_ON (pmd_numa (*pmdp));
@@ -1037,6 +1060,8 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, unsigned long addr, out_unlock:spin_unlock (&mm->page_table_lock); +if (page) +put_page (page);return 0 ; }
mm/memory.c +27 -5
@@ -57,6 +57,7 @@#include <linux/swapops.h> #include <linux/elf.h> #include <linux/gfp.h> +#include <linux/migrate.h> #include <asm/io.h> #include <asm/pgalloc.h>
@@ -3451,8 +3452,9 @@ static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,int do_numa_page (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr,pte_t pte,pte_t *ptep,pmd_t *pmd) { -struct page *page; +struct page *page =NULL ;spinlock_t *ptl; +int current_nid, target_nid;/* * The "pte" at this point cannot be used safely without
@@ -3465,8 +3467,11 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,*/ ptl =pte_lockptr (mm, pmd);spin_lock (ptl); -if (unlikely (!pte_same (*ptep, pte))) - goto out_unlock; +if (unlikely (!pte_same (*ptep, pte))) { +pte_unmap_unlock (ptep, ptl); + goto out; + } + pte =pte_mknonnuma (pte);set_pte_at (mm, addr, ptep, pte);update_mmu_cache (vma, addr, ptep);
@@ -3477,8 +3482,25 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,return 0 ; } -out_unlock: +get_page (page); + current_nid =page_to_nid (page); + target_nid =mpol_misplaced (page, vma, addr);pte_unmap_unlock (ptep, ptl); +if (target_nid ==-1 ) { +/* +* Account for the fault against the current node if it not +* being replaced regardless of where the page is located. +*/ + current_nid =numa_node_id (); +put_page (page); + goto out; + } + +/* Migrate to the requested node */ +if (migrate_misplaced_page (page, target_nid)) + current_nid = target_nid; + +out:return 0 ; }
@@ -3647,7 +3669,7 @@ retry:barrier ();if (pmd_trans_huge (orig_pmd)) {if (pmd_numa (*pmd)) -return do_huge_pmd_numa_page (mm, address, +return do_huge_pmd_numa_page (mm, vma, address, orig_pmd, pmd);if ((flags &FAULT_FLAG_WRITE ) && !pmd_write (orig_pmd)) {
Signature · 7 lines
1.7.11.7 -- 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 14/52 mm/mempolicy: Add MPOL_MF_LAZY
In reply to Ingo MolnarFrom: Lee Schermerhorn <[email protected]>
NOTE: Once again there is a lot of patch reuse and the end
result is sufficiently different that I had to drop the prior signed-offs.
Will re-add if the original authors are ok with that.
This patch adds another mbind() flag to request "lazy migration". The flag, MPOL_MF_LAZY, modifies MPOL_MF_MOVE* such that the selected pages are marked PROT_NONE. The pages will be migrated in the fault path on "first touch", if the policy dictates at that time.
"Lazy Migration" will allow testing of migrate-on-fault via mbind(). Also allows applications to specify that only subsequently touched pages be migrated to obey new policy, instead of all pages in range. This can be useful for multi-threaded applications working on a large shared data area that is initialized by an initial thread resulting in all pages on one [or a few, if overflowed] nodes. After PROT_NONE, the pages in regions assigned to the worker threads will be automatically migrated local to the threads on 1st touch.
--- include/linux/mm.h | 5 ++ include/uapi/linux/mempolicy.h | 13 ++- mm/mempolicy.c | 185 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 185 insertions(+), 18 deletions(-)
include/linux/mm.h +5 -0
@@ -1551,6 +1551,11 @@ static inline pgprot_t vm_get_page_prot(unsigned long vm_flags) }#endif +#ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE +void change_prot_numa (struct vm_area_struct *vma, +unsigned long start,unsigned long end); +#endif +struct vm_area_struct *find_extend_vma (struct mm_struct *,unsigned long addr);int remap_pfn_range (struct vm_area_struct *,unsigned long addr,unsigned long pfn,unsigned long size,pgprot_t );
include/uapi/linux/mempolicy.h +10 -3
@@ -49,9 +49,16 @@ enum mpol_rebind_step {/* Flags for mbind */ #define MPOL_MF_STRICT (1<<0)/* Verify existing pages in the mapping */ -#define MPOL_MF_MOVE (1<<1)/* Move pages owned by this process to conform to mapping */ -#define MPOL_MF_MOVE_ALL (1<<2)/* Move every page to conform to mapping */ -#define MPOL_MF_INTERNAL (1<<3)/* Internal flags start here */ +#define MPOL_MF_MOVE (1<<1)/* Move pages owned by this process to conform +to policy */ +#define MPOL_MF_MOVE_ALL (1<<2)/* Move every page to conform to policy */ +#define MPOL_MF_LAZY (1<<3)/* Modifies '_MOVE: lazy migrate on fault */ +#define MPOL_MF_INTERNAL (1<<4)/* Internal flags start here */ + +#define MPOL_MF_VALID (MPOL_MF_STRICT | \ + MPOL_MF_MOVE | \ + MPOL_MF_MOVE_ALL | \ + MPOL_MF_LAZY)/* * Internal flags that share the struct mempolicy flags word with
mm/mempolicy.c +170 -15
244 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 15/52 mm/mempolicy: Implement change_prot_numa() in terms of change_protection()
In reply to Ingo MolnarFrom: Lee Schermerhorn <[email protected]>
This patch converts change_prot_numa() to use change_protection(). As pte_numa and friends check the PTE bits directly it is necessary for change_protection() to use pmd_mknuma(). Hence the required modifications to change_protection() are a little clumsy but the end result is that most of the numa page table helpers are just one or two instructions.
Original-From: Lee Schermerhorn <[email protected]>
--- include/linux/huge_mm.h | 3 +- include/linux/mm.h | 4 +- mm/huge_memory.c | 14 ++++- mm/mempolicy.c | 137 +++++------------------------------------------- mm/mprotect.c | 62 ++++++++++++++++------ 5 files changed, 75 insertions(+), 145 deletions(-)
include/linux/huge_mm.h +2 -1
@@ -27,7 +27,8 @@ extern int move_huge_pmd(struct vm_area_struct *vma, unsigned long new_addr, unsigned long old_end, pmd_t *old_pmd, pmd_t *new_pmd);extern int change_huge_pmd (struct vm_area_struct *vma,pmd_t *pmd, -unsigned long addr,pgprot_t newprot); +unsigned long addr,pgprot_t newprot, +int prot_numa);enum transparent_hugepage_flag {TRANSPARENT_HUGEPAGE_FLAG ,
include/linux/mm.h +2 -2
@@ -1080,7 +1080,7 @@ extern unsigned long do_mremap(unsigned long addr, unsigned long flags, unsigned long new_addr);extern unsigned long change_protection (struct vm_area_struct *vma,unsigned long start,unsigned long end,pgprot_t newprot, -int dirty_accountable); +int dirty_accountable,int prot_numa);extern int mprotect_fixup (struct vm_area_struct *vma,struct vm_area_struct **pprev,unsigned long start,unsigned long end,unsigned long newflags);
@@ -1552,7 +1552,7 @@ static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)#endif #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE -void change_prot_numa (struct vm_area_struct *vma, +unsigned long change_prot_numa (struct vm_area_struct *vma,unsigned long start,unsigned long end);#endif
mm/huge_memory.c +12 -2
@@ -1147,7 +1147,7 @@ out: }int change_huge_pmd (struct vm_area_struct *vma,pmd_t *pmd, -unsigned long addr,pgprot_t newprot) +unsigned long addr,pgprot_t newprot,int prot_numa) {struct mm_struct *mm = vma->vm_mm;int ret =0 ;
@@ -1155,7 +1155,17 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,if (__pmd_trans_huge_lock (pmd, vma) ==1 ) {pmd_t entry; entry =pmdp_get_and_clear (mm, addr, pmd); - entry =pmd_modify (entry, newprot); +if (!prot_numa) + entry =pmd_modify (entry, newprot); +else { +struct page *page =pmd_page (*pmd); + +/* only check non-shared pages */ +if (page_mapcount (page) ==1 && + !pmd_numa (*pmd)) { + entry =pmd_mknuma (entry); + } + }set_pmd_at (mm, addr, pmd, entry);spin_unlock (&vma->vm_mm->page_table_lock); ret =1 ;
mm/mempolicy.c +13 -124
147 lines not on this page · raw message
mm/mprotect.c +46 -16
146 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 16/52 mm/mempolicy: Hide MPOL_NOOP and MPOL_MF_LAZY from userspace for now
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
The use of MPOL_NOOP and MPOL_MF_LAZY to allow an application to explicitly request lazy migration is a good idea but the actual API has not been well reviewed and once released we have to support it. For now this patch prevents an application using the services. This will need to be revisited.
--- include/uapi/linux/mempolicy.h | 4 +--- mm/mempolicy.c | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-)
include/uapi/linux/mempolicy.h +1 -3
@@ -21,7 +21,6 @@ enum {MPOL_BIND ,MPOL_INTERLEAVE ,MPOL_LOCAL , -MPOL_NOOP ,/* retain existing policy for range */ MPOL_MAX, /* always last member of enum */ };
@@ -57,8 +56,7 @@ enum mpol_rebind_step {#define MPOL_MF_VALID (MPOL_MF_STRICT | \ MPOL_MF_MOVE | \ - MPOL_MF_MOVE_ALL | \ - MPOL_MF_LAZY) + MPOL_MF_MOVE_ALL)/* * Internal flags that share the struct mempolicy flags word with
mm/mempolicy.c +4 -5
@@ -252,7 +252,7 @@ static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,pr_debug ("setting mode %d flags %d nodes[0] %lx\n" , mode, flags, nodes ?nodes_addr (*nodes)[0 ] :-1 ); -if (mode ==MPOL_DEFAULT || mode ==MPOL_NOOP ) { +if (mode ==MPOL_DEFAULT ) {if (nodes && !nodes_empty (*nodes))return ERR_PTR (-EINVAL );return NULL ;
@@ -1186,7 +1186,7 @@ static long do_mbind(unsigned long start, unsigned long len,if (start & ~PAGE_MASK )return -EINVAL ; -if (mode ==MPOL_DEFAULT || mode ==MPOL_NOOP ) +if (mode ==MPOL_DEFAULT ) flags &= ~MPOL_MF_STRICT ; len = (len +PAGE_SIZE -1 ) &PAGE_MASK ;
@@ -1241,7 +1241,7 @@ static long do_mbind(unsigned long start, unsigned long len, flags | MPOL_MF_INVERT, &pagelist); err =PTR_ERR (vma);/* maybe ... */ -if (!IS_ERR (vma) && mode !=MPOL_NOOP ) +if (!IS_ERR (vma)) err =mbind_range (mm, start, end, new);if (!err) {
@@ -2530,7 +2530,6 @@ static const char * const policy_modes[] = [MPOL_BIND] = "bind", [MPOL_INTERLEAVE] = "interleave", [MPOL_LOCAL] = "local", - [MPOL_NOOP] = "noop", /* should not actually be used */ };
@@ -2581,7 +2580,7 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)break ; } } -if (mode >=MPOL_MAX || mode ==MPOL_NOOP ) +if (mode >=MPOL_MAX ) goto out;switch (mode) {
Signature · 7 lines
1.7.11.7 -- 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 17/52 mm/numa: Add pte updates, hinting and migration stats
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
It is tricky to quantify the basic cost of automatic NUMA placement in a meaningful manner. This patch adds some vmstats that can be used as part of a basic costing model.
u = basic unit = sizeof(void *)
Ca = cost of struct page access = sizeof(struct page) / u
Cpte = Cost PTE access = Ca
Cupdate = Cost PTE update = (2 * Cpte) + (2 * Wlock)
where Cpte is incurred twice for a read and a write and Wlock is a constant representing the cost of taking or releasing a lock
Cnumahint = Cost of a minor page fault = some high constant e.g. 1000 Cpagerw = Cost to read or write a full page = Ca + PAGE_SIZE/u Ci = Cost of page isolation = Ca + Wi
where Wi is a constant that should reflect the approximate cost of the locking operation
Cpagecopy = Cpagerw + (Cpagerw * Wnuma) + Ci + (Ci * Wnuma)
where Wnuma is the approximate NUMA factor. 1 is local. 1.2 would imply that remote accesses are 20% more expensive
Balancing cost = Cpte * numa_pte_updates +
Cnumahint * numa_hint_faults +
Ci * numa_pages_migrated +
Cpagecopy * numa_pages_migrated
Note that numa_pages_migrated is used as a measure of how many pages were isolated even though it would miss pages that failed to migrate. A vmstat counter could have been added for it but the isolation cost is pretty marginal in comparison to the overall cost so it seemed overkill.
The ideal way to measure automatic placement benefit would be to count the number of remote accesses versus local accesses and do something like
benefit = (remote_accesses_before - remove_access_after) * Wnuma
but the information is not readily available. As a workload converges, the expection would be that the number of remote numa hints would reduce to 0.
convergence = numa_hint_faults_local / numa_hint_faults
where this is measured for the last N number of numa hints recorded. When the workload is fully converged the value is 1.
This can measure if the placement policy is converging and how fast it is doing it.
--- include/linux/vm_event_item.h | 6 ++++++ include/linux/vmstat.h | 8 ++++++++ mm/huge_memory.c | 1 + mm/memory.c | 14 ++++++++++++++ mm/mempolicy.c | 2 ++ mm/migrate.c | 3 ++- mm/vmstat.c | 6 ++++++ 7 files changed, 39 insertions(+), 1 deletion(-)
include/linux/vm_event_item.h +6 -0
@@ -38,6 +38,12 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,KSWAPD_LOW_WMARK_HIT_QUICKLY ,KSWAPD_HIGH_WMARK_HIT_QUICKLY ,KSWAPD_SKIP_CONGESTION_WAIT ,PAGEOUTRUN ,ALLOCSTALL ,PGROTATED , +#ifdef CONFIG_NUMA_BALANCING +NUMA_PTE_UPDATES , +NUMA_HINT_FAULTS , +NUMA_HINT_FAULTS_LOCAL , +NUMA_PAGE_MIGRATE , +#endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL, #endif
include/linux/vmstat.h +8 -0
@@ -80,6 +80,14 @@ static inline void vm_events_fold_cpu(int cpu)#endif /* CONFIG_VM_EVENT_COUNTERS */ +#ifdef CONFIG_NUMA_BALANCING +#define count_vm_numa_event (x) count_vm_event(x) +#define count_vm_numa_events (x, y) count_vm_events(x, y) +#else +#define count_vm_numa_event (x) do {} while (0) +#define count_vm_numa_events (x, y) do {} while (0) +#endif /* CONFIG_NUMA_BALANCING */ +#define __count_zone_vm_events (item, zone, delta) \ __count_vm_events(item##_NORMAL - ZONE_NORMAL + \ zone_idx(zone), delta)
mm/huge_memory.c +1 -0
@@ -1034,6 +1034,7 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, page =pmd_page (pmd);get_page (page);spin_unlock (&mm->page_table_lock); +count_vm_numa_event (NUMA_HINT_FAULTS ); target_nid =mpol_misplaced (page, vma, haddr);if (target_nid ==-1 )
mm/memory.c +14 -0
@@ -3476,6 +3476,7 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,set_pte_at (mm, addr, ptep, pte);update_mmu_cache (vma, addr, ptep); +count_vm_numa_event (NUMA_HINT_FAULTS ); page =vm_normal_page (vma, addr, pte);if (!page) {pte_unmap_unlock (ptep, ptl);
@@ -3484,6 +3485,8 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,get_page (page); current_nid =page_to_nid (page); +if (current_nid ==numa_node_id ()) +count_vm_numa_event (NUMA_HINT_FAULTS_LOCAL ); target_nid =mpol_misplaced (page, vma, addr);pte_unmap_unlock (ptep, ptl);if (target_nid ==-1 ) {
@@ -3514,6 +3517,10 @@ int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,unsigned long offset;spinlock_t *ptl;bool numa = false; +int local_nid =numa_node_id (); +int curr_nid; +unsigned long nr_faults =0 ; +unsigned long nr_faults_local =0 ;spin_lock (&mm->page_table_lock); pmd = *pmdp;
@@ -3553,9 +3560,16 @@ int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, page =vm_normal_page (vma, addr, pteval);if (unlikely (!page))continue ; + curr_nid =page_to_nid (page); + + nr_faults++; +if (curr_nid == local_nid) + nr_faults_local++; }pte_unmap_unlock (orig_pte, ptl); +count_vm_numa_events (NUMA_HINT_FAULTS , nr_faults); +count_vm_numa_events (NUMA_HINT_FAULTS_LOCAL , nr_faults_local);return 0 ; }
mm/mempolicy.c +2 -0
@@ -583,6 +583,8 @@ unsigned long change_prot_numa(struct vm_area_struct *vma,BUILD_BUG_ON (_PAGE_NUMA != _PAGE_PROTNONE); nr_updated =change_protection (vma, addr, end, vma->vm_page_prot,0 ,1 ); +if (nr_updated) +count_vm_numa_events (NUMA_PTE_UPDATES , nr_updated);return nr_updated; }
mm/migrate.c +2 -1
@@ -1511,7 +1511,8 @@ int migrate_misplaced_page(struct page *page, int node)if (nr_remaining) {putback_lru_pages (&migratepages); isolated =0 ; - } + }else +count_vm_numa_event (NUMA_PAGE_MIGRATE ); }BUG_ON (!list_empty (&migratepages)); out:
mm/vmstat.c +6 -0
@@ -774,6 +774,12 @@ const char * const vmstat_text[] = {"pgrotated" , +#ifdef CONFIG_NUMA_BALANCING +"numa_pte_updates" , +"numa_hint_faults" , +"numa_hint_faults_local" , +"numa_pages_migrated" , +#endif #ifdef CONFIG_MIGRATION"pgmigrate_success" , "pgmigrate_fail",
Signature · 7 lines
1.7.11.7 -- 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 18/52 mm/numa: Migrate on reference policy
In reply to Ingo MolnarFrom: Mel Gorman <[email protected]>
This is the simplest possible policy that still does something of note. When a pte_numa is faulted, it is moved immediately. Any replacement policy must at least do better than this and in all likelihood this policy regresses normal workloads.
--- include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)
include/uapi/linux/mempolicy.h +1 -0
@@ -67,6 +67,7 @@ enum mpol_rebind_step {#define MPOL_F_LOCAL (1 << 1)/* preferred local allocation */ #define MPOL_F_REBINDING (1 << 2)/* identify policies in rebinding */ #define MPOL_F_MOF (1 << 3)/* this policy wants migrate on fault */ +#define MPOL_F_MORON (1 << 4)/* Migrate On pte_numa Reference On Node */ #endif /* _UAPI_LINUX_MEMPOLICY_H */
mm/mempolicy.c +36 -2
@@ -118,6 +118,26 @@ static struct mempolicy default_policy = { .flags = MPOL_F_LOCAL, }; +static struct mempolicy preferred_node_policy[MAX_NUMNODES ]; + +static struct mempolicy *get_task_policy (struct task_struct *p) +{ +struct mempolicy *pol = p->mempolicy; +int node; + +if (!pol) { + node =numa_node_id (); +if (node !=-1 ) + pol = &preferred_node_policy[node]; + +/* preferred_node_policy is not initialised early in boot */ +if (!pol->mode) + pol =NULL ; + } + +return pol; +} + static const struct mempolicy_operations { int (*create)(struct mempolicy *pol, const nodemask_t *nodes); /*
@@ -1598,7 +1618,7 @@ asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,struct mempolicy *get_vma_policy (struct task_struct *task,struct vm_area_struct *vma,unsigned long addr) { -struct mempolicy *pol = task->mempolicy; +struct mempolicy *pol =get_task_policy (task);if (vma) {if (vma->vm_ops && vma->vm_ops->get_policy) {
@@ -2021,7 +2041,7 @@ retry_cpuset:*/ struct page *alloc_pages_current (gfp_t gfp,unsigned order) { -struct mempolicy *pol = current->mempolicy; +struct mempolicy *pol =get_task_policy (current);struct page *page;unsigned int cpuset_mems_cookie;
@@ -2295,6 +2315,11 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned longdefault :BUG (); } + +/* Migrate the page towards the node whose CPU is referencing it */ +if (pol->flags &MPOL_F_MORON ) + polnid =numa_node_id (); +if (curnid != polnid) ret = polnid; out:
@@ -2483,6 +2508,15 @@ void __init numa_policy_init(void)sizeof (struct sp_node ), 0, SLAB_PANIC, NULL); +for_each_node (nid) { + preferred_node_policy[nid] = (struct mempolicy ) { + .refcnt =ATOMIC_INIT (1 ), + .mode =MPOL_PREFERRED , + .flags =MPOL_F_MOF |MPOL_F_MORON , + .v = { .preferred_node = nid, }, + }; + } +/* * Set interleaving policy for system init. Interleaving is only * enabled across suitably sized nodes (default is >= 16MB), or
Signature · 7 lines
1.7.11.7 -- 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 19/52 sched, numa, mm: Add last_cpu to page flags
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Introduce a per-page last_cpu field, fold this into the struct page::flags field whenever possible.
The unlikely/rare 32bit NUMA configs will likely grow the page-frame.
[ Completely dropping 32bit support for CONFIG_NUMA_BALANCING would simplify
things, but it would also remove the warning if we grow enough 64bit only page-flags to push the last-cpu out. ]
This patch takes the reset_page_last_nid() equivalent from Mel Gorman's patch:
mm: Numa: Introduce last_nid to the page frame
--- include/linux/mm.h | 105 +++++++++++++++++++++++--------------- include/linux/mm_types.h | 5 ++ include/linux/mmzone.h | 14 +---- include/linux/page-flags-layout.h | 83 ++++++++++++++++++++++++++++++ kernel/bounds.c | 4 ++ mm/memory.c | 4 ++ mm/page_alloc.c | 2 + 7 files changed, 163 insertions(+), 54 deletions(-) create mode 100644 include/linux/page-flags-layout.h
include/linux/mm.h +64 -41
@@ -581,50 +581,11 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)* sets it, so none of the operations on it need to be atomic. */ - -/* -* page->flags layout: -* -* There are three possibilities for how page->flags get -* laid out. The first is for the normal case, without -* sparsemem. The second is for sparsemem when there is -* plenty of space for node and section. The last is when -* we have run out of space and have to fall back to an -* alternate (slower) way of determining the node. -* -* No sparsemem or sparsemem vmemmap: | NODE | ZONE | ... | FLAGS | -* classic sparse with space for node:| SECTION | NODE | ZONE | ... | FLAGS | -* classic sparse no space for node: | SECTION | ZONE | ... | FLAGS | -*/ -#if defined(CONFIG_SPARSEMEM ) && !defined(CONFIG_SPARSEMEM_VMEMMAP ) -#define SECTIONS_WIDTH SECTIONS_SHIFT -#else -#define SECTIONS_WIDTH 0 -#endif - -#define ZONES_WIDTH ZONES_SHIFT - -#if SECTIONS_WIDTH +ZONES_WIDTH +NODES_SHIFT <=BITS_PER_LONG -NR_PAGEFLAGS -#define NODES_WIDTH NODES_SHIFT -#else -#ifdef CONFIG_SPARSEMEM_VMEMMAP -#error "Vmemmap: No space for nodes field in page flags" -#endif -#define NODES_WIDTH 0 -#endif - -/* Page flags: | [SECTION] | [NODE] | ZONE | ... | FLAGS | */ +/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPU] | ... | FLAGS | */ #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH) - -/* -* We are going to use the flags for the page to node mapping if its in -* there. This includes the case where there is no node, so it is implicit. -*/ -#if !(NODES_WIDTH >0 ||NODES_SHIFT ==0 ) -#define NODE_NOT_IN_PAGE_FLAGS -#endif +#define LAST_CPU_PGOFF (ZONES_PGOFF - LAST_CPU_WIDTH)/* * Define the bit shifts to access each section. For non-existent
@@ -634,6 +595,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)#define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))#define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0))#define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0)) +#define LAST_CPU_PGSHIFT (LAST_CPU_PGOFF * (LAST_CPU_WIDTH != 0))/* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */ #ifdef NODE_NOT_IN_PAGE_FLAGS
@@ -655,6 +617,7 @@ static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)#define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)#define NODES_MASK ((1UL << NODES_WIDTH) - 1)#define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1) +#define LAST_CPU_MASK ((1UL << LAST_CPU_WIDTH) - 1)#define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1)static inline enum zone_type page_zonenum (const struct page *page)
@@ -693,6 +656,66 @@ static inline int page_to_nid(const struct page *page) }#endif +#ifdef CONFIG_NUMA_BALANCING +#ifdef LAST_CPU_NOT_IN_PAGE_FLAGS +static inline int page_xchg_last_cpu (struct page *page,int cpu) +{ +return xchg (&page->_last_cpu, cpu); +} + +static inline int page_last_cpu (struct page *page) +{ +return page->_last_cpu; +} + +static inline void reset_page_last_cpu (struct page *page) +{ + page->_last_cpu =-1 ; +} +#else +static inline int page_xchg_last_cpu (struct page *page,int cpu) +{ +unsigned long old_flags, flags; +int last_cpu; + +do { + old_flags = flags = page->flags; + last_cpu = (flags >>LAST_CPU_PGSHIFT ) &LAST_CPU_MASK ; + + flags &= ~(LAST_CPU_MASK <<LAST_CPU_PGSHIFT ); + flags |= (cpu &LAST_CPU_MASK ) <<LAST_CPU_PGSHIFT ; + }while (unlikely (cmpxchg (&page->flags, old_flags, flags) != old_flags)); + +return last_cpu; +} + +static inline int page_last_cpu (struct page *page) +{ +return (page->flags >>LAST_CPU_PGSHIFT ) &LAST_CPU_MASK ; +} + +static inline void reset_page_last_cpu (struct page *page) +{ +} + +#endif /* LAST_CPU_NOT_IN_PAGE_FLAGS */ +#else /* CONFIG_NUMA_BALANCING */ +static inline int page_xchg_last_cpu (struct page *page,int cpu) +{ +return page_to_nid (page); +} + +static inline int page_last_cpu (struct page *page) +{ +return page_to_nid (page); +} + +static inline void reset_page_last_cpu (struct page *page) +{ +} + +#endif /* CONFIG_NUMA_BALANCING */ +static inline struct zone *page_zone (const struct page *page) {return &NODE_DATA (page_to_nid (page))->node_zones[page_zonenum (page)];
include/linux/mm_types.h +5 -0
@@ -12,6 +12,7 @@#include <linux/cpumask.h> #include <linux/page-debug-flags.h> #include <linux/uprobes.h> +#include <linux/page-flags-layout.h> #include <asm/page.h> #include <asm/mmu.h>
@@ -175,6 +176,10 @@ struct page {*/ void *shadow;#endif + +#ifdef LAST_CPU_NOT_IN_PAGE_FLAGS +int _last_cpu; +#endif }/* * The struct page can be forced to be double word aligned so that atomic ops
include/linux/mmzone.h +1 -13
@@ -15,7 +15,7 @@#include <linux/seqlock.h> #include <linux/nodemask.h> #include <linux/pageblock-flags.h> -#include <generated/bounds.h> +#include <linux/page-flags-layout.h> #include <linux/atomic.h> #include <asm/page.h>
@@ -318,16 +318,6 @@ enum zone_type {* match the requested limits. See gfp_zone() in include/linux/gfp.h */ -#if MAX_NR_ZONES <2 -#define ZONES_SHIFT 0 -#elif MAX_NR_ZONES <=2 -#define ZONES_SHIFT 1 -#elif MAX_NR_ZONES <=4 -#define ZONES_SHIFT 2 -#else -#error ZONES_SHIFT -- too many zones configured adjust calculation -#endif -struct zone {/* Fields commonly accessed by the page allocator */
@@ -1030,8 +1020,6 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)* PA_SECTION_SHIFT physical address to/from section number * PFN_SECTION_SHIFT pfn to/from section number */ -#define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS) -#define PA_SECTION_SHIFT (SECTION_SIZE_BITS)#define PFN_SECTION_SHIFT (SECTION_SIZE_BITS - PAGE_SHIFT)
include/linux/page-flags-layout.h new file +83 -0
83 lines not on this page · raw message
kernel/bounds.c +4 -0
@@ -10,6 +10,7 @@#include <linux/mmzone.h> #include <linux/kbuild.h> #include <linux/page_cgroup.h> +#include <linux/log2.h> void foo (void ) {
@@ -17,5 +18,8 @@ void foo(void)DEFINE (NR_PAGEFLAGS , __NR_PAGEFLAGS);DEFINE (MAX_NR_ZONES , __MAX_NR_ZONES);DEFINE (NR_PCG_FLAGS , __NR_PCG_FLAGS); +#ifdef CONFIG_SMP +DEFINE (NR_CPUS_BITS ,ilog2 (CONFIG_NR_CPUS )); +#endif /* End of constants */ }
mm/memory.c +4 -0
@@ -68,6 +68,10 @@#include "internal.h" +#ifdef LAST_CPU_NOT_IN_PAGE_FLAGS +#warning Unfortunate NUMA config, growing page-frame for last_cpu. +#endif +#ifndef CONFIG_NEED_MULTIPLE_NODES /* use the per-pgdat data instead for discontigmem - mbligh */ unsigned long max_mapnr;
mm/page_alloc.c +2 -0
@@ -608,6 +608,7 @@ static inline int free_pages_check(struct page *page)bad_page (page);return 1 ; } +reset_page_last_cpu (page);if (page->flags &PAGE_FLAGS_CHECK_AT_PREP ) page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP ;return 0 ;
@@ -3826,6 +3827,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,mminit_verify_page_links (page, zone, nid, pfn);init_page_count (page);reset_page_mapcount (page); +reset_page_last_cpu (page);SetPageReserved (page);/* * Mark the block movable so that blocks are reserved for
Signature · 7 lines
1.7.11.7 -- 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 20/52 mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Add regular page and TH-page lazy migration for the NUMA working set scanning fault case.
This code imports and integrates code heavily from various NUMA migration and fault based lazy migration patches sent to lkml:
mm, mempolicy: Lazy migration
Author: Lee Schermerhorn <[email protected]>
autonuma: memory follows CPU algorithm and task/mm_autonuma stats collection
Author: Andrea Arcangeli <[email protected]>
mm/migrate: Introduce migrate_misplaced_page()
Author: Peter Zijlstra <[email protected]>
mm: Numa: Migrate pages handled during a pmd_numa hinting fault
Author: Mel Gorman <[email protected]>
And it also includes fixes sent by Hugh Dickins and Johannes Weiner.
On regular pages we use the migrate_pages() facility.
On THP we use the page lock to serialize. No migration pte dance is necessary because the pte is already unmapped when we decide to migrate.
Author: Lee Schermerhorn <[email protected]>
Author: Andrea Arcangeli <[email protected]>
Author: Peter Zijlstra <[email protected]>
Author: Mel Gorman <[email protected]>
--- include/linux/migrate.h | 29 ++++++-- mm/huge_memory.c | 169 ++++++++++++++++++++++++++++++++++++--------- mm/internal.h | 7 +- mm/memcontrol.c | 7 +- mm/memory.c | 94 ++++++++++++++++--------- mm/mempolicy.c | 61 +++++++++++++---- mm/migrate.c | 178 +++++++++++++++++++++++++++++++++++++++--------- mm/mprotect.c | 26 +++++-- 8 files changed, 445 insertions(+), 126 deletions(-)
include/linux/migrate.h +22 -7
@@ -40,16 +40,31 @@ extern int migrate_vmas(struct mm_struct *mm,extern void migrate_page_copy (struct page *newpage,struct page *page);extern int migrate_huge_page_move_mapping (struct address_space *mapping,struct page *newpage,struct page *page); -#ifdef CONFIG_NUMA_BALANCING -extern int migrate_misplaced_page (struct page *page,int node); -#else +# ifdef CONFIG_NUMA_BALANCING +extern int migrate_misplaced_page_put (struct page *page,int node); +extern int migrate_misplaced_transhuge_page_put (struct mm_struct *mm, +struct vm_area_struct *vma, +pmd_t *pmd,pmd_t entry, +unsigned long address, +struct page *page,int node); +# else /* !CONFIG_NUMA_BALANCING: */ static inline -int migrate_misplaced_page (struct page *page,int node) +int migrate_misplaced_page_put (struct page *page,int node) {return -EAGAIN ;/* can't migrate now */ } -#endif -#else + +static inline +int migrate_misplaced_transhuge_page_put (struct mm_struct *mm, +struct vm_area_struct *vma, +pmd_t *pmd,pmd_t entry, +unsigned long address, +struct page *page,int node) +{ +return -EAGAIN ; +} +# endif +#else /* !CONFIG_MIGRATION: */ static inline void putback_lru_pages (struct list_head *l) {} static inline int migrate_pages(struct list_head *l, new_page_t x,
@@ -83,7 +98,7 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,#define fail_migrate_page NULLstatic inline -int migrate_misplaced_page (struct page *page,int node) +int migrate_misplaced_page_put (struct page *page,int node) {return -EAGAIN ;/* can't migrate now */ }
mm/huge_memory.c +137 -32
203 lines not on this page · raw message
mm/internal.h +5 -2
@@ -212,15 +212,18 @@ static inline void mlock_migrate_page(struct page *newpage, struct page *page) {if (TestClearPageMlocked (page)) {unsigned long flags; +int nr_pages =hpage_nr_pages (page);local_irq_save (flags); -__dec_zone_page_state (page,NR_MLOCK ); +__mod_zone_page_state (page_zone (page),NR_MLOCK , -nr_pages);SetPageMlocked (newpage); -__inc_zone_page_state (newpage,NR_MLOCK ); +__mod_zone_page_state (page_zone (newpage),NR_MLOCK , nr_pages);local_irq_restore (flags); } } +extern pmd_t maybe_pmd_mkwrite (pmd_t pmd,struct vm_area_struct *vma); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE extern unsigned long vma_address (struct page *page,struct vm_area_struct *vma);
mm/memcontrol.c +5 -2
@@ -3288,15 +3288,18 @@ void mem_cgroup_prepare_migration(struct page *page, struct page *newpage, struct mem_cgroup **memcgp) {struct mem_cgroup *memcg =NULL ; +unsigned int nr_pages =1 ;struct page_cgroup *pc;enum charge_type ctype; *memcgp =NULL ; -VM_BUG_ON (PageTransHuge (page));if (mem_cgroup_disabled ())return ; +if (PageTransHuge (page)) + nr_pages <<=compound_order (page); + pc =lookup_page_cgroup (page);lock_page_cgroup (pc);if (PageCgroupUsed (pc)) {
@@ -3358,7 +3361,7 @@ void mem_cgroup_prepare_migration(struct page *page, struct page *newpage,* charged to the res_counter since we plan on replacing the * old one and only one page is going to be left afterwards. */ -__mem_cgroup_commit_charge (memcg, newpage,1 , ctype, false); +__mem_cgroup_commit_charge (memcg, newpage, nr_pages, ctype, false); }/* remove redundant charge if migration failed*/
mm/memory.c +63 -31
157 lines not on this page · raw message
mm/mempolicy.c +48 -13
100 lines not on this page · raw message
mm/migrate.c +145 -33
211 lines not on this page · raw message
mm/mprotect.c +20 -6
@@ -37,12 +37,14 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)static unsigned long change_pte_range (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t newprot, -int dirty_accountable,int prot_numa) +int dirty_accountable,int prot_numa,bool *ret_all_same_node) {struct mm_struct *mm = vma->vm_mm;pte_t *pte, oldpte;spinlock_t *ptl;unsigned long pages =0 ; +bool all_same_node = true; +int last_nid =-1 ; pte =pte_offset_map_lock (mm, pmd, addr, &ptl);arch_enter_lazy_mmu_mode ();
@@ -61,6 +63,12 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, page =vm_normal_page (vma, addr, oldpte);if (page) { +int this_nid =page_to_nid (page); +if (last_nid ==-1 ) + last_nid = this_nid; +if (last_nid != this_nid) + all_same_node = false; +/* only check non-shared pages */ if (!pte_numa (oldpte) &&page_mapcount (page) ==1 ) {
@@ -81,7 +89,6 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,if (updated) pages++; -ptep_modify_prot_commit (mm, addr, pte, ptent); }else if (IS_ENABLED (CONFIG_MIGRATION ) && !pte_file (oldpte)) {swp_entry_t entry =pte_to_swp_entry (oldpte);
@@ -101,6 +108,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,arch_leave_lazy_mmu_mode ();pte_unmap_unlock (pte -1 , ptl); + *ret_all_same_node = all_same_node;return pages; }
@@ -111,6 +119,7 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma, pud_t *pmd_t *pmd;unsigned long next;unsigned long pages =0 ; +bool all_same_node; pmd =pmd_offset (pud, addr); do {
@@ -127,16 +136,21 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma, pud_t *if (pmd_none_or_clear_bad (pmd))continue ; pages +=change_pte_range (vma, pmd, addr, next, newprot, - dirty_accountable, prot_numa); - -if (prot_numa) { + dirty_accountable, prot_numa, &all_same_node); + +/* +* If we are changing protections for NUMA hinting faults then +* set pmd_numa if the examined pages were all on the same +* node. This allows a regular PMD to be handled as one fault +* and effectively batches the taking of the PTL +*/ +if (prot_numa && all_same_node) {struct mm_struct *mm = vma->vm_mm;spin_lock (&mm->page_table_lock);set_pmd_at (mm, addr &PMD_MASK , pmd,pmd_mknuma (*pmd));spin_unlock (&mm->page_table_lock); } - }while (pmd++, addr = next, addr != end);return pages;
Signature · 7 lines
1.7.11.7 -- 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 21/52 sched: Make find_busiest_queue() a method
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Its a bit awkward but it was the least painful means of modifying the queue selection. Used in a later patch to conditionally use a random queue.
--- kernel/sched/fair.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
kernel/sched/fair.c +12 -8
@@ -3600,6 +3600,9 @@ struct lb_env {unsigned int loop;unsigned int loop_break;unsigned int loop_max; + +struct rq * (*find_busiest_queue)(struct lb_env *, +struct sched_group *); };/*
@@ -4779,13 +4782,14 @@ static int load_balance(int this_cpu, struct rq *this_rq,struct cpumask *cpus =__get_cpu_var (load_balance_tmpmask);struct lb_env env = { - .sd = sd, - .dst_cpu = this_cpu, - .dst_rq = this_rq, - .dst_grpmask =sched_group_cpus (sd->groups), - .idle = idle, - .loop_break = sched_nr_migrate_break, - .cpus = cpus, + .sd = sd, + .dst_cpu = this_cpu, + .dst_rq = this_rq, + .dst_grpmask =sched_group_cpus (sd->groups), + .idle = idle, + .loop_break = sched_nr_migrate_break, + .cpus = cpus, + .find_busiest_queue = find_busiest_queue, };cpumask_copy (cpus, cpu_active_mask);
@@ -4804,7 +4808,7 @@ redo: goto out_balanced; } - busiest =find_busiest_queue (&env, group); + busiest = env.find_busiest_queue (&env, group);if (!busiest) {schedstat_inc (sd, lb_nobusyq[idle]); goto out_balanced;
Signature · 7 lines
1.7.11.7 -- 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 22/52 sched, numa, mm: Add credits for NUMA placement
In reply to Ingo MolnarFrom: Rik van Riel <[email protected]>
The NUMA placement code has been rewritten several times, but the basic ideas took a lot of work to develop. The people who put in the work deserve credit for it. Thanks Andrea & Peter :)
[ The Documentation/scheduler/numa-problem.txt file should
probably be rewritten once we figure out the final details of what the NUMA code needs to do, and why. ]
----
This is against tip.git numa/core
--- CREDITS | 1 + kernel/sched/fair.c | 3 +++ mm/memory.c | 2 ++ 3 files changed, 6 insertions(+)
CREDITS +1 -0
@@ -125,6 +125,7 @@ D: Author of pscan that helps to fix lp/parport bugs D: Author of lil (Linux Interrupt Latency benchmark) D: Fixed the shm swap deallocation at swapoff time (try_to_unuse message) D: VM hacker +D: NUMA task placement D: Various other kernel hacks S: Imola 40026 S: Italy
kernel/sched/fair.c +3 -0
@@ -18,6 +18,9 @@* * Adaptive scheduling granularity, math enhancements by Peter Zijlstra * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> +* +* NUMA placement, statistics and algorithm by Andrea Arcangeli, +* CFS balancing changes by Peter Zijlstra. Copyright (C) 2012 Red Hat, Inc. */ #include <linux/latencytop.h>
mm/memory.c +2 -0
@@ -36,6 +36,8 @@* ([email protected]) * * Aug/Sep 2004 Changed to four level page tables (Andi Kleen) +* +* 2012 - NUMA placement page faults (Andrea Arcangeli, Peter Zijlstra) */ #include <linux/kernel_stat.h>
Signature · 7 lines
1.7.11.7 -- 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 23/52 sched, numa, mm: Describe the NUMA scheduling problem formally
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
This is probably a first: formal description of a complex high-level computing problem, within the kernel source.
--- Documentation/scheduler/numa-problem.txt | 230 +++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 Documentation/scheduler/numa-problem.txt
Documentation/scheduler/numa-problem.txt new file +230 -0
@@ -0,0 +1,230 @@ + + +Effective NUMA scheduling problem statement, described formally: + + * minimize interconnect traffic + +For each task 't_i' we have memory, this memory can be spread over multiple +physical nodes, let us denote this as: 'p_i,k', the memory task 't_i' has on +node 'k' in [pages]. + +If a task shares memory with another task let us denote this as: +'s_i,k', the memory shared between tasks including 't_i' residing on node +'k'. + +Let 'M' be the distribution that governs all 'p' and 's', ie. the page placement. + +Similarly, lets define 'fp_i,k' and 'fs_i,k' resp. as the (average) usage +frequency over those memory regions [1/s] such that the product gives an +(average) bandwidth 'bp' and 'bs' in [pages/s]. + +(note: multiple tasks sharing memory naturally avoid duplicat accounting + because each task will have its own access frequency 'fs') + +(pjt: I think this frequency is more numerically consistent if you explicitly + restrict p/s above to be the working-set. (It also makes explicit the + requirement for <C0,M0> to change about a change in the working set.) + + Doing this does have the nice property that it lets you use your frequency + measurement as a weak-ordering for the benefit a task would receive when + we can't fit everything. + + e.g. task1 has working set 10mb, f=90% + task2 has working set 90mb, f=10% + + Both are using 9mb/s of bandwidth, but we'd expect a much larger benefit + from task1 being on the right node than task2. ) + +Let 'C' map every task 't_i' to a cpu 'c_i' and its corresponding node 'n_i': + + C: t_i -> {c_i, n_i} + +This gives us the total interconnect traffic between nodes 'k' and 'l', +'T_k,l', as: + + T_k,l = \Sum_i bp_i,l + bs_i,l + \Sum bp_j,k + bs_j,k where n_i == k, n_j == l + +And our goal is to obtain C0 and M0 such that: + + T_k,l(C0, M0) =< T_k,l(C, M) for all C, M where k != l + +(note: we could introduce 'nc(k,l)' as the cost function of accessing memory + on node 'l' from node 'k', this would be useful for bigger NUMA systems + + pjt: I agree nice to have, but intuition suggests diminishing returns on more + usual systems given factors like things like Haswell's enormous 35mb l3 + cache and QPI being able to do a direct fetch.) + +(note: do we need a limit on the total memory per node?) + + + * fairness + +For each task 't_i' we have a weight 'w_i' (related to nice), and each cpu +'c_n' has a compute capacity 'P_n', again, using our map 'C' we can formulate a +load 'L_n': + + L_n = 1/P_n * \Sum_i w_i for all c_i = n + +using that we can formulate a load difference between CPUs + + L_n,m = | L_n - L_m | + +Which allows us to state the fairness goal like: + + L_n,m(C0) =< L_n,m(C) for all C, n != m + +(pjt: It can also be usefully stated that, having converged at C0: + + | L_n(C0) - L_m(C0) | <= 4/3 * | G_n( U(t_i, t_j) ) - G_m( U(t_i, t_j) ) | + + Where G_n,m is the greedy partition of tasks between L_n and L_m. This is + the "worst" partition we should accept; but having it gives us a useful + bound on how much we can reasonably adjust L_n/L_m at a Pareto point to + favor T_n,m. ) + +Together they give us the complete multi-objective optimization problem: + + min_C,M [ L_n,m(C), T_k,l(C,M) ] + + + +Notes: + + - the memory bandwidth problem is very much an inter-process problem, in + particular there is no such concept as a process in the above problem. + + - the naive solution would completely prefer fairness over interconnect + traffic, the more complicated solution could pick another Pareto point using + an aggregate objective function such that we balance the loss of work + efficiency against the gain of running, we'd want to more or less suggest + there to be a fixed bound on the error from the Pareto line for any + such solution. + +References: + + http://en.wikipedia.org/wiki/Mathematical_optimization + http://en.wikipedia.org/wiki/Multi-objective_optimization + + +* warning, significant hand-waving ahead, improvements welcome * + + +Partial solutions / approximations: + + 1) have task node placement be a pure preference from the 'fairness' pov. + +This means we always prefer fairness over interconnect bandwidth. This reduces +the problem to: + + min_C,M [ T_k,l(C,M) ] + + 2a) migrate memory towards 'n_i' (the task's node). + +This creates memory movement such that 'p_i,k for k != n_i' becomes 0 -- +provided 'n_i' stays stable enough and there's sufficient memory (looks like +we might need memory limits for this). + +This does however not provide us with any 's_i' (shared) information. It does +however remove 'M' since it defines memory placement in terms of task +placement. + +XXX properties of this M vs a potential optimal + + 2b) migrate memory towards 'n_i' using 2 samples. + +This separates pages into those that will migrate and those that will not due +to the two samples not matching. We could consider the first to be of 'p_i' +(private) and the second to be of 's_i' (shared). + +This interpretation can be motivated by the previously observed property that +'p_i,k for k != n_i' should become 0 under sufficient memory, leaving only +'s_i' (shared). (here we loose the need for memory limits again, since it +becomes indistinguishable from shared). + +XXX include the statistical babble on double sampling somewhere near + +This reduces the problem further; we loose 'M' as per 2a, it further reduces +the 'T_k,l' (interconnect traffic) term to only include shared (since per the +above all private will be local): + + T_k,l = \Sum_i bs_i,l for every n_i = k, l != k + +[ more or less matches the state of sched/numa and describes its remaining + problems and assumptions. It should work well for tasks without significant + shared memory usage between tasks. ] + +Possible future directions: + +Motivated by the form of 'T_k,l', try and obtain each term of the sum, so we +can evaluate it; + + 3a) add per-task per node counters + +At fault time, count the number of pages the task faults on for each node. +This should give an approximation of 'p_i' for the local node and 's_i,k' for +all remote nodes. + +While these numbers provide pages per scan, and so have the unit [pages/s] they +don't count repeat access and thus aren't actually representable for our +bandwidth numberes. + + 3b) additional frequency term + +Additionally (or instead if it turns out we don't need the raw 'p' and 's' +numbers) we can approximate the repeat accesses by using the time since marking +the pages as indication of the access frequency. + +Let 'I' be the interval of marking pages and 'e' the elapsed time since the +last marking, then we could estimate the number of accesses 'a' as 'a = I / e'. +If we then increment the node counters using 'a' instead of 1 we might get +a better estimate of bandwidth terms. + + 3c) additional averaging; can be applied on top of either a/b. + +[ Rik argues that decaying averages on 3a might be sufficient for bandwidth since + the decaying avg includes the old accesses and therefore has a measure of repeat + accesses. + + Rik also argued that the sample frequency is too low to get accurate access + frequency measurements, I'm not entirely convinced, event at low sample + frequencies the avg elapsed time 'e' over multiple samples should still + give us a fair approximation of the avg access frequency 'a'. + + So doing both b&c has a fair chance of working and allowing us to distinguish + between important and less important memory accesses. + + Experimentation has shown no benefit from the added frequency term so far. ] + +This will give us 'bp_i' and 'bs_i,k' so that we can approximately compute +'T_k,l' Our optimization problem now reads: + + min_C [ \Sum_i bs_i,l for every n_i = k, l != k ] + +And includes only shared terms, this makes sense since all task private memory +will become local as per 2. + +This suggests that if there is significant shared memory, we should try and +move towards it. + + 4) move towards where 'most' memory is + +The simplest significance test is comparing the biggest shared 's_i,k' against +the private 'p_i'. If we have more shared than private, move towards it. + +This effectively makes us move towards where most our memory is and forms a +feed-back loop with 2. We migrate memory towards us and we migrate towards +where 'most' memory is. + +(Note: even if there were two tasks fully trashing the same shared memory, it + is very rare for there to be an 50/50 split in memory, lacking a perfect + split, the small will move towards the larger. In case of the perfect + split, we'll tie-break towards the lower node number.) + + 5) 'throttle' 4's node placement + +Since per 2b our 's_i,k' and 'p_i' require at least two scans to 'stabilize' +and show representative numbers, we should limit node-migration to not be +faster than this. + + n) poke holes in previous that require more stuff and describe it.
Signature · 7 lines
1.7.11.7 -- 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 24/52 sched: Add adaptive NUMA affinity support
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
The principal ideas behind this patch are the fundamental difference between shared and privately used memory and the very strong desire to only rely on per-task behavioral state for scheduling decisions.
We define 'shared memory' as all user memory that is frequently accessed by multiple tasks and conversely 'private memory' is the user memory used predominantly by a single task.
To approximate the above strict definition we recognise that task placement is dominantly per cpu and thus using cpu granular page access state is a natural fit. Thus we introduce page::last_cpu as the cpu that last accessed a page.
Using this, we can construct two per-task node-vectors, 'S_i' and 'P_i' reflecting the amount of shared and privately used pages of this task respectively. Pages for which two consecutive 'hits' are of the same cpu are assumed private and the others are shared.
[ This means that we will start evaluating this state when the
task has not migrated for at least 2 scans, see NUMA_SETTLE ]
Using these vectors we can compute the total number of shared/private pages of this task and determine which dominates.
[ Note that for shared tasks we only see '1/n' the total number
of shared pages for the other tasks will take the other faults; where 'n' is the number of tasks sharing the memory. So for an equal comparison we should divide total private by 'n' as well, but we don't have 'n' so we pick 2. ]
We can also compute which node holds most of our memory, running on this node will be called 'ideal placement' (As per previous patches we will prefer to pull memory towards wherever we run.)
We change the load-balancer to prefer moving tasks in order of:
1) !numa tasks and numa tasks in the direction of more faults
2) allow !ideal tasks getting worse in the direction of faults
3) allow private tasks to get worse
4) allow shared tasks to get worse
This order ensures we prefer increasing memory locality but when we do have to make hard decisions we prefer spreading private over shared, because spreading shared tasks significantly increases the interconnect bandwidth since not all memory can follow.
We also add an extra 'lateral' force to the load balancer that perturbs the state when otherwise 'fairly' balanced. This ensures we don't get 'stuck' in a state which is fair but undesired from a memory location POV (see can_do_numa_run()).
Lastly, we allow shared tasks to defeat the default spreading of tasks such that, when possible, they can aggregate on a single node.
Shared tasks aggregate for the very simple reason that there has to be a single node that holds most of their memory and a second most, etc.. and tasks want to move up the faults ladder.
Enable it on x86. A number of other architectures are most likely fine too - but they should enable and test this feature explicitly.
--- Documentation/scheduler/numa-problem.txt | 20 +- arch/x86/Kconfig | 2 + include/linux/init_task.h | 8 + include/linux/mm_types.h | 5 + include/linux/sched.h | 51 +- kernel/sched/core.c | 72 ++- kernel/sched/fair.c | 975 +++++++++++++++++++++++++------ kernel/sched/features.h | 8 + kernel/sched/sched.h | 38 +- mm/huge_memory.c | 7 +- mm/memory.c | 6 + 11 files changed, 989 insertions(+), 203 deletions(-)
Documentation/scheduler/numa-problem.txt +13 -7
@@ -133,6 +133,8 @@ XXX properties of this M vs a potential optimal 2b) migrate memory towards 'n_i' using 2 samples. +XXX include the statistical babble on double sampling somewhere near + This separates pages into those that will migrate and those that will not due to the two samples not matching. We could consider the first to be of 'p_i' (private) and the second to be of 's_i' (shared).
@@ -142,7 +144,17 @@ This interpretation can be motivated by the previously observed property that 's_i' (shared). (here we loose the need for memory limits again, since it becomes indistinguishable from shared). -XXX include the statistical babble on double sampling somewhere near + 2c) use cpu samples instead of node samples + +The problem with sampling on node granularity is that one looses 's_i' for +the local node, since one cannot distinguish between two accesses from the +same node. + +By increasing the granularity to per-cpu we gain the ability to have both an +'s_i' and 'p_i' per node. Since we do all task placement per-cpu as well this +seems like a natural match. The line where we overcommit cpus is where we loose +granularity again, but when we loose overcommit we naturally spread tasks. +Therefore it should work out nicely. This reduces the problem further; we loose 'M' as per 2a, it further reduces the 'T_k,l' (interconnect traffic) term to only include shared (since per the
@@ -150,12 +162,6 @@ above all private will be local): T_k,l = \Sum_i bs_i,l for every n_i = k, l != k -[ more or less matches the state of sched/numa and describes its remaining - problems and assumptions. It should work well for tasks without significant - shared memory usage between tasks. ] - -Possible future directions: - Motivated by the form of 'T_k,l', try and obtain each term of the sum, so we can evaluate it;
arch/x86/Kconfig +2 -0
@@ -22,6 +22,8 @@ config X86 def_bool y select HAVE_AOUT if X86_32 select HAVE_UNSTABLE_SCHED_CLOCK + select ARCH_SUPPORTS_NUMA_BALANCING + select ARCH_WANT_PROT_NUMA_PROT_NONE select HAVE_IDE select HAVE_OPROFILE select HAVE_PCSPKR_PLATFORM
include/linux/init_task.h +8 -0
@@ -143,6 +143,13 @@ extern struct task_group root_task_group;#define INIT_TASK_COMM "swapper" +#ifdef CONFIG_NUMA_BALANCING +# define INIT_TASK_NUMA (tsk) \ + .numa_shared = -1, +#else +# define INIT_TASK_NUMA (tsk) +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -210,6 +217,7 @@ extern struct task_group root_task_group; INIT_TRACE_RECURSION \ INIT_TASK_RCU_PREEMPT(tsk) \ INIT_CPUSET_SEQ \ + INIT_TASK_NUMA(tsk) \ }
include/linux/mm_types.h +5 -0
@@ -403,6 +403,11 @@ struct mm_struct {#ifdef CONFIG_CPUMASK_OFFSTACK struct cpumask cpumask_allocation;#endif +#ifdef CONFIG_NUMA_BALANCING +unsigned long numa_next_scan; +unsigned long numa_scan_offset; +int numa_scan_seq; +#endif struct uprobes_state uprobes_state; };
include/linux/sched.h +47 -4
89 lines not on this page · raw message
kernel/sched/core.c +69 -3
126 lines not on this page · raw message
kernel/sched/fair.c +791 -184
1,305 lines not on this page · raw message
kernel/sched/features.h +8 -0
@@ -66,3 +66,11 @@ SCHED_FEAT(TTWU_QUEUE, true) SCHED_FEAT(FORCE_SD_OVERLAP, false) SCHED_FEAT(RT_RUNTIME_SHARE, true) SCHED_FEAT(LB_MIN, false) + +#ifdef CONFIG_NUMA_BALANCING +/* Do the working set probing faults: */ +SCHED_FEAT(NUMA, true) +SCHED_FEAT(NUMA_FAULTS_UP, true) +SCHED_FEAT(NUMA_FAULTS_DOWN, false) +SCHED_FEAT(NUMA_SETTLE, true) +#endif
kernel/sched/sched.h +35 -3
@@ -3,6 +3,7 @@#include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/stop_machine.h> +#include <linux/slab.h> #include "cpupri.h"
@@ -420,17 +421,29 @@ struct rq {unsigned long cpu_power;unsigned char idle_balance; -/* For active balancing */ int post_schedule; + +/* For active balancing */ int active_balance; -int push_cpu; -struct cpu_stop_work active_balance_work; +int ab_dst_cpu; +int ab_flags; +int ab_failed; +int ab_idle; +struct cpu_stop_work ab_work; +/* cpu of this runqueue: */ int cpu;int online;struct list_head cfs_tasks; +#ifdef CONFIG_NUMA_BALANCING +unsigned long numa_weight; +unsigned long nr_numa_running; +unsigned long nr_ideal_running; +#endif +unsigned long nr_shared_running;/* 0 on non-NUMA */ +u64 rt_avg;u64 age_stamp;u64 idle_stamp;
@@ -501,6 +514,18 @@ DECLARE_PER_CPU(struct rq, runqueues);#define cpu_curr (cpu) (cpu_rq(cpu)->curr)#define raw_rq () (&__raw_get_cpu_var(runqueues)) +#ifdef CONFIG_NUMA_BALANCING +extern void sched_setnuma (struct task_struct *p,int node,int shared); +static inline void task_numa_free (struct task_struct *p) +{ +kfree (p->numa_faults); +} +#else /* CONFIG_NUMA_BALANCING */ +static inline void task_numa_free (struct task_struct *p) +{ +} +#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_SMP #define rcu_dereference_check_sched_domain (p) \
@@ -544,6 +569,7 @@ static inline struct sched_domain *highest_flag_domain(int cpu, int flag) DECLARE_PER_CPU(struct sched_domain *, sd_llc);DECLARE_PER_CPU (int, sd_llc_id); +DECLARE_PER_CPU(struct sched_domain *, sd_node);extern int group_balance_cpu (struct sched_group *sg);
@@ -663,6 +689,12 @@ extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];#define sched_feat (x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))#endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */ +#ifdef CONFIG_NUMA_BALANCING +#define sched_feat_numa (x) sched_feat(x) +#else +#define sched_feat_numa (x) (0) +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
mm/huge_memory.c +5 -2
@@ -1069,9 +1069,10 @@ fixup: unlock:spin_unlock (&mm->page_table_lock); -if (page) +if (page) { +task_numa_fault (page_to_nid (page), last_cpu,HPAGE_PMD_NR );put_page (page); - + }return 0 ; migrate:
@@ -1153,6 +1154,8 @@ migrate:mem_cgroup_end_migration (memcg, page, new_page, true);spin_unlock (&mm->page_table_lock); +task_numa_fault (node, last_cpu,HPAGE_PMD_NR ); +unlock_page (new_page);unlock_page (page);put_page (page);/* Drop the rmap reference */
mm/memory.c +6 -0
@@ -3523,6 +3523,9 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,if (migrated) page_nid = target_nid; out: +/* Always account where the page currently is, physically: */ +task_numa_fault (page_nid, last_cpu,1 ); +return 0 ; }
@@ -3605,6 +3608,9 @@ int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,if (migrated) page_nid = target_nid; +/* Always account where the page currently is, physically: */ +task_numa_fault (page_nid, last_cpu,1 ); + pte =pte_offset_map_lock (mm, pmdp, addr, &ptl); }pte_unmap_unlock (orig_pte, ptl);
Signature · 7 lines
1.7.11.7 -- 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 25/52 sched, numa: Improve the CONFIG_NUMA_BALANCING help text
In reply to Ingo MolnarAdd information about cost, type of optimizations, etc., so that the user knows what to expect.
--- init/Kconfig | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
init/Kconfig +31 -2
@@ -721,13 +721,42 @@ config ARCH_USES_NUMA_PROT_NONE depends on NUMA_BALANCING config NUMA_BALANCING - bool "Memory placement aware NUMA scheduler" + bool "NUMA-optimizing scheduler" default n depends on ARCH_SUPPORTS_NUMA_BALANCING depends on !ARCH_WANT_NUMA_VARIABLE_LOCALITY depends on SMP && NUMA && MIGRATION help - This option adds support for automatic NUMA aware memory/task placement. + This option enables NUMA-aware, transparent, automatic + placement optimizations of memory, tasks and task groups. + + The optimizations work by (transparently) runtime sampling the + workload sharing relationship between threads and processes + of long-run workloads, and scheduling them based on these + measured inter-task relationships (or the lack thereof). + + ("Long-run" means several seconds of CPU runtime at least.) + + Tasks that predominantly perform their own processing, without + interacting with other tasks much will be independently balanced + to a CPU and their working set memory will migrate to that CPU/node. + + Tasks that share a lot of data with each other will be attempted to + be scheduled on as few nodes as possible, with their memory + following them there and being distributed between those nodes. + + This optimization can improve the performance of long-run CPU-bound + workloads by 10% or more. The sampling and migration has a small + but nonzero cost, so if your NUMA workload is already perfectly + placed (for example by use of explicit CPU and memory bindings, + or because the stock scheduler does a good job already) then you + probably don't need this feature. + + [ On non-NUMA systems this feature will not be active. You can query + whether your system is a NUMA system via looking at the output of + "numactl --hardware". ] + + Say N if unsure. menuconfig CGROUPS boolean "Control Group support"
Signature · 7 lines
1.7.11.7 -- 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 26/52 sched: Implement constant, per task Working Set Sampling (WSS) rate
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Previously, to probe the working set of a task, we'd use a very simple and crude method: mark all of its address space PROT_NONE.
That method has various (obvious) disadvantages:
- it samples the working set at dissimilar rates, giving some tasks a sampling quality advantage over others.
- creates performance problems for tasks with very large working sets
- over-samples processes with large address spaces but which only very rarely execute
Improve that method by keeping a rotating offset into the address space that marks the current position of the scan, and advance it by a constant rate (in a CPU cycles execution proportional manner). If the offset reaches the last mapped address of the mm then it then it starts over at the first address.
The per-task nature of the working set sampling functionality in this tree allows such constant rate, per task, execution-weight proportional sampling of the working set, with an adaptive sampling interval/frequency that goes from once per 100 msecs up to just once per 1.6 seconds. The current sampling volume is 256 MB per interval.
As tasks mature and converge their working set, so does the sampling rate slow down to just a trickle, 256 MB per 1.6 seconds of CPU time executed.
This, beyond being adaptive, also rate-limits rarely executing systems and does not over-sample on overloaded systems.
[ In AutoNUMA speak, this patch deals with the effective sampling
rate of the 'hinting page fault'. AutoNUMA's scanning is currently rate-limited, but it is also fundamentally single-threaded, executing in the knuma_scand kernel thread, so the limit in AutoNUMA is global and does not scale up with the number of CPUs, nor does it scan tasks in an execution proportional manner.
So the idea of rate-limiting the scanning was first implemented in the AutoNUMA tree via a global rate limit. This patch goes beyond that by implementing an execution rate proportional working set sampling rate that is not implemented via a single global scanning daemon. ]
[ Dan Carpenter pointed out a possible NULL pointer dereference in the
first version of this patch. ]
--- kernel/sched/fair.c | 41 +++++++++++++++++++++++++++++------------ kernel/sysctl.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 14 deletions(-)
kernel/sched/fair.c +29 -12
@@ -825,8 +825,9 @@ static void account_numa_dequeue(struct rq *rq, struct task_struct *p)/* * numa task sample period in ms: 5s */ -unsigned int sysctl_sched_numa_scan_period_min =5000 ; -unsigned int sysctl_sched_numa_scan_period_max =5000 *16 ; +unsigned int sysctl_sched_numa_scan_period_min =100 ; +unsigned int sysctl_sched_numa_scan_period_max =100 *16 ; +unsigned int sysctl_sched_numa_scan_size =256 ;/* MB */ /* * Wait for the 2-sample stuff to settle before migrating again
@@ -912,6 +913,9 @@ void task_numa_work(struct callback_head *work)unsigned long migrate, next_scan, now = jiffies;struct task_struct *p = current;struct mm_struct *mm = p->mm; +struct vm_area_struct *vma; +unsigned long offset, end; +long length; WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
@@ -938,18 +942,31 @@ void task_numa_work(struct callback_head *work)if (cmpxchg (&mm->numa_next_scan, migrate, next_scan) != migrate)return ; -ACCESS_ONCE (mm->numa_scan_seq)++; - { -struct vm_area_struct *vma; + offset = mm->numa_scan_offset; + length = sysctl_sched_numa_scan_size; + length <<=20 ; -down_write (&mm->mmap_sem); -for (vma = mm->mmap; vma; vma = vma->vm_next) { -if (!vma_migratable (vma)) -continue ; -change_prot_numa (vma, vma->vm_start, vma->vm_end); - } -up_write (&mm->mmap_sem); +down_write (&mm->mmap_sem); + vma =find_vma (mm, offset); +if (!vma) { +ACCESS_ONCE (mm->numa_scan_seq)++; + offset =0 ; + vma = mm->mmap; + } +for (; vma && length >0 ; vma = vma->vm_next) { +if (!vma_migratable (vma)) +continue ; + + offset =max (offset, vma->vm_start); + end =min (ALIGN (offset + length,HPAGE_SIZE ), vma->vm_end); + length -= end - offset; + +change_prot_numa (vma, offset, end); + + offset = end; } + mm->numa_scan_offset = offset; +up_write (&mm->mmap_sem); }/*
kernel/sysctl.c +36 -2
@@ -256,9 +256,11 @@ static int min_sched_granularity_ns = 100000; /* 100 usecs */static int max_sched_granularity_ns =NSEC_PER_SEC ;/* 1 second */ static int min_wakeup_granularity_ns;/* 0 usecs */ static int max_wakeup_granularity_ns =NSEC_PER_SEC ;/* 1 second */ +#ifdef CONFIG_SMP static int min_sched_tunable_scaling =SCHED_TUNABLESCALING_NONE ;static int max_sched_tunable_scaling =SCHED_TUNABLESCALING_END -1 ; -#endif +#endif /* CONFIG_SMP */ +#endif /* CONFIG_SCHED_DEBUG */ #ifdef CONFIG_COMPACTION static int min_extfrag_threshold;
@@ -301,6 +303,7 @@ static struct ctl_table kern_table[] = { .extra1 = &min_wakeup_granularity_ns, .extra2 = &max_wakeup_granularity_ns, }, +#ifdef CONFIG_SMP { .procname = "sched_tunable_scaling", .data = &sysctl_sched_tunable_scaling,
@@ -347,7 +350,38 @@ static struct ctl_table kern_table[] = { .extra1 = &zero, .extra2 = &one, }, -#endif +#endif /* CONFIG_SMP */ +#ifdef CONFIG_NUMA_BALANCING + { + .procname = "sched_numa_scan_period_min_ms", + .data = &sysctl_sched_numa_scan_period_min, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { + .procname = "sched_numa_scan_period_max_ms", + .data = &sysctl_sched_numa_scan_period_max, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { + .procname = "sched_numa_scan_size_mb", + .data = &sysctl_sched_numa_scan_size, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { + .procname = "sched_numa_settle_count", + .data = &sysctl_sched_numa_settle_count, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, +#endif /* CONFIG_NUMA_BALANCING */ +#endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us", .data = &sysctl_sched_rt_period,
Signature · 7 lines
1.7.11.7 -- 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 27/52 sched, numa, mm: Count WS scanning against present PTEs, not virtual memory ranges
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
By accounting against the present PTEs, scanning speed reflects the actual present (mapped) memory.
--- kernel/sched/fair.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
kernel/sched/fair.c +21 -16
@@ -914,8 +914,8 @@ void task_numa_work(struct callback_head *work)struct task_struct *p = current;struct mm_struct *mm = p->mm;struct vm_area_struct *vma; -unsigned long offset, end; -long length; +unsigned long start, end; +long pages; WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
@@ -942,30 +942,35 @@ void task_numa_work(struct callback_head *work)if (cmpxchg (&mm->numa_next_scan, migrate, next_scan) != migrate)return ; - offset = mm->numa_scan_offset; - length = sysctl_sched_numa_scan_size; - length <<=20 ; + start = mm->numa_scan_offset; + pages = sysctl_sched_numa_scan_size; + pages <<=20 -PAGE_SHIFT ;/* MB in pages */ +if (!pages) +return ;down_write (&mm->mmap_sem); - vma =find_vma (mm, offset); + vma =find_vma (mm, start);if (!vma) {ACCESS_ONCE (mm->numa_scan_seq)++; - offset =0 ; + start =0 ; vma = mm->mmap; } -for (; vma && length >0 ; vma = vma->vm_next) { +for (; vma; vma = vma->vm_next) {if (!vma_migratable (vma))continue ; - offset =max (offset, vma->vm_start); - end =min (ALIGN (offset + length,HPAGE_SIZE ), vma->vm_end); - length -= end - offset; - -change_prot_numa (vma, offset, end); - - offset = end; +do { + start =max (start, vma->vm_start); + end =ALIGN (start + (pages <<PAGE_SHIFT ),HPAGE_SIZE ); + end =min (end, vma->vm_end); + pages -=change_prot_numa (vma, start, end); + start = end; +if (pages <=0 ) + goto out; + }while (end != vma->vm_end); } - mm->numa_scan_offset = offset; +out: + mm->numa_scan_offset = start;up_write (&mm->mmap_sem); }
Signature · 7 lines
1.7.11.7 -- 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 28/52 sched: Implement slow start for working set sampling
In reply to Ingo MolnarFrom: Peter Zijlstra <[email protected]>
Add a 1 second delay before starting to scan the working set of a task and starting to balance it amongst nodes.
[ note that before the constant per task WSS sampling rate patch
the initial scan would happen much later still, in effect that patch caused this regression. ]
The theory is that short-run tasks benefit very little from NUMA
placement: they come and go, and they better stick to the node they were started on. As tasks mature and rebalance to other CPUs and nodes, so does their NUMA placement have to change and so does it start to matter more and more.
In practice this change fixes an observable kbuild regression:
# [ a perf stat --null --repeat 10 test of ten bzImage builds to /dev/shm ]
!NUMA:
45.291088843 seconds time elapsed ( +- 0.40% ) 45.154231752 seconds time elapsed ( +- 0.36% )
+NUMA, no slow start:
46.172308123 seconds time elapsed ( +- 0.30% ) 46.343168745 seconds time elapsed ( +- 0.25% )
+NUMA, 1 sec slow start:
45.224189155 seconds time elapsed ( +- 0.25% ) 45.160866532 seconds time elapsed ( +- 0.17% )
and it also fixes an observable perf bench (hackbench) regression:
# perf stat --null --repeat 10 perf bench sched messaging
-NUMA:
-NUMA: 0.246225691 seconds time elapsed ( +- 1.31% ) +NUMA no slow start: 0.252620063 seconds time elapsed ( +- 1.13% )
+NUMA 1sec delay: 0.248076230 seconds time elapsed ( +- 1.35% )
The implementation is simple and straightforward, most of the patch deals with adding the /proc/sys/kernel/sched_numa_scan_delay_ms tunable knob.
--- include/linux/sched.h | 1 + kernel/sched/core.c | 1 + kernel/sched/fair.c | 16 ++++++++++------ kernel/sysctl.c | 7 +++++++ 4 files changed, 19 insertions(+), 6 deletions(-)
include/linux/sched.h +1 -0
@@ -2051,6 +2051,7 @@ enum sched_tunable_scaling { };extern enum sched_tunable_scaling sysctl_sched_tunable_scaling; +extern unsigned int sysctl_sched_numa_scan_delay;extern unsigned int sysctl_sched_numa_scan_period_min;extern unsigned int sysctl_sched_numa_scan_period_max;extern unsigned int sysctl_sched_numa_scan_size;
kernel/sched/core.c +1 -0
@@ -1556,6 +1556,7 @@ static void __sched_fork(struct task_struct *p) p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq :0 ; p->numa_migrate_seq =2 ; p->numa_faults =NULL ; + p->numa_scan_period = sysctl_sched_numa_scan_delay; p->numa_work.next = &p->numa_work; p->shared_buddy =NULL ;
kernel/sched/fair.c +10 -6
@@ -823,11 +823,12 @@ static void account_numa_dequeue(struct rq *rq, struct task_struct *p) }/* -* numa task sample period in ms: 5s +* Scan @scan_size MB every @scan_period after an initial @scan_delay. */ -unsigned int sysctl_sched_numa_scan_period_min =100 ; -unsigned int sysctl_sched_numa_scan_period_max =100 *16 ; -unsigned int sysctl_sched_numa_scan_size =256 ;/* MB */ +unsigned int sysctl_sched_numa_scan_delay =1000 ;/* ms */ +unsigned int sysctl_sched_numa_scan_period_min =100 ;/* ms */ +unsigned int sysctl_sched_numa_scan_period_max =100 *16 ;/* ms */ +unsigned int sysctl_sched_numa_scan_size =256 ;/* MB */ /* * Wait for the 2-sample stuff to settle before migrating again
@@ -938,10 +939,12 @@ void task_numa_work(struct callback_head *work)if (time_before (now, migrate))return ; - next_scan = now +2 *msecs_to_jiffies (sysctl_sched_numa_scan_period_min); + next_scan = now +msecs_to_jiffies (sysctl_sched_numa_scan_period_min);if (cmpxchg (&mm->numa_next_scan, migrate, next_scan) != migrate)return ; + current->numa_scan_period +=jiffies_to_msecs (2 ); + start = mm->numa_scan_offset; pages = sysctl_sched_numa_scan_size; pages <<=20 -PAGE_SHIFT ;/* MB in pages */
@@ -998,7 +1001,8 @@ void task_tick_numa(struct rq *rq, struct task_struct *curr) period = (u64 )curr->numa_scan_period *NSEC_PER_MSEC ;if (now - curr->node_stamp > period) { - curr->node_stamp = now; + curr->node_stamp += period; + curr->numa_scan_period = sysctl_sched_numa_scan_period_min;/* * We are comparing runtime to wall clock time here, which
kernel/sysctl.c +7 -0
@@ -353,6 +353,13 @@ static struct ctl_table kern_table[] = {#endif /* CONFIG_SMP */ #ifdef CONFIG_NUMA_BALANCING { + .procname = "sched_numa_scan_delay_ms", + .data = &sysctl_sched_numa_scan_delay, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { .procname = "sched_numa_scan_period_min_ms", .data = &sysctl_sched_numa_scan_period_min, .maxlen = sizeof(unsigned int),
Signature · 7 lines
1.7.11.7 -- 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 29/52 sched: Implement NUMA scanning backoff
In reply to Ingo MolnarBack off slowly from scanning, up to sysctl_sched_numa_scan_period_max (1.6 seconds). Scan faster again if we were forced to switch to another node.
This makes sure that workload in equilibrium don't get scanned as often as workloads that are still converging.
--- kernel/sched/core.c | 6 ++++++ kernel/sched/fair.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
kernel/sched/core.c +6 -0
@@ -6029,6 +6029,12 @@ void sched_setnuma(struct task_struct *p, int node, int shared)if (on_rq)enqueue_task (rq, p,0 );task_rq_unlock (rq, p, &flags); + +/* +* Reset the scanning period. If the task converges +* on this node then we'll back off again: +*/ + p->numa_scan_period = sysctl_sched_numa_scan_period_min; }#endif /* CONFIG_NUMA_BALANCING */
kernel/sched/fair.c +7 -1
@@ -865,8 +865,10 @@ static void task_numa_placement(struct task_struct *p) } } -if (max_node != p->numa_max_node) +if (max_node != p->numa_max_node) {sched_setnuma (p, max_node,task_numa_shared (p)); + goto out_backoff; + } p->numa_migrate_seq++; if (sched_feat(NUMA_SETTLE) &&
@@ -882,7 +884,11 @@ static void task_numa_placement(struct task_struct *p)if (shared !=task_numa_shared (p)) {sched_setnuma (p, p->numa_max_node, shared); p->numa_migrate_seq =0 ; + goto out_backoff; } +return ; +out_backoff: + p->numa_scan_period =min (p->numa_scan_period *2 , sysctl_sched_numa_scan_period_max); }/*
Signature · 7 lines
1.7.11.7 -- 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 30/52 sched: Improve convergence
In reply to Ingo Molnar - break out of can_do_numa_run() earlier if we can make no progress
- don't flip between siblings that often
- turn on bidirectional fault balancing
- improve the flow in task_numa_work()
--- kernel/sched/fair.c | 46 ++++++++++++++++++++++++++++++++-------------- kernel/sched/features.h | 2 +- 2 files changed, 33 insertions(+), 15 deletions(-)
kernel/sched/fair.c +32 -14
@@ -917,12 +917,12 @@ void task_numa_fault(int node, int last_cpu, int pages)*/ void task_numa_work (struct callback_head *work) { +long pages_total, pages_left, pages_changed;unsigned long migrate, next_scan, now = jiffies; +unsigned long start0, start, end;struct task_struct *p = current;struct mm_struct *mm = p->mm;struct vm_area_struct *vma; -unsigned long start, end; -long pages; WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
@@ -951,35 +951,42 @@ void task_numa_work(struct callback_head *work) current->numa_scan_period +=jiffies_to_msecs (2 ); - start = mm->numa_scan_offset; - pages = sysctl_sched_numa_scan_size; - pages <<=20 -PAGE_SHIFT ;/* MB in pages */ -if (!pages) + start0 = start = end = mm->numa_scan_offset; + pages_total = sysctl_sched_numa_scan_size; + pages_total <<=20 -PAGE_SHIFT ;/* MB in pages */ +if (!pages_total)return ; + pages_left = pages_total; +down_write (&mm->mmap_sem); vma =find_vma (mm, start);if (!vma) {ACCESS_ONCE (mm->numa_scan_seq)++; - start =0 ; - vma = mm->mmap; + end =0 ; + vma =find_vma (mm, end); }for (; vma; vma = vma->vm_next) {if (!vma_migratable (vma))continue ;do { - start =max (start, vma->vm_start); - end =ALIGN (start + (pages <<PAGE_SHIFT ),HPAGE_SIZE ); + start =max (end, vma->vm_start); + end =ALIGN (start + (pages_left <<PAGE_SHIFT ),HPAGE_SIZE ); end =min (end, vma->vm_end); - pages -=change_prot_numa (vma, start, end); - start = end; -if (pages <=0 ) + pages_changed =change_prot_numa (vma, start, end); + +WARN_ON_ONCE (pages_changed > pages_total); +BUG_ON (pages_changed <0 ); + + pages_left -= pages_changed; +if (pages_left <=0 ) goto out; }while (end != vma->vm_end); } out: - mm->numa_scan_offset = start; + mm->numa_scan_offset = end; +up_write (&mm->mmap_sem); }
@@ -3306,6 +3313,13 @@ static int select_idle_sibling(struct task_struct *p, int target)int i;/* +* For NUMA tasks constant, reliable placement is more important +* than flipping tasks between siblings: +*/ +if (task_numa_shared (p) >=0 ) +return target; + +/* * If the task is going to be woken-up on this cpu and if it is * already idle, then it is the right target. */
@@ -4581,6 +4595,10 @@ static bool can_do_numa_run(struct lb_env *env, struct sd_lb_stats *sds)* If we got capacity allow stacking up on shared tasks. */ if ((sds->this_shared_running < sds->this_group_capacity) && sds->numa_shared_running) { +/* There's no point in trying to move if all are here already: */ +if (sds->numa_shared_running == sds->this_shared_running) +return false; + env->flags |=LBF_NUMA_SHARED ;return true; }
kernel/sched/features.h +1 -1
@@ -71,6 +71,6 @@ SCHED_FEAT(LB_MIN, false)/* Do the working set probing faults: */ SCHED_FEAT(NUMA, true) SCHED_FEAT(NUMA_FAULTS_UP, true) -SCHED_FEAT(NUMA_FAULTS_DOWN, false) +SCHED_FEAT(NUMA_FAULTS_DOWN, true) SCHED_FEAT(NUMA_SETTLE, true)#endif
Signature · 7 lines
1.7.11.7 -- 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 31/52 sched: Introduce staged average NUMA faults
In reply to Ingo MolnarThe current way of building the p->numa_faults[2][node] faults statistics has a sampling artifact:
The continuous and immediate nature of propagating new fault stats to the numa_faults array creates a 'pulsating' dynamic, that starts at the average value at the beginning of the scan, increases monotonically until we finish the scan to about twice the average, and then drops back to half of its value due to the running average.
Since we rely on these values to balance tasks, the pulsating nature resulted in false migrations and general noise in the stats.
To solve this, introduce buffering of the current scan via p->task_numa_faults_curr[]. The array is co-allocated with the p->task_numa[] for efficiency reasons, but it is otherwise an ordinary separate array.
At the end of the scan we propagate the latest stats into the average stats value. Most of the balancing code stays unmodified.
The cost of this change is that we delay the effects of the latest round of faults by 1 scan - but using the partial faults info was creating artifacts.
This instantly stabilized the page fault stats and improved numa02-alike workloads by making them faster to converge.
--- kernel/sched/fair.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
kernel/sched/fair.c +17 -3
@@ -852,12 +852,26 @@ static void task_numa_placement(struct task_struct *p) p->numa_scan_seq = seq; +/* +* Update the fault average with the result of the latest +* scan: +*/ for (node =0 ; node < nr_node_ids; node++) { faults =0 ;for (priv =0 ; priv <2 ; priv++) { - faults += p->numa_faults[2 *node + priv]; - total[priv] += p->numa_faults[2 *node + priv]; - p->numa_faults[2 *node + priv] /=2 ; +unsigned int new_faults; +unsigned int idx; + + idx =2 *node + priv; + new_faults = p->numa_faults_curr[idx]; + p->numa_faults_curr[idx] =0 ; + +/* Keep a simple running average: */ + p->numa_faults[idx] += new_faults; + p->numa_faults[idx] /=2 ; + + faults += p->numa_faults[idx]; + total[priv] += p->numa_faults[idx]; }if (faults > max_faults) { max_faults = faults;
Signature · 7 lines
1.7.11.7 -- 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 32/52 sched: Track groups of shared tasks
In reply to Ingo MolnarTo be able to cluster memory-related tasks more efficiently, introduce a new metric that tracks the 'best' buddy task
Track our "memory buddies": the tasks we actively share memory with.
Firstly we establish the identity of some other task that we are sharing memory with by looking at rq[page::last_cpu].curr - i.e. we check the task that is running on that CPU right now.
This is not entirely correct as this task might have scheduled or migrate ther - but statistically there will be correlation to the tasks that we share memory with, and correlation is all we need.
We map out the relation itself by filtering out the highest address ask that is below our own task address, per working set scan iteration.
This creates a natural ordering relation between groups of tasks:
t1 < t2 < t3 < t4
t1->memory_buddy == NULL
t2->memory_buddy == t1
t3->memory_buddy == t2
t4->memory_buddy == t3The load-balancer can then use this information to speed up NUMA convergence, by moving such tasks together if capacity and load constraints allow it.
(This is all statistical so there are no preemption or locking worries.)
--- kernel/sched/fair.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 3 deletions(-)
kernel/sched/fair.c +141 -3
@@ -840,6 +840,43 @@ static void task_numa_migrate(struct task_struct *p, int next_cpu) p->numa_migrate_seq =0 ; } +/* +* Called for every full scan - here we consider switching to a new +* shared buddy, if the one we found during this scan is good enough: +*/ +static void shared_fault_full_scan_done (struct task_struct *p) +{ +/* +* If we have a new maximum rate buddy task then pick it +* as our new best friend: +*/ +if (p->shared_buddy_faults_curr > p->shared_buddy_faults) { +WARN_ON_ONCE (!p->shared_buddy_curr); + p->shared_buddy = p->shared_buddy_curr; + p->shared_buddy_faults = p->shared_buddy_faults_curr; + p->ideal_cpu = p->ideal_cpu_curr; + + goto clear_buddy; + } +/* +* If the new buddy is lower rate than the previous average +* fault rate then don't switch buddies yet but lower the average by +* averaging in the new rate, with a 1/3 weight. +* +* Eventually, if the current buddy is not a buddy anymore +* then we'll switch away from it: a higher rate buddy will +* replace it. +*/ + p->shared_buddy_faults *=3 ; + p->shared_buddy_faults += p->shared_buddy_faults_curr; + p->shared_buddy_faults /=4 ; + +clear_buddy: + p->shared_buddy_curr =NULL ; + p->shared_buddy_faults_curr =0 ; + p->ideal_cpu_curr =-1 ; +} +static void task_numa_placement (struct task_struct *p) {int seq =ACCESS_ONCE (p->mm->numa_scan_seq);
@@ -852,6 +889,8 @@ static void task_numa_placement(struct task_struct *p) p->numa_scan_seq = seq; +shared_fault_full_scan_done (p); +/* * Update the fault average with the result of the latest * scan:
@@ -906,23 +945,122 @@ out_backoff: }/* +* Track our "memory buddies" the tasks we actively share memory with. +* +* Firstly we establish the identity of some other task that we are +* sharing memory with by looking at rq[page::last_cpu].curr - i.e. +* we check the task that is running on that CPU right now. +* +* This is not entirely correct as this task might have scheduled or +* migrate ther - but statistically there will be correlation to the +* tasks that we share memory with, and correlation is all we need. +* +* We map out the relation itself by filtering out the highest address +* ask that is below our own task address, per working set scan +* iteration. +* +* This creates a natural ordering relation between groups of tasks: +* +* t1 < t2 < t3 < t4 +* +* t1->memory_buddy == NULL +* t2->memory_buddy == t1 +* t3->memory_buddy == t2 +* t4->memory_buddy == t3 +* +* The load-balancer can then use this information to speed up NUMA +* convergence, by moving such tasks together if capacity and load +* constraints allow it. +* +* (This is all statistical so there are no preemption or locking worries.) +*/ +static void shared_fault_tick (struct task_struct *this_task,int node,int last_cpu,int pages) +{ +struct task_struct *last_task; +struct rq *last_rq; +int last_node; +int this_node; +int this_cpu; + + last_node =cpu_to_node (last_cpu); + this_cpu =raw_smp_processor_id (); + this_node =cpu_to_node (this_cpu); + +/* Ignore private memory access faults: */ +if (last_cpu == this_cpu) +return ; + +/* +* Ignore accesses from foreign nodes to our memory. +* +* Yet still recognize tasks accessing a third node - i.e. one that is +* remote to both of them. +*/ +if (node != this_node) +return ; + +/* We are in a shared fault - see which task we relate to: */ + last_rq =cpu_rq (last_cpu); + last_task = last_rq->curr; + +/* Task might be gone from that runqueue already: */ +if (!last_task || last_task == last_rq->idle) +return ; + +if (last_task == this_task->shared_buddy_curr) + goto out_hit; + +/* Order our memory buddies by address: */ +if (last_task >= this_task) +return ; + +if (this_task->shared_buddy_curr > last_task) +return ; + +/* New shared buddy! */ + this_task->shared_buddy_curr = last_task; + this_task->shared_buddy_faults_curr =0 ; + this_task->ideal_cpu_curr = last_rq->cpu; + +out_hit: +/* +* Give threads that we share a process with an advantage, +* but don't stop the discovery of process level sharing +* either: +*/ +if (this_task->mm == last_task->mm) + pages *=2 ; + + this_task->shared_buddy_faults_curr += pages; +} + +/* * Got a PROT_NONE fault for a page on @node. */ void task_numa_fault (int node,int last_cpu,int pages) {struct task_struct *p = current;int priv = (task_cpu (p) == last_cpu); +int idx =2 *node + priv;if (unlikely (!p->numa_faults)) { -int size =sizeof (*p->numa_faults) *2 * nr_node_ids; +int entries =2 *nr_node_ids; +int size =sizeof (*p->numa_faults) * entries; - p->numa_faults =kzalloc (size,GFP_KERNEL ); + p->numa_faults =kzalloc (2 *size,GFP_KERNEL );if (!p->numa_faults)return ; +/* +* For efficiency reasons we allocate ->numa_faults[] +* and ->numa_faults_curr[] at once and split the +* buffer we get. They are separate otherwise. +*/ + p->numa_faults_curr = p->numa_faults + entries; } + p->numa_faults_curr[idx] += pages; +shared_fault_tick (p, node, last_cpu, pages);task_numa_placement (p); - p->numa_faults[2 *node + priv] += pages; }/*
Signature · 7 lines
1.7.11.7 -- 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 33/52 sched: Use the best-buddy 'ideal cpu' in balancing decisions
In reply to Ingo MolnarNow that we have a notion of (one of the) best CPUs we interrelate with in terms of memory usage, use that information to improve can_migrate_task() balancing decisions: allow the migration to occur even if we locally cache-hot, if we are on another node and want to migrate towards our best buddy's node.
( Note that this is not hard affinity - if imbalance persists long
enough then the scheduler will eventually balance tasks anyway, to maximize CPU utilization. )
--- kernel/sched/fair.c | 35 ++++++++++++++++++++++++++++++++--- kernel/sched/features.h | 2 ++ 2 files changed, 34 insertions(+), 3 deletions(-)
kernel/sched/fair.c +32 -3
@@ -840,6 +840,14 @@ static void task_numa_migrate(struct task_struct *p, int next_cpu) p->numa_migrate_seq =0 ; } +static int task_ideal_cpu (struct task_struct *p) +{ +if (!sched_feat (IDEAL_CPU )) +return -1 ; + +return p->ideal_cpu; +} +/* * Called for every full scan - here we consider switching to a new * shared buddy, if the one we found during this scan is good enough:
@@ -1028,7 +1036,7 @@ out_hit:* but don't stop the discovery of process level sharing * either: */ -if (this_task->mm == last_task->mm) +if (sched_feat (IDEAL_CPU_THREAD_BIAS ) && this_task->mm == last_task->mm) pages *=2 ; this_task->shared_buddy_faults_curr += pages;
@@ -1189,6 +1197,7 @@ void task_tick_numa(struct rq *rq, struct task_struct *curr) }#else /* !CONFIG_NUMA_BALANCING: */ #ifdef CONFIG_SMP +static inline int task_ideal_cpu (struct task_struct *p) {return -1 ; }static inline void account_numa_enqueue (struct rq *rq,struct task_struct *p) { }#endif static inline void account_numa_dequeue (struct rq *rq,struct task_struct *p) { }
@@ -4064,6 +4073,7 @@ struct lb_env {static void move_task (struct task_struct *p,struct lb_env *env) {deactivate_task (env->src_rq, p,0 ); +set_task_cpu (p, env->dst_cpu);activate_task (env->dst_rq, p,0 );check_preempt_curr (env->dst_rq, p,0 );
@@ -4242,15 +4252,17 @@ static bool can_migrate_numa_task(struct task_struct *p, struct lb_env *env)* * LBF_NUMA_RUN -- numa only, only allow improvement * LBF_NUMA_SHARED -- shared only +* LBF_NUMA_IDEAL -- ideal only * * LBF_KEEP_SHARED -- do not touch shared tasks */ /* a numa run can only move numa tasks about to improve things */ if (env->flags &LBF_NUMA_RUN ) { -if (task_numa_shared (p) <0 ) +if (task_numa_shared (p) <0 &&task_ideal_cpu (p) <0 )return false; -/* can only pull shared tasks */ + +/* If we are only allowed to pull shared tasks: */ if ((env->flags &LBF_NUMA_SHARED ) && !task_numa_shared (p))return false; }else {
@@ -4307,6 +4319,23 @@ static int can_migrate_task(struct task_struct *p, struct lb_env *env)if (!can_migrate_running_task (p, env))return false; +#ifdef CONFIG_NUMA_BALANCING +/* If we are only allowed to pull ideal tasks: */ +if ((task_ideal_cpu (p) >=0 ) && (p->shared_buddy_faults >1000 )) { +int ideal_node; +int dst_node; + +BUG_ON (env->dst_cpu <0 ); + + ideal_node =cpu_to_node (p->ideal_cpu); + dst_node =cpu_to_node (env->dst_cpu); + +if (ideal_node == dst_node) +return true; +return false; + } +#endif +if (env->sd->flags &SD_NUMA )return can_migrate_numa_task (p, env);
kernel/sched/features.h +2 -0
@@ -66,6 +66,8 @@ SCHED_FEAT(TTWU_QUEUE, true) SCHED_FEAT(FORCE_SD_OVERLAP, false) SCHED_FEAT(RT_RUNTIME_SHARE, true) SCHED_FEAT(LB_MIN, false) +SCHED_FEAT(IDEAL_CPU, true) +SCHED_FEAT(IDEAL_CPU_THREAD_BIAS, false)#ifdef CONFIG_NUMA_BALANCING /* Do the working set probing faults: */
Signature · 7 lines
1.7.11.7 -- 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 34/52 sched: Average the fault stats longer
In reply to Ingo MolnarWe will rely on the per CPU fault statistics and its shared/private derivative even more in the future, so stabilize this metric even better.
The staged updates introduced in commit:
sched: Introduce staged average NUMA faults
Already stabilized this key metric significantly, but in real workloads it was still reacting to temporary load balancing transients too quickly.
Slow down by weighting the average. The weighting value was found via experimentation.
--- kernel/sched/fair.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
@@ -914,8 +914,8 @@ static void task_numa_placement(struct task_struct *p) p->numa_faults_curr[idx] =0 ;/* Keep a simple running average: */ - p->numa_faults[idx] += new_faults; - p->numa_faults[idx] /=2 ; + p->numa_faults[idx] = p->numa_faults[idx]*7 + new_faults; + p->numa_faults[idx] /=8 ; faults += p->numa_faults[idx]; total[priv] += p->numa_faults[idx];
Signature · 7 lines
1.7.11.7 -- 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 35/52 sched: Use the ideal CPU to drive active balancing
In reply to Ingo MolnarUse our shared/private distinction to allow the separate handling of 'private' versus 'shared' workloads, which enables the active-balancing of them:
- private tasks, via the sched_update_ideal_cpu_private() function, try to 'spread' the system as evenly as possible.
- shared-access tasks that also share their mm (threads), via the sched_update_ideal_cpu_shared() function, try to 'compress' with other shared tasks on as few nodes as possible.
[ We'll be able to extend this grouping beyond threads in the
future, by using the existing p->shared_buddy directed graph. ]
Introduce the sched_rebalance_to() primitive to trigger active rebalancing.
The result of this patch is 2-3 times faster convergence and much more stable convergence points.
--- include/linux/sched.h | 1 + kernel/sched/core.c | 19 ++++ kernel/sched/fair.c | 244 +++++++++++++++++++++++++++++++++++++++++++++--- kernel/sched/features.h | 7 +- kernel/sched/sched.h | 1 + 5 files changed, 257 insertions(+), 15 deletions(-)
include/linux/sched.h +1 -0
@@ -2019,6 +2019,7 @@ task_sched_runtime(struct task_struct *task);/* sched_exec is called by processes performing an exec */ #ifdef CONFIG_SMP extern void sched_exec (void ); +extern void sched_rebalance_to (int dest_cpu);#else #define sched_exec () {}#endif
kernel/sched/core.c +19 -0
@@ -2589,6 +2589,22 @@ unlock: raw_spin_unlock_irqrestore(&p->pi_lock, flags); } +/* +* sched_rebalance_to() +* +* Active load-balance to a target CPU. +*/ +void sched_rebalance_to (int dest_cpu) +{ +struct task_struct *p = current; +struct migration_arg arg = { p, dest_cpu }; + +if (!cpumask_test_cpu (dest_cpu,tsk_cpus_allowed (p))) +return ; + +stop_one_cpu (raw_smp_processor_id (), migration_cpu_stop, &arg); +} +#endif DEFINE_PER_CPU(struct kernel_stat, kstat);
@@ -4746,6 +4762,9 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) done: ret =1 ; fail: +#ifdef CONFIG_NUMA_BALANCING + rq_dest->curr_buddy =NULL ; +#endif double_rq_unlock (rq_src, rq_dest);raw_spin_unlock (&p->pi_lock);return ret;
kernel/sched/fair.c +231 -13
294 lines not on this page · raw message
kernel/sched/features.h +5 -2
@@ -68,11 +68,14 @@ SCHED_FEAT(RT_RUNTIME_SHARE, true) SCHED_FEAT(LB_MIN, false) SCHED_FEAT(IDEAL_CPU, true) SCHED_FEAT(IDEAL_CPU_THREAD_BIAS, false) +SCHED_FEAT(PUSH_PRIVATE_BUDDIES, true) +SCHED_FEAT(PUSH_SHARED_BUDDIES, true) +SCHED_FEAT(WAKE_ON_IDEAL_CPU, false)#ifdef CONFIG_NUMA_BALANCING /* Do the working set probing faults: */ SCHED_FEAT(NUMA, true) -SCHED_FEAT(NUMA_FAULTS_UP, true) -SCHED_FEAT(NUMA_FAULTS_DOWN, true) +SCHED_FEAT(NUMA_FAULTS_UP, false) +SCHED_FEAT(NUMA_FAULTS_DOWN, false) SCHED_FEAT(NUMA_SETTLE, true)#endif
kernel/sched/sched.h +1 -0
@@ -441,6 +441,7 @@ struct rq {unsigned long numa_weight;unsigned long nr_numa_running;unsigned long nr_ideal_running; +struct task_struct *curr_buddy;#endif unsigned long nr_shared_running;/* 0 on non-NUMA */
Signature · 7 lines
1.7.11.7 -- 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 36/52 sched: Add hysteresis to p->numa_shared
In reply to Ingo MolnarMake p->numa_shared flip/flop less around unstable equilibriums, instead require a significant move in either direction to trigger 'dominantly shared accesses' versus 'dominantly private accesses' NUMA status.
--- kernel/sched/fair.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/sched/fair.c +14 -1
@@ -1111,7 +1111,20 @@ static void task_numa_placement(struct task_struct *p)* we might want to consider a different equation below to reduce * the impact of a little private memory accesses. */ - shared = (total[0 ] >= total[1 ] /2 ); + shared = p->numa_shared; + +if (shared <0 ) { + shared = (total[0 ] >= total[1 ]); + }else if (shared ==0 ) { +/* If it was private before, make it harder to become shared: */ +if (total[0 ] >= total[1 ]*2 ) + shared =1 ; + }else if (shared ==1 ) { +/* If it was shared before, make it harder to become private: */ +if (total[0 ]*2 <= total[1 ]) + shared =0 ; + } +if (shared) p->ideal_cpu =sched_update_ideal_cpu_shared (p);else
Signature · 7 lines
1.7.11.7 -- 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 37/52 sched, numa, mm: Interleave shared tasks
In reply to Ingo MolnarInterleave tasks that are 'shared' - i.e. whose memory access patterns indicate that they are intensively sharing memory with other tasks.
If such a task ends up converging then it switches back into the lazy node-local policy.
--- mm/mempolicy.c | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-)
mm/mempolicy.c +41 -14
@@ -112,12 +112,29 @@ enum zone_type policy_zone = 0;/* * run-time system-wide default policy => local allocation */ -static struct mempolicy default_policy = { - .refcnt =ATOMIC_INIT (1 ),/* never free it */ - .mode =MPOL_PREFERRED , - .flags =MPOL_F_LOCAL , +static struct mempolicy default_policy_local = { + .refcnt =ATOMIC_INIT (1 ),/* never free it */ + .mode =MPOL_PREFERRED , + .flags =MPOL_F_LOCAL , }; +/* +* .v.nodes is set by numa_policy_init(): +*/ +static struct mempolicy default_policy_shared = { + .refcnt =ATOMIC_INIT (1 ),/* never free it */ + .mode =MPOL_INTERLEAVE , + .flags =0 , +}; + +static struct mempolicy *default_policy (void ) +{ +if (task_numa_shared (current) ==1 ) +return &default_policy_shared; + +return &default_policy_local; +} +static struct mempolicy preferred_node_policy[MAX_NUMNODES ];static struct mempolicy *get_task_policy (struct task_struct *p)
@@ -855,7 +872,7 @@ out:static void get_policy_nodemask (struct mempolicy *p,nodemask_t *nodes) {nodes_clear (*nodes); -if (p == &default_policy) +if (p ==default_policy ())return ;switch (p->mode) {
@@ -930,7 +947,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,return -EINVAL ;if (!pol) - pol = &default_policy;/* indicates default behavior */ + pol =default_policy ();/* indicates default behavior */ if (flags &MPOL_F_NODE ) {if (flags &MPOL_F_ADDR ) {
@@ -946,7 +963,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, goto out; } }else { - *policy = pol == &default_policy ?MPOL_DEFAULT : + *policy = pol ==default_policy () ?MPOL_DEFAULT : pol->mode;/* * Internal mempolicy flags must be masked off before exposing
@@ -1640,7 +1657,7 @@ struct mempolicy *get_vma_policy(struct task_struct *task, } }if (!pol) - pol = &default_policy; + pol =default_policy ();return pol; }
@@ -2046,7 +2063,7 @@ struct page *alloc_pages_current(gfp_t gfp, unsigned order)unsigned int cpuset_mems_cookie;if (!pol ||in_interrupt () || (gfp & __GFP_THISNODE)) - pol = &default_policy; + pol =default_policy (); retry_cpuset: cpuset_mems_cookie =get_mems_allowed ();
@@ -2269,7 +2286,6 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned longstruct mempolicy *pol;struct zone *zone;int page_nid =page_to_nid (page); -unsigned long pgoff;int target_node = page_nid;BUG_ON (!vma);
@@ -2280,13 +2296,22 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned longswitch (pol->mode) {case MPOL_INTERLEAVE : + { +int shift; +BUG_ON (addr >= vma->vm_end);BUG_ON (addr < vma->vm_start); - pgoff = vma->vm_pgoff; - pgoff += (addr - vma->vm_start) >>PAGE_SHIFT ; - target_node =offset_il_node (pol, vma, pgoff); +#ifdef CONFIG_HUGETLB_PAGE +if (transparent_hugepage_enabled (vma) || vma->vm_flags &VM_HUGETLB ) + shift =HPAGE_SHIFT ; + else +#endif + shift =PAGE_SHIFT ; + + target_node =interleave_nid (pol, vma, addr, shift);break ; + }case MPOL_PREFERRED :if (pol->flags &MPOL_F_LOCAL )
@@ -2552,6 +2577,8 @@ void __init numa_policy_init(void) }; } + default_policy_shared.v.nodes = node_online_map; +/* * Set interleaving policy for system init. Interleaving is only * enabled across suitably sized nodes (default is >= 16MB), or
@@ -2771,7 +2798,7 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)*/ VM_BUG_ON (maxlen <strlen ("interleave" ) +strlen ("relative" ) +16 ); -if (!pol || pol == &default_policy) +if (!pol || pol ==default_policy ()) mode =MPOL_DEFAULT ;else mode = pol->mode;
Signature · 7 lines
1.7.11.7 -- 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 38/52 sched, mm, mempolicy: Add per task mempolicy
In reply to Ingo MolnarWe are going to make use of it in the NUMA code: each thread will converge not just to a group of related tasks, but to a specific group of memory nodes as well.
--- include/linux/mempolicy.h | 39 +-------------------------------------- include/linux/mm_types.h | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/sched.h | 1 + kernel/sched/core.c | 7 +++++++ mm/mempolicy.c | 16 +++------------- 5 files changed, 52 insertions(+), 51 deletions(-)
include/linux/mempolicy.h +1 -38
@@ -6,11 +6,11 @@#define _LINUX_MEMPOLICY_H 1 +#include <linux/mm_types.h> #include <linux/mmzone.h> #include <linux/slab.h> #include <linux/rbtree.h> #include <linux/spinlock.h> -#include <linux/nodemask.h> #include <linux/pagemap.h> #include <uapi/linux/mempolicy.h>
@@ -19,43 +19,6 @@ struct mm_struct;#ifdef CONFIG_NUMA /* -* Describe a memory policy. -* -* A mempolicy can be either associated with a process or with a VMA. -* For VMA related allocations the VMA policy is preferred, otherwise -* the process policy is used. Interrupts ignore the memory policy -* of the current process. -* -* Locking policy for interlave: -* In process context there is no locking because only the process accesses -* its own state. All vma manipulation is somewhat protected by a down_read on -* mmap_sem. -* -* Freeing policy: -* Mempolicy objects are reference counted. A mempolicy will be freed when -* mpol_put() decrements the reference count to zero. -* -* Duplicating policy objects: -* mpol_dup() allocates a new mempolicy and copies the specified mempolicy -* to the new storage. The reference count of the new object is initialized -* to 1, representing the caller of mpol_dup(). -*/ -struct mempolicy { -atomic_t refcnt; -unsigned short mode;/* See MPOL_* above */ -unsigned short flags;/* See set_mempolicy() MPOL_F_* above */ -union { -short preferred_node;/* preferred */ -nodemask_t nodes;/* interleave/bind */ -/* undefined for default */ - } v; -union { -nodemask_t cpuset_mems_allowed;/* relative to these nodes */ -nodemask_t user_nodemask;/* nodemask passed by user */ - } w; -}; - -/* * Support for managing mempolicy data objects (clone, copy, destroy) * The default fast path of a NULL MPOL_DEFAULT policy is always inlined. */
include/linux/mm_types.h +40 -0
@@ -13,6 +13,7 @@#include <linux/page-debug-flags.h> #include <linux/uprobes.h> #include <linux/page-flags-layout.h> +#include <linux/nodemask.h> #include <asm/page.h> #include <asm/mmu.h>
@@ -203,6 +204,45 @@ struct page_frag {typedef unsigned long __nocast vm_flags_t ; +#ifdef CONFIG_NUMA +/* +* Describe a memory policy. +* +* A mempolicy can be either associated with a process or with a VMA. +* For VMA related allocations the VMA policy is preferred, otherwise +* the process policy is used. Interrupts ignore the memory policy +* of the current process. +* +* Locking policy for interlave: +* In process context there is no locking because only the process accesses +* its own state. All vma manipulation is somewhat protected by a down_read on +* mmap_sem. +* +* Freeing policy: +* Mempolicy objects are reference counted. A mempolicy will be freed when +* mpol_put() decrements the reference count to zero. +* +* Duplicating policy objects: +* mpol_dup() allocates a new mempolicy and copies the specified mempolicy +* to the new storage. The reference count of the new object is initialized +* to 1, representing the caller of mpol_dup(). +*/ +struct mempolicy { +atomic_t refcnt; +unsigned short mode;/* See MPOL_* above */ +unsigned short flags;/* See set_mempolicy() MPOL_F_* above */ +union { +short preferred_node;/* preferred */ +nodemask_t nodes;/* interleave/bind */ +/* undefined for default */ + } v; +union { +nodemask_t cpuset_mems_allowed;/* relative to these nodes */ +nodemask_t user_nodemask;/* nodemask passed by user */ + } w; +}; +#endif +/* * A region containing a mapping of a non-memory backed file under NOMMU * conditions. These are held in a global tree and are pinned by the VMAs that
include/linux/sched.h +1 -0
@@ -1517,6 +1517,7 @@ struct task_struct {struct task_struct *shared_buddy, *shared_buddy_curr;unsigned long shared_buddy_faults, shared_buddy_faults_curr;int ideal_cpu, ideal_cpu_curr, ideal_cpu_candidate; +struct mempolicy numa_policy;#endif /* CONFIG_NUMA_BALANCING */
kernel/sched/core.c +7 -0
@@ -72,6 +72,7 @@#include <linux/slab.h> #include <linux/init_task.h> #include <linux/binfmts.h> +#include <uapi/linux/mempolicy.h> #include <asm/switch_to.h> #include <asm/tlb.h>
@@ -1563,6 +1564,12 @@ static void __sched_fork(struct task_struct *p) p->shared_buddy_faults =0 ; p->ideal_cpu =-1 ; p->ideal_cpu_curr =-1 ; +atomic_set (&p->numa_policy.refcnt,1 ); + p->numa_policy.mode =MPOL_INTERLEAVE ; + p->numa_policy.flags =0 ; + p->numa_policy.v.preferred_node =0 ; + p->numa_policy.v.nodes = node_online_map; +#endif /* CONFIG_NUMA_BALANCING */ }
mm/mempolicy.c +3 -13
@@ -118,20 +118,12 @@ static struct mempolicy default_policy_local = { .flags = MPOL_F_LOCAL, }; -/* -* .v.nodes is set by numa_policy_init(): -*/ -static struct mempolicy default_policy_shared = { - .refcnt =ATOMIC_INIT (1 ),/* never free it */ - .mode =MPOL_INTERLEAVE , - .flags =0 , -}; -static struct mempolicy *default_policy (void ) { +#ifdef CONFIG_NUMA_BALANCING if (task_numa_shared (current) ==1 ) -return &default_policy_shared; - +return ¤t->numa_policy; +#endif return &default_policy_local; }
@@ -2577,8 +2569,6 @@ void __init numa_policy_init(void) }; } - default_policy_shared.v.nodes = node_online_map; -/* * Set interleaving policy for system init. Interleaving is only * enabled across suitably sized nodes (default is >= 16MB), or
Signature · 7 lines
1.7.11.7 -- 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 39/52 sched: Track shared task's node groups and interleave their memory allocations
In reply to Ingo MolnarThis patch shows the power of the shared/private distinction: in the shared tasks active balancing function (sched_update_ideal_cpu_shared()) we are able to to build a per (shared) task node mask of the nodes that it and its buddies occupy at the moment.
Private tasks on the other hand are not affected and continue to do efficient node-local allocations.
There's two important special cases:
- if a group of shared tasks fits on a single node. In this case the interleaving happens on a single bit, a single node and thus turns into nice node-local allocations.
- if a large group spans the whole system: in this case the node masks will cover the whole system, and all memory gets evenly interleaved and available RAM bandwidth gets utilized. This is preferable to allocating memory assymetrically and overloading certain CPU links and running into their bandwidth limitations.
This patch, in combination with the private/shared buddies patch, optimizes the "4x JVM", "single JVM" and "2x JVM" SPECjbb workloads on a 4-node system produce almost completely perfect memory placement.
For example a 4-JVM workload on a 4-node, 32-CPU system has this performance (8 SPECjbb warehouses per JVM):
spec1.txt: throughput = 177460.44 SPECjbb2005 bops spec2.txt: throughput = 176175.08 SPECjbb2005 bops spec3.txt: throughput = 175053.91 SPECjbb2005 bops spec4.txt: throughput = 171383.52 SPECjbb2005 bops
Which is close to the hard binding performance figures.
while previously it would regress compared to mainline.
Mainline has the following 4x JVM performance:
spec1.txt: throughput = 157839.25 SPECjbb2005 bops spec2.txt: throughput = 156969.15 SPECjbb2005 bops spec3.txt: throughput = 157571.59 SPECjbb2005 bops spec4.txt: throughput = 157873.86 SPECjbb2005 bops
So the patch brings a 12% speedup.
This placement idea came while discussing interleaving strategies with Christoph Lameter.
--- kernel/sched/fair.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/sched/fair.c +4 -0
@@ -922,6 +922,10 @@ static int sched_update_ideal_cpu_shared(struct task_struct *p) buddies++; }WARN_ON_ONCE (buddies > full_buddies); +if (buddies) +node_set (node, p->numa_policy.v.nodes); +else +node_clear (node, p->numa_policy.v.nodes);/* Don't go to a node that is already at full capacity: */ if (buddies == full_buddies)
Signature · 7 lines
1.7.11.7 -- 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 40/52 sched: Add "task flipping" support
In reply to Ingo MolnarNUMA balancing will make use of the new sched_rebalance_to() mode:
the ability to 'flip' two tasks.
When two tasks have a similar weight but one of them executes on the wrong CPU or node, then it's beneficial to do a quick flipping operation. This will not change the general load of the source and the target CPUs, so it won't disturb the scheduling balance.
With this we can do NUMA placement while the system is otherwise in equilibrium.
The code has to be careful about races and whether the source and target CPUs are allowed for the tasks in question.
This method is also faster: it can execute two migrations via one migration-thread call in essence - instead of two such calls. The thread on the target CPU acts as the 'migration thread' for the replaced task.
--- include/linux/sched.h | 1 - kernel/sched/core.c | 68 +++++++++++++++++++++++++++++++++++++-------------- kernel/sched/fair.c | 2 +- kernel/sched/sched.h | 6 +++++ 4 files changed, 57 insertions(+), 20 deletions(-)
include/linux/sched.h +0 -1
@@ -2020,7 +2020,6 @@ task_sched_runtime(struct task_struct *task);/* sched_exec is called by processes performing an exec */ #ifdef CONFIG_SMP extern void sched_exec (void ); -extern void sched_rebalance_to (int dest_cpu);#else #define sched_exec () {}#endif
kernel/sched/core.c +50 -18
86 lines not on this page · raw message
kernel/sched/fair.c +1 -1
@@ -1176,7 +1176,7 @@ static void task_numa_placement(struct task_struct *p)struct rq *rq =cpu_rq (p->ideal_cpu); rq->curr_buddy = p; -sched_rebalance_to (p->ideal_cpu); +sched_rebalance_to (p->ideal_cpu,0 ); } }
kernel/sched/sched.h +6 -0
@@ -1260,3 +1260,9 @@ static inline u64 irq_time_read(int cpu) }#endif /* CONFIG_64BIT */ #endif /* CONFIG_IRQ_TIME_ACCOUNTING */ + +#ifdef CONFIG_SMP +extern void sched_rebalance_to (int dest_cpu,int flip_tasks); +#else +static inline void sched_rebalance_to (int dest_cpu,int flip_tasks) { } +#endif
Signature · 7 lines
1.7.11.7 -- 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 41/52 sched: Move the NUMA placement logic to a worklet
In reply to Ingo MolnarAs an implementational detail, to be able to do directed task placement we have to change how task_numa_fault() interfaces with the scheduler:
instead of the placement logic being executed directly from the fault path we now trigger a worklet, similarly to how we do the NUMA hinting fault work.
This moves placement into process context and allows the execution of the directed task-flipping code via sched_rebalance_to().
This further decouples the NUMA hinting fault engine from the actual NUMA placement logic.
[ Also move __sched_fork() out of preemptible context. ]
--- include/linux/sched.h | 3 +- kernel/sched/core.c | 25 ++++++++- kernel/sched/fair.c | 153 +++++++++++++++++++++++++++++++------------------- kernel/sched/sched.h | 5 ++ 4 files changed, 126 insertions(+), 60 deletions(-)
include/linux/sched.h +2 -1
@@ -1512,7 +1512,8 @@ struct task_struct {unsigned long numa_weight;unsigned long *numa_faults;unsigned long *numa_faults_curr; -struct callback_head numa_work; +struct callback_head numa_scan_work; +struct callback_head numa_placement_work;struct task_struct *shared_buddy, *shared_buddy_curr;unsigned long shared_buddy_faults, shared_buddy_faults_curr;
kernel/sched/core.c +23 -2
@@ -39,6 +39,7 @@#include <linux/kernel_stat.h> #include <linux/debug_locks.h> #include <linux/perf_event.h> +#include <linux/task_work.h> #include <linux/security.h> #include <linux/notifier.h> #include <linux/profile.h>
@@ -1558,7 +1559,6 @@ static void __sched_fork(struct task_struct *p) p->numa_migrate_seq =2 ; p->numa_faults =NULL ; p->numa_scan_period = sysctl_sched_numa_scan_delay; - p->numa_work.next = &p->numa_work; p->shared_buddy =NULL ; p->shared_buddy_faults =0 ;
@@ -1570,6 +1570,25 @@ static void __sched_fork(struct task_struct *p) p->numa_policy.v.preferred_node =0 ; p->numa_policy.v.nodes = node_online_map; +init_task_work (&p->numa_scan_work, task_numa_scan_work); + p->numa_scan_work.next = &p->numa_scan_work; + +init_task_work (&p->numa_placement_work, task_numa_placement_work); + p->numa_placement_work.next = &p->numa_placement_work; + +if (p->mm) { +int entries =2 *nr_node_ids; +int size =sizeof (*p->numa_faults) * entries; + +/* +* For efficiency reasons we allocate ->numa_faults[] +* and ->numa_faults_curr[] at once and split the +* buffer we get. They are separate otherwise. +*/ + p->numa_faults =kzalloc (2 *size,GFP_KERNEL ); +if (p->numa_faults) + p->numa_faults_curr = p->numa_faults + entries; + }#endif /* CONFIG_NUMA_BALANCING */ }
@@ -1579,9 +1598,11 @@ static void __sched_fork(struct task_struct *p)void sched_fork (struct task_struct *p) {unsigned long flags; -int cpu =get_cpu (); +int cpu;__sched_fork (p); + + cpu =get_cpu ();/* * We mark the process as running here. This guarantees that * nobody will actually run it, and a signal or other external
kernel/sched/fair.c +96 -57
208 lines not on this page · raw message
kernel/sched/sched.h +5 -0
@@ -1261,6 +1261,11 @@ static inline u64 irq_time_read(int cpu)#endif /* CONFIG_64BIT */ #endif /* CONFIG_IRQ_TIME_ACCOUNTING */ +#ifdef CONFIG_NUMA_BALANCING +extern void task_numa_scan_work (struct callback_head *work); +extern void task_numa_placement_work (struct callback_head *work); +#endif +#ifdef CONFIG_SMP extern void sched_rebalance_to (int dest_cpu,int flip_tasks);#else
Signature · 7 lines
1.7.11.7 -- 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 42/52 numa, mempolicy: Improve CONFIG_NUMA_BALANCING=y OOM behavior
In reply to Ingo MolnarZhouping Liu reported worse out-of-memory behavior with CONFIG_NUMA_BALANCING=y, compared to the mainline kernel.
One reason for that change in behavior is that with typical applications the mainline kernel allocates memory essentially randomly, and leaves it where it was.
"Random" placement is not the worst possible placement - in fact it's a pretty good placement strategy. It's definitely possible for a NUMA-aware kernel to do worse than that, and CONFIG_NUMA_BALANCING=y regressed because it's very opinionated about which node tasks should execute and on which node they should allocate memory on.
One such problematic case is when a node has already used up most of its memory - in that case it's pointless trying to allocate even more memory from there. Doing so would trigger OOMs even though the system has more memory on other nodes.
The migration code is already trying to be nice when allocating memory for NUMA purposes - extend this concept to mempolicy driven allocations as well.
Expose migrate_balanced_pgdat() and use it. If all fails try just as hard as the old code would.
Hopefully this improves behavior in memory allocation corner cases.
[ migrate_balanced_pgdat() should probably be moved to
mm/page_alloc.c and be renamed to balanced_pgdat() or so - but this patch tries to be minimalistic. ]
--- include/linux/migrate.h | 12 +++++++ kernel/sched/core.c | 2 +- mm/huge_memory.c | 9 +++++ mm/mempolicy.c | 89 ++++++++++++++++++++++++++++++++++++++++--------- mm/migrate.c | 3 +- 5 files changed, 96 insertions(+), 19 deletions(-)
include/linux/migrate.h +12 -0
@@ -41,6 +41,7 @@ extern void migrate_page_copy(struct page *newpage, struct page *page);extern int migrate_huge_page_move_mapping (struct address_space *mapping,struct page *newpage,struct page *page);# ifdef CONFIG_NUMA_BALANCING +extern bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages);extern int migrate_misplaced_page_put (struct page *page,int node); extern int migrate_misplaced_transhuge_page_put(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -48,6 +49,12 @@ extern int migrate_misplaced_transhuge_page_put(struct mm_struct *mm,unsigned long address, struct page *page, int node);# else /* !CONFIG_NUMA_BALANCING: */ + +static inline bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages) +{ +return true; +} +static inline int migrate_misplaced_page_put (struct page *page,int node) {
@@ -93,6 +100,11 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,return -ENOSYS ; } +static inline bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages) +{ +return true; +} +/* Possible settings for the migrate_page() method in address_operations */ #define migrate_page NULL#define fail_migrate_page NULL
kernel/sched/core.c +1 -1
@@ -1566,7 +1566,7 @@ static void __sched_fork(struct task_struct *p) p->ideal_cpu_curr =-1 ;atomic_set (&p->numa_policy.refcnt,1 ); p->numa_policy.mode =MPOL_INTERLEAVE ; - p->numa_policy.flags =0 ; + p->numa_policy.flags =MPOL_F_MOF ; p->numa_policy.v.preferred_node =0 ; p->numa_policy.v.nodes = node_online_map;
mm/huge_memory.c +9 -0
@@ -1078,6 +1078,15 @@ unlock: migrate:spin_unlock (&mm->page_table_lock); +/* +* If this node is getting full then don't migrate even +* more pages here: +*/ +if (!migrate_balanced_pgdat (NODE_DATA (node),HPAGE_PMD_NR )) { +put_page (page); +return 0 ; + } +lock_page (page);spin_lock (&mm->page_table_lock);if (unlikely (!pmd_same (*pmd, entry))) {
mm/mempolicy.c +73 -16
159 lines not on this page · raw message
mm/migrate.c +1 -2
@@ -1421,8 +1421,7 @@ int migrate_vmas(struct mm_struct *mm, const nodemask_t *to,* Returns true if this is a safe migration target node for misplaced NUMA * pages. Currently it only checks the watermarks which crude */ -static bool migrate_balanced_pgdat (struct pglist_data *pgdat, -int nr_migrate_pages) +bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages) {int z;for (z = pgdat->nr_zones -1 ; z >=0 ; z--) {
Signature · 7 lines
1.7.11.7 -- 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 43/52 sched: Introduce directed NUMA convergence
In reply to Ingo MolnarThis patch replaces the purely statistical NUMA convergence method with a directed one.
These balancing functions gets called when CPU loads are otherwise more or less in balance, so we check whether a NUMA task wants to migrate to another node, to improve NUMA task group clustering.
Our general goal is to converge the load in such a way that minimizes internode memory access traffic. We do this in a 'directed', non-statistical way, which drastically improves the speed of convergence.
We do this directed convergence via using the 'memory buddy' task relation which we build out of the page::last_cpu NUMA hinting page fault driven statistics, plus the following two sets of directed task migration rules.
The first set of rules 'compresses' groups by moving related tasks closer to each other.
The second set of rules 'spreads' groups, when compression creates a stable but not yet converging (optimal) layout of tasks.
1) "group spreading"
This rule checks whether the smallest group on the current node could move to another node.
This logic is implemented in the improve_group_balance_spread() function.
2) "group compression"
This logic triggers if the 'spreading' logic finds no more work to do.
First we search for the 'maximum node', i.e. the node on which we have the most buddies, but which node is not yet completely full with our buddies.
If this 'maximum node' is the current node, then we stop.
If this 'maximum node' is a different node from the current node then we check the size of the smallest buddy group on it.
If our own buddy group size on that CPU is equal or larger than the minimum buddy group size, then we can disrupt the smallest group and migrate to one of their CPUs - even if that CPU is not idle.
Special cases: idle tasks, non-NUMA tasks or NUMA-private tasks are special 1-task 'buddy groups' and are preferred over NUMA-shared tasks, in that order.
If we replace a busy task then once we migrate to the destination CPU we try to migrate that task to our original CPU. It will not be able to replace us in the next round of balancing because the flipping rule is not symmetric: our group will be larger there than theirs.
This logic is implemented in the improve_group_balance_compress() function.
An example of a valid group convergence transition:
( G1 is a buddy group of tasks T1, T2, T3 on node 1 and
T6, T7, T8 on node 2, G2 is a second buddy group on node 1 with tasks T4, T5, G3 is a third buddy group on node 2 with task T9 and T10, G4 and G5 are two one-task groups of singleton tasks T11 and T12. Both nodes are equally loaded with 6 tasks and are at full capacity.):
node 1 node 2
G1(T1, T2, T3), G2(T4, T5), G4(T11) G1(T6, T7, T8) G3(T9, T10), G5(T12)
||
\||/
\/
node 1 node 2
G1(T1, T2, T3, T6), G2(T4, T5) G1(T7, T8), G3(T9, T10), G4(T11), G5(T12)I.e. task T6 migrated from node 2 to node 1, flipping task T11. This was a valid migration that increased the size of group G1 on node 1, at the expense of (smaller) group G4.
The next valid migration step would be for T7 and T8 to migrate from node 2 to node 1 as well:
||
\||/
\/
node 1 node 2
G1(T1, T2, T3, T6, T7, T8) G2(T4, T5), G3(T9, T10), G4(T11), G5(T12)Which is fully converged, with all 5 groups running on their own node with no cross-node traffic between group member tasks.
These two migrations were valid too because group G2 is smaller than group G1, so it can be disrupted by G1.
"Resonance"
On its face, 'compression' and 'spreading' are opposing forces and are thus subject to bad resonance feedback effects: what 'compression' does could be undone by 'spreading', all the time, without it stopping.
But because 'compression' only gets called when 'spreading' can find no more work anymore, and because 'compression' creates larger groups on otherwise balanced nodes, which then cannot be torn apart by 'spreading', no permanent resonance should occur between the two.
Transients can occur, as both algorithms are lockless and can (although typically and statistically don't) run at once on parallel CPUs.
Choice of the convergence algorithms:
=====================================
I went for directed convergence instead of statistical convergence, because especially on larger systems convergence speed was getting very slow with statistical methods, only convering the most trivial, often artificial benchmark workloads.
The mathematical proof looks somewhat difficult to outline (I have not even tried to formally construct one), but the above logic will monotonically sort the system until it converges into a fully and ideally sorted state, and will do that in a finite number of steps.
In the final state each group is the largest possible and each CPU is loaded to the fullest: i.e. inter-node traffic is minimize.
This direct path of convergence is very fast (much faster than the statistical, Monte-Carlo / Brownian motion convergence) but it is not the mathematically shortest possible route to equilibrium.
By my thinking, finding the minimum-steps route would have O(NR_CPUS^3) complexity or worse, with memory allocation and complexity constraints unpractical and unacceptable for kernel space ...
[ If you thought that the lockdep dependency graph logic was complex,
then such a routine would be a true monster in comparison! ]
Especially with fast moving workloads it's also doubtful whether it's worth spending kernel resources to calculate the best path to begin with - by the time we calculate it the scheduling situation might have changed already ;-)
This routine fits into our existing load-balancing patterns and algorithm complexity pretty well: it is essentially O(NR_CPUs), it runs only rarely and tries hard to never at once run on multiple CPUs.
--- include/linux/sched.h | 1 + init/Kconfig | 1 + kernel/sched/core.c | 3 - kernel/sched/fair.c | 1185 +++++++++++++++++++++++++++++++++++++++++++---- kernel/sched/features.h | 20 +- 5 files changed, 1099 insertions(+), 111 deletions(-)
include/linux/sched.h +1 -0
@@ -1506,6 +1506,7 @@ struct task_struct {int numa_shared;int numa_max_node;int numa_scan_seq; +unsigned long numa_scan_ts_secs;int numa_migrate_seq;unsigned int numa_scan_period;u64 node_stamp;/* migration stamp */
init/Kconfig +1 -0
@@ -1090,6 +1090,7 @@ config UIDGID_STRICT_TYPE_CHECKS config SCHED_AUTOGROUP bool "Automatic process group scheduling" + depends on !NUMA_BALANCING select EVENTFD select CGROUPS select CGROUP_SCHED
kernel/sched/core.c +0 -3
@@ -4774,9 +4774,6 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) done: ret =1 ; fail: -#ifdef CONFIG_NUMA_BALANCING - rq_dest->curr_buddy =NULL ; -#endif double_rq_unlock (rq_src, rq_dest);raw_spin_unlock (&p->pi_lock);return ret;
kernel/sched/fair.c +1084 -101
1,461 lines not on this page · raw message
kernel/sched/features.h +13 -7
@@ -63,9 +63,9 @@ SCHED_FEAT(NONTASK_POWER, true)*/ SCHED_FEAT(TTWU_QUEUE, true) -SCHED_FEAT(FORCE_SD_OVERLAP, false) -SCHED_FEAT(RT_RUNTIME_SHARE, true) -SCHED_FEAT(LB_MIN, false) +SCHED_FEAT(FORCE_SD_OVERLAP, false) +SCHED_FEAT(RT_RUNTIME_SHARE, true) +SCHED_FEAT(LB_MIN, false) SCHED_FEAT(IDEAL_CPU, true) SCHED_FEAT(IDEAL_CPU_THREAD_BIAS, false)SCHED_FEAT (PUSH_PRIVATE_BUDDIES , true)
@@ -74,8 +74,14 @@ SCHED_FEAT(WAKE_ON_IDEAL_CPU, false)#ifdef CONFIG_NUMA_BALANCING /* Do the working set probing faults: */ -SCHED_FEAT(NUMA, true) -SCHED_FEAT(NUMA_FAULTS_UP, false) -SCHED_FEAT(NUMA_FAULTS_DOWN, false) -SCHED_FEAT(NUMA_SETTLE, true) +SCHED_FEAT(NUMA, true) +SCHED_FEAT(NUMA_FAULTS_UP, false) +SCHED_FEAT(NUMA_FAULTS_DOWN, false) +SCHED_FEAT(NUMA_SETTLE, false) +SCHED_FEAT(NUMA_BALANCE_ALL, false) +SCHED_FEAT(NUMA_BALANCE_INTERNODE, false) +SCHED_FEAT(NUMA_LB, false) +SCHED_FEAT(NUMA_GROUP_LB_COMPRESS, true) +SCHED_FEAT(NUMA_GROUP_LB_SPREAD, true) +SCHED_FEAT(MIGRATE_FAULT_STATS, false)#endif
Signature · 7 lines
1.7.11.7 -- 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 44/52 sched: Remove statistical NUMA scheduling
In reply to Ingo MolnarRemove leftovers of the (now inactive) statistical NUMA scheduling code.
--- include/linux/sched.h | 2 - kernel/sched/core.c | 1 - kernel/sched/fair.c | 436 +----------------------------------------------- kernel/sched/features.h | 3 - kernel/sched/sched.h | 3 - 5 files changed, 6 insertions(+), 439 deletions(-)
include/linux/sched.h +0 -2
@@ -1507,10 +1507,8 @@ struct task_struct {int numa_max_node;int numa_scan_seq;unsigned long numa_scan_ts_secs; -int numa_migrate_seq;unsigned int numa_scan_period;u64 node_stamp;/* migration stamp */ -unsigned long numa_weight;unsigned long *numa_faults;unsigned long *numa_faults_curr;struct callback_head numa_scan_work;
kernel/sched/core.c +0 -1
@@ -1556,7 +1556,6 @@ static void __sched_fork(struct task_struct *p) p->numa_shared =-1 ; p->node_stamp =0ULL ; p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq :0 ; - p->numa_migrate_seq =2 ; p->numa_faults =NULL ; p->numa_scan_period = sysctl_sched_numa_scan_delay;
kernel/sched/fair.c +6 -430
597 lines not on this page · raw message
kernel/sched/features.h +0 -3
@@ -75,9 +75,6 @@ SCHED_FEAT(WAKE_ON_IDEAL_CPU, false)#ifdef CONFIG_NUMA_BALANCING /* Do the working set probing faults: */ SCHED_FEAT(NUMA, true) -SCHED_FEAT(NUMA_FAULTS_UP, false) -SCHED_FEAT(NUMA_FAULTS_DOWN, false) -SCHED_FEAT(NUMA_SETTLE, false) SCHED_FEAT(NUMA_BALANCE_ALL, false) SCHED_FEAT(NUMA_BALANCE_INTERNODE, false)SCHED_FEAT (NUMA_LB , false)
kernel/sched/sched.h +0 -3
@@ -438,9 +438,6 @@ struct rq {struct list_head cfs_tasks;#ifdef CONFIG_NUMA_BALANCING -unsigned long numa_weight; -unsigned long nr_numa_running; -unsigned long nr_ideal_running;struct task_struct *curr_buddy;#endif unsigned long nr_shared_running;/* 0 on non-NUMA */
Signature · 7 lines
1.7.11.7 -- 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 45/52 sched: Track quality and strength of convergence
In reply to Ingo MolnarTrack strength of convergence, which is a value between 1 and 1024. This will be used by the placement logic later on.
A strength value of 1024 means that the workload has fully converged, all faults after the last scan period came from a single node.
A value of 1024/nr_nodes means a totally spread out working set.
'max_faults' is the number of faults observed on the highest-faulting node. 'sum_faults' are all faults from the last scan, averaged over ~16 periods.
The goal of the scheduler is to maximize convergence system-wide. Once a task has converged, it carries with it a non-trivial amount of working set. If such a task is migrated to another node later on then its working set will migrate there as well, which is a non-trivial cost.
So the ultimate goal of NUMA scheduling is to let as many tasks converge as possible, and to run them as close to their memory as possible.
( Note: we could also sample migration activities to directly measure
how much convergence influx there is. )
--- include/linux/sched.h | 2 ++ kernel/sched/core.c | 2 ++ kernel/sched/fair.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+)
include/linux/sched.h +2 -0
@@ -1509,6 +1509,8 @@ struct task_struct {unsigned long numa_scan_ts_secs;unsigned int numa_scan_period;u64 node_stamp;/* migration stamp */ +unsigned long convergence_strength; +int convergence_node;unsigned long *numa_faults;unsigned long *numa_faults_curr;struct callback_head numa_scan_work;
kernel/sched/core.c +2 -0
@@ -1555,6 +1555,8 @@ static void __sched_fork(struct task_struct *p) p->numa_shared =-1 ; p->node_stamp =0ULL ; + p->convergence_strength =0 ; + p->convergence_node =-1 ; p->numa_scan_seq = p->mm ? p->mm->numa_scan_seq :0 ; p->numa_faults =NULL ; p->numa_scan_period = sysctl_sched_numa_scan_delay;
kernel/sched/fair.c +46 -0
58 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 46/52 sched: Converge NUMA migrations
In reply to Ingo MolnarConsolidate the various convergence models and add a new one: when a strongly converged NUMA task migrates, prefer to migrate it in the direction of its preferred node.
--- kernel/sched/fair.c | 59 +++++++++++++++++++++++++++++++++++-------------- kernel/sched/features.h | 3 ++- 2 files changed, 44 insertions(+), 18 deletions(-)
kernel/sched/fair.c +42 -17
@@ -4750,6 +4750,35 @@ done:return target; } +static bool numa_allow_migration (struct task_struct *p,int prev_cpu,int new_cpu) +{ +#ifdef CONFIG_NUMA_BALANCING +if (sched_feat (NUMA_CONVERGE_MIGRATIONS )) { +/* Help in the direction of expected convergence: */ +if (p->convergence_node >=0 && (cpu_to_node (new_cpu) != p->convergence_node)) +return false; + +return true; + } + +if (sched_feat (NUMA_BALANCE_ALL )) { +if (task_numa_shared (p) >=0 ) +return false; + +return true; + } + +if (sched_feat (NUMA_BALANCE_INTERNODE )) { +if (task_numa_shared (p) >=0 ) { +if (cpu_to_node (prev_cpu) !=cpu_to_node (new_cpu)) +return false; + } + } +#endif +return true; +} + +/* * sched_balance_self: balance the current task (running on cpu) in domains * that have the 'flag' flag set. In practice, this is SD_BALANCE_FORK and
@@ -4766,7 +4795,8 @@ select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags) {struct sched_domain *tmp, *affine_sd =NULL , *sd =NULL ;int cpu =smp_processor_id (); -int prev_cpu =task_cpu (p); +int prev0_cpu =task_cpu (p); +int prev_cpu = prev0_cpu;int new_cpu = cpu;int want_affine =0 ;int sync = wake_flags &WF_SYNC ;
@@ -4775,10 +4805,6 @@ select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags)return prev_cpu;#ifdef CONFIG_NUMA_BALANCING -/* We do NUMA balancing elsewhere: */ -if (sched_feat (NUMA_BALANCE_ALL ) &&task_numa_shared (p) >=0 ) -return prev_cpu; -if (sched_feat (WAKE_ON_IDEAL_CPU ) && p->ideal_cpu >=0 )return p->ideal_cpu;#endif
@@ -4857,8 +4883,8 @@ select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags) unlock:rcu_read_unlock (); -if (sched_feat (NUMA_BALANCE_INTERNODE ) &&task_numa_shared (p) >=0 && (cpu_to_node (prev_cpu) !=cpu_to_node (new_cpu))) -return prev_cpu; +if (!numa_allow_migration (p, prev0_cpu, new_cpu)) +return prev0_cpu;return new_cpu; }
@@ -5401,8 +5427,11 @@ static bool can_migrate_running_task(struct task_struct *p, struct lb_env *env)static int can_migrate_task (struct task_struct *p,struct lb_env *env) {/* We do NUMA balancing elsewhere: */ -if (sched_feat (NUMA_BALANCE_ALL ) &&task_numa_shared (p) >0 && env->failed <= env->sd->cache_nice_tries) -return false; + +if (env->failed <= env->sd->cache_nice_tries) { +if (!numa_allow_migration (p, env->src_rq->cpu, env->dst_cpu)) +return false; + }if (!can_migrate_pinned_task (p, env))return false;
@@ -5461,10 +5490,7 @@ static int move_one_task(struct lb_env *env)if (!can_migrate_task (p, env))continue ; -if (sched_feat (NUMA_BALANCE_ALL ) &&task_numa_shared (p) >=0 ) -continue ; - -if (sched_feat (NUMA_BALANCE_INTERNODE ) &&task_numa_shared (p) >=0 && (cpu_to_node (env->src_rq->cpu) !=cpu_to_node (env->dst_cpu))) +if (!numa_allow_migration (p, env->src_rq->cpu, env->dst_cpu))continue ;move_task (p, env);
@@ -5527,10 +5553,7 @@ static int move_tasks(struct lb_env *env)if (!can_migrate_task (p, env)) goto next; -if (sched_feat (NUMA_BALANCE_ALL ) &&task_numa_shared (p) >=0 ) -continue ; - -if (sched_feat (NUMA_BALANCE_INTERNODE ) &&task_numa_shared (p) >=0 && (cpu_to_node (env->src_rq->cpu) !=cpu_to_node (env->dst_cpu))) +if (!numa_allow_migration (p, env->src_rq->cpu, env->dst_cpu)) goto next;move_task (p, env);
@@ -6520,8 +6543,10 @@ static int load_balance(int this_cpu, struct rq *this_rq, .iteration = 0, }; +#ifdef CONFIG_NUMA_BALANCING if (sched_feat (NUMA_BALANCE_ALL ))return 1 ; +#endif cpumask_copy (cpus, cpu_active_mask); max_lb_iterations =cpumask_weight (env.dst_grpmask);
kernel/sched/features.h +2 -1
@@ -76,9 +76,10 @@ SCHED_FEAT(WAKE_ON_IDEAL_CPU, false)/* Do the working set probing faults: */ SCHED_FEAT(NUMA, true) SCHED_FEAT(NUMA_BALANCE_ALL, false) -SCHED_FEAT(NUMA_BALANCE_INTERNODE, false) +SCHED_FEAT(NUMA_BALANCE_INTERNODE, false) SCHED_FEAT(NUMA_LB, false) SCHED_FEAT(NUMA_GROUP_LB_COMPRESS, true) SCHED_FEAT(NUMA_GROUP_LB_SPREAD, true) SCHED_FEAT(MIGRATE_FAULT_STATS, false) +SCHED_FEAT(NUMA_CONVERGE_MIGRATIONS, true)#endif
Signature · 7 lines
1.7.11.7 -- 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 47/52 sched: Add convergence strength based adaptive NUMA page fault rate
In reply to Ingo MolnarMel Gorman reported that the NUMA code is system-time intense even after a workload has converged.
To remedy this, turn sched_numa_scan_size into a range:
sched_numa_scan_size_min [default: 32 MB]
sched_numa_scan_size_max [default: 512 MB]
As workloads converge, so does their scanning activity get reduced. If they unconverge again - for example because system load changes, then their scanning will pick up again.
--- include/linux/sched.h | 3 ++- kernel/sched/fair.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- kernel/sysctl.c | 11 ++++++++-- 3 files changed, 59 insertions(+), 12 deletions(-)
include/linux/sched.h +2 -1
@@ -2057,7 +2057,8 @@ extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;extern unsigned int sysctl_sched_numa_scan_delay;extern unsigned int sysctl_sched_numa_scan_period_min;extern unsigned int sysctl_sched_numa_scan_period_max; -extern unsigned int sysctl_sched_numa_scan_size; +extern unsigned int sysctl_sched_numa_scan_size_min; +extern unsigned int sysctl_sched_numa_scan_size_max;extern unsigned int sysctl_sched_numa_settle_count;#ifdef CONFIG_SCHED_DEBUG
kernel/sched/fair.c +48 -9
88 lines not on this page · raw message
kernel/sysctl.c +9 -2
@@ -374,8 +374,15 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec, }, { - .procname = "sched_numa_scan_size_mb", - .data = &sysctl_sched_numa_scan_size, + .procname = "sched_numa_scan_size_min_mb", + .data = &sysctl_sched_numa_scan_size_min, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { + .procname = "sched_numa_scan_size_max_mb", + .data = &sysctl_sched_numa_scan_size_max, .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec,
Signature · 7 lines
1.7.11.7 -- 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 48/52 sched: Refine the 'shared tasks' memory interleaving logic
In reply to Ingo MolnarChange the adaptive memory policy code to take a majority of buddies on a node into account. Previously, since this commit:
"sched: Track shared task's node groups and interleave their memory allocations"
We'd include any node that has run a buddy in the past, which was too aggressive and spread the allocations of 'mostly converged' workloads too much, and prevented their further convergence.
Add a few other variants for testing:
NUMA_POLICY_ADAPTIVE: use memory on every node that runs a buddy of this task
NUMA_POLICY_SYSWIDE: use a simple, static, system-wide mask
NUMA_POLICY_MAXNODE: use memory on this task's 'maximum node'
NUMA_POLICY_MAXBUDDIES: use memory on the node with the most buddies
NUMA_POLICY_MANYBUDDIES: this is the default, a quorum of buddies
determines the allocation mask
The 'many buddies' quorum logic appears to work best in practice, but the 'maxnode' and 'syswide' ones are good, robust policies too.
[ Also extend the sched_feat() code from 32 to 64 features because
we are hitting that limit on 32-bit CPUs, and address a warning on !CONFIG_BUG kernels. ]
--- kernel/sched/core.c | 6 ++++-- kernel/sched/fair.c | 45 ++++++++++++++++++++++++++++++++++++++------- kernel/sched/features.h | 6 ++++++ kernel/sched/sched.h | 4 ++-- 4 files changed, 50 insertions(+), 11 deletions(-)
kernel/sched/core.c +4 -2
@@ -132,9 +132,9 @@ void update_rq_clock(struct rq *rq)*/ #define SCHED_FEAT (name, enabled) \ - (1UL << __SCHED_FEAT_##name) * enabled | + (1ULL << __SCHED_FEAT_##name) * enabled | -const_debug unsigned int sysctl_sched_features = +const_debug u64 sysctl_sched_features =#include "features.h" 0 ;
@@ -2833,6 +2833,8 @@ pick_next_task(struct rq *rq) }BUG ();/* the idle class will always have a runnable task */ + +return NULL ;/* if BUG() is a NOP then return NULL to crash the scheduler */ }/*
kernel/sched/fair.c +38 -7
79 lines not on this page · raw message
kernel/sched/features.h +6 -0
@@ -81,5 +81,11 @@ SCHED_FEAT(NUMA_LB, false) SCHED_FEAT(NUMA_GROUP_LB_COMPRESS, true) SCHED_FEAT(NUMA_GROUP_LB_SPREAD, true) SCHED_FEAT(MIGRATE_FAULT_STATS, false) +SCHED_FEAT(NUMA_POLICY_ADAPTIVE, false) +SCHED_FEAT(NUMA_POLICY_SYSWIDE, false) +SCHED_FEAT(NUMA_POLICY_MAXNODE, false) +SCHED_FEAT(NUMA_POLICY_MAXBUDDIES, false) +SCHED_FEAT(NUMA_POLICY_MANYBUDDIES, true) + SCHED_FEAT(NUMA_CONVERGE_MIGRATIONS, true)#endif
kernel/sched/sched.h +2 -2
@@ -648,7 +648,7 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)# define const_debug const#endif -extern const_debug unsigned int sysctl_sched_features; +extern const_debug u64 sysctl_sched_features;#define SCHED_FEAT (name, enabled) \ __SCHED_FEAT_##name ,
@@ -684,7 +684,7 @@ static __always_inline bool static_branch_##name(struct static_key *key) \extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];#define sched_feat (x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))#else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */ -#define sched_feat (x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x)) +#define sched_feat (x) (sysctl_sched_features & (1ULL << __SCHED_FEAT_##x))#endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */ #ifdef CONFIG_NUMA_BALANCING
Signature · 7 lines
1.7.11.7 -- 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 49/52 mm/rmap: Convert the struct anon_vma::mutex to an rwsem
In reply to Ingo MolnarConvert the struct anon_vma::mutex to an rwsem, which will help in solving a page-migration scalability problem. (Addressed in a separate patch.)
The conversion is simple and straightforward: in every case where we mutex_lock()ed we'll now down_write().
--- include/linux/rmap.h | 16 ++++++++-------- mm/huge_memory.c | 4 ++-- mm/mmap.c | 8 ++++---- mm/rmap.c | 22 +++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-)
include/linux/rmap.h +8 -8
@@ -7,7 +7,7 @@#include <linux/list.h> #include <linux/slab.h> #include <linux/mm.h> -#include <linux/mutex.h> +#include <linux/rwsem.h> #include <linux/memcontrol.h> /*
@@ -25,8 +25,8 @@* pointing to this anon_vma once its vma list is empty. */ struct anon_vma { -struct anon_vma *root;/* Root of this anon_vma tree */ -struct mutex mutex;/* Serialize access to vma list */ +struct anon_vma *root;/* Root of this anon_vma tree */ +struct rw_semaphore rwsem;/* W: modification, R: walking the list */ /* * The refcount is taken on an anon_vma when there is no * guarantee that the vma of page tables will exist for
@@ -64,7 +64,7 @@ struct anon_vma_chain {struct vm_area_struct *vma;struct anon_vma *anon_vma;struct list_head same_vma;/* locked by mmap_sem & page_table_lock */ -struct rb_node rb;/* locked by anon_vma->mutex */ +struct rb_node rb;/* locked by anon_vma->rwsem */ unsigned long rb_subtree_last;#ifdef CONFIG_DEBUG_VM_RB unsigned long cached_vma_start, cached_vma_last;
@@ -108,24 +108,24 @@ static inline void vma_lock_anon_vma(struct vm_area_struct *vma) {struct anon_vma *anon_vma = vma->anon_vma;if (anon_vma) -mutex_lock (&anon_vma->root->mutex); +down_write (&anon_vma->root->rwsem); }static inline void vma_unlock_anon_vma (struct vm_area_struct *vma) {struct anon_vma *anon_vma = vma->anon_vma;if (anon_vma) -mutex_unlock (&anon_vma->root->mutex); +up_write (&anon_vma->root->rwsem); }static inline void anon_vma_lock (struct anon_vma *anon_vma) { -mutex_lock (&anon_vma->root->mutex); +down_write (&anon_vma->root->rwsem); }static inline void anon_vma_unlock (struct anon_vma *anon_vma) { -mutex_unlock (&anon_vma->root->mutex); +up_write (&anon_vma->root->rwsem); }/*
mm/huge_memory.c +2 -2
@@ -1381,7 +1381,7 @@ static int __split_huge_page_splitting(struct page *page,* We can't temporarily set the pmd to null in order * to split it, the pmd must remain marked huge at all * times or the VM won't take the pmd_trans_huge paths -* and it won't wait on the anon_vma->root->mutex to +* and it won't wait on the anon_vma->root->rwsem to * serialize against split_huge_page*. */ pmdp_splitting_flush (vma, address, pmd);
@@ -1583,7 +1583,7 @@ static int __split_huge_page_map(struct page *page,return ret; } -/* must be called with anon_vma->root->mutex hold */ +/* must be called with anon_vma->root->rwsem held */ static void __split_huge_page (struct page *page,struct anon_vma *anon_vma) {
mm/mmap.c +4 -4
@@ -2561,15 +2561,15 @@ static void vm_lock_anon_vma(struct mm_struct *mm, struct anon_vma *anon_vma)* The LSB of head.next can't change from under us * because we hold the mm_all_locks_mutex. */ -mutex_lock_nest_lock (&anon_vma->root->mutex, &mm->mmap_sem); +down_write (&anon_vma->root->rwsem);/* * We can safely modify head.next after taking the -* anon_vma->root->mutex. If some other vma in this mm shares +* anon_vma->root->rwsem. If some other vma in this mm shares * the same anon_vma we won't take it again. * * No need of atomic instructions here, head.next * can't change from under us thanks to the -* anon_vma->root->mutex. +* anon_vma->root->rwsem. */ if (__test_and_set_bit (0 , (unsigned long *) &anon_vma->root->rb_root.rb_node))
@@ -2671,7 +2671,7 @@ static void vm_unlock_anon_vma(struct anon_vma *anon_vma)* * No need of atomic instructions here, head.next * can't change from under us until we release the -* anon_vma->root->mutex. +* anon_vma->root->rwsem. */ if (!__test_and_clear_bit (0 , (unsigned long *) &anon_vma->root->rb_root.rb_node))
mm/rmap.c +11 -11
@@ -24,7 +24,7 @@* mm->mmap_sem * page->flags PG_locked (lock_page) * mapping->i_mmap_mutex -* anon_vma->mutex +* anon_vma->rwsem * mm->page_table_lock or pte_lock * zone->lru_lock (in mark_page_accessed, isolate_lru_page) * swap_lock (in swap_duplicate, swap_info_get)
@@ -37,7 +37,7 @@* in arch-dependent flush_dcache_mmap_lock, * within bdi.wb->list_lock in __sync_single_inode) * -* anon_vma->mutex,mapping->i_mutex (memory_failure, collect_procs_anon) +* anon_vma->rwsem,mapping->i_mutex (memory_failure, collect_procs_anon) * ->tasklist_lock * pte map lock */
@@ -103,7 +103,7 @@ static inline void anon_vma_free(struct anon_vma *anon_vma)* LOCK should suffice since the actual taking of the lock must * happen _before_ what follows. */ -if (mutex_is_locked (&anon_vma->root->mutex)) { +if (rwsem_is_locked (&anon_vma->root->rwsem)) {anon_vma_lock (anon_vma);anon_vma_unlock (anon_vma); }
@@ -219,9 +219,9 @@ static inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, structstruct anon_vma *new_root = anon_vma->root;if (new_root != root) {if (WARN_ON_ONCE (root)) -mutex_unlock (&root->mutex); +up_write (&root->rwsem); root = new_root; -mutex_lock (&root->mutex); +down_write (&root->rwsem); }return root; }
@@ -229,7 +229,7 @@ static inline struct anon_vma *lock_anon_vma_root(struct anon_vma *root, structstatic inline void unlock_anon_vma_root (struct anon_vma *root) {if (root) -mutex_unlock (&root->mutex); +up_write (&root->rwsem); }/*
@@ -349,7 +349,7 @@ void unlink_anon_vmas(struct vm_area_struct *vma)/* * Iterate the list once more, it now only contains empty and unlinked * anon_vmas, destroy them. Could not do before due to __put_anon_vma() -* needing to acquire the anon_vma->root->mutex. +* needing to write-acquire the anon_vma->root->rwsem. */ list_for_each_entry_safe (avc, next, &vma->anon_vma_chain, same_vma) {struct anon_vma *anon_vma = avc->anon_vma;
@@ -365,7 +365,7 @@ static void anon_vma_ctor(void *data) {struct anon_vma *anon_vma = data; -mutex_init (&anon_vma->mutex); +init_rwsem (&anon_vma->rwsem);atomic_set (&anon_vma->refcount,0 ); anon_vma->rb_root =RB_ROOT ; }
@@ -457,14 +457,14 @@ struct anon_vma *page_lock_anon_vma(struct page *page) anon_vma = (struct anon_vma *) (anon_mapping -PAGE_MAPPING_ANON ); root_anon_vma =ACCESS_ONCE (anon_vma->root); -if (mutex_trylock (&root_anon_vma->mutex)) { +if (down_write_trylock (&root_anon_vma->rwsem)) {/* * If the page is still mapped, then this anon_vma is still * its anon_vma, and holding the mutex ensures that it will * not go away, see anon_vma_free(). */ if (!page_mapped (page)) { -mutex_unlock (&root_anon_vma->mutex); +up_write (&root_anon_vma->rwsem); anon_vma =NULL ; } goto out;
@@ -1299,7 +1299,7 @@ out_mlock:/* * We need mmap_sem locking, Otherwise VM_LOCKED check makes * unstable result and race. Plus, We can't wait here because -* we now hold anon_vma->mutex or mapping->i_mmap_mutex. +* we now hold anon_vma->rwsem or mapping->i_mmap_mutex. * if trylock failed, the page remain in evictable lru and later * vmscan could retry to move the page to unevictable lru if the * page is actually mlocked.
Signature · 7 lines
1.7.11.7 -- 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 50/52 mm/rmap, migration: Make rmap_walk_anon() and try_to_unmap_anon() more scalable
In reply to Ingo Molnarrmap_walk_anon() and try_to_unmap_anon() appears to be too careful about locking the anon vma: while it needs protection against anon vma list modifications, it does not need exclusive access to the list itself.
Transforming this exclusive lock to a read-locked rwsem removes a global lock from the hot path of page-migration intense threaded workloads which can cause pathological performance like this:
96.43% process 0 [kernel.kallsyms] [k] perf_trace_sched_switch
|
--- perf_trace_sched_switch
__schedule
schedule
schedule_preempt_disabled
__mutex_lock_common.isra.6
__mutex_lock_slowpath
mutex_lock
|
|--50.61%-- rmap_walk
| move_to_new_page
| migrate_pages
| migrate_misplaced_page
| __do_numa_page.isra.69
| handle_pte_fault
| handle_mm_fault
| __do_page_fault
| do_page_fault
| page_fault
| __memset_sse2
| |
| --100.00%-- worker_thread
| |
| --100.00%-- start_thread
|
--49.39%-- page_lock_anon_vma
try_to_unmap_anon
try_to_unmap
migrate_pages
migrate_misplaced_page
__do_numa_page.isra.69
handle_pte_fault
handle_mm_fault
__do_page_fault
do_page_fault
page_fault
__memset_sse2
|
--100.00%-- worker_thread
start_threadWith this change applied the profile is now nicely flat and there's no anon-vma related scheduling/blocking.
Rename anon_vma_[un]lock() => anon_vma_[un]lock_write(), to make it clearer that it's an exclusive write-lock in that case - suggested by Rik van Riel.
--- include/linux/huge_mm.h | 2 +- include/linux/rmap.h | 17 ++++++++++++++--- mm/huge_memory.c | 6 +++--- mm/ksm.c | 6 +++--- mm/memory-failure.c | 4 ++-- mm/migrate.c | 2 +- mm/mmap.c | 2 +- mm/mremap.c | 2 +- mm/rmap.c | 48 ++++++++++++++++++++++++------------------------ 9 files changed, 50 insertions(+), 39 deletions(-)
include/linux/huge_mm.h +1 -1
@@ -102,7 +102,7 @@ extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd);#define wait_split_huge_page (__anon_vma, __pmd) \ do { \ pmd_t *____pmd = (__pmd); \ - anon_vma_lock(__anon_vma); \ + anon_vma_lock_write(__anon_vma); \ anon_vma_unlock(__anon_vma); \ BUG_ON(pmd_trans_splitting(*____pmd) || \ pmd_trans_huge(*____pmd)); \
include/linux/rmap.h +14 -3
@@ -118,7 +118,7 @@ static inline void vma_unlock_anon_vma(struct vm_area_struct *vma)up_write (&anon_vma->root->rwsem); } -static inline void anon_vma_lock (struct anon_vma *anon_vma) +static inline void anon_vma_lock_write (struct anon_vma *anon_vma) {down_write (&anon_vma->root->rwsem); }
@@ -128,6 +128,17 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)up_write (&anon_vma->root->rwsem); } +static inline void anon_vma_lock_read (struct anon_vma *anon_vma) +{ +down_read (&anon_vma->root->rwsem); +} + +static inline void anon_vma_unlock_read (struct anon_vma *anon_vma) +{ +up_read (&anon_vma->root->rwsem); +} + +/* * anon_vma helper functions. */
@@ -220,8 +231,8 @@ int try_to_munlock(struct page *);/* * Called by memory-failure.c to kill processes. */ -struct anon_vma *page_lock_anon_vma (struct page *page); -void page_unlock_anon_vma (struct anon_vma *anon_vma); +struct anon_vma *page_lock_anon_vma_read (struct page *page); +void page_unlock_anon_vma_read (struct anon_vma *anon_vma);int page_mapped_in_vma (struct page *page,struct vm_area_struct *vma);/*
mm/huge_memory.c +3 -3
@@ -1637,7 +1637,7 @@ int split_huge_page(struct page *page)int ret =1 ;BUG_ON (!PageAnon (page)); - anon_vma =page_lock_anon_vma (page); + anon_vma =page_lock_anon_vma_read (page);if (!anon_vma) goto out; ret =0 ;
@@ -1650,7 +1650,7 @@ int split_huge_page(struct page *page)BUG_ON (PageCompound (page)); out_unlock: -page_unlock_anon_vma (anon_vma); +page_unlock_anon_vma_read (anon_vma); out:return ret; }
@@ -2162,7 +2162,7 @@ static void collapse_huge_page(struct mm_struct *mm,if (!pmd_present (*pmd) ||pmd_trans_huge (*pmd)) goto out; -anon_vma_lock (vma->anon_vma); +anon_vma_lock_write (vma->anon_vma); pte =pte_offset_map (pmd, address); ptl =pte_lockptr (mm, pmd);
mm/ksm.c +3 -3
@@ -1634,7 +1634,7 @@ again:struct anon_vma_chain *vmac;struct vm_area_struct *vma; -anon_vma_lock (anon_vma); +anon_vma_lock_write (anon_vma);anon_vma_interval_tree_foreach (vmac, &anon_vma->rb_root, 0, ULONG_MAX) { vma = vmac->vma;
@@ -1688,7 +1688,7 @@ again:struct anon_vma_chain *vmac;struct vm_area_struct *vma; -anon_vma_lock (anon_vma); +anon_vma_lock_write (anon_vma);anon_vma_interval_tree_foreach (vmac, &anon_vma->rb_root, 0, ULONG_MAX) { vma = vmac->vma;
@@ -1741,7 +1741,7 @@ again:struct anon_vma_chain *vmac;struct vm_area_struct *vma; -anon_vma_lock (anon_vma); +anon_vma_lock_write (anon_vma);anon_vma_interval_tree_foreach (vmac, &anon_vma->rb_root, 0, ULONG_MAX) { vma = vmac->vma;
mm/memory-failure.c +2 -2
@@ -402,7 +402,7 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill,struct anon_vma *av;pgoff_t pgoff; - av =page_lock_anon_vma (page); + av =page_lock_anon_vma_read (page);if (av ==NULL )/* Not actually mapped anymore */ return ;
@@ -423,7 +423,7 @@ static void collect_procs_anon(struct page *page, struct list_head *to_kill, } }read_unlock (&tasklist_lock); -page_unlock_anon_vma (av); +page_unlock_anon_vma_read (av); }/*
mm/migrate.c +1 -1
@@ -754,7 +754,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,*/ if (PageAnon (page)) {/* -* Only page_lock_anon_vma() understands the subtleties of +* Only page_lock_anon_vma_read() understands the subtleties of * getting a hold on an anon_vma from outside one of its mms. */ anon_vma =page_get_anon_vma (page);
mm/mmap.c +1 -1
@@ -602,7 +602,7 @@ again: remove_next = 1 + (end > next->vm_end);if (anon_vma) {VM_BUG_ON (adjust_next && next->anon_vma && anon_vma != next->anon_vma); -anon_vma_lock (anon_vma); +anon_vma_lock_write (anon_vma);anon_vma_interval_tree_pre_update_vma (vma);if (adjust_next)anon_vma_interval_tree_pre_update_vma (next);
mm/mremap.c +1 -1
@@ -104,7 +104,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, }if (vma->anon_vma) { anon_vma = vma->anon_vma; -anon_vma_lock (anon_vma); +anon_vma_lock_write (anon_vma); } }
mm/rmap.c +24 -24
163 lines not on this page · raw message
Signature · 7 lines
1.7.11.7 -- 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 51/52 sched: Exclude pinned tasks from the NUMA-balancing logic
In reply to Ingo MolnarDon't try to NUMA-balance hard-bound tasks in vein. This also makes it easier to compare hard-bound workloads against NUMA-balanced workloads, because the NUMA code will be completely inactive for those hard-bound tasks.
( Keep a debugging feature flag around: for development it
makes sense to observe what NUMA balancing tries to do with hard-affine tasks. )
[ Note: the duplicated test condition will be consolidated
in the next patch. ]
--- kernel/sched/core.c | 6 ++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 7 +++++++ kernel/sched/features.h | 1 + 4 files changed, 15 insertions(+)
kernel/sched/core.c +6 -0
@@ -4664,6 +4664,12 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)cpumask_copy (&p->cpus_allowed, new_mask); p->nr_cpus_allowed =cpumask_weight (new_mask); + +#ifdef CONFIG_NUMA_BALANCING +/* Don't disturb hard-bound tasks: */ +if (sched_feat (NUMA_EXCLUDE_AFFINE ) && (p->nr_cpus_allowed !=num_online_cpus ())) + p->numa_shared =-1 ; +#endif }/*
kernel/sched/debug.c +1 -0
@@ -448,6 +448,7 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m) nr_switches = p->nvcsw + p->nivcsw; +P (nr_cpus_allowed);#ifdef CONFIG_SCHEDSTATS PN (se.statistics.wait_start);PN (se.statistics.sleep_start);
kernel/sched/fair.c +7 -0
@@ -2495,6 +2495,13 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)if (!curr->mm || (curr->flags &PF_EXITING ) || !curr->numa_faults)return ; +/* Don't disturb hard-bound tasks: */ +if (sched_feat (NUMA_EXCLUDE_AFFINE ) && (curr->nr_cpus_allowed !=num_online_cpus ())) { +if (curr->numa_shared >=0 ) + curr->numa_shared =-1 ; +return ; + } +task_tick_numa_scan (rq, curr);task_tick_numa_placement (rq, curr); }
kernel/sched/features.h +1 -0
@@ -77,6 +77,7 @@ SCHED_FEAT(WAKE_ON_IDEAL_CPU, false) SCHED_FEAT(NUMA, true) SCHED_FEAT(NUMA_BALANCE_ALL, false) SCHED_FEAT(NUMA_BALANCE_INTERNODE, false) +SCHED_FEAT(NUMA_EXCLUDE_AFFINE, true) SCHED_FEAT(NUMA_LB, false) SCHED_FEAT(NUMA_GROUP_LB_COMPRESS, true)SCHED_FEAT (NUMA_GROUP_LB_SPREAD , true)
Signature · 7 lines
1.7.11.7 -- 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 52/52 sched: Add RSS filter to NUMA-balancing
In reply to Ingo MolnarNUMA-balancing, combined with NUMA-affine memory migration, is a relatively long-term process (compared to the typical time scale of scheduling) that takes time to establish and converge - on the time scale of of several seconds or more.
Small, short-lived and don't have much of a NUMA placement cost to begin with, so don't NUMA-balance them. A task needs to execute long enough and needs to establish a large enough user-space memory image to benefit from more intelligent NUMA balancing.
We already have a CPU time limit before tasks are affected by NUMA balancing - this change adds the memory equivalent:
by introducing an RSS limit of 128 MBs.
In practice this excludes most short-lived tasks - the limit is in fact probably a bit on the conservative side - but with intrusive kernel features conservative is good.
The /proc/sys/kernel/sched_numa_rss_threshold_mb value can be tuned runtime - setting it to 0 turns off this filter.
To implement the RSS filter first factor out a clean task_numa_candidate() function and comment on the various reasons of why we wouldn't want to begin to NUMA-balance a particular task (yet). Then add the RSS check.
Note, we are using the p->hiwater_rss value instead of the current RSS size. We do this to avoid tasks flipping in and out of the limit, if their RSS fluctuates around the limit. The RSS high-water value increases monotonically in the life-time of a task, so there's a single, precise transition to NUMA-balancing as the limit is crossed.
--- include/linux/sched.h | 1 + kernel/sched/fair.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ kernel/sysctl.c | 7 +++++++ 3 files changed, 52 insertions(+), 6 deletions(-)
include/linux/sched.h +1 -0
@@ -2059,6 +2059,7 @@ extern unsigned int sysctl_sched_numa_scan_period_min;extern unsigned int sysctl_sched_numa_scan_period_max;extern unsigned int sysctl_sched_numa_scan_size_min;extern unsigned int sysctl_sched_numa_scan_size_max; +extern unsigned int sysctl_sched_numa_rss_threshold;extern unsigned int sysctl_sched_numa_settle_count;#ifdef CONFIG_SCHED_DEBUG
kernel/sched/fair.c +44 -6
67 lines not on this page · raw message
kernel/sysctl.c +7 -0
@@ -388,6 +388,13 @@ static struct ctl_table kern_table[] = { .proc_handler = proc_dointvec, }, { + .procname = "sched_numa_rss_threshold_mb", + .data = &sysctl_sched_numa_rss_threshold, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { .procname = "sched_numa_settle_count", .data = &sysctl_sched_numa_settle_count, .maxlen = sizeof(unsigned int),
Signature · 7 lines
1.7.11.7 -- 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>
The unified NUMA Git tree can be found in the -tip numa/base branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git numa/base
The PROT_NONE -v18 numa/core tree can be found in tip:master:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master
Thanks,
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>
[GIT] Unified NUMA balancing tree, v2
I've pushed out a new update into:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git numa/base
which eliminates a few integration kinks/bugs in -v1:
- I unified the THP migration code
- there's also an MPOL_BIND bugfix.
- added the fixed hiwater_rss patch.
Thanks,
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
reviewerRe: [PATCH 18/52] mm/numa: Migrate on reference policy
In reply to Ingo MolnarQuoted 7 lines · Ingo Molnar
From: Mel Gorman <[email protected]>
This is the simplest possible policy that still does something of note. When a
pte_numais faulted, it is moved immediately. Any replacement policy must at least do better than this and in all likelihood this policy regresses normal workloads.
Quoted 13 lines
Signed-off-by Mel Gorman <[email protected]>Acked-by Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Hugh Dickins <[email protected]>Cc Paul Turner <[email protected]>Cc Lee Schermerhorn <[email protected]>Cc Alex Shi <[email protected]>Cc Srikar Dronamraju <[email protected]>Cc Aneesh Kumar <[email protected]>Cc Linus Torvalds <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Andrea Arcangeli <[email protected]>Signed-off-by Ingo Molnar <[email protected]>
It is worth noting that at this point in your combined tree that this policy and patch does not and cannot do anything. It has none of the faulting machinery, pte scanning, two-stage filter etc that are necessary for it to work. So for example, you can not take this point of your tree, compare it with balancenuma and get a meaningful comparison.
So while superfically this patch looks like a useful bisection point, it isn't. A plain rebase on top of balancenuma would have given us a comparison between "do nothing", "do the bare minimum to be useful (balancenuma)" and "do something complex (numacore)" even *if* you decided to revert parts of balancenuma during your rebase. For example, you might have decided to force the removal of migrate rate-limiting even though I stand by it being a valid decision to mitigate worst-case behaviour. The key is that it would have been possible to bisect parts of numacore to help identify the source of any regressions.
This restructure is an all or nothing approach. It does not look like it's possible to do a comparison between "do nothing", "do the bare minimum (balancenuma)" and "do something complex (numacore)". It would also be impossible to do any sort of rebase of autonuma policies on top as was the case with balancenuma.
FWIW, I pulled tip again this morning and rebased tip/numa/base to 3.7-rc7 and queued the result. I had pulled tip/master but it didn't boot.
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>
Quoted 6 lines · Ingo Molnar
Most of the outstanding objections against numa/core centered around Mel and Rik objecting to the
PROT_NONEapproach Peter implemented in numa/core. To settle that question objectively I've performed performance testing of those differences, by picking up the minimum number of essentials needed to be able to remove thePROT_NONEapproach and use thePTE_NUMAapproach Mel took from the AutoNUMA tree and elsewhere.
For the record, I have no objection to either of
the pte marking approaches.
Quoted 2 lines
Rik van Riel (1):
sched, numa, mm: Add credits for NUMA placement
Where did the TLB flush optimizations go? :)
--
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 · Rik van Riel
Quoted 2 lines
Rik van Riel (1):
sched, numa, mm: Add credits for NUMA placementWhere did the TLB flush optimizations go? :)
They are still very much there, unchanged for a long time and acked by everyone - I thought I'd spare a few electrons by not doing a 60+ patches full resend.
Here is how it looks like in the full diffstat:
Rik van Riel (6):
mm/generic: Only flush the local TLB in ptep_set_access_flags() x86/mm: Only do a local tlb flush in ptep_set_access_flags() x86/mm: Introduce pte_accessible()
mm: Only flush the TLB when clearing an accessible pte x86/mm: Completely drop the TLB flush from ptep_set_access_flags() sched, numa, mm: Add credits for NUMA placement
I'm really fond of these btw., they make a real difference.
Thanks,
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>
Re: [PATCH 29/52] sched: Implement NUMA scanning backoff
In reply to Ingo MolnarQuoted 10 lines · Ingo Molnar
Back off slowly from scanning, up to
sysctl_sched_numa_scan_period_max(1.6 seconds). Scan faster again if we were forced to switch to another node.kernel/sched/fair.c +0
-0@@ -865,8 +865,10 @@ static void task_numa_placement(struct task_struct *p) }
kernel/sched/fair.c static void task_numa_placement(struct task_struct *p) · line 874
Quoted 10 lines
kernel/sched/fair.c +3
-1} -if (max_node != p->numa_max_node) +if (max_node != p->numa_max_node) {sched_setnuma (p, max_node,task_numa_shared (p)); + goto out_backoff; + } p->numa_migrate_seq++; if (sched_feat(NUMA_SETTLE) &&
Is that correct?
It looks like the code only jumps to the out_backoff label after resetting p->numa_scan_period to sysctl_sched_numa_scan_period_min in sched_setnuma?
Should it not be the other way around, slowly increasing the process's numa_scan_period when we do NOT do a sched_setnuma call for the process at all?
kernel/sched/fair.c static void task_numa_placement(struct task_struct *p) · line 889
Quoted 7 lines
kernel/sched/fair.c +2
-0@@ -882,7 +884,11 @@ static void task_numa_placement(struct task_struct *p)if (shared !=task_numa_shared (p)) {sched_setnuma (p, p->numa_max_node, shared); p->numa_migrate_seq =0 ; + goto out_backoff; } +return ;
We can never reach the backoff code, except by an explicit goto, which is only there after a call to sched_setnuma.
That is the opposite from what the changelog suggests...
kernel/sched/fair.c static void task_numa_placement(struct task_struct *p) · line 894
Quoted 6 lines
kernel/sched/fair.c +2
-0+out_backoff: + p->numa_scan_period =min (p->numa_scan_period *2 , sysctl_sched_numa_scan_period_max); }/*
--
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 32/52] sched: Track groups of shared tasks
In reply to Ingo MolnarQuoted 2 lines · Ingo Molnar
This is not entirely correct as this task might have scheduled or migrate ther - but statistically there will be correlation to the
^^^^ there?
Quoted 4 lines
tasks that we share memory with, and correlation is all we need.
We map out the relation itself by filtering out the highest address ask that is below our own task address, per working set scan
^^^ task?
Quoted 4 lines
iteration.
kernel/sched/fair.c +0
-0@@ -906,23 +945,122 @@ out_backoff: }
kernel/sched/fair.c out_backoff: · line 955
Quoted 10 lines
kernel/sched/fair.c +8
-0/* +* Track our "memory buddies" the tasks we actively share memory with. +* +* Firstly we establish the identity of some other task that we are +* sharing memory with by looking at rq[page::last_cpu].curr - i.e. +* we check the task that is running on that CPU right now. +* +* This is not entirely correct as this task might have scheduled or +* migrate ther - but statistically there will be correlation to the
^^^^ there
kernel/sched/fair.c out_backoff: · line 959
Quoted 4 lines
kernel/sched/fair.c +4
-0+* tasks that we share memory with, and correlation is all we need. +* +* We map out the relation itself by filtering out the highest address +* ask that is below our own task address, per working set scan
^^^ task?
If that word is "task", the comment makes sense. If it is something else, I'm back to square one on what the code does :)
kernel/sched/fair.c out_backoff: · line 1050
Quoted 13 lines
kernel/sched/fair.c +4
-2void task_numa_fault (int node,int last_cpu,int pages) {struct task_struct *p = current;int priv = (task_cpu (p) == last_cpu); +int idx =2 *node + priv;if (unlikely (!p->numa_faults)) { -int size =sizeof (*p->numa_faults) *2 * nr_node_ids; +int entries =2 *nr_node_ids; +int size =sizeof (*p->numa_faults) * entries; - p->numa_faults =kzalloc (size,GFP_KERNEL ); + p->numa_faults =kzalloc (2 *size,GFP_KERNEL );
So we multiply nr_node_ids by 2. Twice.
That kind of magic deserves a comment explaining how and why. How about:
/*
* We track two arrays with private and shared faults
* for each NUMA node. The p->numa_faults_curr array
* is allocated at the same time as the p->numa_faults
* array.
*/
int size = sizeof(*p->numa_faults) * 4 * nr_node_ids;
kernel/sched/fair.c out_backoff: · line 1059
Quoted 9 lines
kernel/sched/fair.c +6
-0if (!p->numa_faults)return ; +/* +* For efficiency reasons we allocate ->numa_faults[] +* and ->numa_faults_curr[] at once and split the +* buffer we get. They are separate otherwise. +*/ + p->numa_faults_curr = p->numa_faults + entries; }
--
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 49/52] mm/rmap: Convert the struct anon_vma::mutex to an rwsem
In reply to Ingo MolnarQuoted 6 lines · Ingo Molnar
Convert the struct
anon_vma::mutexto an rwsem, which will help in solving a page-migration scalability problem. (Addressed in a separate patch.)The conversion is simple and straightforward: in every case where we mutex_lock()ed we'll now
down_write().
Looks good.
Signature · 8 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. -- 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 20/52] mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages
In reply to Ingo MolnarCommit "mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages" breaks the build because HPAGE_PMD_SHIFT and HPAGE_PMD_MASK defined to explode without CONFIG_TRANSPARENT_HUGEPAGE:
mm/migrate.c: In function 'migrate_misplaced_transhuge_page_put':mm/migrate.c:1549: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed mm/migrate.c:1564: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed mm/migrate.c:1566: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed mm/migrate.c:1573: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed mm/migrate.c:1606: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed mm/migrate.c:1648: error: call to '__build_bug_failed' declared with attribute error: BUILD_BUG failed
CONFIG_NUMA_BALANCING allows compilation without enabling transparent hugepages, so define the dummy function for such a configuration and only define migrate_misplaced_transhuge_page_put() when transparent hugepages are enabled.
--- include/linux/migrate.h | 18 +++++++++++------- mm/migrate.c | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-)
include/linux/migrate.h +11 -7
@@ -78,12 +78,6 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,#ifdef CONFIG_NUMA_BALANCING extern bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages);extern int migrate_misplaced_page_put (struct page *page,int node); -extern int migrate_misplaced_transhuge_page_put (struct mm_struct *mm, -struct vm_area_struct *vma, -pmd_t *pmd,pmd_t entry, -unsigned long address, -struct page *page,int node); -#else static inline bool migrate_balanced_pgdat (struct pglist_data *pgdat,int nr_migrate_pages) {
@@ -93,6 +87,16 @@ static inline int migrate_misplaced_page_put(struct page *page, int node) {return -EAGAIN ;/* can't migrate now */ } +#endif /* CONFIG_NUMA_BALANCING */ + +#if defined(CONFIG_NUMA_BALANCING ) && defined(CONFIG_TRANSPARENT_HUGEPAGE ) +extern int migrate_misplaced_transhuge_page_put (struct mm_struct *mm, +struct vm_area_struct *vma, +pmd_t *pmd,pmd_t entry, +unsigned long address, +struct page *page,int node); + +#else static inline int migrate_misplaced_transhuge_page_put(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmd, pmd_t entry,
@@ -101,6 +105,6 @@ static inline int migrate_misplaced_transhuge_page_put(struct mm_struct *mm, {return -EAGAIN ; } -#endif /* CONFIG_NUMA_BALANCING */ +#endif /* CONFIG_NUMA_BALANCING && CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_MIGRATE_H */
mm/migrate.c +3 -0
@@ -1540,6 +1540,7 @@ out:return isolated; } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE int migrate_misplaced_transhuge_page_put(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmd, pmd_t entry,
@@ -1653,6 +1654,8 @@ out_dropref: out_keep_locked:return 0 ; } +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +#endif /* CONFIG_NUMA_BALANCING */ #endif /* CONFIG_NUMA */
--
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 20/52] mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages
Quoted 12 lines · David Rientjes
Commit "mm, numa: Implement migrate-on-fault lazy NUMA strategy for regular and THP pages" breaks the build because
HPAGE_PMD_SHIFTandHPAGE_PMD_MASKdefined to explode withoutCONFIG_TRANSPARENT_HUGEPAGE:
mm/migrate.c: In function 'migrate_misplaced_transhuge_page_put':mm/migrate.c:1549: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailedmm/migrate.c:1564: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailedmm/migrate.c:1566: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailedmm/migrate.c:1573: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailedmm/migrate.c:1606: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailedmm/migrate.c:1648: error: call to '__build_bug_failed' declared with attribute error:BUILD_BUGfailed
Quoted 6 lines
CONFIG_NUMA_BALANCINGallows compilation without enabling transparent hugepages, so define the dummy function for such a configuration and only definemigrate_misplaced_transhuge_page_put()when transparent hugepages are enabled.Signed-off-by David Rientjes <[email protected]>
Thanks David. I pushed the equivalent for the balancenuma tree and should be included in the balancenuma-v10 tag or mm-balancenuma-v10r3 branch atgit://git.kernel.org/pub/scm/linux/kernel/git/mel/linux-balancenuma.git
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>