[netfilter-cvslog] r7361 - trunk/patch-o-matic-ng/patchlets/set/linux-2.6/include/linux/netfilter_ipv4

kadlec at blackhole.kfki.hu kadlec at blackhole.kfki.hu
Tue Feb 12 11:04:22 CET 2008


Author: kadlec at blackhole.kfki.hu
Date: 2008-02-12 11:04:22 +0100 (Tue, 12 Feb 2008)
New Revision: 7361

Modified:
   trunk/patch-o-matic-ng/patchlets/set/linux-2.6/include/linux/netfilter_ipv4/ip_set_malloc.h
Log:
Hammer the memory less harder: take into account fragmented pages.


Modified: trunk/patch-o-matic-ng/patchlets/set/linux-2.6/include/linux/netfilter_ipv4/ip_set_malloc.h
===================================================================
--- trunk/patch-o-matic-ng/patchlets/set/linux-2.6/include/linux/netfilter_ipv4/ip_set_malloc.h	2008-02-10 02:08:42 UTC (rev 7360)
+++ trunk/patch-o-matic-ng/patchlets/set/linux-2.6/include/linux/netfilter_ipv4/ip_set_malloc.h	2008-02-12 10:04:22 UTC (rev 7361)
@@ -3,30 +3,25 @@
 
 #ifdef __KERNEL__
 
-/* Memory allocation and deallocation */
-static size_t max_malloc_size = 0;
+static size_t max_malloc_size = 0, max_page_size = 0;
 
-static inline void init_max_malloc_size(void)
+static inline bool init_max_page_size(void)
 {
-#define CACHE(x) max_malloc_size = x;
+	size_t page_size = 0;
+	
+#define CACHE(x) if (max_page_size == 0 || x < max_page_size)	\
+			page_size = x;
 #include <linux/kmalloc_sizes.h>
 #undef CACHE
-}
+	if (page_size) {
+		if (!max_malloc_size)
+			max_malloc_size = page_size;
 
-static inline void * ip_set_malloc(size_t bytes)
-{
-	if (bytes > max_malloc_size)
-		return vmalloc(bytes);
-	else
-		return kmalloc(bytes, GFP_KERNEL);
-}
+		max_page_size = page_size;
 
-static inline void ip_set_free(void * data, size_t bytes)
-{
-	if (bytes > max_malloc_size)
-		vfree(data);
-	else
-		kfree(data);
+		return 1;
+	}
+	return 0;
 }
 
 struct harray {
@@ -35,18 +30,15 @@
 };
 
 static inline void * 
-harray_malloc(size_t hashsize, size_t typesize, int flags)
+__harray_malloc(size_t hashsize, size_t typesize, int flags)
 {
 	struct harray *harray;
 	size_t max_elements, size, i, j;
 
-	if (!max_malloc_size)
-		init_max_malloc_size();
-
-	if (typesize > max_malloc_size)
+	if (typesize > max_page_size)
 		return NULL;
 
-	max_elements = max_malloc_size/typesize;
+	max_elements = max_page_size/typesize;
 	size = hashsize/max_elements;
 	if (hashsize % max_elements)
 		size++;
@@ -83,6 +75,21 @@
     	return NULL;
 }
 
+static inline void *
+harray_malloc(size_t hashsize, size_t typesize, int flags)
+{
+	void *harray;
+	
+	if (!max_page_size)
+		init_max_page_size();
+
+	do {
+		harray = __harray_malloc(hashsize, typesize, flags|__GFP_NOWARN);
+	} while (harray == NULL && init_max_page_size());
+	
+	return harray;
+}		
+
 static inline void harray_free(void *h)
 {
 	struct harray *harray = (struct harray *) h;
@@ -111,6 +118,26 @@
 		+ (which)%(__h)->max_elements);			\
 })
 
+/* General memory allocation and deallocation */
+static inline void * ip_set_malloc(size_t bytes)
+{
+	if (!max_malloc_size)
+		init_max_page_size();
+
+	if (bytes > max_malloc_size)
+		return vmalloc(bytes);
+	else
+		return kmalloc(bytes, GFP_KERNEL);
+}
+
+static inline void ip_set_free(void * data, size_t bytes)
+{
+	if (bytes > max_malloc_size)
+		vfree(data);
+	else
+		kfree(data);
+}
+
 #endif				/* __KERNEL__ */
 
 #endif /*_IP_SET_MALLOC_H*/




More information about the netfilter-cvslog mailing list