All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rolandd@cisco.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Linus Torvalds <torvalds@osdl.org>,
	zippel@linux-m68k.org, ak@suse.de, rmk+lkml@arm.linux.org.uk,
	tony.luck@gmail.com, paolo.ciarrocchi@gmail.com,
	linux-kernel@vger.kernel.org
Subject: Re: New (now current development process)
Date: Tue, 01 Nov 2005 21:01:01 -0800	[thread overview]
Message-ID: <52y847abjm.fsf@cisco.com> (raw)
In-Reply-To: <20051031163408.41a266f3.akpm@osdl.org> (Andrew Morton's message of "Mon, 31 Oct 2005 16:34:08 -0800")

> And a lot of it is us just being bloated. Argh.

Perhaps it's time to dust this patch off:


Reduce kernel text by moving many uses of GFP_KERNEL out of line, by
creating __kmem_cache_alloc_gfp_kernel(), __kmalloc_gfp_kernel() and
__kzalloc_gfp_kernel() wrapper functions.  Then kmem_cache_alloc(),
kmalloc() and kzalloc() can be inline functions that just call their
_gfp_kernel version if their flags parameter is a compile-time
constant and is GFP_KERNEL, and call their ordinary version otherwise.

On an x86_64 allnoconfig kernel, I see the following sizes:

	   text	   data	    bss	    dec	    hex	filename
	 795683	 197356	 116384	1109423	 10edaf	vmlinux-before
	 794894	 197420	 116384	1108698	 10eada	vmlinux-after

for a net savings of 789 bytes of text.  More realistic configs will
save even more.  With my usual config, the patched kernel boots and
runs fine.

Signed-off-by: Roland Dreier <rolandd@cisco.com>

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 09b9aa6..618331d 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -61,7 +61,8 @@ extern kmem_cache_t *kmem_cache_create(c
 				       void (*)(void *, kmem_cache_t *, unsigned long));
 extern int kmem_cache_destroy(kmem_cache_t *);
 extern int kmem_cache_shrink(kmem_cache_t *);
-extern void *kmem_cache_alloc(kmem_cache_t *, gfp_t);
+extern void *__kmem_cache_alloc(kmem_cache_t *, gfp_t);
+extern void *__kmem_cache_alloc_gfp_kernel(kmem_cache_t *);
 extern void kmem_cache_free(kmem_cache_t *, void *);
 extern unsigned int kmem_cache_size(kmem_cache_t *);
 extern const char *kmem_cache_name(kmem_cache_t *);
@@ -75,6 +76,15 @@ struct cache_sizes {
 };
 extern struct cache_sizes malloc_sizes[];
 extern void *__kmalloc(size_t, gfp_t);
+extern void *__kmalloc_gfp_kernel(size_t);
+
+static inline void *kmem_cache_alloc(kmem_cache_t *cache, gfp_t flags)
+{
+	if (__builtin_constant_p(flags) && flags == GFP_KERNEL)
+		return __kmem_cache_alloc_gfp_kernel(cache);
+
+	return __kmem_cache_alloc(cache, flags);
+}
 
 static inline void *kmalloc(size_t size, gfp_t flags)
 {
@@ -96,10 +106,22 @@ found:
 			malloc_sizes[i].cs_dmacachep :
 			malloc_sizes[i].cs_cachep, flags);
 	}
+
+	if (__builtin_constant_p(flags) && flags == GFP_KERNEL)
+		return __kmalloc_gfp_kernel(size);
 	return __kmalloc(size, flags);
 }
 
-extern void *kzalloc(size_t, gfp_t);
+extern void *__kzalloc(size_t, gfp_t);
+extern void *__kzalloc_gfp_kernel(size_t);
+
+static inline void *kzalloc(size_t size, gfp_t flags)
+{
+	if (__builtin_constant_p(flags) && flags == GFP_KERNEL)
+		return __kzalloc_gfp_kernel(size);
+
+	return __kzalloc(size, flags);
+}
 
 /**
  * kcalloc - allocate memory for an array. The memory is set to zero.
diff --git a/mm/slab.c b/mm/slab.c
index 22bfb0b..2971e1c 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2788,11 +2788,17 @@ static inline void __cache_free(kmem_cac
  * Allocate an object from this cache.  The flags are only relevant
  * if the cache has no available objects.
  */
-void *kmem_cache_alloc(kmem_cache_t *cachep, gfp_t flags)
+void *__kmem_cache_alloc(kmem_cache_t *cachep, gfp_t flags)
 {
 	return __cache_alloc(cachep, flags);
 }
-EXPORT_SYMBOL(kmem_cache_alloc);
+EXPORT_SYMBOL(__kmem_cache_alloc);
+
+void *__kmem_cache_alloc_gfp_kernel(kmem_cache_t *cachep)
+{
+	return __cache_alloc(cachep, GFP_KERNEL);
+}
+EXPORT_SYMBOL(__kmem_cache_alloc_gfp_kernel);
 
 /**
  * kmem_ptr_validate - check if an untrusted pointer might
@@ -2925,6 +2931,12 @@ void *__kmalloc(size_t size, gfp_t flags
 }
 EXPORT_SYMBOL(__kmalloc);
 
+void *__kmalloc_gfp_kernel(size_t size)
+{
+	return __kmalloc(size, GFP_KERNEL);
+}
+EXPORT_SYMBOL(__kmalloc_gfp_kernel);
+
 #ifdef CONFIG_SMP
 /**
  * __alloc_percpu - allocate one copy of the object for every present
@@ -2998,14 +3010,20 @@ EXPORT_SYMBOL(kmem_cache_free);
  * @size: how many bytes of memory are required.
  * @flags: the type of memory to allocate.
  */
