Skip to contentSkip to conversation

Experiment on usefuleness of cache coloring on ia32

DISCUSSION Kanoj Sarcar 3 participants 3 messages Jun 10, 1999 – Jun 11, 1999

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

In an attempt to characterize the effects of cache coloring in the os for a modern Intel processor, I spent a couple of days hacking the Linux kernel and experimenting with a toy program. The kernel patch does a gross type of colored allocation by grabbing pages from the free list until it gets one of the right color - the intent is not to study the os overheads of doing colored allocations, rather the benefits a program might see from using pages allocated in such fashion. My findings are at

http://reality.sgi.com/kanoj_engr/ccdis.html

and it has at least one unexplained observation. If you are interested in this sort of thing, please browse it and send me comments about how I can improve the study. Pointers to apps which are suspected to benefit from cache coloring would also help.

Thanks.

Kanoj
[email protected]
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#1 lore raw
Quoted 2 lines · Kanoj Sarcar

In an attempt to characterize the effects of cache coloring in the os for a modern Intel processor,

Cool. I think my Intel Neptune (one of the dumber chipsets available) can really use something like that.

I've observed 15-25% variation in CPU usage for x11amp on my dual P120. I guess page colouring will have a very nice influence on the usability of older machines...

cheers,

Rik -- Open Source: you deserve to be in control of your data.

+-------------------------------------------------------------------+
| Le Reseau netwerksystemen BV:               http://www.reseau.nl/ |
| Linux Memory Management site:   http://www.linux.eu.org/Linux-MM/ |
| Nederlandse Linux documentatie:          http://www.nl.linux.org/ |
+-------------------------------------------------------------------+

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#2 lore raw
In reply to Kanoj Sarcar

The kernel patch does a gross type of colored allocation by grabbing pages from the free list until it gets one of the right color - the intent is not to study the os overheads of doing colored allocations, rather the benefits a program might see from using pages allocated in such fashion.

I, some time ago, spent a day or two playing with a similar patch of my own. I enclose it below, it is a first stage effort in efficient page coloring. The next stage would make the COLOR_HASH lists true chains, and not just a single entry hash.

However it is enough that you can play with the color stepping/init heuristics to see what works better/worse with various tweaks. Feel free to play around with it and improve it.

Note: you'll need to make appropriate changes to asm-i386/cache.h

include/asm-sparc64/cache.h renamed from include/asm-sparc64/cache.h.~1~ +4 -0
@@ -9,4 +9,8 @@
 
 #define        L1_CACHE_ALIGN(x)       (((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1))
 
+/* L2 cache heuristics, only define if you want page coloring */
+#define        L2_CACHE_BYTES		64
+#define        L2_CACHE_SIZE		(512 * 1024)
+
 #endif
include/linux/mm.h renamed from include/linux/mm.h.~1~ +2 -0
@@ -262,6 +262,8 @@ extern inline unsigned long get_free_pag
 	return page;
 }
 
+extern unsigned long get_colored_page(int gfp_mask, int *colorp);
+
 extern int low_on_memory;
 
 /* memory.c & swap.c*/
include/linux/fs.h renamed from include/linux/fs.h.~1~ +1 -0
@@ -339,6 +339,7 @@ struct inode {
 	struct list_head	i_dentry;
 
 	unsigned long		i_ino;
+	unsigned int		i_color;
 	unsigned int		i_count;
 	kdev_t			i_dev;
 	umode_t			i_mode;
include/linux/sched.h renamed from include/linux/sched.h.~1~ +2 -1
@@ -166,6 +166,7 @@ struct mm_struct {
 	pgd_t * pgd;
 	atomic_t count;
 	int map_count;				/* number of VMAs */
+	int color;
 	struct semaphore mmap_sem;
 	unsigned long context;
 	unsigned long start_code, end_code, start_data, end_data;
@@ -184,7 +185,7 @@ struct mm_struct {
 #define INIT_MM {					\
 		&init_mmap, NULL, NULL,			\
 		swapper_pg_dir, 			\
-		ATOMIC_INIT(1), 1,			\
+		ATOMIC_INIT(1), 1, 0,			\
 		MUTEX,					\
 		0,					\
 		0, 0, 0, 0,				\
kernel/ksyms.c renamed from kernel/ksyms.c.~1~ +1 -0
@@ -87,6 +87,7 @@ EXPORT_SYMBOL(exit_sighand);
 
 /* internal kernel memory management */
 EXPORT_SYMBOL(__get_free_pages);
+EXPORT_SYMBOL(get_colored_page);
 EXPORT_SYMBOL(free_pages);
 EXPORT_SYMBOL(__free_page);
 EXPORT_SYMBOL(kmem_find_general_cachep);
mm/filemap.c renamed from mm/filemap.c.~1~ +6 -6
@@ -253,7 +253,7 @@ static unsigned long try_to_read_ahead(s
 	offset &= PAGE_MASK;
 	switch (page_cache) {
 	case 0:
-		page_cache = __get_free_page(GFP_USER);
+		page_cache = get_colored_page(GFP_USER, &inode->i_color);
 		if (!page_cache)
 			break;
 	default:
@@ -675,7 +675,7 @@ no_cached_page:
 		 * page..
 		 */
 		if (!page_cache) {
-			page_cache = __get_free_page(GFP_USER);
+			page_cache = get_colored_page(GFP_USER, &inode->i_color);
 			/*
 			 * That could have slept, so go around to the
 			 * very beginning..
@@ -941,7 +941,7 @@ found_page:
 	 * extra page -- better to overlap the allocation with the I/O.
 	 */
 	if (no_share && !new_page) {
-		new_page = __get_free_page(GFP_USER);
+		new_page = get_colored_page(GFP_USER, &inode->i_color);
 		if (!new_page)
 			goto failure;
 	}
@@ -989,7 +989,7 @@ no_cached_page:
 		new_page = try_to_read_ahead(file, reada, new_page);
 
 	if (!new_page)
-		new_page = __get_free_page(GFP_USER);
+		new_page = get_colored_page(GFP_USER, &inode->i_color);
 	if (!new_page)
 		goto no_page;
 
@@ -1464,7 +1464,7 @@ generic_file_write(struct file *file, co
 		page = __find_page(inode, pgpos, *hash);
 		if (!page) {
 			if (!page_cache) {
-				page_cache = __get_free_page(GFP_USER);
+				page_cache = get_colored_page(GFP_USER, &inode->i_color);
 				if (page_cache)
 					continue;
 				status = -ENOMEM;
@@ -1535,7 +1535,7 @@ unsigned long get_cached_page(struct ino
 	if (!page) {
 		if (!new)
 			goto out;
-		page_cache = get_free_page(GFP_USER);
+		page_cache = get_colored_page(GFP_USER, &inode->i_color);
 		if (!page_cache)
 			goto out;
 		page = mem_map + MAP_NR(page_cache);
mm/page_alloc.c renamed from mm/page_alloc.c.~1~ +69 -1

106 lines not on this page · raw message

mm/memory.c renamed from mm/memory.c.~1~ +1 -1
@@ -808,7 +808,7 @@ static int do_anonymous_page(struct task
 {
 	pte_t entry = pte_wrprotect(mk_pte(ZERO_PAGE, vma->vm_page_prot));
 	if (write_access) {
-		unsigned long page = __get_free_page(GFP_USER);
+		unsigned long page = get_colored_page(GFP_USER, &vma->vm_mm->color);
 		if (!page)
 			return 0;
 		clear_page(page);

--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/