incoming
Subsystems (76)
Andrew Morton
maintainerPATCH 189/212 mm: compaction: support triggering of proactive compaction by user
In reply to Andrew MortonFrom: Charan Teja Reddy <[email protected]>
Subject: mm: compaction: support triggering of proactive compaction by user
The proactive compaction[1] gets triggered for every 500msec and run compaction on the node for COMPACTION_HPAGE_ORDER (usually order-9) pages based on the value set to sysctl.compaction_proactiveness. Triggering the compaction for every 500msec in search of COMPACTION_HPAGE_ORDER pages is not needed for all applications, especially on the embedded system usecases which may have few MB's of RAM. Enabling the proactive compaction in its state will endup in running almost always on such systems.
Other side, proactive compaction can still be very much useful for getting a set of higher order pages in some controllable manner(controlled by using the sysctl.compaction_proactiveness). So, on systems where enabling the proactive compaction always may proove not required, can trigger the same from user space on write to its sysctl interface. As an example, say app launcher decide to launch the memory heavy application which can be launched fast if it gets more higher order pages thus launcher can prepare the system in advance by triggering the proactive compaction from userspace.
This triggering of proactive compaction is done on a write to sysctl.compaction_proactiveness by user.
---
Documentation/admin-guide/sysctl/vm.rst | 3 + include/linux/compaction.h | 2 + include/linux/mmzone.h | 1 kernel/sysctl.c | 2 - mm/compaction.c | 38 ++++++++++++++++++++-- 5 files changed, 42 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysctl/vm.rst renamed from Documentation/admin-guide/sysctl/vm.rst~mm-compaction-support-triggering-of-proactive-compaction-by-user +2 -1
@@ -118,7 +118,8 @@ compaction_proactiveness This tunable takes a value in the range [0, 100] with a default value of 20. This tunable determines how aggressively compaction is done in the -background. Setting it to 0 disables proactive compaction. +background. Write of a non zero value to this tunable will immediately +trigger the proactive compaction. Setting it to 0 disables proactive compaction. Note that compaction has a non-trivial system-wide impact as pages belonging to different processes are moved around, which could also lead
include/linux/compaction.h renamed from include/linux/compaction.h~mm-compaction-support-triggering-of-proactive-compaction-by-user +2 -0
@@ -84,6 +84,8 @@ static inline unsigned long compact_gap(extern unsigned int sysctl_compaction_proactiveness;extern int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos); +extern int compaction_proactiveness_sysctl_handler (struct ctl_table *table, +int write,void *buffer,size_t *length,loff_t *ppos);extern int sysctl_extfrag_threshold;extern int sysctl_compact_unevictable_allowed;
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-compaction-support-triggering-of-proactive-compaction-by-user +1 -0
@@ -846,6 +846,7 @@ typedef struct pglist_data {enum zone_type kcompactd_highest_zoneidx;wait_queue_head_t kcompactd_wait;struct task_struct *kcompactd; +bool proactive_compact_trigger;#endif /* * This is a per-node reserve of pages that are not available
kernel/sysctl.c renamed from kernel/sysctl.c~mm-compaction-support-triggering-of-proactive-compaction-by-user +1 -1
@@ -2871,7 +2871,7 @@ static struct ctl_table vm_table[] = { .data = &sysctl_compaction_proactiveness, .maxlen = sizeof(sysctl_compaction_proactiveness), .mode = 0644, - .proc_handler = proc_dointvec_minmax, + .proc_handler = compaction_proactiveness_sysctl_handler, .extra1 = SYSCTL_ZERO, .extra2 = &one_hundred, },
mm/compaction.c renamed from mm/compaction.c~mm-compaction-support-triggering-of-proactive-compaction-by-user +36 -2
@@ -2706,6 +2706,30 @@ static void compact_nodes(void)*/ unsigned int __read_mostly sysctl_compaction_proactiveness =20 ; +int compaction_proactiveness_sysctl_handler (struct ctl_table *table,int write, +void *buffer,size_t *length,loff_t *ppos) +{ +int rc, nid; + + rc =proc_dointvec_minmax (table, write, buffer, length, ppos); +if (rc) +return rc; + +if (write && sysctl_compaction_proactiveness) { +for_each_online_node (nid) { +pg_data_t *pgdat =NODE_DATA (nid); + +if (pgdat->proactive_compact_trigger) +continue ; + + pgdat->proactive_compact_trigger = true; +wake_up_interruptible (&pgdat->kcompactd_wait); + } + } + +return 0 ; +} +/* * This is the entry point for compacting all nodes via * /proc/sys/vm/compact_memory
@@ -2750,7 +2774,8 @@ void compaction_unregister_node(struct nstatic inline bool kcompactd_work_requested (pg_data_t *pgdat) { -return pgdat->kcompactd_max_order >0 ||kthread_should_stop (); +return pgdat->kcompactd_max_order >0 ||kthread_should_stop () || + pgdat->proactive_compact_trigger; }static bool kcompactd_node_suitable (pg_data_t *pgdat)
@@ -2901,9 +2926,16 @@ static int kcompactd(void *p)while (!kthread_should_stop ()) {unsigned long pflags; +/* +* Avoid the unnecessary wakeup for proactive compaction +* when it is disabled. +*/ +if (!sysctl_compaction_proactiveness) + timeout =MAX_SCHEDULE_TIMEOUT ;trace_mm_compaction_kcompactd_sleep (pgdat->node_id);if (wait_event_freezable_timeout (pgdat->kcompactd_wait, -kcompactd_work_requested (pgdat), timeout)) { +kcompactd_work_requested (pgdat), timeout) && + !pgdat->proactive_compact_trigger) {psi_memstall_enter (&pflags);kcompactd_do_work (pgdat);
@@ -2938,6 +2970,8 @@ static int kcompactd(void *p) timeout = default_timeout <<COMPACT_MAX_DEFER_SHIFT ; } +if (unlikely (pgdat->proactive_compact_trigger)) + pgdat->proactive_compact_trigger = false; }return 0 ;
_
Andrew Morton
maintainerPATCH 190/212 mm/mempolicy: use readable NUMA_NO_NODE macro instead of magic number
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: mm/mempolicy: use readable NUMA_NO_NODE macro instead of magic number
The caller of mpol_misplaced() already use NUMA_NO_NODE to check whether current page node is misplaced, thus using NUMA_NO_NODE in mpol_misplaced() instead of magic number is more readable.
---
mm/mempolicy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-use-readable-numa_no_node-macro-instead-of-magic-numer +3 -3
@@ -2425,8 +2425,8 @@ static void sp_free(struct sp_node *n)* node id. Policy determination "mimics" alloc_page_vma(). * Called from fault path where we know the vma and faulting address. * -* Return: -1 if the page is in a node that is valid for this policy, or a -* suitable node ID to allocate a replacement page from. +* Return: NUMA_NO_NODE if the page is in a node that is valid for this +* policy, or a suitable node ID to allocate a replacement page from. */ int mpol_misplaced (struct page *page,struct vm_area_struct *vma,unsigned long addr) {
@@ -2437,7 +2437,7 @@ int mpol_misplaced(struct page *page, stint thiscpu =raw_smp_processor_id ();int thisnid =cpu_to_node (thiscpu);int polnid =NUMA_NO_NODE ; -int ret =-1 ; +int ret =NUMA_NO_NODE ; pol =get_vma_policy (vma, addr);if (!(pol->flags &MPOL_F_MOF ))
_
Andrew Morton
maintainerPATCH 191/212 mm/mempolicy: add MPOL_PREFERRED_MANY for multiple preferred nodes
In reply to Andrew MortonFrom: Dave Hansen <[email protected]>
Subject: mm/mempolicy: add MPOL_PREFERRED_MANY for multiple preferred nodes
Patch series "Introduce multi-preference mempolicy", v7.
This patch series introduces the concept of the MPOL_PREFERRED_MANY mempolicy. This mempolicy mode can be used with either the set_mempolicy(2) or mbind(2) interfaces. Like the MPOL_PREFERRED interface, it allows an application to set a preference for nodes which will fulfil memory allocation requests. Unlike the MPOL_PREFERRED mode, it takes a set of nodes. Like the MPOL_BIND interface, it works over a set of nodes. Unlike MPOL_BIND, it will not cause a SIGSEGV or invoke the OOM killer if those preferred nodes are not available.
Along with these patches are patches for libnuma, numactl, numademo, and memhog. They still need some polish, but can be found here:
https://gitlab.com/bwidawsk/numactl/-/tree/prefer-many It allows new
usage: numactl -P 0,3,4
The goal of the new mode is to enable some use-cases when using tiered memory usage models which I've lovingly named.
1a. The Hare - The interconnect is fast enough to meet bandwidth and
latency requirements allowing preference to be given to all nodes with "fast" memory.
1b. The Indiscriminate Hare - An application knows it wants fast
memory (or perhaps slow memory), but doesn't care which node it runs on. The application can prefer a set of nodes and then xpu bind to the local node (cpu, accelerator, etc). This reverses the nodes are chosen today where the kernel attempts to use local memory to the CPU whenever possible. This will attempt to use the local accelerator to the memory.
2. The Tortoise - The administrator (or the application itself) is aware it only needs slow memory, and so can prefer that.
Much of this is almost achievable with the bind interface, but the bind interface suffers from an inability to fallback to another set of nodes if binding fails to all nodes in the nodemask.
Like MPOL_BIND a nodemask is given. Inherently this removes ordering from the preference.
Quoted 7 lines
/* Set first two nodes as preferred in an 8 node system. */ const unsigned long nodes =
0x3set_mempolicy(MPOL_PREFER_MANY, &nodes, 8);/* Mimic interleave policy, but have fallback *.
const unsigned long nodes =0xaaset_mempolicy(MPOL_PREFER_MANY, &nodes, 8);
Some internal discussion took place around the interface. There are two alternatives which we have discussed, plus one I stuck in:
1. Ordered list of nodes. Currently it's believed that the added complexity is nod needed for expected usecases.
2. A flag for bind to allow falling back to other nodes. This confuses the notion of binding and is less flexible than the current solution.
3. Create flags or new modes that helps with some ordering. This offers both a friendlier API as well as a solution for more customized usage. It's unknown if it's worth the complexity to support this. Here is sample code for how this might work:
Quoted 8 lines
// Prefer specific nodes for some something wacky
set_mempolicy(MPOL_PREFER_MANY, 0x17c, 1024);// Default
set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_SOCKET, NULL, 0); // which is the same asset_mempolicy(MPOL_DEFAULT, NULL, 0);
Quoted 9 lines
// The Hare
set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE, NULL, 0);// The Tortoise
set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE_REV, NULL, 0);// Prefer the fast memory of the first two sockets
set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE, -1, 2);
This patch (of 5):
The NUMA APIs currently allow passing in a "preferred node" as a single bit set in a nodemask. If more than one bit it set, bits after the first are ignored.
This single node is generally OK for location-based NUMA where memory being allocated will eventually be operated on by a single CPU. However, in systems with multiple memory types, folks want to target a *type* of memory instead of a location. For instance, someone might want some high-bandwidth memory but do not care about the CPU next to which it is allocated. Or, they want a cheap, high capacity allocation and want to target all NUMA nodes which have persistent memory in volatile mode. In both of these cases, the application wants to target a *set* of nodes, but does not want strict MPOL_BIND behavior as that could lead to OOM killer or SIGSEGV.
So add MPOL_PREFERRED_MANY policy to support the multiple preferred nodes requirement. This is not a pie-in-the-sky dream for an API. This was a response to a specific ask of more than one group at Intel. Specifically:
1. There are existing libraries that target memory types such as
https://github.com/memkind/memkind. These are known to suffer from SIGSEGV's when memory is low on targeted memory "kinds" that span more than one node. The MCDRAM on a Xeon Phi in "Cluster on Die" mode is an example of this.
2. Volatile-use persistent memory users want to have a memory policy which is targeted at either "cheap and slow" (PMEM) or "expensive and fast" (DRAM). However, they do not want to experience allocation failures when the targeted type is unavailable.
3. Allocate-then-run. Generally, we let the process scheduler decide on which physical CPU to run a task. That location provides a default allocation policy, and memory availability is not generally considered when placing tasks. For situations where memory is valuable and constrained, some users want to allocate memory first, *then* allocate close compute resources to the allocation. This is the reverse of the normal (CPU) model. Accelerators such as GPUs that operate on core-mm-managed memory are interested in this model.
A check is added in sanitize_mpol_flags() to not permit 'prefer_many' policy to be used for now, and will be removed in later patch after all implementations for 'prefer_many' are ready, as suggested by Michal Hocko.
---
include/uapi/linux/mempolicy.h | 1 mm/mempolicy.c | 73 +++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 14 deletions(-)
include/uapi/linux/mempolicy.h renamed from include/uapi/linux/mempolicy.h~mm-mempolicy-add-mpol_preferred_many-for-multiple-preferred-nodes +1 -0
@@ -22,6 +22,7 @@ enum {MPOL_BIND ,MPOL_INTERLEAVE ,MPOL_LOCAL , +MPOL_PREFERRED_MANY , MPOL_MAX, /* always last member of enum */ };
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-add-mpol_preferred_many-for-multiple-preferred-nodes +59 -14
193 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 192/212 mm/memplicy: add page allocation function for MPOL_PREFERRED_MANY policy
In reply to Andrew MortonFrom: Feng Tang <[email protected]>
Subject: mm/memplicy: add page allocation function for MPOL_PREFERRED_MANY policy
The semantics of MPOL_PREFERRED_MANY is similar to MPOL_PREFERRED, that it will first try to allocate memory from the preferred node(s), and fallback to all nodes in system when first try fails.
Add a dedicated function alloc_pages_preferred_many() for it just like for 'interleave' policy, which will be used by 2 general memoory allocation
APIs: alloc_pages() and alloc_pages_vma()
---
mm/mempolicy.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-memplicy-add-page-allocation-function-for-mpol_preferred_many-policy +30 -0
@@ -2166,6 +2166,27 @@ static struct page *alloc_page_interleavreturn page; } +static struct page *alloc_pages_preferred_many (gfp_t gfp,unsigned int order, +int nid,struct mempolicy *pol) +{ +struct page *page; +gfp_t preferred_gfp; + +/* +* This is a two pass approach. The first pass will only try the +* preferred nodes but skip the direct reclaim and allow the +* allocation to fail, while the second pass will try all the +* nodes in system. +*/ + preferred_gfp = gfp | __GFP_NOWARN; + preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); + page =__alloc_pages (preferred_gfp, order, nid, &pol->nodes); +if (!page) + page =__alloc_pages (gfp, order,numa_node_id (),NULL ); + +return page; +} +/** * alloc_pages_vma - Allocate a page for a VMA. * @gfp: GFP flags.
@@ -2201,6 +2222,12 @@ struct page *alloc_pages_vma(gfp_t gfp, goto out; } +if (pol->mode ==MPOL_PREFERRED_MANY ) { + page =alloc_pages_preferred_many (gfp, order, node, pol); +mpol_cond_put (pol); + goto out; + } +if (unlikely (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && hugepage)) {int hpage_node = node;
@@ -2278,6 +2305,9 @@ struct page *alloc_pages(gfp_t gfp, unsi*/ if (pol->mode ==MPOL_INTERLEAVE ) page =alloc_page_interleave (gfp, order,interleave_nodes (pol)); +else if (pol->mode ==MPOL_PREFERRED_MANY ) + page =alloc_pages_preferred_many (gfp, order, +numa_node_id (), pol);else page = __alloc_pages(gfp, order, policy_node(gfp, pol, numa_node_id()),
_
Andrew Morton
maintainerPATCH 193/212 mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY
In reply to Andrew MortonFrom: Ben Widawsky <[email protected]>
Subject: mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY
Implement the missing huge page allocation functionality while obeying the preferred node semantics. This is similar to the implementation for general page allocation, as it uses a fallback mechanism to try multiple preferred nodes first, and then all other nodes.
To avoid adding too many "#ifdef CONFIG_NUMA" check, add a helper function in mempolicy.h to check whether a mempolicy is MPOL_PREFERRED_MANY.
---
include/linux/mempolicy.h | 12 ++++++++++++ mm/hugetlb.c | 30 +++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-)
include/linux/mempolicy.h renamed from include/linux/mempolicy.h~mm-hugetlb-add-support-for-mempolicy-mpol_preferred_many +12 -0
@@ -186,6 +186,12 @@ extern void mpol_put_task_policy(structextern bool numa_demotion_enabled; +static inline bool mpol_is_preferred_many (struct mempolicy *pol) +{ +return (pol->mode ==MPOL_PREFERRED_MANY ); +} + +#else struct mempolicy {};
@@ -296,5 +302,11 @@ static inline nodemask_t *policy_nodemas }#define numa_demotion_enabled false + +static inline bool mpol_is_preferred_many (struct mempolicy *pol) +{ +return false; +} +#endif /* CONFIG_NUMA */ #endif
mm/hugetlb.c renamed from mm/hugetlb.c~mm-hugetlb-add-support-for-mempolicy-mpol_preferred_many +25 -5
@@ -1145,7 +1145,7 @@ static struct page *dequeue_huge_page_vm unsigned long address, int avoid_reserve, long chg) { - struct page *page; + struct page *page = NULL;struct mempolicy *mpol;gfp_t gfp_mask;nodemask_t *nodemask;
@@ -1166,7 +1166,17 @@ static struct page *dequeue_huge_page_vm gfp_mask =htlb_alloc_mask (h); nid =huge_node (vma, address, gfp_mask, &mpol, &nodemask); - page =dequeue_huge_page_nodemask (h, gfp_mask, nid, nodemask); + +if (mpol_is_preferred_many (mpol)) { + page =dequeue_huge_page_nodemask (h, gfp_mask, nid, nodemask); + +/* Fallback to all nodes if page==NULL */ + nodemask =NULL ; + } + +if (!page) + page =dequeue_huge_page_nodemask (h, gfp_mask, nid, nodemask); +if (page && !avoid_reserve &&vma_has_reserves (vma, chg)) {SetHPageRestoreReserve (page); h->resv_huge_pages--;
@@ -2142,16 +2152,26 @@ staticstruct page *alloc_buddy_huge_page_with_mpol (struct hstate *h,struct vm_area_struct *vma,unsigned long addr) { -struct page *page; +struct page *page =NULL ;struct mempolicy *mpol;gfp_t gfp_mask =htlb_alloc_mask (h);int nid;nodemask_t *nodemask; nid =huge_node (vma, addr, gfp_mask, &mpol, &nodemask); - page =alloc_surplus_huge_page (h, gfp_mask, nid, nodemask, false); -mpol_cond_put (mpol); +if (mpol_is_preferred_many (mpol)) { +gfp_t gfp = gfp_mask | __GFP_NOWARN; + + gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); + page =alloc_surplus_huge_page (h, gfp, nid, nodemask, false); +/* Fallback to all nodes if page==NULL */ + nodemask =NULL ; + } + +if (!page) + page =alloc_surplus_huge_page (h, gfp_mask, nid, nodemask, false); +mpol_cond_put (mpol);return page; }
_
Andrew Morton
maintainerPATCH 194/212 mm/mempolicy: advertise new MPOL_PREFERRED_MANY
In reply to Andrew MortonFrom: Ben Widawsky <[email protected]>
Subject: mm/mempolicy: advertise new MPOL_PREFERRED_MANY
Adds a new mode to the existing mempolicy modes, MPOL_PREFERRED_MANY.
MPOL_PREFERRED_MANY will be adequately documented in the internal admin-guide with this patch. Eventually, the man pages for mbind(2), get_mempolicy(2), set_mempolicy(2) and numactl(8) will also have text about this mode. Those shall contain the canonical reference.
NUMA systems continue to become more prevalent. New technologies like PMEM make finer grain control over memory access patterns increasingly desirable. MPOL_PREFERRED_MANY allows userspace to specify a set of nodes that will be tried first when performing allocations. If those allocations fail, all remaining nodes will be tried. It's a straight forward API which solves many of the presumptive needs of system administrators wanting to optimize workloads on such machines. The mode will work either per VMA, or per thread.
---
Documentation/admin-guide/mm/numa_memory_policy.rst | 15 +++++++--- mm/mempolicy.c | 7 ---- 2 files changed, 12 insertions(+), 10 deletions(-)
Documentation/admin-guide/mm/numa_memory_policy.rst renamed from Documentation/admin-guide/mm/numa_memory_policy.rst~mm-mempolicy-advertise-new-mpol_preferred_many +11 -4
@@ -245,6 +245,13 @@ MPOL_INTERLEAVED address range or file. During system boot up, the temporary interleaved system default policy works in this mode. +MPOL_PREFERRED_MANY + This mode specifices that the allocation should be preferrably + satisfied from the nodemask specified in the policy. If there is + a memory pressure on all nodes in the nodemask, the allocation + can fall back to all existing numa nodes. This is effectively + MPOL_PREFERRED allowed for a mask rather than a single node. + NUMA memory policy supports the following optional mode flags: MPOL_F_STATIC_NODES
@@ -253,10 +260,10 @@ MPOL_F_STATIC_NODES nodes changes after the memory policy has been defined. Without this flag, any time a mempolicy is rebound because of a - change in the set of allowed nodes, the node (Preferred) or - nodemask (Bind, Interleave) is remapped to the new set of - allowed nodes. This may result in nodes being used that were - previously undesired. + change in the set of allowed nodes, the preferred nodemask (Preferred + Many), preferred node (Preferred) or nodemask (Bind, Interleave) is + remapped to the new set of allowed nodes. This may result in nodes + being used that were previously undesired. With this flag, if the user-specified nodes overlap with the nodes allowed by the task's cpuset, then the memory policy is
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-advertise-new-mpol_preferred_many +1 -6
@@ -1463,12 +1463,7 @@ static inline int sanitize_mpol_flags(in *flags = *mode &MPOL_MODE_FLAGS ; *mode &= ~MPOL_MODE_FLAGS ; -/* -* The check should be 'mode >= MPOL_MAX', but as 'prefer_many' -* is not fully implemented, don't permit it to be used for now, -* and the logic will be restored in following patch -*/ -if ((unsigned int )(*mode) >=MPOL_PREFERRED_MANY ) +if ((unsigned int )(*mode) >=MPOL_MAX )return -EINVAL ;if ((*flags &MPOL_F_STATIC_NODES ) && (*flags &MPOL_F_RELATIVE_NODES ))return -EINVAL ;
_
Andrew Morton
maintainerPATCH 195/212 mm/mempolicy: unify the create() func for bind/interleave/prefer-many policies
In reply to Andrew MortonFrom: Feng Tang <[email protected]>
Subject: mm/mempolicy: unify the create() func for bind/interleave/prefer-many policies
As they all do the same thing: sanity check and save nodemask info, create one mpol_new_nodemask() to reduce redundancy.
---
mm/mempolicy.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-unify-the-create-func-for-bind-interleave-prefer-many-policies +4 -20
@@ -192,7 +192,7 @@ static void mpol_relative_nodemask(nodemnodes_onto (*ret, tmp, *rel); } -static int mpol_new_interleave (struct mempolicy *pol,const nodemask_t *nodes) +static int mpol_new_nodemask (struct mempolicy *pol,const nodemask_t *nodes) {if (nodes_empty (*nodes))return -EINVAL ;
@@ -210,22 +210,6 @@ static int mpol_new_preferred(struct memreturn 0 ; } -static int mpol_new_preferred_many (struct mempolicy *pol,const nodemask_t *nodes) -{ -if (nodes_empty (*nodes)) -return -EINVAL ; - pol->nodes = *nodes; -return 0 ; -} - -static int mpol_new_bind (struct mempolicy *pol,const nodemask_t *nodes) -{ -if (nodes_empty (*nodes)) -return -EINVAL ; - pol->nodes = *nodes; -return 0 ; -} -/* * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if * any, for the new policy. mpol_new() has already validated the nodes
@@ -405,7 +389,7 @@ static const struct mempolicy_operations .rebind = mpol_rebind_default, }, [MPOL_INTERLEAVE] = { - .create = mpol_new_interleave, + .create = mpol_new_nodemask, .rebind = mpol_rebind_nodemask, }, [MPOL_PREFERRED] = {
@@ -413,14 +397,14 @@ static const struct mempolicy_operations .rebind = mpol_rebind_preferred, }, [MPOL_BIND] = { - .create = mpol_new_bind, + .create = mpol_new_nodemask, .rebind = mpol_rebind_nodemask, }, [MPOL_LOCAL] = { .rebind = mpol_rebind_default, }, [MPOL_PREFERRED_MANY] = { - .create = mpol_new_preferred_many, + .create = mpol_new_nodemask, .rebind = mpol_rebind_preferred, }, };
_
Andrew Morton
maintainerPATCH 196/212 mm/mempolicy.c: use in_task() in mempolicy_slab_node()
In reply to Andrew MortonFrom: Vasily Averin <[email protected]>
Subject: mm/mempolicy.c: use in_task() in mempolicy_slab_node()
Obsoleted in_intrrupt() include task context with disabled BH, it's better to use in_task() instead.
---
mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-use-in_task-in-mempolicy_slab_node +1 -1
@@ -1934,7 +1934,7 @@ unsigned int mempolicy_slab_node(void)struct mempolicy *policy;int node =numa_mem_id (); -if (in_interrupt ()) +if (!in_task ())return node; policy = current->mempolicy;
_
Andrew Morton
maintainerPATCH 197/212 memblock: make memblock_find_in_range method private
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: memblock: make memblock_find_in_range method private
There are a lot of uses of memblock_find_in_range() along with memblock_reserve() from the times memblock allocation APIs did not exist.
memblock_find_in_range() is the very core of memblock allocations, so any future changes to its internal behaviour would mandate updates of all the users outside memblock.
Replace the calls to memblock_find_in_range() with an equivalent calls to memblock_phys_alloc() and memblock_phys_alloc_range() and make memblock_find_in_range() private method of memblock.
This simplifies the callers, ensures that (unlikely) errors in memblock_reserve() are handled and improves maintainability of memblock_find_in_range().
---
arch/arm/kernel/setup.c | 20 ++++-------- arch/arm64/kvm/hyp/reserved_mem.c | 9 +---- arch/arm64/mm/init.c | 38 +++++++----------------- arch/mips/kernel/setup.c | 14 +++----- arch/riscv/mm/init.c | 44 ++++++++-------------------- arch/s390/kernel/setup.c | 9 +++-- arch/x86/kernel/aperture_64.c | 5 +-- arch/x86/mm/init.c | 23 +++++++++----- arch/x86/mm/numa.c | 5 +-- arch/x86/mm/numa_emulation.c | 5 +-- arch/x86/realmode/init.c | 2 - drivers/acpi/tables.c | 5 +-- drivers/base/arch_numa.c | 5 --- drivers/of/of_reserved_mem.c | 12 +++++-- include/linux/memblock.h | 2 - mm/memblock.c | 2 - 16 files changed, 82 insertions(+), 118 deletions(-)
arch/arm64/kvm/hyp/reserved_mem.c renamed from arch/arm64/kvm/hyp/reserved_mem.c~memblock-make-memblock_find_in_range-method-private +3 -6
@@ -92,12 +92,10 @@ void __init kvm_hyp_reserve(void)* this is unmapped from the host stage-2, and fallback to PAGE_SIZE. */ hyp_mem_size = hyp_mem_pages <<PAGE_SHIFT ; - hyp_mem_base =memblock_find_in_range (0 ,memblock_end_of_DRAM (), -ALIGN (hyp_mem_size,PMD_SIZE ), -PMD_SIZE ); + hyp_mem_base =memblock_phys_alloc (ALIGN (hyp_mem_size,PMD_SIZE ), +PMD_SIZE );if (!hyp_mem_base) - hyp_mem_base =memblock_find_in_range (0 ,memblock_end_of_DRAM (), - hyp_mem_size,PAGE_SIZE ); + hyp_mem_base =memblock_phys_alloc (hyp_mem_size,PAGE_SIZE );else hyp_mem_size =ALIGN (hyp_mem_size,PMD_SIZE );
@@ -105,7 +103,6 @@ void __init kvm_hyp_reserve(void)kvm_err ("Failed to reserve hyp memory\n" );return ; } -memblock_reserve (hyp_mem_base, hyp_mem_size);kvm_info ("Reserved %lld MiB at 0x%llx\n" , hyp_mem_size >>20 , hyp_mem_base);
arch/arm64/mm/init.c renamed from arch/arm64/mm/init.c~memblock-make-memblock_find_in_range-method-private +12 -26
@@ -74,6 +74,7 @@ phys_addr_t arm64_dma_phys_limit __ro_afstatic void __init reserve_crashkernel (void ) {unsigned long long crash_base, crash_size; +unsigned long long crash_max = arm64_dma_phys_limit;int ret; ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
@@ -84,33 +85,18 @@ static void __init reserve_crashkernel(v crash_size =PAGE_ALIGN (crash_size); -if (crash_base ==0 ) { -/* Current arm64 boot protocol requires 2MB alignment */ - crash_base =memblock_find_in_range (0 , arm64_dma_phys_limit, - crash_size,SZ_2M ); -if (crash_base ==0 ) { -pr_warn ("cannot allocate crashkernel (size:0x%llx)\n" , - crash_size); -return ; - } - }else { -/* User specifies base address explicitly. */ -if (!memblock_is_region_memory (crash_base, crash_size)) { -pr_warn ("cannot reserve crashkernel: region is not memory\n" ); -return ; - } - -if (memblock_is_region_reserved (crash_base, crash_size)) { -pr_warn ("cannot reserve crashkernel: region overlaps reserved memory\n" ); -return ; - } - -if (!IS_ALIGNED (crash_base,SZ_2M )) { -pr_warn ("cannot reserve crashkernel: base address is not 2MB aligned\n" ); -return ; - } +/* User specifies base address explicitly. */ +if (crash_base) + crash_max = crash_base + crash_size; + +/* Current arm64 boot protocol requires 2MB alignment */ + crash_base =memblock_phys_alloc_range (crash_size,SZ_2M , + crash_base, crash_max); +if (!crash_base) { +pr_warn ("cannot allocate crashkernel (size:0x%llx)\n" , + crash_size); +return ; } -memblock_reserve (crash_base, crash_size);pr_info ("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n" , crash_base, crash_base + crash_size, crash_size >>20 );
arch/arm/kernel/setup.c renamed from arch/arm/kernel/setup.c~memblock-make-memblock_find_in_range-method-private +7 -13
@@ -1012,31 +1012,25 @@ static void __init reserve_crashkernel(vunsigned long long lowmem_max =__pa (high_memory -1 ) +1 ;if (crash_max > lowmem_max) crash_max = lowmem_max; - crash_base =memblock_find_in_range (CRASH_ALIGN , crash_max, - crash_size,CRASH_ALIGN ); + + crash_base =memblock_phys_alloc_range (crash_size,CRASH_ALIGN , +CRASH_ALIGN , crash_max);if (!crash_base) {pr_err ("crashkernel reservation failed - No suitable area found.\n" );return ; } }else { +unsigned long long crash_max = crash_base + crash_size;unsigned long long start; - start =memblock_find_in_range (crash_base, - crash_base + crash_size, - crash_size,SECTION_SIZE ); -if (start != crash_base) { + start =memblock_phys_alloc_range (crash_size,SECTION_SIZE , + crash_base, crash_max); +if (!start) {pr_err ("crashkernel reservation failed - memory is in use.\n" );return ; } } - ret =memblock_reserve (crash_base, crash_size); -if (ret <0 ) { -pr_warn ("crashkernel reservation failed - memory is in use (0x%lx)\n" , - (unsigned long )crash_base); -return ; - } - pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", (unsigned long)(crash_size >> 20), (unsigned long)(crash_base >> 20),
arch/mips/kernel/setup.c renamed from arch/mips/kernel/setup.c~memblock-make-memblock_find_in_range-method-private +6 -8
@@ -452,8 +452,9 @@ static void __init mips_parse_crashkernereturn ;if (crash_base <=0 ) { - crash_base =memblock_find_in_range (CRASH_ALIGN ,CRASH_ADDR_MAX , - crash_size,CRASH_ALIGN ); + crash_base =memblock_phys_alloc_range (crash_size,CRASH_ALIGN , +CRASH_ALIGN , +CRASH_ADDR_MAX );if (!crash_base) {pr_warn ("crashkernel reservation failed - No suitable area found.\n" );return ;
@@ -461,8 +462,9 @@ static void __init mips_parse_crashkerne }else {unsigned long long start; - start =memblock_find_in_range (crash_base, crash_base + crash_size, - crash_size,1 ); + start =memblock_phys_alloc_range (crash_size,1 , + crash_base, + crash_base + crash_size);if (start != crash_base) {pr_warn ("Invalid memory region reserved for crash kernel\n" );return ;
@@ -656,10 +658,6 @@ static void __init arch_mem_init(char **mips_reserve_vmcore ();mips_parse_crashkernel (); -#ifdef CONFIG_KEXEC -if (crashk_res.start != crashk_res.end) -memblock_reserve (crashk_res.start,resource_size (&crashk_res)); -#endif device_tree_init ();/*
arch/riscv/mm/init.c renamed from arch/riscv/mm/init.c~memblock-make-memblock_find_in_range-method-private +14 -30
52 lines not on this page · raw message
arch/s390/kernel/setup.c renamed from arch/s390/kernel/setup.c~memblock-make-memblock_find_in_range-method-private +6 -3
@@ -626,8 +626,9 @@ static void __init reserve_crashkernel(vreturn ; } low = crash_base ?: low; - crash_base =memblock_find_in_range (low, high, crash_size, -KEXEC_CRASH_MEM_ALIGN ); + crash_base =memblock_phys_alloc_range (crash_size, +KEXEC_CRASH_MEM_ALIGN , + low, high); }if (!crash_base) {
@@ -636,8 +637,10 @@ static void __init reserve_crashkernel(vreturn ; } -if (register_memory_notifier (&kdump_mem_nb)) +if (register_memory_notifier (&kdump_mem_nb)) { +memblock_free (crash_base, crash_size);return ; + }if (!OLDMEM_BASE &&MACHINE_IS_VM )diag10_range (PFN_DOWN (crash_base),PFN_DOWN (crash_size));
arch/x86/kernel/aperture_64.c renamed from arch/x86/kernel/aperture_64.c~memblock-make-memblock_find_in_range-method-private +2 -3
@@ -109,14 +109,13 @@ static u32 __init allocate_aperture(void* memory. Unfortunately we cannot move it up because that would * make the IOMMU useless. */ - addr =memblock_find_in_range (GART_MIN_ADDR ,GART_MAX_ADDR , - aper_size, aper_size); + addr =memblock_phys_alloc_range (aper_size, aper_size, +GART_MIN_ADDR ,GART_MAX_ADDR );if (!addr) {pr_err ("Cannot allocate aperture memory hole [mem %#010lx-%#010lx] (%uKB)\n" , addr, addr + aper_size -1 , aper_size >>10 );return 0 ; } -memblock_reserve (addr, aper_size);pr_info ("Mapping aperture over RAM [mem %#010lx-%#010lx] (%uKB)\n" , addr, addr + aper_size -1 , aper_size >>10 ); register_nosave_region(addr >> PAGE_SHIFT,
arch/x86/mm/init.c renamed from arch/x86/mm/init.c~memblock-make-memblock_find_in_range-method-private +15 -8
@@ -127,14 +127,12 @@ __ref void *alloc_low_pages(unsigned intunsigned long ret =0 ;if (min_pfn_mapped < max_pfn_mapped) { - ret =memblock_find_in_range ( + ret =memblock_phys_alloc_range ( +PAGE_SIZE * num,PAGE_SIZE , min_pfn_mapped <<PAGE_SHIFT , - max_pfn_mapped <<PAGE_SHIFT , -PAGE_SIZE * num ,PAGE_SIZE ); + max_pfn_mapped <<PAGE_SHIFT ); } -if (ret) -memblock_reserve (ret,PAGE_SIZE * num); -else if (can_use_brk_pgt) +if (!ret && can_use_brk_pgt) ret =__pa (extend_brk (PAGE_SIZE * num,PAGE_SIZE ));if (!ret)
@@ -610,8 +608,17 @@ static void __init memory_map_top_down(uunsigned long addr;unsigned long mapped_ram_size =0 ; -/* xen has big range in reserved near end of ram, skip it at first.*/ - addr =memblock_find_in_range (map_start, map_end,PMD_SIZE ,PMD_SIZE ); +/* +* Systems that have many reserved areas near top of the memory, +* e.g. QEMU with less than 1G RAM and EFI enabled, or Xen, will +* require lots of 4K mappings which may exhaust pgt_buf. +* Start with top-most PMD_SIZE range aligned at PMD_SIZE to ensure +* there is enough mapped memory that can be allocated from +* memblock. +*/ + addr =memblock_phys_alloc_range (PMD_SIZE ,PMD_SIZE , map_start, + map_end); +memblock_free (addr,PMD_SIZE ); real_end = addr +PMD_SIZE ;/* step_size need to be small so pgt_buf from BRK could cover it */
arch/x86/mm/numa.c renamed from arch/x86/mm/numa.c~memblock-make-memblock_find_in_range-method-private +2 -3
@@ -376,15 +376,14 @@ static int __init numa_alloc_distance(vo cnt++; size = cnt * cnt *sizeof (numa_distance[0 ]); - phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn_mapped), - size,PAGE_SIZE ); + phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 , +PFN_PHYS (max_pfn_mapped));if (!phys) {pr_warn ("Warning: can't allocate distance table!\n" );/* don't retry until explicitly reset */ numa_distance = (void *)1LU ;return -ENOMEM ; } -memblock_reserve (phys, size); numa_distance =__va (phys); numa_distance_cnt = cnt;
arch/x86/mm/numa_emulation.c renamed from arch/x86/mm/numa_emulation.c~memblock-make-memblock_find_in_range-method-private +2 -3
@@ -447,13 +447,12 @@ void __init numa_emulation(struct numa_mif (numa_dist_cnt) {u64 phys; - phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn_mapped), - phys_size,PAGE_SIZE ); + phys =memblock_phys_alloc_range (phys_size,PAGE_SIZE ,0 , +PFN_PHYS (max_pfn_mapped));if (!phys) {pr_warn ("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n" ); goto no_emu; } -memblock_reserve (phys, phys_size); phys_dist =__va (phys);for (i =0 ; i < numa_dist_cnt; i++)
arch/x86/realmode/init.c renamed from arch/x86/realmode/init.c~memblock-make-memblock_find_in_range-method-private +1 -1
@@ -28,7 +28,7 @@ void __init reserve_real_mode(void)WARN_ON (slab_is_available ());/* Has to be under 1M so we can execute real-mode AP code. */ - mem =memblock_find_in_range (0 ,1 <<20 , size,PAGE_SIZE ); + mem =memblock_phys_alloc_range (size,PAGE_SIZE ,0 ,1 <<20 );if (!mem)pr_info ("No sub-1M memory is available for the trampoline\n" );else
drivers/acpi/tables.c renamed from drivers/acpi/tables.c~memblock-make-memblock_find_in_range-method-private +2 -3
@@ -583,8 +583,8 @@ void __init acpi_table_upgrade(void) } acpi_tables_addr = -memblock_find_in_range (0 ,ACPI_TABLE_UPGRADE_MAX_PHYS , - all_tables_size,PAGE_SIZE ); +memblock_phys_alloc_range (all_tables_size,PAGE_SIZE , +0 ,ACPI_TABLE_UPGRADE_MAX_PHYS );if (!acpi_tables_addr) {WARN_ON (1 );return ;
@@ -599,7 +599,6 @@ void __init acpi_table_upgrade(void)* Both memblock_reserve and e820__range_add (via arch_reserve_mem_area) * works fine. */ -memblock_reserve (acpi_tables_addr, all_tables_size);arch_reserve_mem_area (acpi_tables_addr, all_tables_size);/*
drivers/base/arch_numa.c renamed from drivers/base/arch_numa.c~memblock-make-memblock_find_in_range-method-private +1 -4
@@ -279,13 +279,10 @@ static int __init numa_alloc_distance(voint i, j; size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); - phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), - size,PAGE_SIZE ); + phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 ,PFN_PHYS (max_pfn));if (WARN_ON (!phys))return -ENOMEM ; -memblock_reserve (phys, size); - numa_distance =__va (phys); numa_distance_cnt = nr_node_ids;
drivers/of/of_reserved_mem.c renamed from drivers/of/of_reserved_mem.c~memblock-make-memblock_find_in_range-method-private +8 -4
@@ -33,18 +33,22 @@ static int __init early_init_dt_alloc_re phys_addr_t *res_base) {phys_addr_t base; +int err =0 ; end = !end ?MEMBLOCK_ALLOC_ANYWHERE : end; align = !align ?SMP_CACHE_BYTES : align; - base =memblock_find_in_range (start, end, size, align); + base =memblock_phys_alloc_range (size, align, start, end);if (!base)return -ENOMEM ; *res_base = base; -if (nomap) -return memblock_mark_nomap (base, size); +if (nomap) { + err =memblock_mark_nomap (base, size); +if (err) +memblock_free (base, size); + } -return memblock_reserve (base, size); +return err; }/*
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-make-memblock_find_in_range-method-private +0 -2
@@ -99,8 +99,6 @@ void memblock_discard(void);static inline void memblock_discard (void ) {}#endif -phys_addr_t memblock_find_in_range (phys_addr_t start,phys_addr_t end, -phys_addr_t size,phys_addr_t align);void memblock_allow_resize (void );int memblock_add_node (phys_addr_t base,phys_addr_t size,int nid);int memblock_add (phys_addr_t base,phys_addr_t size);
mm/memblock.c renamed from mm/memblock.c~memblock-make-memblock_find_in_range-method-private +1 -1
@@ -315,7 +315,7 @@ static phys_addr_t __init_memblock membl* Return: * Found address on success, 0 on failure. */ -phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start, +static phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,phys_addr_t end,phys_addr_t size,phys_addr_t align) {
_
Andrew Morton
maintainerPATCH 198/212 mm: introduce process_mrelease system call
In reply to Andrew MortonFrom: Suren Baghdasaryan <[email protected]>
Subject: mm: introduce process_mrelease system call
In modern systems it's not unusual to have a system component monitoring memory conditions of the system and tasked with keeping system memory pressure under control. One way to accomplish that is to kill non-essential processes to free up memory for more important ones. Examples of this are Facebook's OOM killer daemon called oomd and Android's low memory killer daemon called lmkd.
For such system component it's important to be able to free memory quickly and efficiently. Unfortunately the time process takes to free up its memory after receiving a SIGKILL might vary based on the state of the process (uninterruptible sleep), size and OPP level of the core the process is running. A mechanism to free resources of the target process in a more predictable way would improve system's ability to control its memory pressure.
Introduce process_mrelease system call that releases memory of a dying process from the context of the caller. This way the memory is freed in a more controllable way with CPU affinity and priority of the caller. The workload of freeing the memory will also be charged to the caller. The operation is allowed only on a dying process.
After previous discussions [1, 2, 3] the decision was made [4] to introduce a dedicated system call to cover this use case.
The API is as follows,
int process_mrelease(int pidfd, unsigned int flags);
DESCRIPTION
The process_mrelease() system call is used to free the memory of an exiting process.
The pidfd selects the process referred to by the PID file descriptor.
(See pidfd_open(2) for further information)
The flags argument is reserved for future use; currently, this argument must be specified as 0.
RETURN VALUE
On success, process_mrelease() returns 0. On error, -1 is returned and errno is set to indicate the error.
ERRORS
EBADF pidfd is not a valid PID file descriptor.
EAGAIN Failed to release part of the address space.
EINTR The call was interrupted by a signal; see signal(7).
EINVAL flags is not 0.
EINVAL The memory of the task cannot be released because the
process is not exiting, the address space is shared with another live process or there is a core dump in progress.
ENOSYS This system call is not supported, for example, without
MMU support built into Linux.
ESRCH The target process does not exist (i.e., it has terminated
and been waited on).
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/linux-api/[email protected]/
[3] https://lore.kernel.org/linux-api/[email protected]/
[4] https://lore.kernel.org/linux-api/[email protected]/
---
mm/oom_kill.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
mm/oom_kill.c renamed from mm/oom_kill.c~mm-introduce-process_mrelease-system-call +70 -0
@@ -28,6 +28,7 @@#include <linux/sched/task.h> #include <linux/sched/debug.h> #include <linux/swap.h> +#include <linux/syscalls.h> #include <linux/timex.h> #include <linux/jiffies.h> #include <linux/cpuset.h>
@@ -1141,3 +1142,72 @@ void pagefault_out_of_memory(void)out_of_memory (&oc);mutex_unlock (&oom_lock); } + +SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) +{ +#ifdef CONFIG_MMU +struct mm_struct *mm =NULL ; +struct task_struct *task; +struct task_struct *p; +unsigned int f_flags; +bool reap = true; +struct pid *pid; +long ret =0 ; + +if (flags) +return -EINVAL ; + + pid =pidfd_get_pid (pidfd, &f_flags); +if (IS_ERR (pid)) +return PTR_ERR (pid); + + task =get_pid_task (pid,PIDTYPE_TGID ); +if (!task) { + ret = -ESRCH ; + goto put_pid; + } + +/* +* Make sure to choose a thread which still has a reference to mm +* during the group exit +*/ + p =find_lock_task_mm (task); +if (!p) { + ret = -ESRCH ; + goto put_task; + } + + mm = p->mm; +mmgrab (mm); + +/* If the work has been done already, just exit with success */ +if (test_bit (MMF_OOM_SKIP , &mm->flags)) + reap = false; +else if (!task_will_free_mem (p)) { + reap = false; + ret = -EINVAL ; + } +task_unlock (p); + +if (!reap) + goto drop_mm; + +if (mmap_read_lock_killable (mm)) { + ret = -EINTR ; + goto drop_mm; + } +if (!__oom_reap_task_mm (mm)) + ret = -EAGAIN ; +mmap_read_unlock (mm); + +drop_mm: +mmdrop (mm); +put_task: +put_task_struct (task); +put_pid: +put_pid (pid); +return ret; +#else +return -ENOSYS ; +#endif /* CONFIG_MMU */ +}
_
Andrew Morton
maintainerPATCH 199/212 mm: wire up syscall process_mrelease
In reply to Andrew MortonFrom: Suren Baghdasaryan <[email protected]>
Subject: mm: wire up syscall process_mrelease
Split off from prev patch in the series that implements the syscall.
---
arch/alpha/kernel/syscalls/syscall.tbl | 2 ++ arch/arm/tools/syscall.tbl | 2 ++ arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 ++ arch/ia64/kernel/syscalls/syscall.tbl | 2 ++ arch/m68k/kernel/syscalls/syscall.tbl | 2 ++ arch/microblaze/kernel/syscalls/syscall.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_n32.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_n64.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_o32.tbl | 2 ++ arch/parisc/kernel/syscalls/syscall.tbl | 2 ++ arch/powerpc/kernel/syscalls/syscall.tbl | 2 ++ arch/s390/kernel/syscalls/syscall.tbl | 2 ++ arch/sh/kernel/syscalls/syscall.tbl | 2 ++ arch/sparc/kernel/syscalls/syscall.tbl | 2 ++ arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 ++ include/linux/syscalls.h | 1 + include/uapi/asm-generic/unistd.h | 4 +++- kernel/sys_ni.c | 1 + 21 files changed, 38 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl renamed from arch/alpha/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -486,3 +486,5 @@ 554 common landlock_create_ruleset sys_landlock_create_ruleset 555 common landlock_add_rule sys_landlock_add_rule 556 common landlock_restrict_self sys_landlock_restrict_self +# 557 reserved for memfd_secret +558 common process_mrelease sys_process_mrelease
arch/arm64/include/asm/unistd32.h renamed from arch/arm64/include/asm/unistd32.h~mm-wire-up-syscall-process_mrelease +2 -0
@@ -901,6 +901,8 @@ __SYSCALL(__NR_landlock_create_ruleset, __SYSCALL(__NR_landlock_add_rule, sys_landlock_add_rule)#define __NR_landlock_restrict_self 446 __SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self) +#define __NR_process_mrelease 448 +__SYSCALL (__NR_process_mrelease, sys_process_mrelease)/* * Please add new compat syscalls above this comment and update
arch/arm64/include/asm/unistd.h renamed from arch/arm64/include/asm/unistd.h~mm-wire-up-syscall-process_mrelease +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 447 +#define __NR_compat_syscalls 449#endif #define __ARCH_WANT_SYS_CLONE
arch/arm/tools/syscall.tbl renamed from arch/arm/tools/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -460,3 +460,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/ia64/kernel/syscalls/syscall.tbl renamed from arch/ia64/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -367,3 +367,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/m68k/kernel/syscalls/syscall.tbl renamed from arch/m68k/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -446,3 +446,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/microblaze/kernel/syscalls/syscall.tbl renamed from arch/microblaze/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -452,3 +452,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/mips/kernel/syscalls/syscall_n32.tbl renamed from arch/mips/kernel/syscalls/syscall_n32.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -385,3 +385,5 @@ 444 n32 landlock_create_ruleset sys_landlock_create_ruleset 445 n32 landlock_add_rule sys_landlock_add_rule 446 n32 landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 n32 process_mrelease sys_process_mrelease
arch/mips/kernel/syscalls/syscall_n64.tbl renamed from arch/mips/kernel/syscalls/syscall_n64.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -361,3 +361,5 @@ 444 n64 landlock_create_ruleset sys_landlock_create_ruleset 445 n64 landlock_add_rule sys_landlock_add_rule 446 n64 landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 n64 process_mrelease sys_process_mrelease
arch/mips/kernel/syscalls/syscall_o32.tbl renamed from arch/mips/kernel/syscalls/syscall_o32.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -434,3 +434,5 @@ 444 o32 landlock_create_ruleset sys_landlock_create_ruleset 445 o32 landlock_add_rule sys_landlock_add_rule 446 o32 landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 o32 process_mrelease sys_process_mrelease
arch/parisc/kernel/syscalls/syscall.tbl renamed from arch/parisc/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -444,3 +444,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/powerpc/kernel/syscalls/syscall.tbl renamed from arch/powerpc/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -526,3 +526,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/s390/kernel/syscalls/syscall.tbl renamed from arch/s390/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -449,3 +449,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease sys_process_mrelease
arch/sh/kernel/syscalls/syscall.tbl renamed from arch/sh/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -449,3 +449,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/sparc/kernel/syscalls/syscall.tbl renamed from arch/sparc/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -492,3 +492,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
arch/x86/entry/syscalls/syscall_32.tbl renamed from arch/x86/entry/syscalls/syscall_32.tbl~mm-wire-up-syscall-process_mrelease +1 -0
@@ -452,3 +452,4 @@ 445 i386 landlock_add_rule sys_landlock_add_rule 446 i386 landlock_restrict_self sys_landlock_restrict_self 447 i386 memfd_secret sys_memfd_secret +448 i386 process_mrelease sys_process_mrelease
arch/x86/entry/syscalls/syscall_64.tbl renamed from arch/x86/entry/syscalls/syscall_64.tbl~mm-wire-up-syscall-process_mrelease +1 -0
@@ -369,6 +369,7 @@ 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self 447 common memfd_secret sys_memfd_secret +448 common process_mrelease sys_process_mrelease # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl renamed from arch/xtensa/kernel/syscalls/syscall.tbl~mm-wire-up-syscall-process_mrelease +2 -0
@@ -417,3 +417,5 @@ 444 common landlock_create_ruleset sys_landlock_create_ruleset 445 common landlock_add_rule sys_landlock_add_rule 446 common landlock_restrict_self sys_landlock_restrict_self +# 447 reserved for memfd_secret +448 common process_mrelease sys_process_mrelease
include/linux/syscalls.h renamed from include/linux/syscalls.h~mm-wire-up-syscall-process_mrelease +1 -0
@@ -915,6 +915,7 @@ asmlinkage long sys_mincore(unsigned lonasmlinkage long sys_madvise (unsigned long start,size_t len,int behavior);asmlinkage long sys_process_madvise (int pidfd,const struct iovec __user *vec,size_t vlen,int behavior,unsigned int flags); +asmlinkage long sys_process_mrelease (int pidfd,unsigned int flags);asmlinkage long sys_remap_file_pages (unsigned long start,unsigned long size,unsigned long prot,unsigned long pgoff,unsigned long flags);
include/uapi/asm-generic/unistd.h renamed from include/uapi/asm-generic/unistd.h~mm-wire-up-syscall-process_mrelease +3 -1
@@ -877,9 +877,11 @@ __SYSCALL(__NR_landlock_restrict_self, s#define __NR_memfd_secret 447 __SYSCALL(__NR_memfd_secret, sys_memfd_secret)#endif +#define __NR_process_mrelease 448 +__SYSCALL(__NR_process_mrelease, sys_process_mrelease)#undef __NR_syscalls -#define __NR_syscalls 448 +#define __NR_syscalls 449/* * 32 bit systems traditionally used different
kernel/sys_ni.c renamed from kernel/sys_ni.c~mm-wire-up-syscall-process_mrelease +1 -0
@@ -289,6 +289,7 @@ COND_SYSCALL(munlockall);COND_SYSCALL (mincore);COND_SYSCALL (madvise);COND_SYSCALL (process_madvise); +COND_SYSCALL (process_mrelease);COND_SYSCALL (remap_file_pages);COND_SYSCALL (mbind);COND_SYSCALL_COMPAT (mbind);
_
Andrew Morton
maintainerPATCH 200/212 mm/migrate: correct kernel-doc notation
In reply to Andrew MortonFrom: Randy Dunlap <[email protected]>
Subject: mm/migrate: correct kernel-doc notation
Use the expected "Return:" format to prevent a kernel-doc warning.
mm/migrate.c:1157: warning: Excess function parameter 'returns' description in 'next_demotion_node'
---
mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/migrate.c renamed from mm/migrate.c~mm-migrate-correct-kernel-doc-notation +1 -1
@@ -1149,7 +1149,7 @@ static int node_demotion[MAX_NUMNODES] _* next_demotion_node() - Get the next node in the demotion path * @node: The starting node to lookup the next node * -* @returns: node id for next memory node in the demotion path hierarchy +* Return: node id for next memory node in the demotion path hierarchy * from @node; NUMA_NO_NODE if @node is terminal. This does not keep * @node online or guarantee that it *continues* to be the next demotion * target.
_
Andrew Morton
maintainerPATCH 201/212 selftests: vm: add KSM merge test
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add KSM merge test
Patch series "add KSM selftests".
Introduce selftests to validate the functionality of KSM. The tests are run on private anonymous pages. Since some KSM tunables are modified, their starting values are saved and restored after testing. At the start, run is set to 2 to ensure that only test pages will be merged (we assume that no applications make madvise syscalls in the background). If KSM config not enabled, all tests will be skipped.
This patch (of 4):
Add check_ksm_merge() function to check the basic merging feature of KSM. First, some number of identical pages are allocated and the MADV_MERGEABLE advice is given to merge these pages. Then, pages_shared and pages_sharing values are compared with the expected numbers using assert_ksm_pages_count() function. The number of pages can be changed using -p option.
---
tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 1 tools/testing/selftests/vm/ksm_tests.c | 306 ++++++++++++++++++++ tools/testing/selftests/vm/run_vmtests.sh | 16 + 4 files changed, 324 insertions(+)
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~selftests-vm-add-ksm-merge-test +1 -0
@@ -27,3 +27,4 @@ hmm-tests memfd_secret local_config.* split_huge_page_test +ksm_tests
tools/testing/selftests/vm/ksm_tests.c new file +306 -0
306 lines not on this page · raw message
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-add-ksm-merge-test +1 -0
@@ -45,6 +45,7 @@ TEST_GEN_FILES += thuge-gen TEST_GEN_FILES += transhuge-stress TEST_GEN_FILES += userfaultfd TEST_GEN_FILES += split_huge_page_test +TEST_GEN_FILES += ksm_tests ifeq ($(MACHINE),x86_64) CAN_BUILD_I386 := $(shell ./../x86/check_cc.sh $(CC) ../x86/trivial_32bit_program.c -m32)
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~selftests-vm-add-ksm-merge-test +16 -0
@@ -377,6 +377,22 @@ else exitcode=1 fi +echo "-------------------------------------------------------" +echo "running KSM MADV_MERGEABLE test with 10 identical pages" +echo "-------------------------------------------------------" +./ksm_tests -p 10 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + exit $exitcode exit $exitcode
_
Andrew Morton
maintainerPATCH 202/212 selftests: vm: add KSM unmerge test
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add KSM unmerge test
Add check_ksm_unmerge() function to verify that KSM is properly unmerging shared pages. For this, two duplicate pages are merged first and then their contents are modified. Since they are not identical anymore, the pages must be unmerged and the number of merged pages has to be 0. The test is run as follows: ./ksm_tests -U
---
tools/testing/selftests/vm/ksm_tests.c | 72 ++++++++++++++++++-- tools/testing/selftests/vm/run_vmtests.sh | 18 ++++- 2 files changed, 85 insertions(+), 5 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-ksm-unmerge-test +68 -4
@@ -23,6 +23,11 @@ struct ksm_sysfs {unsigned long use_zero_pages; }; +enum ksm_test_name { +CHECK_KSM_MERGE , +CHECK_KSM_UNMERGE +}; +static int ksm_write_sysfs (const char *file_path,unsigned long val) {FILE *f =fopen (file_path,"w" );
@@ -75,7 +80,12 @@ static int str_to_prot(char *prot_str)static void print_help (void ) { -printf ("usage: ksm_tests [-h] [-a prot] [-p page_count] [-l timeout]\n" ); +printf ("usage: ksm_tests [-h] <test type> [-a prot] [-p page_count] [-l timeout]\n" ); + +printf ("Supported <test type>:\n" +" -M (page merging)\n" +" -U (page unmerging)\n\n" ); +printf (" -a: specify the access protections of pages.\n" " <prot> must be of the form [rwx].\n" " Default: %s\n" ,KSM_PROT_STR_DEFAULT );
@@ -239,6 +249,46 @@ err_out:return KSFT_FAIL ; } +static int check_ksm_unmerge (int mapping,int prot,int timeout,size_t page_size) +{ +void *map_ptr; +struct timespec start_time; +int page_count =2 ; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); +return KSFT_FAIL ; + } + +/* fill pages with the same data and merge them */ + map_ptr =allocate_memory (NULL , prot, mapping,'*' , page_size * page_count); +if (!map_ptr) +return KSFT_FAIL ; + +if (ksm_merge_pages (map_ptr, page_size * page_count, start_time, timeout)) + goto err_out; + +/* change 1 byte in each of the 2 pages -- KSM must automatically unmerge them */ +memset (map_ptr,'-' ,1 ); +memset (map_ptr + page_size,'+' ,1 ); + +/* get at least 1 scan, so KSM can detect that the pages were modified */ +if (ksm_do_scan (1 , start_time, timeout)) + goto err_out; + +/* check that unmerging was successful and 0 pages are currently merged */ +if (assert_ksm_pages_count (0 )) { +printf ("OK\n" ); +munmap (map_ptr, page_size * page_count); +return KSFT_PASS ; + } + +err_out: +printf ("Not OK\n" ); +munmap (map_ptr, page_size * page_count); +return KSFT_FAIL ; +} +int main (int argc,char *argv[]) {int ret, opt;
@@ -247,8 +297,9 @@ int main(int argc, char *argv[])long page_count =KSM_PAGE_COUNT_DEFAULT ;size_t page_size =sysconf (_SC_PAGESIZE);struct ksm_sysfs ksm_sysfs_old; +int test_name =CHECK_KSM_MERGE ; -while ((opt =getopt (argc, argv,"ha:p:l:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:MU" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -270,6 +321,11 @@ int main(int argc, char *argv[])case 'h' :print_help ();break ; +case 'M' : +break ; +case 'U' : + test_name =CHECK_KSM_UNMERGE ; +break ;default :return KSFT_FAIL ; }
@@ -294,8 +350,16 @@ int main(int argc, char *argv[]) ksm_write_sysfs(KSM_FP("pages_to_scan"), page_count))return KSFT_FAIL ; - ret =check_ksm_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, ksm_scan_limit_sec, - page_size); +switch (test_name) { +case CHECK_KSM_MERGE : + ret =check_ksm_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, + ksm_scan_limit_sec, page_size); +break ; +case CHECK_KSM_UNMERGE : + ret =check_ksm_unmerge (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, + page_size); +break ; + }if (ksm_restore (&ksm_sysfs_old)) {printf ("Cannot restore default tunables\n" );
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~selftests-vm-add-ksm-unmerge-test +17 -1
@@ -380,7 +380,23 @@ fi echo "-------------------------------------------------------" echo "running KSM MADV_MERGEABLE test with 10 identical pages" echo "-------------------------------------------------------" -./ksm_tests -p 10 +./ksm_tests -M -p 10 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + +echo "------------------------" +echo "running KSM unmerge test" +echo "------------------------" +./ksm_tests -U ret_val=$? if [ $ret_val -eq 0 ]; then
_
Andrew Morton
maintainerPATCH 203/212 selftests: vm: add KSM zero page merging test
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add KSM zero page merging test
Add check_ksm_zero_page_merge() function to test that empty pages are being handled properly. For this, several zero pages are allocated and merged using madvise. If use_zero_pages is enabled, the pages must be shared with the special kernel zero pages; otherwise, they are merged as usual duplicate pages. The test is run as follows: ./ksm_tests -Z
---
tools/testing/selftests/vm/ksm_tests.c | 70 +++++++++++++++++++- tools/testing/selftests/vm/run_vmtests.sh | 32 +++++++++ 2 files changed, 99 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-ksm-zero-page-merging-test +67 -3
@@ -12,6 +12,7 @@#define KSM_SCAN_LIMIT_SEC_DEFAULT 120#define KSM_PAGE_COUNT_DEFAULT 10l#define KSM_PROT_STR_DEFAULT "rw" +#define KSM_USE_ZERO_PAGES_DEFAULT falsestruct ksm_sysfs {unsigned long max_page_sharing;
@@ -25,7 +26,8 @@ struct ksm_sysfs {enum ksm_test_name {CHECK_KSM_MERGE , -CHECK_KSM_UNMERGE +CHECK_KSM_UNMERGE , +CHECK_KSM_ZERO_PAGE_MERGE };static int ksm_write_sysfs (const char *file_path,unsigned long val)
@@ -80,10 +82,12 @@ static int str_to_prot(char *prot_str)static void print_help (void ) { -printf ("usage: ksm_tests [-h] <test type> [-a prot] [-p page_count] [-l timeout]\n" ); +printf ("usage: ksm_tests [-h] <test type> [-a prot] [-p page_count] [-l timeout]\n" +"[-z use_zero_pages]\n" );printf ("Supported <test type>:\n" " -M (page merging)\n" +" -Z (zero pages merging)\n" " -U (page unmerging)\n\n" ); printf(" -a: specify the access protections of pages.\n"
@@ -93,6 +97,8 @@ static void print_help(void) " Default: %ld\n", KSM_PAGE_COUNT_DEFAULT);printf (" -l: limit the maximum running time (in seconds) for a test.\n" " Default: %d seconds\n" ,KSM_SCAN_LIMIT_SEC_DEFAULT ); +printf (" -z: change use_zero_pages tunable\n" +" Default: %d\n" ,KSM_USE_ZERO_PAGES_DEFAULT );exit (0 ); }
@@ -289,6 +295,50 @@ err_out:return KSFT_FAIL ; } +static int check_ksm_zero_page_merge (int mapping,int prot,long page_count,int timeout, +bool use_zero_pages,size_t page_size) +{ +void *map_ptr; +struct timespec start_time; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); +return KSFT_FAIL ; + } + +if (ksm_write_sysfs (KSM_FP ("use_zero_pages" ), use_zero_pages)) +return KSFT_FAIL ; + +/* fill pages with zero and try to merge them */ + map_ptr =allocate_memory (NULL , prot, mapping,0 , page_size * page_count); +if (!map_ptr) +return KSFT_FAIL ; + +if (ksm_merge_pages (map_ptr, page_size * page_count, start_time, timeout)) + goto err_out; + +/* +* verify that the right number of pages are merged: +* 1) if use_zero_pages is set to 1, empty pages are merged +* with the kernel zero page instead of with each other; +* 2) if use_zero_pages is set to 0, empty pages are not treated specially +* and merged as usual. +*/ +if (use_zero_pages && !assert_ksm_pages_count (0 )) + goto err_out; +else if (!use_zero_pages && !assert_ksm_pages_count (page_count)) + goto err_out; + +printf ("OK\n" ); +munmap (map_ptr, page_size * page_count); +return KSFT_PASS ; + +err_out: +printf ("Not OK\n" ); +munmap (map_ptr, page_size * page_count); +return KSFT_FAIL ; +} +int main (int argc,char *argv[]) {int ret, opt;
@@ -298,8 +348,9 @@ int main(int argc, char *argv[])size_t page_size =sysconf (_SC_PAGESIZE);struct ksm_sysfs ksm_sysfs_old;int test_name =CHECK_KSM_MERGE ; +bool use_zero_pages =KSM_USE_ZERO_PAGES_DEFAULT ; -while ((opt =getopt (argc, argv,"ha:p:l:MU" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:z:MUZ" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -321,11 +372,20 @@ int main(int argc, char *argv[])case 'h' :print_help ();break ; +case 'z' : +if (strcmp (optarg,"0" ) ==0 ) + use_zero_pages =0 ; +else + use_zero_pages =1 ; +break ;case 'M' :break ;case 'U' : test_name =CHECK_KSM_UNMERGE ;break ; +case 'Z' : + test_name =CHECK_KSM_ZERO_PAGE_MERGE ; +break ;default :return KSFT_FAIL ; }
@@ -359,6 +419,10 @@ int main(int argc, char *argv[]) ret =check_ksm_unmerge (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, page_size);break ; +case CHECK_KSM_ZERO_PAGE_MERGE : + ret =check_ksm_zero_page_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, + ksm_scan_limit_sec, use_zero_pages, page_size); +break ; }if (ksm_restore (&ksm_sysfs_old)) {
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~selftests-vm-add-ksm-zero-page-merging-test +32 -0
@@ -409,6 +409,38 @@ else exitcode=1 fi +echo "----------------------------------------------------------" +echo "running KSM test with 10 zero pages and use_zero_pages = 0" +echo "----------------------------------------------------------" +./ksm_tests -Z -p 10 -z 0 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + +echo "----------------------------------------------------------" +echo "running KSM test with 10 zero pages and use_zero_pages = 1" +echo "----------------------------------------------------------" +./ksm_tests -Z -p 10 -z 1 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + exit $exitcode exit $exitcode
_
Andrew Morton
maintainerPATCH 204/212 selftests: vm: add KSM merging across nodes test
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add KSM merging across nodes test
Add check_ksm_numa_merge() function to test that pages in different NUMA nodes are being handled properly. First, two duplicate pages are allocated in two separate NUMA nodes using the libnuma library. Since there is one unique page in each node, with merge_across_nodes = 0, there won't be any shared pages. If merge_across_nodes is set to 1, the pages will be treated as usual duplicate pages and will be merged. If NUMA config is not enabled or the number of NUMA nodes is less than two, then the test is skipped. The test is run as follows: ./ksm_tests -N
---
tools/testing/selftests/vm/Makefile | 2 tools/testing/selftests/vm/ksm_tests.c | 88 +++++++++++++++++++- tools/testing/selftests/vm/run_vmtests.sh | 32 +++++++ 3 files changed, 119 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-ksm-merging-across-nodes-test +85 -3
@@ -4,6 +4,7 @@#include <stdbool.h> #include <time.h> #include <string.h> +#include <numa.h> #include "../kselftest.h"
@@ -13,6 +14,7 @@#define KSM_PAGE_COUNT_DEFAULT 10l#define KSM_PROT_STR_DEFAULT "rw"#define KSM_USE_ZERO_PAGES_DEFAULT false +#define KSM_MERGE_ACROSS_NODES_DEFAULT truestruct ksm_sysfs {unsigned long max_page_sharing;
@@ -27,7 +29,8 @@ struct ksm_sysfs {enum ksm_test_name {CHECK_KSM_MERGE ,CHECK_KSM_UNMERGE , -CHECK_KSM_ZERO_PAGE_MERGE +CHECK_KSM_ZERO_PAGE_MERGE , +CHECK_KSM_NUMA_MERGE };static int ksm_write_sysfs (const char *file_path,unsigned long val)
@@ -83,11 +86,12 @@ static int str_to_prot(char *prot_str)static void print_help (void ) {printf ("usage: ksm_tests [-h] <test type> [-a prot] [-p page_count] [-l timeout]\n" -"[-z use_zero_pages]\n" ); +"[-z use_zero_pages] [-m merge_across_nodes]\n" );printf ("Supported <test type>:\n" " -M (page merging)\n" " -Z (zero pages merging)\n" +" -N (merging of pages in different NUMA nodes)\n" " -U (page unmerging)\n\n" ); printf(" -a: specify the access protections of pages.\n"
@@ -99,6 +103,8 @@ static void print_help(void) " Default: %d seconds\n", KSM_SCAN_LIMIT_SEC_DEFAULT);printf (" -z: change use_zero_pages tunable\n" " Default: %d\n" ,KSM_USE_ZERO_PAGES_DEFAULT ); +printf (" -m: change merge_across_nodes tunable\n" +" Default: %d\n" ,KSM_MERGE_ACROSS_NODES_DEFAULT );exit (0 ); }
@@ -339,6 +345,68 @@ err_out:return KSFT_FAIL ; } +static int check_ksm_numa_merge (int mapping,int prot,int timeout,bool merge_across_nodes, +size_t page_size) +{ +void *numa1_map_ptr, *numa2_map_ptr; +struct timespec start_time; +int page_count =2 ; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); +return KSFT_FAIL ; + } + +if (numa_available () <0 ) { +perror ("NUMA support not enabled" ); +return KSFT_SKIP ; + } +if (numa_max_node () <1 ) { +printf ("At least 2 NUMA nodes must be available\n" ); +return KSFT_SKIP ; + } +if (ksm_write_sysfs (KSM_FP ("merge_across_nodes" ), merge_across_nodes)) +return KSFT_FAIL ; + +/* allocate 2 pages in 2 different NUMA nodes and fill them with the same data */ + numa1_map_ptr =numa_alloc_onnode (page_size,0 ); + numa2_map_ptr =numa_alloc_onnode (page_size,1 ); +if (!numa1_map_ptr || !numa2_map_ptr) { +perror ("numa_alloc_onnode" ); +return KSFT_FAIL ; + } + +memset (numa1_map_ptr,'*' , page_size); +memset (numa2_map_ptr,'*' , page_size); + +/* try to merge the pages */ +if (ksm_merge_pages (numa1_map_ptr, page_size, start_time, timeout) || +ksm_merge_pages (numa2_map_ptr, page_size, start_time, timeout)) + goto err_out; + +/* +* verify that the right number of pages are merged: +* 1) if merge_across_nodes was enabled, 2 duplicate pages will be merged; +* 2) if merge_across_nodes = 0, there must be 0 merged pages, since there is +* only 1 unique page in each node and they can't be shared. +*/ +if (merge_across_nodes && !assert_ksm_pages_count (page_count)) + goto err_out; +else if (!merge_across_nodes && !assert_ksm_pages_count (0 )) + goto err_out; + +numa_free (numa1_map_ptr, page_size); +numa_free (numa2_map_ptr, page_size); +printf ("OK\n" ); +return KSFT_PASS ; + +err_out: +numa_free (numa1_map_ptr, page_size); +numa_free (numa2_map_ptr, page_size); +printf ("Not OK\n" ); +return KSFT_FAIL ; +} +int main (int argc,char *argv[]) {int ret, opt;
@@ -349,8 +417,9 @@ int main(int argc, char *argv[])struct ksm_sysfs ksm_sysfs_old;int test_name =CHECK_KSM_MERGE ;bool use_zero_pages =KSM_USE_ZERO_PAGES_DEFAULT ; +bool merge_across_nodes =KSM_MERGE_ACROSS_NODES_DEFAULT ; -while ((opt =getopt (argc, argv,"ha:p:l:z:MUZ" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:z:m:MUZN" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -378,6 +447,12 @@ int main(int argc, char *argv[])else use_zero_pages =1 ;break ; +case 'm' : +if (strcmp (optarg,"0" ) ==0 ) + merge_across_nodes =0 ; +else + merge_across_nodes =1 ; +break ;case 'M' :break ;case 'U' :
@@ -386,6 +461,9 @@ int main(int argc, char *argv[])case 'Z' : test_name =CHECK_KSM_ZERO_PAGE_MERGE ;break ; +case 'N' : + test_name =CHECK_KSM_NUMA_MERGE ; +break ;default :return KSFT_FAIL ; }
@@ -423,6 +501,10 @@ int main(int argc, char *argv[]) ret =check_ksm_zero_page_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, page_count, ksm_scan_limit_sec, use_zero_pages, page_size);break ; +case CHECK_KSM_NUMA_MERGE : + ret =check_ksm_numa_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, + merge_across_nodes, page_size); +break ; }if (ksm_restore (&ksm_sysfs_old)) {
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~selftests-vm-add-ksm-merging-across-nodes-test +2 -0
@@ -146,6 +146,8 @@ $(OUTPUT)/hmm-tests: local_config.h # HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. $(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS) +$(OUTPUT)/ksm_tests: LDLIBS += -lnuma + local_config.mk local_config.h: check_config.sh /bin/sh ./check_config.sh $(CC)
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~selftests-vm-add-ksm-merging-across-nodes-test +32 -0
@@ -441,6 +441,38 @@ else exitcode=1 fi +echo "-------------------------------------------------------------" +echo "running KSM test with 2 NUMA nodes and merge_across_nodes = 1" +echo "-------------------------------------------------------------" +./ksm_tests -N -m 1 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + +echo "-------------------------------------------------------------" +echo "running KSM test with 2 NUMA nodes and merge_across_nodes = 0" +echo "-------------------------------------------------------------" +./ksm_tests -N -m 0 +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "[PASS]" +elif [ $ret_val -eq $ksft_skip ]; then + echo "[SKIP]" + exitcode=$ksft_skip +else + echo "[FAIL]" + exitcode=1 +fi + exit $exitcode exit $exitcode
_
Andrew Morton
maintainerPATCH 205/212 mm: KSM: fix data type
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: mm: KSM: fix data type
ksm_stable_node_chains_prune_millisecs is declared as int, but in stable__node_chains_prune_millisecs_store(), it can store values up to UINT_MAX. Change its type to unsigned int.
---
mm/ksm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/ksm.c renamed from mm/ksm.c~mm-ksm-fix-data-type +4 -4
@@ -259,7 +259,7 @@ static unsigned long ksm_stable_node_chastatic unsigned long ksm_stable_node_dups;/* Delay in pruning stale stable_node_dups in the stable_node_chains */ -static int ksm_stable_node_chains_prune_millisecs =2000 ; +static unsigned int ksm_stable_node_chains_prune_millisecs =2000 ;/* Maximum number of page slots sharing a stable node */ static int ksm_max_page_sharing =256 ;
@@ -3105,11 +3105,11 @@ stable_node_chains_prune_millisecs_storestruct kobj_attribute *attr, const char *buf, size_t count) { - unsigned long msecs; + unsigned int msecs;int err; - err =kstrtoul (buf,10 , &msecs); -if (err || msecs >UINT_MAX ) + err =kstrtouint (buf,10 , &msecs); +if (err)return -EINVAL ; ksm_stable_node_chains_prune_millisecs = msecs;
_
Andrew Morton
maintainerPATCH 206/212 selftests: vm: add KSM merging time test
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add KSM merging time test
Patch series "add KSM performance tests", v3.
Extend KSM self tests with a performance benchmark. These tests are not part of regular regression testing, as they are mainly intended to be used by developers making changes to the memory management subsystem.
This patch (of 2):
Add ksm_merge_time() function to determine speed and time needed for merging. The total spent time is shown in seconds while speed is in MiB/s. User must specify the size of duplicated memory area (in MiB) before running the test.
The test is run as follows: ./ksm_tests -P -s 100
The output:
Total size: 100 MiB Total time: 0.201106786 s Average speed: 497.248 MiB/s
---
tools/testing/selftests/vm/ksm_tests.c | 74 +++++++++++++++++++++-- 1 file changed, 70 insertions(+), 4 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-ksm-merging-time-test +70 -4
@@ -7,6 +7,7 @@#include <numa.h> #include "../kselftest.h" +#include "../../../../include/vdso/time64.h" #define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/"#define KSM_FP (s) (KSM_SYSFS_PATH s)
@@ -15,6 +16,7 @@#define KSM_PROT_STR_DEFAULT "rw"#define KSM_USE_ZERO_PAGES_DEFAULT false#define KSM_MERGE_ACROSS_NODES_DEFAULT true +#define MB (1ul << 20)struct ksm_sysfs {unsigned long max_page_sharing;
@@ -30,7 +32,8 @@ enum ksm_test_name {CHECK_KSM_MERGE ,CHECK_KSM_UNMERGE ,CHECK_KSM_ZERO_PAGE_MERGE , - CHECK_KSM_NUMA_MERGE +CHECK_KSM_NUMA_MERGE , + KSM_MERGE_TIME };static int ksm_write_sysfs (const char *file_path,unsigned long val)
@@ -86,13 +89,16 @@ static int str_to_prot(char *prot_str)static void print_help (void ) {printf ("usage: ksm_tests [-h] <test type> [-a prot] [-p page_count] [-l timeout]\n" -"[-z use_zero_pages] [-m merge_across_nodes]\n" ); +"[-z use_zero_pages] [-m merge_across_nodes] [-s size]\n" );printf ("Supported <test type>:\n" " -M (page merging)\n" " -Z (zero pages merging)\n" " -N (merging of pages in different NUMA nodes)\n" -" -U (page unmerging)\n\n" ); +" -U (page unmerging)\n" +" -P evaluate merging time and speed.\n" +" For this test, the size of duplicated memory area (in MiB)\n" +" must be provided using -s option\n\n" );printf (" -a: specify the access protections of pages.\n" " <prot> must be of the form [rwx].\n"
@@ -105,6 +111,7 @@ static void print_help(void) " Default: %d\n", KSM_USE_ZERO_PAGES_DEFAULT);printf (" -m: change merge_across_nodes tunable\n" " Default: %d\n" ,KSM_MERGE_ACROSS_NODES_DEFAULT ); +printf (" -s: the size of duplicated memory area (in MiB)\n" );exit (0 ); }
@@ -407,6 +414,47 @@ err_out:return KSFT_FAIL ; } +static int ksm_merge_time (int mapping,int prot,int timeout,size_t map_size) +{ +void *map_ptr; +struct timespec start_time, end_time; +unsigned long scan_time_ns; + + map_size *=MB ; + + map_ptr =allocate_memory (NULL , prot, mapping,'*' , map_size); +if (!map_ptr) +return KSFT_FAIL ; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); + goto err_out; + } +if (ksm_merge_pages (map_ptr, map_size, start_time, timeout)) + goto err_out; +if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { +perror ("clock_gettime" ); + goto err_out; + } + + scan_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + + (end_time.tv_nsec - start_time.tv_nsec); + +printf ("Total size: %lu MiB\n" , map_size /MB ); +printf ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , + scan_time_ns %NSEC_PER_SEC ); +printf ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / + ((double )scan_time_ns /NSEC_PER_SEC )); + +munmap (map_ptr, map_size); +return KSFT_PASS ; + +err_out: +printf ("Not OK\n" ); +munmap (map_ptr, map_size); +return KSFT_FAIL ; +} +int main (int argc,char *argv[]) {int ret, opt;
@@ -418,8 +466,9 @@ int main(int argc, char *argv[])int test_name =CHECK_KSM_MERGE ;bool use_zero_pages =KSM_USE_ZERO_PAGES_DEFAULT ;bool merge_across_nodes =KSM_MERGE_ACROSS_NODES_DEFAULT ; +long size_MB =0 ; -while ((opt =getopt (argc, argv,"ha:p:l:z:m:MUZN" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:z:m:s:MUZNP" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -453,6 +502,12 @@ int main(int argc, char *argv[])else merge_across_nodes =1 ;break ; +case 's' : + size_MB =atoi (optarg); +if (size_MB <=0 ) { +printf ("Size must be greater than 0\n" ); +return KSFT_FAIL ; + }case 'M' :break ;case 'U' :
@@ -464,6 +519,9 @@ int main(int argc, char *argv[])case 'N' : test_name =CHECK_KSM_NUMA_MERGE ;break ; +case 'P' : + test_name =KSM_MERGE_TIME ; +break ;default :return KSFT_FAIL ; }
@@ -505,6 +563,14 @@ int main(int argc, char *argv[]) ret =check_ksm_numa_merge (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, merge_across_nodes, page_size);break ; +case KSM_MERGE_TIME : +if (size_MB ==0 ) { +printf ("Option '-s' is required.\n" ); +return KSFT_FAIL ; + } + ret =ksm_merge_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, + size_MB); +break ; }if (ksm_restore (&ksm_sysfs_old)) {
_
Andrew Morton
maintainerPATCH 207/212 selftests: vm: add COW time test for KSM pages
In reply to Andrew MortonFrom: Zhansaya Bagdauletkyzy <[email protected]>
Subject: selftests: vm: add COW time test for KSM pages
Since merged pages are copied every time they need to be modified, the write access time is different between shared and non-shared pages. Add ksm_cow_time() function which evaluates latency of these COW breaks. First, 4000 pages are allocated and the time, required to modify 1 byte in every other page, is measured. After this, the pages are merged into 2000 pairs and in each pair, 1 page is modified (i.e. they are decoupled) to detect COW breaks. The time needed to break COW of merged pages is then compared with performance of non-shared pages.
The test is run as follows: ./ksm_tests -C
The output:
Total size: 15 MiB Not merged pages: Total time: 0.002185489 s Average speed: 3202.945 MiB/s Merged pages: Total time: 0.004386872 s Average speed: 1595.670 MiB/s
---
tools/testing/selftests/vm/ksm_tests.c | 86 ++++++++++++++++++++++- 1 file changed, 83 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-cow-time-test-for-ksm-pages +83 -3
@@ -33,7 +33,8 @@ enum ksm_test_name {CHECK_KSM_UNMERGE ,CHECK_KSM_ZERO_PAGE_MERGE ,CHECK_KSM_NUMA_MERGE , - KSM_MERGE_TIME +KSM_MERGE_TIME , + KSM_COW_TIME };static int ksm_write_sysfs (const char *file_path,unsigned long val)
@@ -98,7 +99,8 @@ static void print_help(void)" -U (page unmerging)\n" " -P evaluate merging time and speed.\n" " For this test, the size of duplicated memory area (in MiB)\n" - " must be provided using -s option\n\n"); +" must be provided using -s option\n" + " -C evaluate the time required to break COW of merged pages.\n\n");printf (" -a: specify the access protections of pages.\n" " <prot> must be of the form [rwx].\n"
@@ -455,6 +457,77 @@ err_out:return KSFT_FAIL ; } +static int ksm_cow_time (int mapping,int prot,int timeout,size_t page_size) +{ +void *map_ptr; +struct timespec start_time, end_time; +unsigned long cow_time_ns; + +/* page_count must be less than 2*page_size */ +size_t page_count =4000 ; + + map_ptr =allocate_memory (NULL , prot, mapping,'*' , page_size * page_count); +if (!map_ptr) +return KSFT_FAIL ; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); +return KSFT_FAIL ; + } +for (size_t i =0 ; i < page_count -1 ; i = i +2 ) +memset (map_ptr + page_size * i,'-' ,1 ); +if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { +perror ("clock_gettime" ); +return KSFT_FAIL ; + } + + cow_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + + (end_time.tv_nsec - start_time.tv_nsec); + +printf ("Total size: %lu MiB\n\n" , (page_size * page_count) /MB ); +printf ("Not merged pages:\n" ); +printf ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , + cow_time_ns %NSEC_PER_SEC ); +printf ("Average speed: %.3f MiB/s\n\n" , ((page_size * (page_count /2 )) /MB ) / + ((double )cow_time_ns /NSEC_PER_SEC )); + +/* Create 2000 pairs of duplicate pages */ +for (size_t i =0 ; i < page_count -1 ; i = i +2 ) { +memset (map_ptr + page_size * i,'+' , i /2 +1 ); +memset (map_ptr + page_size * (i +1 ),'+' , i /2 +1 ); + } +if (ksm_merge_pages (map_ptr, page_size * page_count, start_time, timeout)) + goto err_out; + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); + goto err_out; + } +for (size_t i =0 ; i < page_count -1 ; i = i +2 ) +memset (map_ptr + page_size * i,'-' ,1 ); +if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { +perror ("clock_gettime" ); + goto err_out; + } + + cow_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + + (end_time.tv_nsec - start_time.tv_nsec); + +printf ("Merged pages:\n" ); +printf ("Total time: %ld.%09ld s\n" , cow_time_ns /NSEC_PER_SEC , + cow_time_ns %NSEC_PER_SEC ); +printf ("Average speed: %.3f MiB/s\n" , ((page_size * (page_count /2 )) /MB ) / + ((double )cow_time_ns /NSEC_PER_SEC )); + +munmap (map_ptr, page_size * page_count); +return KSFT_PASS ; + +err_out: +printf ("Not OK\n" ); +munmap (map_ptr, page_size * page_count); +return KSFT_FAIL ; +} +int main (int argc,char *argv[]) {int ret, opt;
@@ -468,7 +541,7 @@ int main(int argc, char *argv[])bool merge_across_nodes =KSM_MERGE_ACROSS_NODES_DEFAULT ;long size_MB =0 ; -while ((opt =getopt (argc, argv,"ha:p:l:z:m:s:MUZNP" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:z:m:s:MUZNPC" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -522,6 +595,9 @@ int main(int argc, char *argv[])case 'P' : test_name =KSM_MERGE_TIME ;break ; +case 'C' : + test_name =KSM_COW_TIME ; +break ;default :return KSFT_FAIL ; }
@@ -571,6 +647,10 @@ int main(int argc, char *argv[]) ret =ksm_merge_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, size_MB);break ; +case KSM_COW_TIME : + ret =ksm_cow_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, + page_size); +break ; }if (ksm_restore (&ksm_sysfs_old)) {
_
Andrew Morton
maintainerPATCH 208/212 mm/percpu,c: remove obsolete comments of pcpu_chunk_populated()
In reply to Andrew MortonFrom: Jing Xiangfeng <[email protected]>
Subject: mm/percpu,c: remove obsolete comments of pcpu_chunk_populated()
Commit b239f7daf553 ("percpu: set PCPU_BITMAP_BLOCK_SIZE to PAGE_SIZE") removed the parameter 'for_alloc', so remove this comment.
---
mm/percpu.c | 3 --- 1 file changed, 3 deletions(-)
mm/percpu.c renamed from mm/percpu.c~percpu-remove-obsolete-comments-of-pcpu_chunk_populated +0 -3
@@ -1520,9 +1520,6 @@ static void pcpu_free_chunk(struct pcpu_* Pages in [@page_start,@page_end) have been populated to @chunk. Update * the bookkeeping information accordingly. Must be called after each * successful population. -* -* If this is @for_alloc, do not increment pcpu_nr_empty_pop_pages because it -* is to serve an allocation in that area. */ static void pcpu_chunk_populated (struct pcpu_chunk *chunk,int page_start,int page_end)
_
Andrew Morton
maintainerPATCH 209/212 mm/vmstat: correct some wrong comments
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/vmstat: correct some wrong comments
Patch series "Cleanup for vmstat".
This series contains cleanups to remove unneeded return value, correct wrong comment and simplify the array size calculation. More details can be found in the respective changelogs.
This patch (of 3):
Correct wrong fls(mem+1) to fls(mem)+1 and remove the duplicated comment with quiet_vmstat().
---
mm/vmstat.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstat-correct-some-wrong-comments +1 -6
@@ -204,7 +204,7 @@ int calculate_normal_threshold(struct zo* * Some sample thresholds: * -* Threshold Processors (fls) Zonesize fls(mem+1) +* Threshold Processors (fls) Zonesize fls(mem)+1 * ------------------------------------------------------------------ * 8 1 1 0.9-1 GB 4 * 16 2 2 0.9-1 GB 4
@@ -1876,11 +1876,6 @@ static void vmstat_update(struct work_st }/* -* Switch off vmstat processing and then fold all the remaining differentials -* until the diffs stay at zero. The function is used by NOHZ and can only be -* invoked when tick processing is not active. -*/ -/* * Check if the diffs for a certain cpu indicate that * an update is needed. */
_
Andrew Morton
maintainerPATCH 210/212 mm/vmstat: simplify the array size calculation
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/vmstat: simplify the array size calculation
We can replace the array_num * sizeof(array[0]) with sizeof(array) to simplify the code.
---
mm/vmstat.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstat-simplify-the-array-size-calculation +3 -5
@@ -1891,17 +1891,15 @@ static bool need_update(int cpu)/* * The fast way of checking if there are any vmstat diffs. */ -if (memchr_inv (pzstats->vm_stat_diff,0 ,NR_VM_ZONE_STAT_ITEMS * -sizeof (pzstats->vm_stat_diff[0 ]))) +if (memchr_inv (pzstats->vm_stat_diff,0 ,sizeof (pzstats->vm_stat_diff)))return true;if (last_pgdat == zone->zone_pgdat)continue ; last_pgdat = zone->zone_pgdat; n =per_cpu_ptr (zone->zone_pgdat->per_cpu_nodestats, cpu); -if (memchr_inv (n->vm_node_stat_diff,0 ,NR_VM_NODE_STAT_ITEMS * -sizeof (n->vm_node_stat_diff[0 ]))) -return true; +if (memchr_inv (n->vm_node_stat_diff,0 ,sizeof (n->vm_node_stat_diff))) +return true; }return false; }
_
Andrew Morton
maintainerPATCH 211/212 mm/vmstat: remove unneeded return value
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/vmstat: remove unneeded return value
The return value of pagetypeinfo_showfree and pagetypeinfo_showblockcount are unused now. Remove them.
---
mm/vmstat.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstat-remove-unneeded-return-value +2 -6
@@ -1454,7 +1454,7 @@ static void pagetypeinfo_showfree_print( }/* Print out the free pages at each order for each migatetype */ -static int pagetypeinfo_showfree (struct seq_file *m,void *arg) +static void pagetypeinfo_showfree (struct seq_file *m,void *arg) {int order;pg_data_t *pgdat = (pg_data_t *)arg;
@@ -1466,8 +1466,6 @@ static int pagetypeinfo_showfree(structseq_putc (m,'\n' );walk_zones_in_node (m, pgdat, true, false, pagetypeinfo_showfree_print); - -return 0 ; } static void pagetypeinfo_showblockcount_print(struct seq_file *m,
@@ -1503,7 +1501,7 @@ static void pagetypeinfo_showblockcount_ }/* Print out the number of pageblocks for each migratetype */ -static int pagetypeinfo_showblockcount (struct seq_file *m,void *arg) +static void pagetypeinfo_showblockcount (struct seq_file *m,void *arg) {int mtype;pg_data_t *pgdat = (pg_data_t *)arg;
@@ -1514,8 +1512,6 @@ static int pagetypeinfo_showblockcount(sseq_putc (m,'\n' );walk_zones_in_node (m, pgdat, true, false, pagetypeinfo_showblockcount_print); - -return 0 ; }/*
_
Andrew Morton
maintainerPATCH 212/212 mm/madvise: add MADV_WILLNEED to process_madvise()
In reply to Andrew MortonFrom: zhangkui <[email protected]>
Subject: mm/madvise: add MADV_WILLNEED to process_madvise()
There is a usecase in Android that an app process's memory is swapped out by process_madvise() with MADV_PAGEOUT, such as the memory is swapped to zram or a backing device. When the process is scheduled to running, like switch to foreground, multiple page faults may cause the app dropped frames.
To reduce the problem, System Management Software can read-ahead memory of the process immediately when the app switches to forground. Calling process_madvise() with MADV_WILLNEED can meet this need.
---
mm/madvise.c | 1 + 1 file changed, 1 insertion(+)
mm/madvise.c renamed from mm/madvise.c~mm-madvise-add-madv_willneed-to-process_madvise +1 -0
@@ -1048,6 +1048,7 @@ process_madvise_behavior_valid(int behavswitch (behavior) {case MADV_COLD :case MADV_PAGEOUT : +case MADV_WILLNEED :return true;default :return false;
_