Another Approach to Use PMEM as NUMA Node
Subsystems (14)
cover Another Approach to Use PMEM as NUMA Node
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
3. Compatible with current NUMA policy semantics.
4. Don't assume hardware topology. But, the patchset still assumes two tier heterogeneous memory system. I understood generalizing multi tier heterogeneous memory had been discussed before. I do agree that is preferred eventually. However, currently kernel doesn't have such capability yet. When HMAT is fully ready we definitely could extract NUMA topology from it.
5. Control memory allocation and hot/cold pages promotion/demotion on per VMA basis.
To achieve the above principles, the design can be summarized by the following points:
1. Per node global fallback zonelists (include both DRAM and PMEM), use def_alloc_nodemask to exclude non-DRAM nodes from default allocation unless they are specified by mempolicy. Currently kernel just can distinguish volatile and non-volatile memory. So, just build the nodemask by SRAT flag. In the future it may be better to build the nodemask with more exposed hardware information, i.e. HMAT attributes so that it could be extended to multi tier memory system easily.
2. Introduce a new mempolicy, called MPOL_HYBRID to keep other mempolicy semantics intact. We would like to have memory placement control on per process or even per VMA granularity. So, mempolicy sounds more reasonable than madvise. The new mempolicy is mainly used for launching processes on PMEM nodes then migrate hot pages to DRAM nodes via NUMA balancing. MPOL_BIND could bind to PMEM nodes too, but migrating to DRAM nodes would just break the semantic of it. MPOL_PREFERRED can't constraint the allocation to PMEM nodes. So, it sounds a new mempolicy is needed to fulfill the usecase.
3. The new mempolicy would promote pages to DRAM via NUMA balancing. IMHO, I don't think kernel is a good place to implement sophisticated hot/cold page distinguish algorithm due to the complexity and overhead. But, kernel should have such capability. NUMA balancing sounds like a good start point.
4. Promote twice faulted page. Use PG_promote to track if a page is faulted twice. This is an optimization to NUMA balancing to reduce the migration thrashing and overhead for migrating from PMEM.
5. When DRAM has memory pressure, demote page to PMEM via page reclaim path. This is quite similar to other proposals. Then NUMA balancing will promote page to DRAM as long as the page is referenced again. But, the promotion/demotion still assumes two tier main memory. And, the demotion may break mempolicy.
6. Anonymous page only for the time being since NUMA balancing can't promote unmapped page cache.
The patchset still misses a some pieces and is pre-mature, but I would like to post to LKML to gather more feedback and comments and have more eyes on it to make sure I'm on the right track.
Any comment is welcome.
TODO:
1. Promote page cache. There are a couple of ways to handle this in kernel, i.e. promote via active LRU in reclaim path on PMEM node, or promote in mark_page_accessed().
2. Promote/demote HugeTLB. Now HugeTLB is not on LRU and NUMA balancing just skips it.
3. May place kernel pages (i.e. page table, slabs, etc) on DRAM only.
4. Support the new mempolicy in userspace tools, i.e. numactl.
[1]: https://lore.kernel.org/linux-mm/[email protected]/
[2]: https://lore.kernel.org/linux-mm/[email protected]/
Yang Shi (10):
mm: control memory placement by nodemask for two tier main memory
mm: mempolicy: introduce MPOL_HYBRID policy
mm: mempolicy: promote page to DRAM for MPOL_HYBRID
mm: numa: promote pages to DRAM when it is accessed twice
mm: page_alloc: make find_next_best_node could skip DRAM node
mm: vmscan: demote anon DRAM pages to PMEM node
mm: vmscan: add page demotion counter
mm: numa: add page promotion counter
doc: add description for MPOL_HYBRID mode
doc: elaborate the PMEM allocation rule
Documentation/admin-guide/mm/numa_memory_policy.rst | 10 ++++ Documentation/vm/numa.rst | 7 ++- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 +++ include/linux/migrate.h | 1 + include/linux/mmzone.h | 3 ++ include/linux/page-flags.h | 4 ++ include/linux/vm_event_item.h | 3 ++ include/linux/vmstat.h | 1 + include/trace/events/migrate.h | 3 +- include/trace/events/mmflags.h | 3 +- include/uapi/linux/mempolicy.h | 1 + mm/debug.c | 1 + mm/huge_memory.c | 14 ++++++ mm/internal.h | 33 ++++++++++++ mm/memory.c | 12 +++++ mm/mempolicy.c | 74 ++++++++++++++++++++++++--- mm/page_alloc.c | 33 +++++++++--- mm/vmscan.c | 113 +++++++++++++++++++++++++++++++++++------- mm/vmstat.c | 3 ++ 20 files changed, 295 insertions(+), 33 deletions(-)
PATCH 1/10 mm: control memory placement by nodemask for two tier main memory
When running applications on the machine with NVDIMM as NUMA node, the memory allocation may end up on NVDIMM node. This may result in silent performance degradation and regression due to the difference of hardware property.
DRAM first should be obeyed to prevent from surprising regression. Any non-DRAM nodes should be excluded from default allocation. Use nodemask to control the memory placement. Introduce def_alloc_nodemask which has DRAM nodes set only. Any non-DRAM allocation should be specified by NUMA policy explicitly.
In the future we may be able to extract the memory charasteristics from HMAT or other source to build up the default allocation nodemask. However, just distinguish DRAM and PMEM (non-DRAM) nodes by SRAT flag for the time being.
--- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 ++++++++ include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)
arch/x86/mm/numa.c +1 -0
@@ -626,6 +626,7 @@ static int __init numa_init(int (*init_func)(void))nodes_clear (numa_nodes_parsed);nodes_clear (node_possible_map);nodes_clear (node_online_map); +nodes_clear (def_alloc_nodemask);memset (&numa_meminfo,0 ,sizeof (numa_meminfo));WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory,MAX_NUMNODES ));
drivers/acpi/numa.c +8 -0
@@ -296,6 +296,14 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) goto out_err_bad_srat; } +/* +* Non volatile memory is excluded from zonelist by default. +* Only regular DRAM nodes are set in default allocation node +* mask. +*/ +if (!(ma->flags &ACPI_SRAT_MEM_NON_VOLATILE )) +node_set (node, def_alloc_nodemask); +node_set (node, numa_nodes_parsed); pr_info("SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]%s%s\n",
include/linux/mmzone.h +3 -0
@@ -927,6 +927,9 @@ extern int numa_zonelist_order_handler(struct ctl_table *, int,extern struct pglist_data *next_online_pgdat (struct pglist_data *pgdat);extern struct zone *next_zone (struct zone *zone); +/* Regular DRAM nodes */ +extern nodemask_t def_alloc_nodemask; +/** * for_each_online_pgdat - helper macro to iterate over all online nodes * @pgdat - pointer to a pg_data_t variable
mm/page_alloc.c +16 -2
@@ -134,6 +134,8 @@ struct pcpu_drain {int percpu_pagelist_fraction;gfp_t gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; +nodemask_t def_alloc_nodemask__read_mostly ; +/* * A cached value of the page's pageblock's migratetype, used when the page is * put on a pcplist. Used to avoid the pageblock migratetype lookup when
@@ -4524,12 +4526,24 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, { ac->high_zoneidx =gfp_zone (gfp_mask); ac->zonelist =node_zonelist (preferred_nid, gfp_mask); - ac->nodemask = nodemask; ac->migratetype =gfpflags_to_migratetype (gfp_mask); +if (!nodemask) { +/* Non-DRAM node is preferred node */ +if (!node_isset (preferred_nid, def_alloc_nodemask)) +/* +* With MPOL_PREFERRED policy, once PMEM is allowed, +* can falback to all memory nodes. +*/ + ac->nodemask = &node_states[N_MEMORY ]; +else + ac->nodemask = &def_alloc_nodemask; + }else + ac->nodemask = nodemask; +if (cpusets_enabled ()) { *alloc_mask |= __GFP_HARDWALL; -if (!ac->nodemask) +if (nodes_equal (*ac->nodemask, def_alloc_nodemask)) ac->nodemask = &cpuset_current_mems_allowed;else *alloc_flags |=ALLOC_CPUSET ;
Signature · 1 line
1.8.3.1
PATCH 3/10 mm: mempolicy: promote page to DRAM for MPOL_HYBRID
In reply to Yang ShiWith MPOL_HYBRID the memory allocation may end up on non-DRAM node, this may be not optimal for performance. Promote pages to DRAM with NUMA balancing for MPOL_HYBRID.
If DRAM nodes are specified, migrate to the specified nodes. If no DRAM node is specified, migrate to the local DRAM node.
--- mm/mempolicy.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
mm/mempolicy.c +19 -1
@@ -2339,6 +2339,7 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned longstruct zoneref *z;int curnid =page_to_nid (page);unsigned long pgoff; +nodemask_t nmask;int thiscpu =raw_smp_processor_id ();int thisnid =cpu_to_node (thiscpu);int polnid =NUMA_NO_NODE ;
@@ -2363,7 +2364,24 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned longbreak ;case MPOL_HYBRID : -/* Fall through */ +if (node_isset (curnid, pol->v.nodes) && +node_isset (curnid, def_alloc_nodemask)) +/* The page is already on DRAM node */ + goto out; + +/* +* Promote to the DRAM node specified by the policy, or +* the local DRAM node if no DRAM node is specified. +*/ +nodes_and (nmask, pol->v.nodes, def_alloc_nodemask); + + z =first_zones_zonelist ( +node_zonelist (numa_node_id (),GFP_HIGHUSER ), +gfp_zone (GFP_HIGHUSER ), +nodes_empty (nmask) ? &def_alloc_nodemask : &nmask); + polnid = z->zone->node; + +break ;case MPOL_BIND :
Signature · 1 line
1.8.3.1
PATCH 9/10 doc: add description for MPOL_HYBRID mode
In reply to Yang ShiAdd description for MPOL_HYBRID mode in kernel documentation.
--- Documentation/admin-guide/mm/numa_memory_policy.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/admin-guide/mm/numa_memory_policy.rst +10 -0
@@ -198,6 +198,16 @@ MPOL_BIND the node in the set with sufficient free memory that is closest to the node where the allocation takes place. +MPOL_HYBRID + This mode specifies that the page allocation must happen on the + nodes specified by the policy. If both DRAM and non-DRAM nodes + are specified, NUMA balancing may promote the pages from non-DRAM + nodes to the specified DRAM nodes. If only non-DRAM nodes are + specified, NUMA balancing may promote the pages to any available + DRAM nodes. Any other policy doesn't do such page promotion. The + default mode may do NUMA balancing, but non-DRAM nodes are masked + off for default mode. + MPOL_PREFERRED This mode specifies that the allocation should be attempted from the single node specified in the policy. If that
Signature · 1 line
1.8.3.1
PATCH 10/10 doc: elaborate the PMEM allocation rule
In reply to Yang Shinon-DRAM nodes are excluded from default allocation node mask, elaborate the rules.
--- Documentation/vm/numa.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/vm/numa.rst +6 -1
@@ -133,7 +133,7 @@ a subsystem allocates per CPU memory resources, for example. A typical model for making such an allocation is to obtain the node id of the node to which the "current CPU" is attached using one of the kernel's -numa_node_id() or CPU_to_node() functions and then request memory from only +numa_node_id() or cpu_to_node() functions and then request memory from only the node id returned. When such an allocation fails, the requesting subsystem may revert to its own fallback path. The slab kernel memory allocator is an example of this. Or, the subsystem may choose to disable or not to enable
@@ -148,3 +148,8 @@ architectures transparently, kernel subsystems can use the numa_mem_id() or cpu_to_mem() function to locate the "local memory node" for the calling or specified CPU. Again, this is the same node from which default, local page allocations will be attempted. + +If the architecture supports non-regular DRAM nodes, i.e. NVDIMM on x86, the +non-DRAM nodes are hidden from default mode, IOWs the default allocation +would not end up on non-DRAM nodes, unless thoes nodes are specified +explicity by mempolicy. [see Documentation/vm/numa_memory_policy.txt.]
Signature · 1 line
1.8.3.1
PATCH 2/10 mm: mempolicy: introduce MPOL_HYBRID policy
In reply to Yang ShiIntroduce a new NUMA policy, MPOL_HYBRID. It behaves like MPOL_BIND, but since we need migrate pages from non-DRAM node (i.e. PMEM node) to DRAM node on demand, MPOL_HYBRID would do page migration on numa fault, so it would have MPOL_F_MOF set by default.
The NUMA balancing stuff will be enabled in the following patch.
--- include/uapi/linux/mempolicy.h | 1 + mm/mempolicy.c | 56 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-)
include/uapi/linux/mempolicy.h +1 -0
@@ -22,6 +22,7 @@ enum {MPOL_BIND ,MPOL_INTERLEAVE ,MPOL_LOCAL , +MPOL_HYBRID , MPOL_MAX, /* always last member of enum */ };
mm/mempolicy.c +50 -6
158 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 5/10 mm: page_alloc: make find_next_best_node could skip DRAM node
In reply to Yang ShiNeed find the cloest non-DRAM node to demote DRAM pages. Add "skip_ram_node" parameter to find_next_best_node() to skip DRAM node on demand.
--- mm/internal.h | 11 +++++++++++ mm/page_alloc.c | 15 +++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-)
mm/internal.h +11 -0
@@ -292,6 +292,17 @@ static inline bool is_data_mapping(vm_flags_t flags)return (flags & (VM_WRITE |VM_SHARED |VM_STACK )) ==VM_WRITE ; } +#ifdef CONFIG_NUMA +extern int find_next_best_node (int node,nodemask_t *used_node_mask, +bool skip_ram_node); +#else +static inline int find_next_best_node (int node,nodemask_t *used_node_mask, +bool skip_ram_node) +{ +return 0 ; +} +#endif +/* mm/util.c */ void __vma_link_list (struct mm_struct *mm,struct vm_area_struct *vma,struct vm_area_struct *prev,struct rb_node *rb_parent);
mm/page_alloc.c +11 -4
@@ -5375,6 +5375,7 @@ int numa_zonelist_order_handler(struct ctl_table *table, int write,* find_next_best_node - find the next node that should appear in a given node's fallback list * @node: node whose fallback list we're appending * @used_node_mask: nodemask_t of already used nodes +* @skip_ram_node: find next best non-DRAM node * * We use a number of factors to determine which is the next node that should * appear on a given node's fallback list. The node should not have appeared
@@ -5386,7 +5387,8 @@ int numa_zonelist_order_handler(struct ctl_table *table, int write,* * Return: node id of the found node or %NUMA_NO_NODE if no node is found. */ -static int find_next_best_node (int node,nodemask_t *used_node_mask) +int find_next_best_node (int node,nodemask_t *used_node_mask, +bool skip_ram_node) {int n, val;int min_val =INT_MAX ;
@@ -5394,13 +5396,19 @@ static int find_next_best_node(int node, nodemask_t *used_node_mask)const struct cpumask *tmp =cpumask_of_node (0 );/* Use the local node if we haven't already */ -if (!node_isset (node, *used_node_mask)) { +if (!node_isset (node, *used_node_mask) && + !skip_ram_node) {node_set (node, *used_node_mask);return node; }for_each_node_state (n,N_MEMORY ) { +/* Find next best non-DRAM node */ +if (skip_ram_node && + (node_isset (n, def_alloc_nodemask))) +continue ; +/* Don't want a node to appear more than once */ if (node_isset (n, *used_node_mask))continue ;
@@ -5432,7 +5440,6 @@ static int find_next_best_node(int node, nodemask_t *used_node_mask)return best_node; } -/* * Build zonelists ordered by node and zones within node. * This results in maximum locality--normal zone overflows into local
@@ -5494,7 +5501,7 @@ static void build_zonelists(pg_data_t *pgdat)nodes_clear (used_mask);memset (node_order,0 ,sizeof (node_order)); -while ((node =find_next_best_node (local_node, &used_mask)) >=0 ) { +while ((node =find_next_best_node (local_node, &used_mask, false)) >=0 ) {/* * We don't want to pressure a particular node. * So adding penalty to the first node in same
Signature · 1 line
1.8.3.1
PATCH 4/10 mm: numa: promote pages to DRAM when it is accessed twice
In reply to Yang ShiNUMA balancing would promote the pages to DRAM once it is accessed, but it might be just one off access. To reduce migration thrashing and memory bandwidth pressure, introduce PG_promote flag to mark promote candidate. The page will be promoted to DRAM when it is accessed twice. This might be a good way to filter out those one-off access pages.
PG_promote flag will be inherited by tail pages when THP gets split. But, it will not be copied to the new page once the migration is done.
This approach is not definitely the optimal one to distinguish the hot or cold pages. It may need much more sophisticated algorithm to distinguish hot or cold pages accurately. Kernel may be not the good place to implement such algorithm considering the complexity and potential overhead. But, kernel may still need such capability.
With NUMA balancing the whole workingset of the process may end up being promoted to DRAM finally. It depends on the page reclaim to demote inactive pages to PMEM implemented by the following patch.
--- include/linux/page-flags.h | 4 ++++ include/trace/events/mmflags.h | 3 ++- mm/huge_memory.c | 10 ++++++++++ mm/memory.c | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-)
include/linux/page-flags.h +4 -0
@@ -131,6 +131,7 @@ enum pageflags { PG_young, PG_idle, #endif + PG_promote,/* Promote candidate for NUMA balancing */ __NR_PAGEFLAGS,/* Filesystems */
@@ -348,6 +349,9 @@ static inline void page_init_poison(struct page *page, size_t size) PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY) TESTCLEARFLAG(OwnerPriv1, owner_priv_1, PF_ANY) +PAGEFLAG(Promote, promote, PF_ANY) __SETPAGEFLAG(Promote, promote, PF_ANY) +__CLEARPAGEFLAG (Promote, promote,PF_ANY ) +/* * Only test-and-set exist for PG_writeback. The unconditional operators are * risky: they bypass page accounting.
include/trace/events/mmflags.h +2 -1
@@ -100,7 +100,8 @@ {1UL << PG_mappedtodisk, "mappedtodisk" }, \ {1UL << PG_reclaim, "reclaim" }, \ {1UL << PG_swapbacked, "swapbacked" }, \ - {1UL << PG_unevictable, "unevictable" } \ + {1UL << PG_unevictable, "unevictable" }, \ + {1UL << PG_promote, "promote" } \ IF_HAVE_PG_MLOCK(PG_mlocked, "mlocked" ) \ IF_HAVE_PG_UNCACHED(PG_uncached, "uncached" ) \IF_HAVE_PG_HWPOISON (PG_hwpoison,"hwpoison" ) \
mm/huge_memory.c +10 -0
@@ -1589,6 +1589,15 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd) haddr + HPAGE_PMD_SIZE); } +/* Promote page to DRAM when referenced twice */ +if (!(node_isset (page_nid, def_alloc_nodemask)) && + !PagePromote (page)) { +SetPagePromote (page); +put_page (page); + page_nid =-1 ; + goto clear_pmdnuma; + } +/* * Migrate the THP to the requested node, returns with page unlocked * and access rights restored.
@@ -2396,6 +2405,7 @@ static void __split_huge_page_tail(struct page *head, int tail, (1L << PG_workingset) | (1L << PG_locked) | (1L << PG_unevictable) | + (1L << PG_promote) | (1L << PG_dirty)));/* ->mapping in first tail page is compound_mapcount */
mm/memory.c +8 -0
@@ -3680,6 +3680,14 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) goto out; } +/* Promote the non-DRAM page when it is referenced twice */ +if (!(node_isset (page_nid, def_alloc_nodemask)) && + !PagePromote (page)) { +SetPagePromote (page); +put_page (page); + goto out; + } +/* Migrate to the requested node */ migrated =migrate_misplaced_page (page, vma, target_nid);if (migrated) {
Signature · 1 line
1.8.3.1
PATCH 8/10 mm: numa: add page promotion counter
In reply to Yang ShiAdd counter for page promotion for NUMA balancing.
--- include/linux/vm_event_item.h | 1 + mm/huge_memory.c | 4 ++++ mm/memory.c | 4 ++++ mm/vmstat.c | 1 + 4 files changed, 10 insertions(+)
include/linux/vm_event_item.h +1 -0
@@ -51,6 +51,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,NUMA_HINT_FAULTS ,NUMA_HINT_FAULTS_LOCAL ,NUMA_PAGE_MIGRATE , +NUMA_PAGE_PROMOTE , #endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
mm/huge_memory.c +4 -0
@@ -1607,6 +1607,10 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd) migrated =migrate_misplaced_transhuge_page (vma->vm_mm, vma, vmf->pmd, pmd, vmf->address, page, target_nid);if (migrated) { +if (!node_isset (page_nid, def_alloc_nodemask) && +node_isset (target_nid, def_alloc_nodemask)) +count_vm_numa_events (NUMA_PAGE_PROMOTE ,HPAGE_PMD_NR ); + flags |=TNF_MIGRATED ; page_nid = target_nid; }else
mm/memory.c +4 -0
@@ -3691,6 +3691,10 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)/* Migrate to the requested node */ migrated =migrate_misplaced_page (page, vma, target_nid);if (migrated) { +if (!node_isset (page_nid, def_alloc_nodemask) && +node_isset (target_nid, def_alloc_nodemask)) +count_vm_numa_event (NUMA_PAGE_PROMOTE ); + page_nid = target_nid; flags |=TNF_MIGRATED ; }else
mm/vmstat.c +1 -0
@@ -1220,6 +1220,7 @@ int fragmentation_index(struct zone *zone, unsigned int order)"numa_hint_faults" ,"numa_hint_faults_local" ,"numa_pages_migrated" , +"numa_pages_promoted" , #endif #ifdef CONFIG_MIGRATION "pgmigrate_success",
Signature · 1 line
1.8.3.1
PATCH 7/10 mm: vmscan: add page demotion counter
In reply to Yang ShiDemoted pages are counted into reclaim_state->nr_demoted instead of nr_reclaimed since they are not reclaimed actually. They are still in memory, but just migrated to PMEM.
Add pgdemote_kswapd and pgdemote_direct VM counters showed in /proc/vmstat.
--- include/linux/vm_event_item.h | 2 ++ include/linux/vmstat.h | 1 + mm/vmscan.c | 14 ++++++++++++++ mm/vmstat.c | 2 ++ 4 files changed, 19 insertions(+)
include/linux/vm_event_item.h +2 -0
@@ -32,6 +32,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,PGREFILL ,PGSTEAL_KSWAPD ,PGSTEAL_DIRECT , +PGDEMOTE_KSWAPD , +PGDEMOTE_DIRECT ,PGSCAN_KSWAPD ,PGSCAN_DIRECT , PGSCAN_DIRECT_THROTTLE,
include/linux/vmstat.h +1 -0
@@ -29,6 +29,7 @@ struct reclaim_stat {unsigned nr_activate;unsigned nr_ref_keep;unsigned nr_unmap_fail; +unsigned nr_demoted; };#ifdef CONFIG_VM_EVENT_COUNTERS
mm/vmscan.c +14 -0
@@ -1286,6 +1286,10 @@ static unsigned long shrink_page_list(struct list_head *page_list,if (has_nonram_online ()) {list_add (&page->lru, &demote_pages); +if (PageTransHuge (page)) + stat->nr_demoted +=HPAGE_PMD_NR ; +else + stat->nr_demoted++;unlock_page (page);continue ; }
@@ -1523,7 +1527,17 @@ static unsigned long shrink_page_list(struct list_head *page_list,putback_movable_pages (&demote_pages);list_splice (&ret_pages, &demote_pages); + +if (err >0 ) + stat->nr_demoted -= err; +else + stat->nr_demoted =0 ; } + +if (current_is_kswapd ()) +__count_vm_events (PGDEMOTE_KSWAPD , stat->nr_demoted); +else +__count_vm_events (PGDEMOTE_DIRECT , stat->nr_demoted); }mem_cgroup_uncharge_list (&free_pages);
mm/vmstat.c +2 -0
@@ -1192,6 +1192,8 @@ int fragmentation_index(struct zone *zone, unsigned int order)"pgrefill" ,"pgsteal_kswapd" ,"pgsteal_direct" , +"pgdemote_kswapd" , +"pgdemote_direct" ,"pgscan_kswapd" ,"pgscan_direct" , "pgscan_direct_throttle",
Signature · 1 line
1.8.3.1
PATCH 6/10 mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Yang ShiSince PMEM provides larger capacity than DRAM and has much lower access latency than disk, so it is a good choice to use as a middle tier between DRAM and disk in page reclaim path.
With PMEM nodes, the demotion path of anonymous pages could be:
DRAM -> PMEM -> swap device
This patch demotes anonymous pages only for the time being and demote THP to PMEM in a whole. However this may cause expensive page reclaim and/or compaction on PMEM node if there is memory pressure on it. But, considering the capacity of PMEM and allocation only happens on PMEM when PMEM is specified explicity, such cases should be not that often. So, it sounds worth keeping THP in a whole instead of splitting it.
Demote pages to the cloest non-DRAM node even though the system is swapless. The current logic of page reclaim just scan anon LRU when swap is on and swappiness is set properly. Demoting to PMEM doesn't need care whether swap is available or not. But, reclaiming from PMEM still skip anon LRU is swap is not available.
The demotion just happens between DRAM node and its cloest PMEM node. Demoting to a remote PMEM node is not allowed for now.
And, define a new migration reason for demotion, called MR_DEMOTE. Demote page via async migration to avoid blocking.
--- include/linux/migrate.h | 1 + include/trace/events/migrate.h | 3 +- mm/debug.c | 1 + mm/internal.h | 22 ++++++++++ mm/vmscan.c | 99 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 107 insertions(+), 19 deletions(-)
include/linux/migrate.h +1 -0
@@ -25,6 +25,7 @@ enum migrate_reason {MR_MEMPOLICY_MBIND ,MR_NUMA_MISPLACED ,MR_CONTIG_RANGE , +MR_DEMOTE , MR_TYPES };
include/trace/events/migrate.h +2 -1
@@ -20,7 +20,8 @@ EM( MR_SYSCALL, "syscall_or_cpuset") \ EM( MR_MEMPOLICY_MBIND, "mempolicy_mbind") \ EM( MR_NUMA_MISPLACED, "numa_misplaced") \ -EMe (MR_CONTIG_RANGE ,"contig_range" ) + EM( MR_CONTIG_RANGE, "contig_range") \ +EMe (MR_DEMOTE ,"demote" )/* * First define the enums in the above macros to be exported to userspace
mm/debug.c +1 -0
@@ -25,6 +25,7 @@"mempolicy_mbind" ,"numa_misplaced" ,"cma" , + "demote", }; const struct trace_print_flags pageflag_names[] = {
mm/internal.h +22 -0
@@ -303,6 +303,19 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask, }#endif +static inline bool has_nonram_online (void ) +{ +int i =0 ; + +for_each_online_node (i) { +/* Have PMEM node online? */ +if (!node_isset (i, def_alloc_nodemask)) +return true; + } + +return false; +} +/* mm/util.c */ void __vma_link_list (struct mm_struct *mm,struct vm_area_struct *vma,struct vm_area_struct *prev,struct rb_node *rb_parent);
@@ -565,5 +578,14 @@ static inline bool is_migrate_highatomic_page(struct page *page) }void setup_zone_pageset (struct zone *zone); + +#ifdef CONFIG_NUMA extern struct page *alloc_new_node_page (struct page *page,unsigned long node); +#else +static inline struct page *alloc_new_node_page (struct page *page, +unsigned long node) +{ +return NULL ; +} +#endif #endif /* __MM_INTERNAL_H */
mm/vmscan.c +81 -18
144 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Zi Yan
reviewerRe: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
Quoted 146 lines · Yang Shi
Since PMEM provides larger capacity than DRAM and has much lower access latency than disk, so it is a good choice to use as a middle tier between DRAM and disk in page reclaim path.
With PMEM nodes, the demotion path of anonymous pages could be:
DRAM -> PMEM -> swap device
This patch demotes anonymous pages only for the time being and demote THP to PMEM in a whole. However this may cause expensive page reclaim and/or compaction on PMEM node if there is memory pressure on it. But, considering the capacity of PMEM and allocation only happens on PMEM when PMEM is specified explicity, such cases should be not that often. So, it sounds worth keeping THP in a whole instead of splitting it.
Demote pages to the cloest non-DRAM node even though the system is swapless. The current logic of page reclaim just scan anon LRU when swap is on and swappiness is set properly. Demoting to PMEM doesn't need care whether swap is available or not. But, reclaiming from PMEM still skip anon LRU is swap is not available.
The demotion just happens between DRAM node and its cloest PMEM node. Demoting to a remote PMEM node is not allowed for now.
And, define a new migration reason for demotion, called
MR_DEMOTE. Demote page via async migration to avoid blocking.Signed-off-by Yang Shi <[email protected]>--- include/linux/migrate.h | 1 + include/trace/events/migrate.h | 3 +- mm/debug.c | 1 + mm/internal.h | 22 ++++++++++ mm/vmscan.c | 99 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 107 insertions(+), 19 deletions(-)include/linux/migrate.h +1
-0@@ -25,6 +25,7 @@ enum migrate_reason {MR_MEMPOLICY_MBIND ,MR_NUMA_MISPLACED ,MR_CONTIG_RANGE , +MR_DEMOTE , MR_TYPES };include/trace/events/migrate.h +2
-1@@ -20,7 +20,8 @@ EM( MR_SYSCALL, "syscall_or_cpuset") \ EM( MR_MEMPOLICY_MBIND, "mempolicy_mbind") \ EM( MR_NUMA_MISPLACED, "numa_misplaced") \ -EMe (MR_CONTIG_RANGE ,"contig_range" ) + EM( MR_CONTIG_RANGE, "contig_range") \ +EMe (MR_DEMOTE ,"demote" )/* * First define the enums in the above macros to be exported to userspace mm/debug.c +1
-0@@ -25,6 +25,7 @@"mempolicy_mbind" ,"numa_misplaced" ,"cma" , + "demote", }; const struct trace_print_flags pageflag_names[] = {mm/internal.h +22
-0@@ -303,6 +303,19 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask, }#endif +static inline bool has_nonram_online (void ) +{ +int i =0 ; + +for_each_online_node (i) { +/* Have PMEM node online? */ +if (!node_isset (i, def_alloc_nodemask)) +return true; + } + +return false; +} +/* mm/util.c */ void __vma_link_list (struct mm_struct *mm,struct vm_area_struct *vma,struct vm_area_struct *prev,struct rb_node *rb_parent);@@ -565,5 +578,14 @@ static inline bool is_migrate_highatomic_page(struct page *page) }void setup_zone_pageset (struct zone *zone); + +#ifdef CONFIG_NUMA extern struct page *alloc_new_node_page (struct page *page,unsigned long node); +#else +static inline struct page *alloc_new_node_page (struct page *page, +unsigned long node) +{ +return NULL ; +} +#endif #endif /* __MM_INTERNAL_H */ mm/vmscan.c +14
-0@@ -1094,6 +1094,19 @@ static void page_check_dirty_writeback(struct page *page, mapping->a_ops->is_dirty_writeback (page, dirty, writeback); } +static inline bool is_demote_ok (struct pglist_data *pgdat) +{ +/* Current node is not DRAM node */ +if (!node_isset (pgdat->node_id, def_alloc_nodemask)) +return false; + +/* No online PMEM node */ +if (!has_nonram_online ()) +return false; + +return true; +} +/* * shrink_page_list() returns the number of reclaimed pages */ @@ -1106,6 +1119,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, {LIST_HEAD (ret_pages);LIST_HEAD (free_pages); +LIST_HEAD (demote_pages);unsigned nr_reclaimed =0 ;memset (stat,0 ,sizeof (*stat));
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1280
Quoted 5 lines
mm/vmscan.c +2
-0@@ -1262,6 +1276,22 @@ static unsigned long shrink_page_list(struct list_head *page_list, }/* +* Demote DRAM pages regardless the mempolicy. +* Demot anonymous pages only for now and skip MADV_FREE
s/Demot/Demote
Quoted 30 lines
mm/vmscan.c +23
-0+* pages. +*/ +if (PageAnon (page) && !PageSwapCache (page) && + (node_isset (page_to_nid (page), def_alloc_nodemask)) && +PageSwapBacked (page)) { + +if (has_nonram_online ()) { +list_add (&page->lru, &demote_pages); +unlock_page (page); +continue ; + } + } + +/* * Anonymous process memory has backing store? * Try to allocate it some swap space here. * Lazyfree page could be freed directly @@ -1477,6 +1507,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,VM_BUG_ON_PAGE (PageLRU (page) ||PageUnevictable (page), page); } +/* Demote pages to PMEM */ +if (!list_empty (&demote_pages)) { +int err, target_nid; +nodemask_t used_mask; + +nodes_clear (used_mask); + target_nid =find_next_best_node (pgdat->node_id, &used_mask, + true); +
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1528
Quoted 10 lines
mm/vmscan.c +10
-0+ err =migrate_pages (&demote_pages, alloc_new_node_page,NULL , + target_nid,MIGRATE_ASYNC ,MR_DEMOTE ); + +if (err) { +putback_movable_pages (&demote_pages); + +list_splice (&ret_pages, &demote_pages); + } + } +
I like your approach here. It reuses the existing migrate_pages() interface without adding extra code. I also would like to be CC’d in your future versions.
Thank you.
--
Best Regards,
Yan Zi
Re: [PATCH 01/10] mm: control memory placement by nodemask for two tier main memory
In reply to Yang ShiQuoted 42 lines · Yang Shi
When running applications on the machine with NVDIMM as NUMA node, the memory allocation may end up on NVDIMM node. This may result in silent performance degradation and regression due to the difference of hardware property.
DRAM first should be obeyed to prevent from surprising regression. Any non-DRAM nodes should be excluded from default allocation. Use nodemask to control the memory placement. Introduce
def_alloc_nodemaskwhich has DRAM nodes set only. Any non-DRAM allocation should be specified by NUMA policy explicitly.In the future we may be able to extract the memory charasteristics from HMAT or other source to build up the default allocation nodemask. However, just distinguish DRAM and PMEM (non-DRAM) nodes by SRAT flag for the time being.
Signed-off-by Yang Shi <[email protected]>--- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 ++++++++ include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)arch/x86/mm/numa.c +1
-0@@ -626,6 +626,7 @@ static int __init numa_init(int (*init_func)(void))nodes_clear (numa_nodes_parsed);nodes_clear (node_possible_map);nodes_clear (node_online_map); +nodes_clear (def_alloc_nodemask);memset (&numa_meminfo,0 ,sizeof (numa_meminfo));WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory,MAX_NUMNODES ));drivers/acpi/numa.c +0
-0
drivers/acpi/numa.c void __init acpi_numa_slit_init(struct acpi_table_slit *slit) · line 305
Quoted 10 lines
drivers/acpi/numa.c +7
-0@@ -296,6 +296,14 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) goto out_err_bad_srat; } +/* +* Non volatile memory is excluded from zonelist by default. +* Only regular DRAM nodes are set in default allocation node +* mask. +*/ +if (!(ma->flags &ACPI_SRAT_MEM_NON_VOLATILE )) +node_set (node, def_alloc_nodemask);
Hmm, no, I don't think we should do this. Especially considering current generation NVDIMMs are energy backed DRAM there is no performance difference that should be assumed by the non-volatile flag.
Why isn't default SLIT distance sufficient for ensuring a DRAM-first default policy?
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Yang ShiQuoted 36 lines · Yang Shi
mm/vmscan.c +28
-0/* +* Demote DRAM pages regardless the mempolicy. +* Demot anonymous pages only for now and skip MADV_FREE +* pages. +*/ +if (PageAnon (page) && !PageSwapCache (page) && + (node_isset (page_to_nid (page), def_alloc_nodemask)) && +PageSwapBacked (page)) { + +if (has_nonram_online ()) { +list_add (&page->lru, &demote_pages); +unlock_page (page); +continue ; + } + } + +/* * Anonymous process memory has backing store? * Try to allocate it some swap space here. * Lazyfree page could be freed directly @@ -1477,6 +1507,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,VM_BUG_ON_PAGE (PageLRU (page) ||PageUnevictable (page), page); } +/* Demote pages to PMEM */ +if (!list_empty (&demote_pages)) { +int err, target_nid; +nodemask_t used_mask; + +nodes_clear (used_mask); + target_nid =find_next_best_node (pgdat->node_id, &used_mask, + true); + + err =migrate_pages (&demote_pages, alloc_new_node_page,NULL , + target_nid,MIGRATE_ASYNC ,MR_DEMOTE ); +
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1531
Quoted 10 lines
mm/vmscan.c +7
-0+if (err) { +putback_movable_pages (&demote_pages); + +list_splice (&ret_pages, &demote_pages); + } + } +mem_cgroup_uncharge_list (&free_pages);try_to_unmap_flush ();free_unref_page_list (&free_pages);
How do these pages eventually get to swap when migration fails? Looks like that's skipped.
And page cache demotion is useful too, we shouldn't consider only anonymous for this feature.
Le 23/03/2019 à 05:44, Yang Shi a écrit :
Quoted 14 lines
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
I am not against the approach for some workloads. However, many HPC people would rather do this manually. But there's currently no easy way to find out from userspace whether a given NUMA node is DDR or PMEM*. We have to assume HMAT is available (and correct) and look at performance attributes. When talking to humans, it would be better to say "I allocated on the local DDR NUMA node" rather than "I allocated on the fastest node according to HMAT latency".
Also, when we'll have HBM+DDR, some applications may want to use DDR by default, which means they want the *slowest* node according to HMAT (by the way, will your hybrid policy work if we ever have HBM+DDR+PMEM?). Performance attributes could help, but how does user-space know for sure that X>Y will still mean HBM>DDR and not DDR>PMEM in 5 years?
It seems to me that exporting a flag in sysfs saying whether a node is PMEM could be convenient. Patch series [1] exported a "type" in sysfs node directories ("pmem" or "dram"). I don't know how if there's an easy way to define what HBM is and expose that type too.
Brice
* As far as I know, the only way is to look at all DAX devices until you find the given NUMA node in the "target_node" attribute. If none, you're likely not PMEM-backed.
Quoted 1 line
Quoted 40 lines · Brice Goglin
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
I am not against the approach for some workloads. However, many HPC people would rather do this manually. But there's currently no easy way to find out from userspace whether a given NUMA node is DDR or PMEM*. We have to assume HMAT is available (and correct) and look at performance attributes. When talking to humans, it would be better to say "I allocated on the local DDR NUMA node" rather than "I allocated on the fastest node according to HMAT latency".
Also, when we'll have HBM+DDR, some applications may want to use DDR by default, which means they want the *slowest* node according to HMAT (by the way, will your hybrid policy work if we ever have HBM+DDR+PMEM?). Performance attributes could help, but how does user-space know for sure that X>Y will still mean HBM>DDR and not DDR>PMEM in 5 years?
Quoted 4 lines
It seems to me that exporting a flag in sysfs saying whether a node is PMEM could be convenient. Patch series [1] exported a "type" in sysfs node directories ("pmem" or "dram"). I don't know how if there's an easy way to define what HBM is and expose that type too.
I'm generally against the concept that a "pmem" or "type" flag should indicate anything about the expected performance of the address range. The kernel should explicitly look to the HMAT for performance data and not otherwise make type-based performance assumptions.
Le 25/03/2019 à 17:56, Dan Williams a écrit :
Quoted 5 lines
I'm generally against the concept that a "pmem" or "type" flag should indicate anything about the expected performance of the address range. The kernel should explicitly look to the HMAT for performance data and not otherwise make type-based performance assumptions.
Oh sorry, I didn't mean to have the kernel use such a flag to decide of placement, but rather to expose more information to userspace to clarify what all these nodes are about when userspace will decide where to allocate things.
I understand that current NVDIMM-F are not slower than DDR and HMAT would better describe this than a flag. But I have seen so many buggy or dummy SLIT tables in the past that I wonder if we can expect HMAT to be widely available (and correct).
Is there a safe fallback in case of missing or buggy HMAT? For instance, is DDR supposed to be listed before NVDIMM (or HBM) in SRAT?
Brice
Re: [PATCH 01/10] mm: control memory placement by nodemask for two tier main memory
In reply to Dan WilliamsQuoted 45 lines · Dan Williams
Quoted 44 lines · Yang Shi
When running applications on the machine with NVDIMM as NUMA node, the memory allocation may end up on NVDIMM node. This may result in silent performance degradation and regression due to the difference of hardware property.
DRAM first should be obeyed to prevent from surprising regression. Any non-DRAM nodes should be excluded from default allocation. Use nodemask to control the memory placement. Introduce
def_alloc_nodemaskwhich has DRAM nodes set only. Any non-DRAM allocation should be specified by NUMA policy explicitly.In the future we may be able to extract the memory charasteristics from HMAT or other source to build up the default allocation nodemask. However, just distinguish DRAM and PMEM (non-DRAM) nodes by SRAT flag for the time being.
Signed-off-by Yang Shi <[email protected]>--- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 ++++++++ include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)arch/x86/mm/numa.c +1
-0@@ -626,6 +626,7 @@ static int __init numa_init(int (*init_func)(void))nodes_clear (numa_nodes_parsed);nodes_clear (node_possible_map);nodes_clear (node_online_map); +nodes_clear (def_alloc_nodemask);memset (&numa_meminfo,0 ,sizeof (numa_meminfo));WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory,MAX_NUMNODES ));drivers/acpi/numa.c +0
-0@@ -296,6 +296,14 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) goto out_err_bad_srat; }
Quoted 11 lines
drivers/acpi/numa.c void __init acpi_numa_slit_init(struct acpi_table_slit *slit) · line 305
Quoted 7 lines
drivers/acpi/numa.c +7
-0+/* +* Non volatile memory is excluded from zonelist by default. +* Only regular DRAM nodes are set in default allocation node +* mask. +*/ +if (!(ma->flags &ACPI_SRAT_MEM_NON_VOLATILE )) +node_set (node, def_alloc_nodemask);Hmm, no, I don't think we should do this. Especially considering current generation NVDIMMs are energy backed DRAM there is no performance difference that should be assumed by the non-volatile flag.
Actually, here I would like to initialize a node mask for default allocation. Memory allocation should not end up on any nodes excluded by this node mask unless they are specified by mempolicy.
We may have a few different ways or criteria to initialize the node mask, for example, we can read from HMAT (when HMAT is ready in the future), and we definitely could have non-DRAM nodes set if they have no performance difference (I'm supposed you mean NVDIMM-F or HBM).
As long as there are different tiers, distinguished by performance, for main memory, IMHO, there should be a defined default allocation node mask to control the memory placement no matter where we get the information.
But, for now we haven't had such information ready for such use yet, so the SRAT flag might be a choice.
Quoted 3 lines
Why isn't default SLIT distance sufficient for ensuring a DRAM-first default policy?
"DRAM-first" may sound ambiguous, actually I mean "DRAM only by default". SLIT should just can tell us what node is local what node is remote, but can't tell us the performance difference.
Thanks,
Yang
Quoted 9 lines · Brice Goglin
Quoted 5 lines · Dan Williams
I'm generally against the concept that a "pmem" or "type" flag should indicate anything about the expected performance of the address range. The kernel should explicitly look to the HMAT for performance data and not otherwise make type-based performance assumptions.
Quoted 4 lines
Oh sorry, I didn't mean to have the kernel use such a flag to decide of placement, but rather to expose more information to userspace to clarify what all these nodes are about when userspace will decide where to allocate things.
I understand, but I'm concerned about the risk of userspace developing vendor-specific, or generation-specific policies around a coarse type identifier. I think the lack of type specificity is a feature rather than a gap, because it requires userspace to consider deeper information.
Perhaps "path" might be a suitable replacement identifier rather than type. I.e. memory that originates from an ACPI.NFIT root device is likely "pmem".
Quoted 4 lines
I understand that current NVDIMM-F are not slower than DDR and HMAT would better describe this than a flag. But I have seen so many buggy or dummy SLIT tables in the past that I wonder if we can expect HMAT to be widely available (and correct).
That's always a fear that the platform BIOS will try to game OS behavior. However, that was the reason that HMAT was defined to indicate actual performance values rather than relative. It is hopefully harder to game than the relative SLIT values, but I'l grant you it's now impossible.
Quoted 2 lines
Is there a safe fallback in case of missing or buggy HMAT? For instance, is DDR supposed to be listed before NVDIMM (or HBM) in SRAT?
One fallback might be to make some of these sysfs attributes writable so userspace can correct the situation, but I'm otherwise unclear of what you mean by "safe". If a platform has hard dependencies on correctly enumerating memory performance capabilities then there's not much the kernel can do if the HMAT is botched. I would expect the general case is that the performance capabilities are a soft dependency. but things still work if the data is wrong.
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Keith BuschQuoted 41 lines · Keith Busch
Quoted 40 lines · Yang Shi
/*
mm/vmscan.c +32
-0+* Demote DRAM pages regardless the mempolicy. +* Demot anonymous pages only for now and skip MADV_FREE +* pages. +*/ +if (PageAnon (page) && !PageSwapCache (page) && + (node_isset (page_to_nid (page), def_alloc_nodemask)) && +PageSwapBacked (page)) { + +if (has_nonram_online ()) { +list_add (&page->lru, &demote_pages); +unlock_page (page); +continue ; + } + } + +/* * Anonymous process memory has backing store? * Try to allocate it some swap space here. * Lazyfree page could be freed directly @@ -1477,6 +1507,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,VM_BUG_ON_PAGE (PageLRU (page) ||PageUnevictable (page), page); } +/* Demote pages to PMEM */ +if (!list_empty (&demote_pages)) { +int err, target_nid; +nodemask_t used_mask; + +nodes_clear (used_mask); + target_nid =find_next_best_node (pgdat->node_id, &used_mask, + true); + + err =migrate_pages (&demote_pages, alloc_new_node_page,NULL , + target_nid,MIGRATE_ASYNC ,MR_DEMOTE ); + +if (err) { +putback_movable_pages (&demote_pages); + +list_splice (&ret_pages, &demote_pages);
Quoted 8 lines
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1531
Quoted 6 lines
mm/vmscan.c +3
-0+ } + } +mem_cgroup_uncharge_list (&free_pages);try_to_unmap_flush ();free_unref_page_list (&free_pages);How do these pages eventually get to swap when migration fails? Looks like that's skipped.
Yes, they will be just put back to LRU. Actually, I don't expect it would be very often to have migration fail at this stage (but I have no test data to support this hypothesis) since the pages have been isolated from LRU, so other reclaim path should not find them anymore.
If it is locked by someone else right before migration, it is likely referenced again, so putting back to LRU sounds not bad.
A potential improvement is to have sync migration for kswapd.
Quoted 3 lines
And page cache demotion is useful too, we shouldn't consider only anonymous for this feature.
Yes, definitely. I'm looking into the page cache case now. Any suggestion is welcome.
Thanks,
Yang
Quoted 23 lines · Brice Goglin
Le 23/03/2019 à 05:44, Yang Shi a écrit :
Quoted 14 lines
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
I am not against the approach for some workloads. However, many HPC people would rather do this manually. But there's currently no easy way to find out from userspace whether a given NUMA node is DDR or PMEM*. We have to assume HMAT is available (and correct) and look at performance attributes. When talking to humans, it would be better to say "I allocated on the local DDR NUMA node" rather than "I allocated on the fastest node according to HMAT latency".
Yes, I agree to have some information exposed to kernel or userspace to tell what nodes are DRAM nodes what nodes are not (maybe HBM or PMEM). I assume the default allocation should end up on DRAM nodes for the most workloads. If someone would like to control this manually other than mempolicy, the default allocation node mask may be exported to user space by sysfs so that it can be changed on demand.
Quoted 6 lines
Also, when we'll have HBM+DDR, some applications may want to use DDR by default, which means they want the *slowest* node according to HMAT (by the way, will your hybrid policy work if we ever have HBM+DDR+PMEM?). Performance attributes could help, but how does user-space know for sure that X>Y will still mean HBM>DDR and not DDR>PMEM in 5 years?
This is what I mentioned above we need the information exported from HMAT or anything similar to tell us what nodes are DRAM nodes since DRAM may be the lowest tier memory.
Or we may be able to assume the nodes associated with CPUs are DRAM nodes by assuming both HBM and PMEM is CPU less node.
Thanks,
Yang
Quoted 14 lines
It seems to me that exporting a flag in sysfs saying whether a node is PMEM could be convenient. Patch series [1] exported a "type" in sysfs node directories ("pmem" or "dram"). I don't know how if there's an easy way to define what HBM is and expose that type too.
Brice
* As far as I know, the only way is to look at all DAX devices until you find the given NUMA node in the "
target_node" attribute. If none, you're likely not PMEM-backed.Quoted 1 line
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Zi YanQuoted 146 lines · Zi Yan
Quoted 144 lines · Yang Shi
Since PMEM provides larger capacity than DRAM and has much lower access latency than disk, so it is a good choice to use as a middle tier between DRAM and disk in page reclaim path.
With PMEM nodes, the demotion path of anonymous pages could be:
DRAM -> PMEM -> swap device
This patch demotes anonymous pages only for the time being and demote THP to PMEM in a whole. However this may cause expensive page reclaim and/or compaction on PMEM node if there is memory pressure on it. But, considering the capacity of PMEM and allocation only happens on PMEM when PMEM is specified explicity, such cases should be not that often. So, it sounds worth keeping THP in a whole instead of splitting it.
Demote pages to the cloest non-DRAM node even though the system is swapless. The current logic of page reclaim just scan anon LRU when swap is on and swappiness is set properly. Demoting to PMEM doesn't need care whether swap is available or not. But, reclaiming from PMEM still skip anon LRU is swap is not available.
The demotion just happens between DRAM node and its cloest PMEM node. Demoting to a remote PMEM node is not allowed for now.
And, define a new migration reason for demotion, called
MR_DEMOTE. Demote page via async migration to avoid blocking.Signed-off-by Yang Shi <[email protected]>--- include/linux/migrate.h | 1 + include/trace/events/migrate.h | 3 +- mm/debug.c | 1 + mm/internal.h | 22 ++++++++++ mm/vmscan.c | 99 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 107 insertions(+), 19 deletions(-)include/linux/migrate.h +1
-0@@ -25,6 +25,7 @@ enum migrate_reason {MR_MEMPOLICY_MBIND ,MR_NUMA_MISPLACED ,MR_CONTIG_RANGE , +MR_DEMOTE , MR_TYPES };include/trace/events/migrate.h +2
-1@@ -20,7 +20,8 @@ EM( MR_SYSCALL, "syscall_or_cpuset") \ EM( MR_MEMPOLICY_MBIND, "mempolicy_mbind") \ EM( MR_NUMA_MISPLACED, "numa_misplaced") \ -EMe (MR_CONTIG_RANGE ,"contig_range" ) + EM( MR_CONTIG_RANGE, "contig_range") \ +EMe (MR_DEMOTE ,"demote" )/* * First define the enums in the above macros to be exported to userspace mm/debug.c +1
-0@@ -25,6 +25,7 @@"mempolicy_mbind" ,"numa_misplaced" ,"cma" , + "demote", }; const struct trace_print_flags pageflag_names[] = {mm/internal.h +22
-0@@ -303,6 +303,19 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask, }#endif +static inline bool has_nonram_online (void ) +{ +int i =0 ; + +for_each_online_node (i) { +/* Have PMEM node online? */ +if (!node_isset (i, def_alloc_nodemask)) +return true; + } + +return false; +} +/* mm/util.c */ void __vma_link_list (struct mm_struct *mm,struct vm_area_struct *vma,struct vm_area_struct *prev,struct rb_node *rb_parent);@@ -565,5 +578,14 @@ static inline bool is_migrate_highatomic_page(struct page *page) }void setup_zone_pageset (struct zone *zone); + +#ifdef CONFIG_NUMA extern struct page *alloc_new_node_page (struct page *page,unsigned long node); +#else +static inline struct page *alloc_new_node_page (struct page *page, +unsigned long node) +{ +return NULL ; +} +#endif #endif /* __MM_INTERNAL_H */ mm/vmscan.c +14
-0@@ -1094,6 +1094,19 @@ static void page_check_dirty_writeback(struct page *page, mapping->a_ops->is_dirty_writeback (page, dirty, writeback); } +static inline bool is_demote_ok (struct pglist_data *pgdat) +{ +/* Current node is not DRAM node */ +if (!node_isset (pgdat->node_id, def_alloc_nodemask)) +return false; + +/* No online PMEM node */ +if (!has_nonram_online ()) +return false; + +return true; +} +/* * shrink_page_list() returns the number of reclaimed pages */ @@ -1106,6 +1119,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, {LIST_HEAD (ret_pages);LIST_HEAD (free_pages); +LIST_HEAD (demote_pages);unsigned nr_reclaimed =0 ;
Quoted 8 lines
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1280
Quoted 7 lines
mm/vmscan.c +2
-0memset (stat,0 ,sizeof (*stat));@@ -1262,6 +1276,22 @@ static unsigned long shrink_page_list(struct list_head *page_list, }/* +* Demote DRAM pages regardless the mempolicy. +* Demot anonymous pages only for now and skip MADV_FREE s/Demot/Demote
Thanks for catching this. Will fix.
Quoted 35 lines
Quoted 35 lines
mm/vmscan.c +27
-0+* pages. +*/ +if (PageAnon (page) && !PageSwapCache (page) && + (node_isset (page_to_nid (page), def_alloc_nodemask)) && +PageSwapBacked (page)) { + +if (has_nonram_online ()) { +list_add (&page->lru, &demote_pages); +unlock_page (page); +continue ; + } + } + +/* * Anonymous process memory has backing store? * Try to allocate it some swap space here. * Lazyfree page could be freed directly @@ -1477,6 +1507,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,VM_BUG_ON_PAGE (PageLRU (page) ||PageUnevictable (page), page); } +/* Demote pages to PMEM */ +if (!list_empty (&demote_pages)) { +int err, target_nid; +nodemask_t used_mask; + +nodes_clear (used_mask); + target_nid =find_next_best_node (pgdat->node_id, &used_mask, + true); + + err =migrate_pages (&demote_pages, alloc_new_node_page,NULL , + target_nid,MIGRATE_ASYNC ,MR_DEMOTE ); + +if (err) {
Quoted 8 lines
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1528
Quoted 6 lines
mm/vmscan.c +6
-0+putback_movable_pages (&demote_pages); + +list_splice (&ret_pages, &demote_pages); + } + } +I like your approach here. It reuses the existing
migrate_pages()interface without adding extra code. I also would like to be CC’d in your future versions.
Yes, sure.
Thanks,
Yang
Quoted 6 lines
Thank you.
--
Best Regards,
Yan Zi
Le 25/03/2019 à 20:29, Dan Williams a écrit :
Quoted 3 lines
Perhaps "path" might be a suitable replacement identifier rather than type. I.e. memory that originates from an ACPI.NFIT root device is likely "pmem".
Could work.
What kind of "path" would we get for other types of memory? (DDR, non-ACPI-based based PMEM if any, NVMe PMR?)
Thanks
Brice
Re: [PATCH 01/10] mm: control memory placement by nodemask for two tier main memory
In reply to Yang ShiQuoted 65 lines · Yang Shi
Quoted 45 lines · Dan Williams
Quoted 44 lines · Yang Shi
When running applications on the machine with NVDIMM as NUMA node, the memory allocation may end up on NVDIMM node. This may result in silent performance degradation and regression due to the difference of hardware property.
DRAM first should be obeyed to prevent from surprising regression. Any non-DRAM nodes should be excluded from default allocation. Use nodemask to control the memory placement. Introduce
def_alloc_nodemaskwhich has DRAM nodes set only. Any non-DRAM allocation should be specified by NUMA policy explicitly.In the future we may be able to extract the memory charasteristics from HMAT or other source to build up the default allocation nodemask. However, just distinguish DRAM and PMEM (non-DRAM) nodes by SRAT flag for the time being.
Signed-off-by Yang Shi <[email protected]>--- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 ++++++++ include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)arch/x86/mm/numa.c +1
-0@@ -626,6 +626,7 @@ static int __init numa_init(int (*init_func)(void))nodes_clear (numa_nodes_parsed);nodes_clear (node_possible_map);nodes_clear (node_online_map); +nodes_clear (def_alloc_nodemask);memset (&numa_meminfo,0 ,sizeof (numa_meminfo));WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory,MAX_NUMNODES ));drivers/acpi/numa.c +0
-0@@ -296,6 +296,14 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) goto out_err_bad_srat; }Quoted 11 lines
drivers/acpi/numa.c void __init acpi_numa_slit_init(struct acpi_table_slit *slit) · line 305
Quoted 7 lines
drivers/acpi/numa.c +7
-0+/* +* Non volatile memory is excluded from zonelist by default. +* Only regular DRAM nodes are set in default allocation node +* mask. +*/ +if (!(ma->flags &ACPI_SRAT_MEM_NON_VOLATILE )) +node_set (node, def_alloc_nodemask);Hmm, no, I don't think we should do this. Especially considering current generation NVDIMMs are energy backed DRAM there is no performance difference that should be assumed by the non-volatile flag.
Actually, here I would like to initialize a node mask for default allocation. Memory allocation should not end up on any nodes excluded by this node mask unless they are specified by mempolicy.
Quoted 8 lines
We may have a few different ways or criteria to initialize the node mask, for example, we can read from HMAT (when HMAT is ready in the future), and we definitely could have non-DRAM nodes set if they have no performance difference (I'm supposed you mean NVDIMM-F or HBM).
As long as there are different tiers, distinguished by performance, for main memory, IMHO, there should be a defined default allocation node mask to control the memory placement no matter where we get the information.
I understand the intent, but I don't think the kernel should have such a hardline policy by default. However, it would be worthwhile mechanism and policy to consider for the dax-hotplug userspace tooling. I.e. arrange for a given device-dax instance to be onlined, but set the policy to require explicit opt-in by numa binding for it to be an allocation / migration option.
I added Vishal to the cc who is looking into such policy tooling.
Quoted 10 lines
But, for now we haven't had such information ready for such use yet, so the SRAT flag might be a choice.
Quoted 3 lines
Why isn't default SLIT distance sufficient for ensuring a DRAM-first default policy?
"DRAM-first" may sound ambiguous, actually I mean "DRAM only by default". SLIT should just can tell us what node is local what node is remote, but can't tell us the performance difference.
I think it's a useful semantic, but let's leave the selection of that policy to an explicit userspace decision.
Re: [PATCH 01/10] mm: control memory placement by nodemask for two tier main memory
Quoted 72 lines · Dan Williams
Quoted 63 lines · Yang Shi
Quoted 45 lines · Dan Williams
Quoted 44 lines · Yang Shi
When running applications on the machine with NVDIMM as NUMA node, the memory allocation may end up on NVDIMM node. This may result in silent performance degradation and regression due to the difference of hardware property.
DRAM first should be obeyed to prevent from surprising regression. Any non-DRAM nodes should be excluded from default allocation. Use nodemask to control the memory placement. Introduce
def_alloc_nodemaskwhich has DRAM nodes set only. Any non-DRAM allocation should be specified by NUMA policy explicitly.In the future we may be able to extract the memory charasteristics from HMAT or other source to build up the default allocation nodemask. However, just distinguish DRAM and PMEM (non-DRAM) nodes by SRAT flag for the time being.
Signed-off-by Yang Shi <[email protected]>--- arch/x86/mm/numa.c | 1 + drivers/acpi/numa.c | 8 ++++++++ include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)arch/x86/mm/numa.c +1
-0@@ -626,6 +626,7 @@ static int __init numa_init(int (*init_func)(void))nodes_clear (numa_nodes_parsed);nodes_clear (node_possible_map);nodes_clear (node_online_map); +nodes_clear (def_alloc_nodemask);memset (&numa_meminfo,0 ,sizeof (numa_meminfo));WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory,MAX_NUMNODES ));drivers/acpi/numa.c +0
-0@@ -296,6 +296,14 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit) goto out_err_bad_srat; }Quoted 11 lines
drivers/acpi/numa.c void __init acpi_numa_slit_init(struct acpi_table_slit *slit) · line 305
Quoted 7 lines
drivers/acpi/numa.c +7
-0+/* +* Non volatile memory is excluded from zonelist by default. +* Only regular DRAM nodes are set in default allocation node +* mask. +*/ +if (!(ma->flags &ACPI_SRAT_MEM_NON_VOLATILE )) +node_set (node, def_alloc_nodemask);Hmm, no, I don't think we should do this. Especially considering current generation NVDIMMs are energy backed DRAM there is no performance difference that should be assumed by the non-volatile flag.
Actually, here I would like to initialize a node mask for default allocation. Memory allocation should not end up on any nodes excluded by this node mask unless they are specified by mempolicy.
Quoted 8 lines
We may have a few different ways or criteria to initialize the node mask, for example, we can read from HMAT (when HMAT is ready in the future), and we definitely could have non-DRAM nodes set if they have no performance difference (I'm supposed you mean NVDIMM-F or HBM).
As long as there are different tiers, distinguished by performance, for main memory, IMHO, there should be a defined default allocation node mask to control the memory placement no matter where we get the information.
Quoted 8 lines
I understand the intent, but I don't think the kernel should have such a hardline policy by default. However, it would be worthwhile mechanism and policy to consider for the dax-hotplug userspace tooling. I.e. arrange for a given device-dax instance to be onlined, but set the policy to require explicit opt-in by numa binding for it to be an allocation / migration option.
I added Vishal to the cc who is looking into such policy tooling.
We may assume the nodes returned by cpu_to_node() would be treated as the default allocation nodes from the kernel point of view.
So, the below code may do the job:
arch/x86/mm/numa.c +0 -0
@@ -764,6 +764,8 @@ void __init init_cpu_to_node(void)
init_memory_less_node(node);
numa_set_node(cpu, node); +
+ node_set(node, def_alloc_nodemask); }
}
Actually, the kernel should not care too much what kind of memory is used, any node could be used for memory allocation. But it may be better to restrict to some default nodes due to the performance disparity, for example, default to regular DRAM only. Here kernel assumes the nodes associated with CPUs would be DRAM nodes.
The node mask could be exported to user space to be override by userspace tool or sysfs or kernel commandline. But I still think kernel does need a default node mask.
Quoted 11 lines
Quoted 9 lines
But, for now we haven't had such information ready for such use yet, so the SRAT flag might be a choice.
Quoted 2 lines
Why isn't default SLIT distance sufficient for ensuring a DRAM-first default policy?
"DRAM-first" may sound ambiguous, actually I mean "DRAM only by default". SLIT should just can tell us what node is local what node is remote, but can't tell us the performance difference.
I think it's a useful semantic, but let's leave the selection of that policy to an explicit userspace decision.
Yes, mempolicy is a kind of userspace decision too.
Thanks,
Yang
Quoted 8 lines · Brice Goglin
Quoted 3 lines · Dan Williams
Perhaps "path" might be a suitable replacement identifier rather than type. I.e. memory that originates from an ACPI.NFIT root device is likely "pmem".
Quoted 4 lines
Could work.
What kind of "path" would we get for other types of memory? (DDR, non-ACPI-based based PMEM if any, NVMe PMR?)
I think for memory that is described by the HMAT "Reservation hint", and no other ACPI table, it would need to have "HMAT" in the path. For anything not ACPI it gets easier because the path can be the parent PCI device.
Re: [PATCH 01/10] mm: control memory placement by nodemask for two tier main memory
In reply to Yang ShiOn Mon, Mar 25, 2019 at 4:36 PM Yang Shi <[email protected]> wrote:
[..]
Quoted 49 lines
Quoted 16 lines
Quoted 8 lines
Quoted 4 lines
Hmm, no, I don't think we should do this. Especially considering current generation NVDIMMs are energy backed DRAM there is no performance difference that should be assumed by the non-volatile flag.
Actually, here I would like to initialize a node mask for default allocation. Memory allocation should not end up on any nodes excluded by this node mask unless they are specified by mempolicy.
Quoted 8 lines
We may have a few different ways or criteria to initialize the node mask, for example, we can read from HMAT (when HMAT is ready in the future), and we definitely could have non-DRAM nodes set if they have no performance difference (I'm supposed you mean NVDIMM-F or HBM).
As long as there are different tiers, distinguished by performance, for main memory, IMHO, there should be a defined default allocation node mask to control the memory placement no matter where we get the information.
Quoted 8 lines
I understand the intent, but I don't think the kernel should have such a hardline policy by default. However, it would be worthwhile mechanism and policy to consider for the dax-hotplug userspace tooling. I.e. arrange for a given device-dax instance to be onlined, but set the policy to require explicit opt-in by numa binding for it to be an allocation / migration option.
I added Vishal to the cc who is looking into such policy tooling.
We may assume the nodes returned by
cpu_to_node()would be treated as the default allocation nodes from the kernel point of view.So, the below code may do the job:
arch/x86/mm/numa.c +2
-0@@ -764,6 +764,8 @@ void __init init_cpu_to_node(void)init_memory_less_node (node);numa_set_node (cpu, node); + +node_set (node, def_alloc_nodemask); } }Actually, the kernel should not care too much what kind of memory is used, any node could be used for memory allocation. But it may be better to restrict to some default nodes due to the performance disparity, for example, default to regular DRAM only. Here kernel assumes the nodes associated with CPUs would be DRAM nodes.
Quoted 2 lines
The node mask could be exported to user space to be override by userspace tool or sysfs or kernel commandline.
Yes, sounds good.
Quoted 1 line
But I still think kernel does need a default node mask.
Yes, just depends on what is less surprising for userspace to contend with by default. I would expect an unaware userspace to be confused by the fact that the system has free memory, but it's unusable. So, usable by default sounds a safer option, and special cases to forbid default usage of given nodes is an administrator / application opt-in mechanism.
Quoted 11 lines · On Mon, 25 Mar 2019 16:37:07 -0700 Dan Williams <[email protected]>…
Quoted 10 lines · Brice Goglin
Quoted 3 lines · Dan Williams
Perhaps "path" might be a suitable replacement identifier rather than type. I.e. memory that originates from an ACPI.NFIT root device is likely "pmem".
Could work.
Quoted 8 lines
Quoted 2 lines
What kind of "path" would we get for other types of memory? (DDR, non-ACPI-based based PMEM if any, NVMe PMR?)
I think for memory that is described by the HMAT "Reservation hint", and no other ACPI table, it would need to have "HMAT" in the path. For anything not ACPI it gets easier because the path can be the parent PCI device.
There is no HMAT reservation hint in ACPI 6.3 - but there are other ways of doing much the same thing so this is just a nitpick.
J
Michal Hocko
reviewerQuoted 15 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
Quoted 2 lines
5. Control memory allocation and hot/cold pages promotion/demotion on per VMA basis.
What does that mean? Anon vs. file backed memory?
[...]
Quoted 8 lines
2. Introduce a new mempolicy, called
MPOL_HYBRIDto keep other mempolicy semantics intact. We would like to have memory placement control on per process or even per VMA granularity. So, mempolicy sounds more reasonable than madvise. The new mempolicy is mainly used for launching processes on PMEM nodes then migrate hot pages to DRAM nodes via NUMA balancing.MPOL_BINDcould bind to PMEM nodes too, but migrating to DRAM nodes would just break the semantic of it.MPOL_PREFERREDcan't constraint the allocation to PMEM nodes. So, it sounds a new mempolicy is needed to fulfill the usecase.
The above restriction pushes you to invent an API which is not really trivial to get right and it seems quite artificial to me already.
Quoted 4 lines
3. The new mempolicy would promote pages to DRAM via NUMA balancing. IMHO, I don't think kernel is a good place to implement sophisticated hot/cold page distinguish algorithm due to the complexity and overhead. But, kernel should have such capability. NUMA balancing sounds like a good start point.
This is what the kernel does all the time. We call it memory reclaim.
Quoted 3 lines
4. Promote twice faulted page. Use
PG_promoteto track if a page is faulted twice. This is an optimization to NUMA balancing to reduce the migration thrashing and overhead for migrating from PMEM.
I am sorry, but page flags are an extremely scarce resource and a new flag is extremely hard to get. On the other hand we already do have use-twice detection for mapped page cache (see page_check_references). I believe we can generalize that to anon pages as well.
Quoted 5 lines
5. When DRAM has memory pressure, demote page to PMEM via page reclaim path. This is quite similar to other proposals. Then NUMA balancing will promote page to DRAM as long as the page is referenced again. But, the promotion/demotion still assumes two tier main memory. And, the demotion may break mempolicy.
Yes, this sounds like a good idea to me ;)
Quoted 2 lines
6. Anonymous page only for the time being since NUMA balancing can't promote unmapped page cache.
As long as the nvdimm access is faster than the regular storage then using any node (including pmem one) should be OK.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Quoted 4 lines
Quoted 3 lines
5. Control memory allocation and hot/cold pages promotion/demotion on per VMA basis.
What does that mean? Anon vs. file backed memory?
Yes, kind of. Basically, we would like to control the memory placement and promotion (by NUMA balancing) per VMA basis. For example, anon VMAs may be DRAM by default, file backed VMAs may be PMEM by default. Anyway, basically this is achieved freely by mempolicy.
Quoted 11 lines
[...]
Quoted 8 lines
2. Introduce a new mempolicy, called
MPOL_HYBRIDto keep other mempolicy semantics intact. We would like to have memory placement control on per process or even per VMA granularity. So, mempolicy sounds more reasonable than madvise. The new mempolicy is mainly used for launching processes on PMEM nodes then migrate hot pages to DRAM nodes via NUMA balancing.MPOL_BINDcould bind to PMEM nodes too, but migrating to DRAM nodes would just break the semantic of it.MPOL_PREFERREDcan't constraint the allocation to PMEM nodes. So, it sounds a new mempolicy is needed to fulfill the usecase.
Quoted 2 lines
The above restriction pushes you to invent an API which is not really trivial to get right and it seems quite artificial to me already.
First of all, the use case is some applications may be not that sensitive to memory access or are willing to achieve net win by trading some performance to save some cost (have some memory on PMEM). So, such applications may be bound to PMEM at the first place then promote hot pages to DRAM via NUMA balancing or whatever mechanism.
Both MPOL_BIND and MPOL_PREFERRED sounds not fit into this usecase quite naturally.
Secondly, it looks just default policy does NUMA balancing. Once the policy is changed to MPOL_BIND, NUMA balancing would not chime in.
So, I invented the new mempolicy.
Quoted 7 lines
Quoted 5 lines
3. The new mempolicy would promote pages to DRAM via NUMA balancing. IMHO, I don't think kernel is a good place to implement sophisticated hot/cold page distinguish algorithm due to the complexity and overhead. But, kernel should have such capability. NUMA balancing sounds like a good start point.
This is what the kernel does all the time. We call it memory reclaim.
Quoted 7 lines
Quoted 3 lines
4. Promote twice faulted page. Use
PG_promoteto track if a page is faulted twice. This is an optimization to NUMA balancing to reduce the migration thrashing and overhead for migrating from PMEM.I am sorry, but page flags are an extremely scarce resource and a new flag is extremely hard to get. On the other hand we already do have use-twice detection for mapped page cache (see
page_check_references). I believe we can generalize that to anon pages as well.
Yes, I agree. A new page flag sounds not preferred. I'm going to take a look at page_check_references().
Quoted 6 lines
Quoted 6 lines
5. When DRAM has memory pressure, demote page to PMEM via page reclaim path. This is quite similar to other proposals. Then NUMA balancing will promote page to DRAM as long as the page is referenced again. But, the promotion/demotion still assumes two tier main memory. And, the demotion may break mempolicy.
Quoted 6 lines
Yes, this sounds like a good idea to me ;)
Quoted 2 lines
6. Anonymous page only for the time being since NUMA balancing can't promote unmapped page cache.
As long as the nvdimm access is faster than the regular storage then using any node (including pmem one) should be OK.
However, it still sounds better to have some frequently accessed page cache on DRAM.
Thanks,
Yang
Michal Hocko
reviewerQuoted 40 lines · Yang Shi
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
Quoted 3 lines
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Again, how is this different from NUMA in general?
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Yang ShiQuoted 9 lines · Yang Shi
Quoted 2 lines · Keith Busch
How do these pages eventually get to swap when migration fails? Looks like that's skipped.
Yes, they will be just put back to LRU. Actually, I don't expect it would be very often to have migration fail at this stage (but I have no test data to support this hypothesis) since the pages have been isolated from LRU, so other reclaim path should not find them anymore.
Quoted 4 lines
If it is locked by someone else right before migration, it is likely referenced again, so putting back to LRU sounds not bad.
A potential improvement is to have sync migration for kswapd.
Well, it's not that migration fails only if the page is recently referenced. Migration would fail if there isn't available memory in the migration node, so this implementation carries an expectation that migration nodes have higher free capacity than source nodes. And since your attempting THP's without ever splitting them, that also requires lower fragmentation for a successful migration.
Applications, however, may allocate and pin pages directly out of that migration node to the point it does not have so much free capacity or physical continuity, so we probably shouldn't assume it's the only way to reclaim pages.
Quoted 39 lines · Michal Hocko
Quoted 38 lines · Yang Shi
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
Quoted 4 lines
Quoted 3 lines
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Again, how is this different from NUMA in general?
It is still NUMA, users still can see all the NUMA nodes.
Introduced default allocation node mask (please refer to patch #1) to control the memory placement. Typically, the node mask just includes DRAM nodes. PMEM nodes are excluded by the node mask for memory allocation.
The node mask could be override by user per the discussion with Dan.
Thanks,
Yang
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Keith BuschQuoted 12 lines · Keith Busch
Quoted 11 lines · Yang Shi
Quoted 2 lines · Keith Busch
How do these pages eventually get to swap when migration fails? Looks like that's skipped.
Yes, they will be just put back to LRU. Actually, I don't expect it would be very often to have migration fail at this stage (but I have no test data to support this hypothesis) since the pages have been isolated from LRU, so other reclaim path should not find them anymore.
If it is locked by someone else right before migration, it is likely referenced again, so putting back to LRU sounds not bad.
Quoted 7 lines
Quoted 1 line
A potential improvement is to have sync migration for kswapd.
Well, it's not that migration fails only if the page is recently referenced. Migration would fail if there isn't available memory in the migration node, so this implementation carries an expectation that migration nodes have higher free capacity than source nodes. And since your attempting THP's without ever splitting them, that also requires lower fragmentation for a successful migration.
Yes, it is possible. However, migrate_pages() already has logic to handle such case. If the target node has not enough space for migrating THP in a whole, it would split THP then retry with base pages.
Swapping THP has been optimized to swap in a whole too. It would try to add THP into swap cache in a whole, split THP if the attempt fails, then add base pages into swap cache.
So, I think we can leave this to migrate_pages() without splitting in advance all the time.
Thanks,
Yang
Quoted 5 lines
Applications, however, may allocate and pin pages directly out of that migration node to the point it does not have so much free capacity or physical continuity, so we probably shouldn't assume it's the only way to reclaim pages.
Michal Hocko
reviewerQuoted 42 lines · Yang Shi
Quoted 39 lines · Michal Hocko
Quoted 38 lines · Yang Shi
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Again, how is this different from NUMA in general?
It is still NUMA, users still can see all the NUMA nodes.
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Yang ShiQuoted 8 lines · Yang Shi
Quoted 3 lines · Keith Busch
migration nodes have higher free capacity than source nodes. And since your attempting THP's without ever splitting them, that also requires lower fragmentation for a successful migration.
Yes, it is possible. However,
migrate_pages()already has logic to handle such case. If the target node has not enough space for migrating THP in a whole, it would split THP then retry with base pages.
Oh, you're right, my mistake on splitting. So you have a good best effort migrate, but I still think it can fail for legitimate reasons that should have a swap fallback.
Zi Yan
reviewerRe: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
Quoted 6 lines · Keith Busch
Quoted 5 lines · Yang Shi
Quoted 3 lines · Keith Busch
migration nodes have higher free capacity than source nodes. And since your attempting THP's without ever splitting them, that also requires lower fragmentation for a successful migration.
Quoted 7 lines
Quoted 3 lines
Yes, it is possible. However,
migrate_pages()already has logic to handle such case. If the target node has not enough space for migrating THP in a whole, it would split THP then retry with base pages.Oh, you're right, my mistake on splitting. So you have a good best effort migrate, but I still think it can fail for legitimate reasons that should have a swap fallback.
Does this mean we might want to factor out the page reclaim code in shrink_page_list() and call it for each page, which fails to migrate to PMEM. Or do you still prefer to migrate one page at a time, like what you did in your patch?
I ask this because I observe that migrating a list of pages can achieve higher throughput compared to migrating individual page. For example, migrating 512 4KB pages can achieve ~750MB/s throughput, whereas migrating one 4KB page might only achieve ~40MB/s throughput. The experiments were done on a two-socket machine with two Xeon E5-2650 v3 @ 2.30GHz across the QPI link.
--
Best Regards,
Yan Zi
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
Quoted 6 lines · Zi Yan
I ask this because I observe that migrating a list of pages can achieve higher throughput compared to migrating individual page. For example, migrating 512 4KB pages can achieve ~750MB/s throughput, whereas migrating one 4KB page might only achieve ~40MB/s throughput. The experiments were done on a two-socket machine with two Xeon E5-2650 v3 @ 2.30GHz across the QPI link.
What kind of migration?
If you're talking about doing sys_migrate_pages() one page at a time, that's a world away from doing something inside of the kernel one page at a time.
Quoted 47 lines · Michal Hocko
Quoted 45 lines · Yang Shi
Quoted 42 lines · Michal Hocko
Quoted 41 lines · Yang Shi
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Again, how is this different from NUMA in general?
It is still NUMA, users still can see all the NUMA nodes.
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
Zi Yan
reviewerRe: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Dave HansenQuoted 8 lines · Dave Hansen
Quoted 6 lines · Zi Yan
I ask this because I observe that migrating a list of pages can achieve higher throughput compared to migrating individual page. For example, migrating 512 4KB pages can achieve ~750MB/s throughput, whereas migrating one 4KB page might only achieve ~40MB/s throughput. The experiments were done on a two-socket machine with two Xeon E5-2650 v3 @ 2.30GHz across the QPI link.
Quoted 5 lines
What kind of migration?
If you're talking about doing
sys_migrate_pages()one page at a time, that's a world away from doing something inside of the kernel one page at a time.
For 40MB/s vs 750MB/s, they were using sys_migrate_pages(). Sorry about the confusion there. As I measure only the migrate_pages() in the kernel, the throughput becomes:
migrating 4KB page: 0.312GB/s vs migrating 512 4KB pages: 0.854GB/s. They are still >2x difference.
Furthermore, if we only consider the migrate_page_copy() in mm/migrate.c, which only calls copy_highpage() and migrate_page_states(), the throughput becomes:
migrating 4KB page: 1.385GB/s vs migrating 512 4KB pages: 1.983GB/s. The gap is smaller, but migrating 512 4KB pages still achieves 40% more throughput.
Do these numbers make sense to you?
--
Best Regards,
Yan Zi
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
Quoted 6 lines · Zi Yan
For 40MB/s vs 750MB/s, they were using
sys_migrate_pages(). Sorry about the confusion there. As I measure only themigrate_pages()in the kernel, the throughput becomes: migrating 4KB page: 0.312GB/s vs migrating 512 4KB pages: 0.854GB/s. They are still >2x difference.
Quoted 8 lines
Furthermore, if we only consider the
migrate_page_copy()inmm/migrate.c, which only callscopy_highpage()andmigrate_page_states(), the throughput becomes: migrating 4KB page:
1.385GB/s vs migrating 512 4KB pages: 1.983GB/s. The gap is smaller, but migrating 512 4KB pages still achieves 40% more throughput.Do these numbers make sense to you?
Yes. It would be very interesting to batch the migrations in the kernel and see how it affects the code. A 50% boost is interesting, but not if it's only in microbenchmarks and takes 2k lines of code.
50% is *very* interesting if it happens in the real world and we can do it in 10 lines of code.
So, let's see what the code looks like.
Quoted 47 lines · Dan Williams
Quoted 46 lines · Michal Hocko
Quoted 45 lines · Yang Shi
Quoted 38 lines · Michal Hocko
Quoted 37 lines · Yang Shi
Quoted 22 lines · Michal Hocko
Quoted 14 lines · Yang Shi
With Dave Hansen's patches merged into Linus's tree
PMEM could be hot plugged as NUMA node now. But, how to use PMEM as NUMA node effectively and efficiently is still a question.
There have been a couple of proposals posted on the mailing list [1] [2].
The patchset is aimed to try a different approach from this proposal [1] to use PMEM as NUMA nodes.
The approach is designed to follow the below principles:
Quoted 7 lines
1. Use PMEM as normal NUMA node, no special gfp flag, zone, zonelist, etc.
2. DRAM first/by default. No surprise to existing applications and default running. PMEM will not be allocated unless its node is specified explicitly by NUMA policy. Some applications may be not very sensitive to memory latency, so they could be placed on PMEM nodes then have hot pages promote to DRAM gradually.
Quoted 7 lines
Why are you pushing yourself into the corner right at the beginning? If the PMEM is exported as a regular NUMA node then the only difference should be performance characteristics (module durability which shouldn't play any role in this particular case, right?). Applications which are already sensitive to memory access should better use proper binding already. Some NUMA topologies might have quite a large interconnect penalties already. So this doesn't sound like an argument to me, TBH.
The major rationale behind this is we assume the most applications should be sensitive to memory access, particularly for meeting the SLA. The applications run on the machine may be agnostic to us, they may be sensitive or non-sensitive. But, assuming they are sensitive to memory access sounds safer from SLA point of view. Then the "cold" pages could be demoted to PMEM nodes by kernel's memory reclaim or other tools without impairing the SLA.
Quoted 4 lines
Quoted 3 lines
If the applications are not sensitive to memory access, they could be bound to PMEM or allowed to use PMEM (nice to have allocation on DRAM) explicitly, then the "hot" pages could be promoted to DRAM.
Again, how is this different from NUMA in general?
It is still NUMA, users still can see all the NUMA nodes.
Quoted 8 lines
Quoted 4 lines
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
In ideal case, yes, I agree. However, in real life world the performance is a concern. It is well-known that PMEM (not considering NVDIMM-F or HBM) has higher latency and lower bandwidth. We observed much higher latency on PMEM than DRAM with multi threads.
In real production environment we don't know what kind of applications would end up on PMEM (DRAM may be full, allocation fall back to PMEM) then have unexpected performance degradation. I understand to have mempolicy to choose to avoid it. But, there might be hundreds or thousands of applications running on the machine, it sounds not that feasible to me to have each single application set mempolicy to avoid it.
So, I think we still need a default allocation node mask. The default value may include all nodes or just DRAM nodes. But, they should be able to be override by user globally, not only per process basis.
Due to the performance disparity, currently our usecases treat PMEM as second tier memory for demoting cold page or binding to not memory access sensitive applications (this is the reason for inventing a new mempolicy) although it is a NUMA node.
Thanks,
Yang
Michal Hocko
reviewerQuoted 5 lines · Yang Shi
Quoted 2 lines · Dan Williams
Quoted 1 line · Michal Hocko
On Tue 26-03-19 19:58:56, Yang Shi wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
It is still NUMA, users still can see all the NUMA nodes.
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
Quoted 4 lines
In ideal case, yes, I agree. However, in real life world the performance is a concern. It is well-known that PMEM (not considering NVDIMM-F or HBM) has higher latency and lower bandwidth. We observed much higher latency on PMEM than DRAM with multi threads.
One rule of thumb is: Do not design user visible interfaces based on the contemporary technology and its up/down sides. This will almost always fire back.
Btw. if you keep arguing about performance without any numbers. Can you present something specific?
Quoted 6 lines
In real production environment we don't know what kind of applications would end up on PMEM (DRAM may be full, allocation fall back to PMEM) then have unexpected performance degradation. I understand to have mempolicy to choose to avoid it. But, there might be hundreds or thousands of applications running on the machine, it sounds not that feasible to me to have each single application set mempolicy to avoid it.
we have cpuset cgroup controller to help here.
Quoted 8 lines
So, I think we still need a default allocation node mask. The default value may include all nodes or just DRAM nodes. But, they should be able to be override by user globally, not only per process basis.
Due to the performance disparity, currently our usecases treat PMEM as second tier memory for demoting cold page or binding to not memory access sensitive applications (this is the reason for inventing a new mempolicy) although it is a NUMA node.
If the performance sucks that badly then do not use the pmem as NUMA, really. There are certainly other ways to export the pmem storage. Use it as a fast swap storage. Or try to work on a swap caching mechanism that still allows much faster access than a slow swap storage. But do not try to pretend to abuse the NUMA interface while you are breaking some of its long term established semantics.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 6 lines · Yang Shi
In real production environment we don't know what kind of applications would end up on PMEM (DRAM may be full, allocation fall back to PMEM) then have unexpected performance degradation. I understand to have mempolicy to choose to avoid it. But, there might be hundreds or thousands of applications running on the machine, it sounds not that feasible to me to have each single application set mempolicy to avoid it.
Maybe not manually, but it's entirely possible to automate this.
It would be trivial to get help from an orchestrator, or even systemd to get apps launched with a particular policy. Or, even a *shell* that launches apps to have a particular policy.
Quoted 10 lines · Dan Williams
Quoted 4 lines · Michal Hocko
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
I think this is sort of true, but sort of different. These are essentially CPU-less nodes; there is no CPU for which they are fast memory. Yes, they're further from some CPUs than from others. I have never paid attention to how Linux treats CPU-less memory nodes, but it would make sense to me if we don't default to allocating from remote nodes. And treating pmem nodes as being remote from all CPUs makes a certain amount of sense to me.
eg on a four CPU-socket system, consider this as being
pmem1 --- node1 --- node2 --- pmem2
| \ / |
| X |
| / \ |pmem3 --- node3 --- node4 --- pmem4
which I could actually see someone building with normal DRAM, and we should probably handle the same way as pmem; for a process running on node3, allocate preferentially from node3, then pmem3, then other nodes, then other pmems.
Zi Yan
reviewerRe: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Dave HansenQuoted 16 lines · Dave Hansen
Quoted 6 lines · Zi Yan
For 40MB/s vs 750MB/s, they were using
sys_migrate_pages(). Sorry about the confusion there. As I measure only themigrate_pages()in the kernel, the throughput becomes: migrating 4KB page: 0.312GB/s vs migrating 512 4KB pages: 0.854GB/s. They are still >2x difference.Quoted 8 lines
Furthermore, if we only consider the
migrate_page_copy()inmm/migrate.c, which only callscopy_highpage()andmigrate_page_states(), the throughput becomes: migrating 4KB page:
1.385GB/s vs migrating 512 4KB pages: 1.983GB/s. The gap is smaller, but migrating 512 4KB pages still achieves 40% more throughput.Do these numbers make sense to you?
Quoted 8 lines
Yes. It would be very interesting to batch the migrations in the kernel and see how it affects the code. A 50% boost is interesting, but not if it's only in microbenchmarks and takes 2k lines of code.
50% is *very* interesting if it happens in the real world and we can do it in 10 lines of code.
So, let's see what the code looks like.
Actually, the migration throughput difference does not come from any kernel changes, it is a pure comparison between migrate_pages(single 4KB page) and migrate_pages(a list of 4KB pages). The point I wanted to make is that Yang’s approach, which migrates a list of pages at the end of shrink_page_list(), can achieve higher throughput than Keith’s approach, which migrates one page at a time in the while loop inside shrink_page_list().
In addition to the above, migrating a single THP can get us even higher throughput. Here is the throughput numbers comparing all three cases:
| migrate_page() | migrate_page_copy() migrating single 4KB page: | 0.312GB/s | 1.385GB/s migrating 512 4KB pages: | 0.854GB/s | 1.983GB/s migrating single 2MB THP: | 2.387GB/s | 2.481GB/s
Obviously, we would like to migrate THPs as a whole instead of 512 4KB pages individually. Of course, this assumes we have free space in PMEM for THPs and all subpages in the THPs are cold.
To batch the migration, I posted some code a while ago: https://lwn.net/Articles/714991/,
which show good throughput improvement for microbenchmarking sys_migrate_page(). It also included using multi threads to copy a page, aggregate multiple migrate_page_copy(), and even using DMA instead of CPUs to copy data. We could revisit the code if necessary.
In terms of end-to-end results, I also have some results from my paper:
http://www.cs.yale.edu/homes/abhishek/ziyan-asplos19.pdf (Figure 8 to Figure 11 show the microbenchmark result and Figure 12 shows end-to-end results). I basically called shrink_active/inactive_list() every 5 seconds to track page hotness and used all my page migration optimizations above, which can get 40% application runtime speedup on average. The experiments were done in a two-socket NUMA machine where one node was slowed down to have 1/2 BW and 2x access latency, compared to the other node. I can discuss about it more if you are interested.
--
Best Regards,
Yan Zi
Quoted 11 lines · Matthew Wilcox
pmem1 --- node1 --- node2 --- pmem2
| \ / | | X | | / \ |pmem3 --- node3 --- node4 --- pmem4
which I could actually see someone building with normal DRAM, and we should probably handle the same way as pmem; for a process running on node3, allocate preferentially from node3, then pmem3, then other nodes, then other pmems.
That makes sense. But, it might _also_ make sense to fill up all DRAM first before using any pmem. That could happen if the NUMA interconnect is really fast and pmem is really slow.
Basically, with the current patches we are depending on the firmware to "nicely" enumerate the topology and we're keeping the behavior that we end up with, for now, whatever it might be.
Now, let's sit back and see how nice the firmware is. :)
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Zi YanQuoted 7 lines · Zi Yan
Actually, the migration throughput difference does not come from any kernel changes, it is a pure comparison between
migrate_pages(single 4KB page)andmigrate_pages(a list of 4KB pages). The point I wanted to make is that Yang’s approach, which migrates a list of pages at the end ofshrink_page_list(), can achieve higher throughput than Keith’s approach, which migrates one page at a time in the while loop insideshrink_page_list().
I look forward to seeing the patches.
Quoted 15 lines · Michal Hocko
Quoted 4 lines · Yang Shi
Quoted 2 lines · Dan Williams
Quoted 1 line · Michal Hocko
On Tue 26-03-19 19:58:56, Yang Shi wrote:
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
It is still NUMA, users still can see all the NUMA nodes.
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
Quoted 7 lines
Quoted 4 lines
In ideal case, yes, I agree. However, in real life world the performance is a concern. It is well-known that PMEM (not considering NVDIMM-F or HBM) has higher latency and lower bandwidth. We observed much higher latency on PMEM than DRAM with multi threads.
One rule of thumb is: Do not design user visible interfaces based on the contemporary technology and its up/down sides. This will almost always fire back.
Thanks. It does make sense to me.
Quoted 3 lines
Btw. if you keep arguing about performance without any numbers. Can you present something specific?
Yes, I did have some numbers. We did simple memory sequential rw latency test with a designed-in-house test program on PMEM (bind to PMEM) and DRAM (bind to DRAM). When running with 20 threads the result is as below:
Threads w/lat r/lat PMEM 20 537.15 68.06 DRAM 20 14.19 6.47
And, sysbench test with command: sysbench --time=600 memory --memory-block-size=8G --memory-total-size=1024T --memory-scope=global --memory-oper=read --memory-access-mode=rnd --rand-type=gaussian --rand-pareto-h=0.1 --threads=1 run
The result is:
lat/ms
PMEM 103766.09
DRAM 31946.30
Quoted 17 lines
Quoted 7 lines
In real production environment we don't know what kind of applications would end up on PMEM (DRAM may be full, allocation fall back to PMEM) then have unexpected performance degradation. I understand to have mempolicy to choose to avoid it. But, there might be hundreds or thousands of applications running on the machine, it sounds not that feasible to me to have each single application set mempolicy to avoid it.
we have cpuset cgroup controller to help here.
Quoted 8 lines
So, I think we still need a default allocation node mask. The default value may include all nodes or just DRAM nodes. But, they should be able to be override by user globally, not only per process basis.
Due to the performance disparity, currently our usecases treat PMEM as second tier memory for demoting cold page or binding to not memory access sensitive applications (this is the reason for inventing a new mempolicy) although it is a NUMA node.
Quoted 6 lines
If the performance sucks that badly then do not use the pmem as NUMA, really. There are certainly other ways to export the pmem storage. Use it as a fast swap storage. Or try to work on a swap caching mechanism that still allows much faster access than a slow swap storage. But do not try to pretend to abuse the NUMA interface while you are breaking some of its long term established semantics.
Yes, we are looking into using it as a fast swap storage too and perhaps other usecases.
Anyway, though nobody thought it makes sense to restrict default allocation nodes, it sounds over-engineered. I'm going to drop it.
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Thanks,
Yang
Michal Hocko
reviewerQuoted 4 lines · Yang Shi
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Do we really have to special case this for PMEM? Why cannot we simply go in the zonelist order? In other words why cannot we use the same logic for a larger NUMA machine and instead of swapping simply fallback to a less contended NUMA node? It can be a regular DRAM, PMEM or whatever other type of memory node.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 75 lines · Yang Shi
Quoted 15 lines · Michal Hocko
Quoted 4 lines · Yang Shi
Quoted 2 lines · Dan Williams
Quoted 1 line · Michal Hocko
On Tue 26-03-19 19:58:56, Yang Shi wrote:
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
It is still NUMA, users still can see all the NUMA nodes.
No, Linux NUMA implementation makes all numa nodes available by default and provides an API to opt-in for more fine tuning. What you are suggesting goes against that semantic and I am asking why. How is pmem NUMA node any different from any any other distant node in principle?
Agree. It's just another NUMA node and shouldn't be special cased. Userspace policy can choose to avoid it, but typical node distance preference should otherwise let the kernel fall back to it as additional memory pressure relief for "near" memory.
Quoted 7 lines
Quoted 4 lines
In ideal case, yes, I agree. However, in real life world the performance is a concern. It is well-known that PMEM (not considering NVDIMM-F or HBM) has higher latency and lower bandwidth. We observed much higher latency on PMEM than DRAM with multi threads.
One rule of thumb is: Do not design user visible interfaces based on the contemporary technology and its up/down sides. This will almost always fire back.
Thanks. It does make sense to me.
Quoted 3 lines
Btw. if you keep arguing about performance without any numbers. Can you present something specific?
Yes, I did have some numbers. We did simple memory sequential rw latency test with a designed-in-house test program on PMEM (bind to PMEM) and DRAM (bind to DRAM). When running with 20 threads the result is as below:
Threads w/lat r/lat
PMEM 20 537.15 68.06 DRAM 20 14.19 6.47And, sysbench test with command: sysbench --time=600 memory --memory-block-size=8G --memory-total-size=1024T --memory-scope=global --memory-oper=read --memory-access-mode=rnd --rand-type=gaussian --rand-pareto-h=0.1 --threads=1 run
The result is:
lat/ms
PMEM 103766.09
DRAM 31946.30Quoted 17 lines
Quoted 7 lines
In real production environment we don't know what kind of applications would end up on PMEM (DRAM may be full, allocation fall back to PMEM) then have unexpected performance degradation. I understand to have mempolicy to choose to avoid it. But, there might be hundreds or thousands of applications running on the machine, it sounds not that feasible to me to have each single application set mempolicy to avoid it.
we have cpuset cgroup controller to help here.
Quoted 8 lines
So, I think we still need a default allocation node mask. The default value may include all nodes or just DRAM nodes. But, they should be able to be override by user globally, not only per process basis.
Due to the performance disparity, currently our usecases treat PMEM as second tier memory for demoting cold page or binding to not memory access sensitive applications (this is the reason for inventing a new mempolicy) although it is a NUMA node.
Quoted 6 lines
If the performance sucks that badly then do not use the pmem as NUMA, really. There are certainly other ways to export the pmem storage. Use it as a fast swap storage. Or try to work on a swap caching mechanism that still allows much faster access than a slow swap storage. But do not try to pretend to abuse the NUMA interface while you are breaking some of its long term established semantics.
Yes, we are looking into using it as a fast swap storage too and perhaps other usecases.
Quoted 7 lines
Anyway, though nobody thought it makes sense to restrict default allocation nodes, it sounds over-engineered. I'm going to drop it.
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
For ACPI platforms the HMAT is effectively going to enforce "cpu-less" nodes for any memory range that has differentiated performance from the conventional memory pool, or differentiated performance for a specific initiator. So "memory-less == PMEM" is not a robust assumption.
The plan is to use the HMAT to populate the default fallback order, but allow for an override if the HMAT information is missing or incorrect.
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Yang Shi
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Do we really have to special case this for PMEM? Why cannot we simply go in the zonelist order? In other words why cannot we use the same logic for a larger NUMA machine and instead of swapping simply fallback to a less contended NUMA node? It can be a regular DRAM, PMEM or whatever other type of memory node.
Thanks for the suggestion. It makes sense. However, if we don't specialize a pmem node, its fallback node may be a DRAM node, then the memory reclaim may move the inactive page to the DRAM node, it sounds not make too much sense since memory reclaim would prefer to move downwards (DRAM -> PMEM -> Disk).
Yang
Michal Hocko
reviewerQuoted 14 lines · Yang Shi
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Yang Shi
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Do we really have to special case this for PMEM? Why cannot we simply go in the zonelist order? In other words why cannot we use the same logic for a larger NUMA machine and instead of swapping simply fallback to a less contended NUMA node? It can be a regular DRAM, PMEM or whatever other type of memory node.
Quoted 4 lines
Thanks for the suggestion. It makes sense. However, if we don't specialize a pmem node, its fallback node may be a DRAM node, then the memory reclaim may move the inactive page to the DRAM node, it sounds not make too much sense since memory reclaim would prefer to move downwards (DRAM -> PMEM -> Disk).
There are certainly many details to sort out. One thing is how to handle cpuless nodes (e.g. PMEM). Those shouldn't get any direct allocations without an explicit binding, right? My first naive idea would be to only migrate-on-reclaim only from the preferred node. We might need additional heuristics but I wouldn't special case PMEM from other cpuless NUMA nodes.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Yang Shi
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Yang Shi
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Do we really have to special case this for PMEM? Why cannot we simply go in the zonelist order? In other words why cannot we use the same logic for a larger NUMA machine and instead of swapping simply fallback to a less contended NUMA node? It can be a regular DRAM, PMEM or whatever other type of memory node.
Quoted 7 lines
Quoted 4 lines
Thanks for the suggestion. It makes sense. However, if we don't specialize a pmem node, its fallback node may be a DRAM node, then the memory reclaim may move the inactive page to the DRAM node, it sounds not make too much sense since memory reclaim would prefer to move downwards (DRAM -> PMEM -> Disk).
There are certainly many details to sort out. One thing is how to handle cpuless nodes (e.g. PMEM). Those shouldn't get any direct allocations without an explicit binding, right? My first naive idea would be to only
Wait a minute. I thought we were arguing about the default allocation node mask yesterday. And, the conclusion is PMEM node should not be excluded from the node mask. PMEM nodes are cpuless nodes. I think I should replace all "PMEM node" to "cpuless node" in the cover letter and commit logs to make it explicitly.
Quoted from Dan "For ACPI platforms the HMAT is effectively going to enforce "cpu-less" nodes for any memory range that has differentiated performance from the conventional memory pool, or differentiated performance for a specific initiator."
I apologize I didn't elaborate PMEM nodes are cpuless nodes at the first place. Of course, cpuless node may be not PMEM node.
To your question, yes, I do agree. Actually, this is what I mean about "DRAM only by default", or I should rephrase it to "exclude cpuless node", I thought they mean the same thing.
Quoted 1 line
migrate-on-reclaim only from the preferred node. We might need
If we exclude cpuless nodes, yes. The preferred node would be DRAM node only. Actually, the patchset does follow "migrate-on-reclaim only from the preferred node".
Thanks,
Yang
Quoted 2 lines
additional heuristics but I wouldn't special case PMEM from other cpuless NUMA nodes.
Michal Hocko
reviewerQuoted 24 lines · Yang Shi
Quoted 13 lines · Michal Hocko
Quoted 12 lines · Yang Shi
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Yang Shi
One question, when doing demote and promote we need define a path, for example, DRAM <-> PMEM (assume two tier memory). When determining what nodes are "DRAM" nodes, does it make sense to assume the nodes with both cpu and memory are DRAM nodes since PMEM nodes are typically cpuless nodes?
Do we really have to special case this for PMEM? Why cannot we simply go in the zonelist order? In other words why cannot we use the same logic for a larger NUMA machine and instead of swapping simply fallback to a less contended NUMA node? It can be a regular DRAM, PMEM or whatever other type of memory node.
Quoted 7 lines
Quoted 4 lines
Thanks for the suggestion. It makes sense. However, if we don't specialize a pmem node, its fallback node may be a DRAM node, then the memory reclaim may move the inactive page to the DRAM node, it sounds not make too much sense since memory reclaim would prefer to move downwards (DRAM -> PMEM -> Disk).
There are certainly many details to sort out. One thing is how to handle cpuless nodes (e.g. PMEM). Those shouldn't get any direct allocations without an explicit binding, right? My first naive idea would be to only
Quoted 5 lines
Wait a minute. I thought we were arguing about the default allocation node mask yesterday. And, the conclusion is PMEM node should not be excluded from the node mask. PMEM nodes are cpuless nodes. I think I should replace all "PMEM node" to "cpuless node" in the cover letter and commit logs to make it explicitly.
No, this is not about the default allocation mask at all. Your allocations start from a local/mempolicy node. CPUless nodes thus cannot be a primary node so it will always be only in a fallback zonelist without an explicit binding.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
In reply to Keith BuschQuoted 11 lines · Keith Busch
Quoted 7 lines · Yang Shi
Quoted 3 lines · Keith Busch
migration nodes have higher free capacity than source nodes. And since your attempting THP's without ever splitting them, that also requires lower fragmentation for a successful migration.
Yes, it is possible. However,
migrate_pages()already has logic to handle such case. If the target node has not enough space for migrating THP in a whole, it would split THP then retry with base pages.Oh, you're right, my mistake on splitting. So you have a good best effort migrate, but I still think it can fail for legitimate reasons that should have a swap fallback.
Yes, it still could fail. I can't tell which way is better for now. I just thought scanning another round then migrating should be still faster than swapping off the top of my head.
Thanks,
Yang
Re: [PATCH 06/10] mm: vmscan: demote anon DRAM pages to PMEM node
Quoted 3 lines · Yang Shi
Yes, it still could fail. I can't tell which way is better for now. I just thought scanning another round then migrating should be still faster than swapping off the top of my head.
I think it depends on the relative capacities between your primary and migration tiers and how it's used. Applications may allocate and pin directly out of pmem if they wish, so it's not a dedicated fallback memory space like swap.
kbuild test robot
build botRe: [PATCH 04/10] mm: numa: promote pages to DRAM when it is accessed twice
In reply to Yang ShiThank you for the patch! Yet something to improve:
Hi Yang,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.1-rc2 next-20190328]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Yang-Shi/Another-Approach-to-Use-PMEM-as-NUMA-Node/20190326-034920
config: i386-randconfig-x076-201912 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
In file included from include/linux/memcontrol.h:29:0,
from include/linux/swap.h:9,
from include/linux/suspend.h:5,
from arch/x86/kernel/asm-offsets.c:13:
>> include/linux/mm.h:862:2: error: #error SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS #error SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
^~~~~
make[2]: *** [arch/x86/kernel/asm-offsets.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [sub-make] Error 2
vim +862 include/linux/mm.h
348f8b6c4 Dave Hansen 2005-06-23 860
9223b4190 Christoph Lameter 2008-04-28 861 #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS 9223b4190 Christoph Lameter 2008-04-28 @862 #error SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS 348f8b6c4 Dave Hansen 2005-06-23 863 #endif
348f8b6c4 Dave Hansen 2005-06-23 864
:::::: The code at line 862 was first introduced by commit
:::::: 9223b4190fa1297a59f292f3419fc0285321d0ea pageflags: get rid of FLAGS_RESERVED
:::::: TO: Christoph Lameter <[email protected]> :::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation