linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: cl@linux.com, penberg@kernel.org, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>
Subject: [PATCH v2] mm/slub: skip node in case there is no slab to acquire
Date: Tue, 13 Nov 2018 17:12:40 +0800	[thread overview]
Message-ID: <20181113091240.23308-1-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20181108011204.9491-1-richard.weiyang@gmail.com>

Current slub has three layers:

  * cpu_slab
  * percpu_partial
  * per node partial list

Slub allocator tries to get an object from top to bottom. When it can't
get an object from the upper two layers, it will search the per node
partial list. The is done in get_partial().

The abstraction of get_partial() may looks like this:

    get_partial()
        get_partial_node()
        get_any_partial()
            for_each_zone_zonelist()

The idea behind this is: it first try a local node, then try other nodes
if caller doesn't specify a node.

When we look one step deeper in get_any_partial(), it tries to get a
proper node by for_each_zone_zonelist(), which iterates on the
node_zonelists.

This behavior would introduce some redundant check on the same node.
Because:

  * the local node is already checked in get_partial_node()
  * one node may have several zones on node_zonelists

We could reduce these redundant check by providing a nodemask during
node_zonelists iteration.

  * clear the local node which is already checked in get_partial_node()
  * clear a node if we can't get an object from it.

This patch replaces for_each_zone_zonelist() with
for_each_zone_zonelist_nodemask() to skip the node which fails to acquire
an object.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
v2: rewrite the changelog and add a comment based on Andrew's comment
---
 mm/slub.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index e3629cd7aff1..e3db5cd52507 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1873,7 +1873,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
  * Get a page from somewhere. Search in increasing NUMA distances.
  */
 static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
-		struct kmem_cache_cpu *c)
+		struct kmem_cache_cpu *c, int except)
 {
 #ifdef CONFIG_NUMA
 	struct zonelist *zonelist;
@@ -1882,6 +1882,9 @@ static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
 	enum zone_type high_zoneidx = gfp_zone(flags);
 	void *object;
 	unsigned int cpuset_mems_cookie;
+	nodemask_t nmask = node_states[N_MEMORY];
+
+	node_clear(except, nmask);
 
 	/*
 	 * The defrag ratio allows a configuration of the tradeoffs between
@@ -1908,7 +1911,8 @@ static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
 	do {
 		cpuset_mems_cookie = read_mems_allowed_begin();
 		zonelist = node_zonelist(mempolicy_slab_node(), flags);
-		for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) {
+		for_each_zone_zonelist_nodemask(zone, z, zonelist,
+						high_zoneidx, &nmask) {
 			struct kmem_cache_node *n;
 
 			n = get_node(s, zone_to_nid(zone));
@@ -1926,6 +1930,11 @@ static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
 					 */
 					return object;
 				}
+				/*
+				 * Fail to get object from this node,
+				 * clear this to skip this node
+				 */
+				node_clear(zone_to_nid(zone), nmask);
 			}
 		}
 	} while (read_mems_allowed_retry(cpuset_mems_cookie));
@@ -1951,7 +1960,7 @@ static void *get_partial(struct kmem_cache *s, gfp_t flags, int node,
 	if (object || node != NUMA_NO_NODE)
 		return object;
 
-	return get_any_partial(s, flags, c);
+	return get_any_partial(s, flags, c, searchnode);
 }
 
 #ifdef CONFIG_PREEMPT
-- 
2.15.1

  parent reply	other threads:[~2018-11-13  9:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08  1:12 [PATCH] mm/slub: skip node in case there is no slab to acquire Wei Yang
2018-11-09 20:48 ` Andrew Morton
2018-11-09 23:47   ` Wei Yang
2018-11-13  9:12 ` Wei Yang [this message]
2018-11-13 13:17 ` Michal Hocko
2018-11-13 13:26   ` Wei Yang
2018-11-13 13:34     ` Michal Hocko
2018-11-20  3:31 ` [PATCH v2] mm/slub: improve performance by skipping checked node in get_any_partial() Wei Yang
2018-11-22  3:05   ` Andrew Morton
2018-11-22  9:13     ` Wei Yang
2018-11-22 23:41     ` Wei Yang
2018-11-23 13:39       ` Michal Hocko
2018-11-23 13:49         ` Michal Hocko
2018-11-23 15:27           ` Wei Yang
2018-12-20 22:41   ` Andrew Morton
2018-12-21  0:25     ` Alexander Duyck
2018-12-21  3:29       ` Wei Yang
2018-12-21  1:37     ` Christopher Lameter
2018-12-21  1:37       ` Christopher Lameter
2018-12-21  3:33       ` Wei Yang
2018-12-24 22:03       ` Wei Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181113091240.23308-1-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).