All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Dobson <colpatch@us.ibm.com>
To: kernel-janitors@lists.osdl.org
Cc: manfred@colorfullife.com, Pekka J Enberg <penberg@cs.Helsinki.FI>,
	linux-kernel@vger.kernel.org
Subject: [KJ] [PATCH 5/9] Create helper for kmem_cache_create()
Date: Fri, 11 Nov 2005 00:03:16 +0000	[thread overview]
Message-ID: <4373DFC4.5020309@us.ibm.com> (raw)
In-Reply-To: <4373DD82.8010606@us.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 189 bytes --]

There's a loop in kmem_cache_create() where we try to determine the best
page order for a slab.  It's a big, ugly loop, so let's move it to its own
function: calculate_slab_order().

-Matt

[-- Attachment #2: calculate_slab_order.patch --]
[-- Type: text/x-patch, Size: 3577 bytes --]

There's a fairly ugly loop in kmem_cache_create() where we determine the
'optimal' size (page order) of cache's slabs.  Let's move this code into
it's own helper function to increase readability.

Thanks to Matthew Wilcox <matthew@wil.cx> for help with this patch.

Signed-off-by: Matthew Dobson <colpatch@us.ibm.com>

Index: linux-2.6.14+slab_cleanup/mm/slab.c
===================================================================
--- linux-2.6.14+slab_cleanup.orig/mm/slab.c	2005-11-10 11:43:42.198046816 -0800
+++ linux-2.6.14+slab_cleanup/mm/slab.c	2005-11-10 11:48:43.827192216 -0800
@@ -1463,6 +1463,53 @@ static inline void set_up_list3s(kmem_ca
 }
 
 /**
+ * calculate_slab_order - calculate size (page order) of slabs and the number
+ *                        of objects per slab.
+ *
+ * This could be made much more intelligent.  For now, try to avoid using
+ * high order pages for slabs.  When the gfp() functions are more friendly
+ * towards high-order requests, this should be changed.
+ */
+static inline size_t calculate_slab_order(kmem_cache_t *cachep, size_t size,
+					  size_t align, gfp_t flags)
+{
+	size_t left_over = 0;
+
+	for ( ; ; cachep->gfporder++) {
+		unsigned int num;
+		size_t remainder;
+
+		if (cachep->gfporder > MAX_GFP_ORDER) {
+			cachep->num = 0;
+			break;
+		}
+
+		cache_estimate(cachep->gfporder, size, align, flags,
+			       &remainder, &num);
+		if (!num)
+			continue;
+		/* More than offslab_limit objects will cause problems */
+		if (flags & CFLGS_OFF_SLAB && cachep->num > offslab_limit)
+			break; 
+
+		cachep->num = num;
+		left_over = remainder;
+
+		/*
+		 * Large number of objects is good, but very large slabs are
+		 * currently bad for the gfp()s.
+		 */
+		if (cachep->gfporder >= slab_break_gfp_order)
+			break;
+
+		if ((left_over * 8) <= (PAGE_SIZE << cachep->gfporder))
+			break;	/* Acceptable internal fragmentation */
+	}
+
+	return left_over;
+}
+
+/**
  * kmem_cache_create - Create a cache.
  * @name: A string which is used in /proc/slabinfo to identify this cache.
  * @size: The size of objects to be created in this cache.
@@ -1646,46 +1693,8 @@ kmem_cache_t *kmem_cache_create(const ch
 		cachep->gfporder = 0;
 		cache_estimate(cachep->gfporder, size, align, flags,
 			       &left_over, &cachep->num);
-	} else {
-		/*
-		 * Calculate size (in pages) of slabs, and the num of objs per
-		 * slab.  This could be made much more intelligent.  For now,
-		 * try to avoid using high page-orders for slabs.  When the
-		 * gfp() funcs are more friendly towards high-order requests,
-		 * this should be changed.
-		 */
-		do {
-			unsigned int break_flag = 0;
-cal_wastage:
-			cache_estimate(cachep->gfporder, size, align, flags,
-				       &left_over, &cachep->num);
-			if (break_flag)
-				break;
-			if (cachep->gfporder >= MAX_GFP_ORDER)
-				break;
-			if (!cachep->num)
-				goto next;
-			if (flags & CFLGS_OFF_SLAB &&
-			    cachep->num > offslab_limit) {
-				/* This num of objs will cause problems. */
-				cachep->gfporder--;
-				break_flag++;
-				goto cal_wastage;
-			}
-
-			/*
-			 * Large num of objs is good, but very large slabs are
-			 * currently bad for the gfp()s.
-			 */
-			if (cachep->gfporder >= slab_break_gfp_order)
-				break;
-
-			if ((left_over * 8) <= (PAGE_SIZE << cachep->gfporder))
-				break;  /* Acceptable internal fragmentation */
-next:
-			cachep->gfporder++;
-		} while (1);
-	}
+	} else
+		left_over = calculate_slab_order(cachep, size, align, flags);
 
 	if (!cachep->num) {
 		printk("kmem_cache_create: couldn't create cache %s.\n", name);

[-- Attachment #3: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

WARNING: multiple messages have this Message-ID (diff)
From: Matthew Dobson <colpatch@us.ibm.com>
To: kernel-janitors@lists.osdl.org
Cc: manfred@colorfullife.com, Pekka J Enberg <penberg@cs.Helsinki.FI>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 5/9] Create helper for kmem_cache_create()
Date: Thu, 10 Nov 2005 16:03:16 -0800	[thread overview]
Message-ID: <4373DFC4.5020309@us.ibm.com> (raw)
In-Reply-To: <4373DD82.8010606@us.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 189 bytes --]