-void *kzalloc(size_t size, gfp_t flags)
+void *__kzalloc(size_t size, gfp_t flags)
 {
 	void *ret = kmalloc(size, flags);
 	if (ret)
 		memset(ret, 0, size);
 	return ret;
 }
-EXPORT_SYMBOL(kzalloc);
+EXPORT_SYMBOL(__kzalloc);
+
+void *__kzalloc_gfp_kernel(size_t size)
+{
+	return __kzalloc(size, GFP_KERNEL);
+}
+EXPORT_SYMBOL(__kzalloc_gfp_kernel);
 
 /**
  * kfree - free previously allocated memory

  parent reply	other threads:[~2005-11-02  5:01 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-29 17:26 New (now current development process) Paolo Ciarrocchi
2005-10-29 18:57 ` Tony Luck
2005-10-29 19:51   ` Russell King
2005-10-29 20:28     ` Linus Torvalds
2005-10-29 20:44       ` Akula2
2005-10-29 23:28         ` Greg KH
2005-10-29 22:29       ` Andi Kleen
2005-10-29 22:37         ` Russell King
2005-10-30 19:12           ` Andrew Morton
2005-10-30 21:43             ` Russell King
2005-10-30 22:31               ` Andrew Morton
2005-10-30 22:45                 ` Russell King
2005-10-30 22:55                   ` Andrew Morton
2005-10-30 23:17                     ` Russell King
2005-10-31  0:48             ` Andi Kleen
2005-10-31  0:16               ` Russell King
2005-10-31  1:22                 ` Andrew Morton
2005-10-31  2:41                   ` Andi Kleen
2005-10-31  6:34                     ` Zwane Mwaikambo
2005-10-31  7:07                     ` Andrew Morton
2005-10-31 23:58                     ` Roman Zippel
2005-11-01  0:05                       ` Andrew Morton
2005-11-01  0:13                         ` Linus Torvalds
2005-11-01  0:34                           ` Andrew Morton
2005-11-01  0:59                             ` Grant Coady
2005-11-01 14:08                             ` Adrian Bunk
2005-11-01 15:15                             ` Nix
2005-11-01 15:26                             ` Bill Davidsen
2005-11-02  5:01                             ` Roland Dreier [this message]
2005-11-02  5:43                               ` Linus Torvalds
2005-11-02  5:56                                 ` Roland Dreier
2005-11-02  6:05                                   ` Linus Torvalds
2005-11-02  6:15                                     ` Roland Dreier
2005-11-02 15:54                                       ` Linus Torvalds
2005-11-02 17:48                                         ` Dave Jones
2005-11-02 18:12                                           ` Adrian Bunk
2005-11-02 20:11                                           ` David Lang
2005-11-02 22:31                                             ` Sam Ravnborg
2005-11-03 18:54                                               ` Andi Kleen
2005-11-02 23:11                                     ` Rob Landley
2005-11-04 22:08                                     ` Tim Bird
2005-11-04 22:35                                       ` Andi Kleen
2005-11-04 23:33                                         ` Tim Bird
2005-11-02 15:41                             ` Andreas Kleen
2005-11-01  7:52                           ` Russell King
2005-11-01  9:09                           ` Rob Landley
2005-11-01 14:15                           ` Adrian Bunk
2005-11-01  0:17                         ` Roman Zippel
2005-11-01  0:34                           ` Jesse Barnes
2005-10-31  1:10               ` Andrew Morton
2005-10-31  5:05               ` Rob Landley
2005-10-31  7:17                 ` Andrew Morton
2005-10-31  8:47                   ` Rogério Brito
2005-10-31  9:54                     ` Andrew Morton
2005-11-02  5:04                   ` Martin J. Bligh
2005-10-30 21:32         ` Theodore Ts'o
2005-10-31  0:45           ` Andi Kleen
2005-10-31  0:18             ` Al Viro
2005-10-31  3:14               ` Paul Jackson
2005-10-31  3:34                 ` Al Viro
2005-10-31  6:17                   ` Paul Jackson
2005-10-31  7:22                   ` Andrew Morton
2005-10-31  7:27                     ` Al Viro
2005-10-31  8:19                       ` Paul Jackson
2005-11-02  4:53                       ` Martin J. Bligh
2005-11-02  4:49               ` Martin J. Bligh
2005-10-31  4:52             ` Rob Landley
2005-11-02 14:44               ` Andreas Kleen
2005-10-30  1:12       ` Tony Luck
2005-10-31  6:41       ` Willy Tarreau
2005-11-07  4:54         ` Eric Sandall
2005-11-07 16:12           ` Krzysztof Halasa
2005-11-07 17:11             ` Christopher Friesen
2005-11-07 17:22               ` Linus Torvalds
2005-11-07 17:28                 ` Linus Torvalds
2005-11-07 20:34                   ` Willy Tarreau
2005-11-07 18:25               ` Krzysztof Halasa
2005-10-30  0:37 ` Jesper Juhl

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=52y847abjm.fsf@cisco.com \
    --to=rolandd@cisco.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paolo.ciarrocchi@gmail.com \
    --cc=rmk+lkml@arm.linux.org.uk \
    --cc=tony.luck@gmail.com \
    --cc=torvalds@osdl.org \
    --cc=zippel@linux-m68k.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 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.