Skip to contentSkip to conversation

lazy_buddy-2.5.19-1

PATCH William Lee Irwin III 1 participant 1 message May 30, 2002

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

Deferred coalescing is an important allocator optimization. In the case of binary buddy system allocators prior implementations have successfully yielded between 10% and 32% reductions in the average latency of allocation and freeing operations. The following patch is a rework of the buddy allocator in page_alloc.c to use deferred coalescing, updated for algorithmic compliance and to report fragmentation statistics, and to fix bugs reported by Randy Hron and Andrew Morton.

The results achieved by this specific implementation are as of yet not entirely known, but some non-rigorous testing seems to reveal approximate parity with mainline. Ruth, Randy, I'd be much obliged to hear of the results of more rigorous testing to determine quality of implementation issues still needing to be addressed.

Martin Bligh contributed the fragmentation statistics reporting, though adaptation was required to provide useful reporting for this algorithm, largely due to the additional reporting not relevant to mainline.

TODO
(1) kill zone_free_pages(), it's useless since ->free_pages has it all now
(2) get more feedback from Pavel Machek about whether he likes this is_head_of_free_region()
(3) rigorous performance analysis for determining whether this has been done properly and may be considered essentially finished

(4)  More concise and to-the-point commentary.
(5)  do some address-ordered queueing
(6)  benchmarking
(7)  audit for unnecessary cacheline dirtying
(8)  port to 2.4.x & rmap
(9)  optimize

(10) collect statistics on the allocation rates for various orders
(11) collect statistics on allocation failures due to fragmentation

The following TODO items essentially fall under the rubric of follow-on patches building upon this one:

(12)  gang allocation support
(13)  per-cpu pools
(14)  gang preassembly and bulk transfer during gang allocation and refill

of per-cpu pools

Cheers,
Bill

fs/proc/proc_misc.c +22 -2
diff -urN --exclude [xprs].* linux-2.5/fs/proc/proc_misc.c lazy_buddy/fs/proc/proc_misc.c
@@ -131,6 +131,7 @@
 	struct sysinfo i;
 	int len;
 	struct page_state ps;
+	extern unsigned long nr_deferred_pages(void);
 
 	get_page_state(&ps);
 /*
@@ -158,7 +159,8 @@
 		"SwapTotal:    %8lu kB\n"
 		"SwapFree:     %8lu kB\n"
 		"Dirty:        %8lu kB\n"
-		"Writeback:    %8lu kB\n",
+		"Writeback:    %8lu kB\n"
+		"Deferred:     %8lu kB\n",
 		K(i.totalram),
 		K(i.freeram),
 		K(i.sharedram),
@@ -173,13 +175,30 @@
 		K(i.totalswap),
 		K(i.freeswap),
 		K(ps.nr_dirty),
-		K(ps.nr_writeback)
+		K(ps.nr_writeback),
+		K(nr_deferred_pages())
 		);
 
 	return proc_calc_metrics(page, start, off, count, eof, len);
 #undef K
 }
 
+extern int fragmentation_stats(char *, int);
+static int fragmentation_read_proc(	char *page,
+					char **start,
+					off_t off,
+					int count,
+					int *eof,
+					void *data)
+{
+	int nid, len = 0;
+
+	for (nid = 0; nid < numnodes; ++nid)
+		len += fragmentation_stats(page + len, nid);
+
+	return proc_calc_metrics(page, start, off, count, eof, len);
+}
+
 static int version_read_proc(char *page, char **start, off_t off,
 				 int count, int *eof, void *data)
 {
@@ -543,6 +562,7 @@
 		{"loadavg",     loadavg_read_proc},
 		{"uptime",	uptime_read_proc},
 		{"meminfo",	meminfo_read_proc},
+		{"fraginfo",	fragmentation_read_proc},
 		{"version",	version_read_proc},
 #ifdef CONFIG_PROC_HARDWARE
 		{"hardware",	hardware_read_proc},
include/linux/mmzone.h +16 -4
diff -urN --exclude [xprs].* linux-2.5/include/linux/mmzone.h lazy_buddy/include/linux/mmzone.h
@@ -20,8 +20,9 @@
 #endif
 
 typedef struct free_area_struct {
-	struct list_head	free_list;
-	unsigned long		*map;
+	unsigned long	globally_free, active, locally_free;
+	list_t		free_list, deferred_pages;
+	unsigned long	*map;
 } free_area_t;
 
 struct pglist_data;
@@ -142,8 +143,19 @@
 extern int numnodes;
 extern pg_data_t *pgdat_list;
 
-#define memclass(pgzone, classzone)	(((pgzone)->zone_pgdat == (classzone)->zone_pgdat) \
-			&& ((pgzone) <= (classzone)))
+static inline int memclass(zone_t *page_zone, zone_t *classzone)
+{
+	if (page_zone->zone_pgdat != classzone->zone_pgdat)
+		return 0;
+	if (page_zone > classzone)
+		return 0;
+	return 1;
+}
+
+static inline unsigned long zone_free_pages(zone_t *zone)
+{
+	return zone->free_pages;
+}
 
 /*
  * The following two are not meant for general usage. They are here as
mm/bootmem.c +4 -0
diff -urN --exclude [xprs].* linux-2.5/mm/bootmem.c lazy_buddy/mm/bootmem.c
@@ -241,6 +241,7 @@
 	return ret;
 }
 
+extern void forced_coalesce(zone_t *zone);
 static unsigned long __init free_all_bootmem_core(pg_data_t *pgdat)
 {
 	struct page *page = pgdat->node_mem_map;
@@ -287,6 +288,9 @@
 	}
 	total += count;
 	bdata->node_bootmem_map = NULL;
+
+	for (i = 0; i < MAX_NR_ZONES; ++i)
+		forced_coalesce(&pgdat->node_zones[i]);
 
 	return total;
 }
mm/page_alloc.c +504 -185

902 lines not on this page · raw message

mm/vmscan.c +1 -1
diff -urN --exclude [xprs].* linux-2.5/mm/vmscan.c lazy_buddy/mm/vmscan.c
@@ -682,7 +682,7 @@
 
 	first_classzone = classzone->zone_pgdat->node_zones;
 	while (classzone >= first_classzone) {
-		if (classzone->free_pages > classzone->pages_high)
+		if (zone_free_pages(classzone) > classzone->pages_high)
 			return 0;
 		classzone--;
 	}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/