There's a loop in kmem_cache_create() where we try to determine the best
page order for a slab.  It's a big, ugly loop, so let's move it to its own
function: calculate_slab_order().

-Matt

[-- Attachment #2: calculate_slab_order.patch --]
[-- Type: text/x-patch, Size: 3577 bytes --]

There's a fairly ugly loop in kmem_cache_create() where we determine the
'optimal' size (page order) of cache's slabs.  Let's move this code into
it's own helper function to increase readability.

Thanks to Matthew Wilcox <matthew@wil.cx> for help with this patch.

Signed-off-by: Matthew Dobson <colpatch@us.ibm.com>

Index: linux-2.6.14+slab_cleanup/mm/slab.c
===================================================================
--- linux-2.6.14+slab_cleanup.orig/mm/slab.c	2005-11-10 11:43:42.198046816 -0800
+++ linux-2.6.14+slab_cleanup/mm/slab.c	2005-11-10 11:48:43.827192216 -0800
@@ -1463,6 +1463,53 @@ static inline void set_up_list3s(kmem_ca
 }
 
 /**
+ * calculate_slab_order - calculate size (page order) of slabs and the number
+ *                        of objects per slab.
+ *
+ * This could be made much more intelligent.  For now, try to avoid using
+ * high order pages for slabs.  When the gfp() functions are more friendly
+ * towards high-order requests, this should be changed.
+ */
+static inline size_t calculate_slab_order(kmem_cache_t *cachep, size_t size,
+					  size_t align, gfp_t flags)
+{
+	size_t left_over = 0;
+
+	for ( ; ; cachep->gfporder++) {
+		unsigned int num;
+		size_t remainder;
+
+		if (cachep->gfporder > MAX_GFP_ORDER) {
+			cachep->num = 0;
+			break;
+		}
+
+		cache_estimate(cachep->gfporder, size, align, flags,
+			       &remainder, &num);
+		if (!num)
+			continue;
+		/* More than offslab_limit objects will cause problems */
+		if (flags & CFLGS_OFF_SLAB && cachep->num > offslab_limit)
+			break; 
+
+		cachep->num = num;
+		left_over = remainder;
+
+		/*
+		 * Large number of objects is good, but very large slabs are
+		 * currently bad for the gfp()s.
+		 */
+		if (cachep->gfporder >= slab_break_gfp_order)
+			break;
+
+		if ((left_over * 8) <= (PAGE_SIZE << cachep->gfporder))
+			break;	/* Acceptable internal fragmentation */
+	}
+
+	return left_over;
+}
+
+/**
  * kmem_cache_create - Create a cache.
  * @name: A string which is used in /proc/slabinfo to identify this cache.
  * @size: The size of objects to be created in this cache.
@@ -1646,46 +1693,8 @@ kmem_cache_t *kmem_cache_create(const ch
 		cachep->gfporder = 0;
 		cache_estimate(cachep->gfporder, size, align, flags,
 			       &left_over, &cachep->num);
-	} else {
-		/*
-		 * Calculate size (in pages) of slabs, and the num of objs per
-		 * slab.  This could be made much more intelligent.  For now,
-		 * try to avoid using high page-orders for slabs.  When the
-		 * gfp() funcs are more friendly towards high-order requests,
-		 * this should be changed.
-		 */
-		do {
-			unsigned int break_flag = 0;
-cal_wastage:
-			cache_estimate(cachep->gfporder, size, align, flags,
-				       &left_over, &cachep->num);
-			if (break_flag)
-				break;
-			if (cachep->gfporder >= MAX_GFP_ORDER)
-				break;
-			if (!cachep->num)
-				goto next;
-			if (flags & CFLGS_OFF_SLAB &&
-			    cachep->num > offslab_limit) {
-				/* This num of objs will cause problems. */
-				cachep->gfporder--;
-				break_flag++;
-				goto cal_wastage;
-			}
-
-			/*
-			 * Large num of objs is good, but very large slabs are
-			 * currently bad for the gfp()s.
-			 */
-			if (cachep->gfporder >= slab_break_gfp_order)
-				break;
-
-			if ((left_over * 8) <= (PAGE_SIZE << cachep->gfporder))
-				break;  /* Acceptable internal fragmentation */
-next:
-			cachep->gfporder++;
-		} while (1);
-	}
+	} else
+		left_over = calculate_slab_order(cachep, size, align, flags);
 
 	if (!cachep->num) {
 		printk("kmem_cache_create: couldn't create cache %s.\n", name);

  parent reply	other threads:[~2005-11-11  0:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-10 23:53 [KJ] [PATCH 0/9] Cleanup mm/slab.c v2 Matthew Dobson
2005-11-10 23:53 ` Matthew Dobson
2005-11-10 23:56 ` [KJ] [PATCH 1/9] CodingStyle-ify mm/slab.c Matthew Dobson
2005-11-10 23:56   ` Matthew Dobson
2005-11-10 23:58 ` [KJ] [PATCH 2/9] Use 'nid' Matthew Dobson
2005-11-10 23:58   ` Matthew Dobson
2005-11-13 20:15   ` [KJ] " Pavel Machek
2005-11-13 20:15     ` Pavel Machek
2005-11-10 23:59 ` [KJ] [PATCH 3/9] Fix alloc_percpu's args Matthew Dobson
2005-11-10 23:59   ` Matthew Dobson
2005-11-11  0:01 ` [KJ] [PATCH 4/9] Create helper for /proc/slabinfo Matthew Dobson
2005-11-11  0:01   ` Matthew Dobson
2005-11-11  8:18   ` [KJ] " walter harms
2005-11-11 18:19   ` Matthew Dobson
2005-11-11  0:03 ` Matthew Dobson [this message]
2005-11-11  0:03   ` [PATCH 5/9] Create helper for kmem_cache_create() Matthew Dobson
2005-11-11  8:10   ` [KJ] " walter harms
2005-11-11 18:25   ` Matthew Dobson
2005-11-11  0:04 ` [KJ] [PATCH 6/9] Cleanup kmem_cache_create() Matthew Dobson
2005-11-11  0:04   ` Matthew Dobson
2005-11-11  8:10   ` [KJ] " Ingo Oeser
2005-11-11  8:10     ` Ingo Oeser
2005-11-11 18:28     ` [KJ] " Matthew Dobson
2005-11-11 18:28       ` Matthew Dobson
2005-11-11 23:46     ` [KJ] " Håkon Løvdal
2005-11-11  0:05 ` [KJ] [PATCH 7/9] Cleanup cache_reap() Matthew Dobson
2005-11-11  0:05   ` Matthew Dobson
2005-11-11  0:06 ` [KJ] [PATCH 8/9] Cleanup slabinfo_write() Matthew Dobson
2005-11-11  0:06   ` Matthew Dobson
2005-11-11  0:07 ` [KJ] [PATCH 9/9] Cleanup a loop in set_slab_attr() Matthew Dobson
2005-11-11  0:07   ` Matthew Dobson
2005-11-11  7:29 ` [KJ] Re: [PATCH 0/9] Cleanup mm/slab.c v2 Pekka J Enberg
2005-11-11  7:29   ` Pekka J Enberg

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=4373DFC4.5020309@us.ibm.com \
    --to=colpatch@us.ibm.com \
    --cc=kernel-janitors@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=penberg@cs.Helsinki.FI \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.