public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] mm: introduce simple_malloc()/simple_free()
@ 2008-11-16  4:33 Lai Jiangshan
  2008-11-16  4:49 ` Alexey Dobriyan
  2008-11-16  4:52 ` Arjan van de Ven
  0 siblings, 2 replies; 29+ messages in thread
From: Lai Jiangshan @ 2008-11-16  4:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Paul Menage, kamezawa.hiroyu, Balbir Singh, Jens Axboe,
	David S. Miller, Jan Kara, Jes Sorensen,
	Linux Kernel Mailing List


some subsystem needs vmalloc() when required memory is large.
but current kernel has not APIs for this requirement.
this patch introduces simple_malloc() and simple_free().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ffee2f7..e9c11f7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -13,6 +13,7 @@
 #include <linux/prio_tree.h>
 #include <linux/debug_locks.h>
 #include <linux/mm_types.h>
+#include <linux/vmalloc.h>
 
 struct mempolicy;
 struct anon_vma;
@@ -278,6 +279,36 @@ static inline int is_vmalloc_addr(const void *x)
 #endif
 }
 
+static inline void *__simple_malloc(unsigned long size, int pages_hint)
+{
+	if (size <= PAGE_SIZE * pages_hint)
+		return kmalloc(size, GFP_KERNEL);
+	else
+		return vmalloc(size);
+}
+
+/**
+ * simple_malloc - allocate memory by kmalloc() or vmalloc()
+ *
+ * if @size <= PAGE_SIZE, memory is allocated by kmalloc(),
+ * otherwise by vmalloc()
+ */
+static inline void *simple_malloc(unsigned long size)
+{
+	return __simple_malloc(size, 1);
+}
+
+/**
+ * simple_free - free the memory by kfree(), or vfree() if it is vmalloc addr
+ */
+static inline void simple_free(void *ptr)
+{
+	if (is_vmalloc_addr(ptr))
+		vfree(ptr);
+	else
+		kfree(ptr);
+}
+
 static inline struct page *compound_head(struct page *page)
 {
 	if (unlikely(PageTail(page)))



^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2008-11-18  5:20 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-16  4:33 [PATCH 1/7] mm: introduce simple_malloc()/simple_free() Lai Jiangshan
2008-11-16  4:49 ` Alexey Dobriyan
2008-11-16  8:14   ` David Miller
2008-11-16 18:42   ` KOSAKI Motohiro
2008-11-16  4:52 ` Arjan van de Ven
2008-11-16  5:03   ` Andrew Morton
2008-11-16  5:35     ` Lai Jiangshan
2008-11-16  5:47       ` Andrew Morton
2008-11-16  5:53       ` Arjan van de Ven
2008-11-16  6:08         ` Eric Dumazet
2008-11-16  8:23         ` David Miller
2008-11-16  8:21     ` David Miller
2008-11-16  8:19   ` David Miller
2008-11-16 18:57     ` Arjan van de Ven
2008-11-16 21:39       ` Dave Airlie
2008-11-16 21:51         ` Arjan van de Ven
2008-11-16 22:42           ` Dave Airlie
2008-11-17  2:08           ` Lai Jiangshan
2008-11-17  4:53             ` Balbir Singh
2008-11-17  5:25               ` KAMEZAWA Hiroyuki
2008-11-17  6:43                 ` KOSAKI Motohiro
2008-11-17  7:13                   ` Andrew Morton
2008-11-17  7:15                     ` David Miller
2008-11-17  8:10                       ` KOSAKI Motohiro
2008-11-17  8:24                       ` Balbir Singh
2008-11-18  4:39                     ` Nick Piggin
2008-11-18  5:16                       ` Lai Jiangshan
2008-11-17  4:46           ` Balbir Singh
2008-11-17  4:43         ` Balbir Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox