Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1365319 > unrolled thread

[PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code

Started byjs1304@gmail.com
First post2016-03-28 07:30 +0200
Last post2016-03-30 10:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code js1304@gmail.com - 2016-03-28 07:30 +0200
    Re: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization  code Christoph Lameter <cl@linux.com> - 2016-03-29 03:00 +0200
      Re: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization  code Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2016-03-30 10:20 +0200

#1365319 — [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code

Fromjs1304@gmail.com
Date2016-03-28 07:30 +0200
Subject[PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code
Message-ID<rhxUv-2rs-21@gated-at.bofh.it>
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>

It can be reused on other place, so factor out it. Following
patch will use it.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 mm/slab.c | 68 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index ba2eacf..569d7db 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -841,6 +841,40 @@ static inline gfp_t gfp_exact_node(gfp_t flags)
 }
 #endif
 
+static int init_cache_node(struct kmem_cache *cachep, int node, gfp_t gfp)
+{
+	struct kmem_cache_node *n;
+
+	/*
+	 * Set up the kmem_cache_node for cpu before we can
+	 * begin anything. Make sure some other cpu on this
+	 * node has not already allocated this
+	 */
+	n = get_node(cachep, node);
+	if (n)
+		return 0;
+
+	n = kmalloc_node(sizeof(struct kmem_cache_node), gfp, node);
+	if (!n)
+		return -ENOMEM;
+
+	kmem_cache_node_init(n);
+	n->next_reap = jiffies + REAPTIMEOUT_NODE +
+		    ((unsigned long)cachep) % REAPTIMEOUT_NODE;
+
+	n->free_limit =
+		(1 + nr_cpus_node(node)) * cachep->batchcount + cachep->num;
+
+	/*
+	 * The kmem_cache_nodes don't come and go as CPUs
+	 * come and go.  slab_mutex is sufficient
+	 * protection here.
+	 */
+	cachep->node[node] = n;
+
+	return 0;
+}
+
 /*
  * Allocates and initializes node for a node on each slab cache, used for
  * either memory or cpu hotplug.  If memory is being hot-added, the kmem_cache_node
@@ -852,39 +886,15 @@ static inline gfp_t gfp_exact_node(gfp_t flags)
  */
 static int init_cache_node_node(int node)
 {
+	int ret;
 	struct kmem_cache *cachep;
-	struct kmem_cache_node *n;
-	const size_t memsize = sizeof(struct kmem_cache_node);
 
 	list_for_each_entry(cachep, &slab_caches, list) {
-		/*
-		 * Set up the kmem_cache_node for cpu before we can
-		 * begin anything. Make sure some other cpu on this
-		 * node has not already allocated this
-		 */
-		n = get_node(cachep, node);
-		if (!n) {
-			n = kmalloc_node(memsize, GFP_KERNEL, node);
-			if (!n)
-				return -ENOMEM;
-			kmem_cache_node_init(n);
-			n->next_reap = jiffies + REAPTIMEOUT_NODE +
-			    ((unsigned long)cachep) % REAPTIMEOUT_NODE;
-
-			/*
-			 * The kmem_cache_nodes don't come and go as CPUs
-			 * come and go.  slab_mutex is sufficient
-			 * protection here.
-			 */
-			cachep->node[node] = n;
-		}
-
-		spin_lock_irq(&n->list_lock);
-		n->free_limit =
-			(1 + nr_cpus_node(node)) *
-			cachep->batchcount + cachep->num;
-		spin_unlock_irq(&n->list_lock);
+		ret = init_cache_node(cachep, node, GFP_KERNEL);
+		if (ret)
+			return ret;
 	}
+
 	return 0;
 }
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1365743 — Re: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code

FromChristoph Lameter <cl@linux.com>
Date2016-03-29 03:00 +0200
SubjectRe: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code
Message-ID<rhQaK-6GM-1@gated-at.bofh.it>
In reply to#1365319
On Mon, 28 Mar 2016, js1304@gmail.com wrote:

> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> -		spin_lock_irq(&n->list_lock);
> -		n->free_limit =
> -			(1 + nr_cpus_node(node)) *
> -			cachep->batchcount + cachep->num;
> -		spin_unlock_irq(&n->list_lock);
> +		ret = init_cache_node(cachep, node, GFP_KERNEL);
> +		if (ret)
> +			return ret;

Drop ret and do a

	return init_cache_node(...);

instead?

[toc] | [prev] | [next] | [standalone]


#1366981 — Re: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code

FromJoonsoo Kim <iamjoonsoo.kim@lge.com>
Date2016-03-30 10:20 +0200
SubjectRe: [PATCH 04/11] mm/slab: factor out kmem_cache_node initialization code
Message-ID<rijw5-2y5-1@gated-at.bofh.it>
In reply to#1365743
On Mon, Mar 28, 2016 at 07:56:15PM -0500, Christoph Lameter wrote:
> On Mon, 28 Mar 2016, js1304@gmail.com wrote:
> 
> > From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> > -		spin_lock_irq(&n->list_lock);
> > -		n->free_limit =
> > -			(1 + nr_cpus_node(node)) *
> > -			cachep->batchcount + cachep->num;
> > -		spin_unlock_irq(&n->list_lock);
> > +		ret = init_cache_node(cachep, node, GFP_KERNEL);
> > +		if (ret)
> > +			return ret;
> 
> Drop ret and do a
> 
> 	return init_cache_node(...);
> 
> instead?

Will do it.

Thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web