Skip to contentSkip to conversation

: block_read_full_page: micro optimization

PATCH In review Paul Drynoff 2 participants 2 messages Jun 24, 2006 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : block_read_full_page: micro optimization

I wonder, may be with such change kernel become little faster?

---

fs/buffer.c +1 -1
Index: linux-2.6.17-mm1/fs/buffer.c
===================================================================
@@ -2093,7 +2093,7 @@ int block_read_full_page(struct page *pa
 			}
 			if (!buffer_mapped(bh)) {
 				void *kaddr = kmap_atomic(page, KM_USER0);
-				memset(kaddr + i * blocksize, 0, blocksize);
+				memset(kaddr + (i << inode->i_blkbits), 0, blocksize);
 				flush_dcache_page(page);
 				kunmap_atomic(kaddr, KM_USER0);
 				if (!err)
#1 lore raw

fs/buffer.c int block_read_full_page(struct page *pa · line 2096

Quoted 3 lines · Paul Drynoff

I wonder, may be with such change kernel become little faster?

fs/buffer.c +1 -1
-                               memset(kaddr + i * blocksize, 0, blocksize);
+                               memset(kaddr + (i << inode->i_blkbits), 0, blocksize);

It's likely slower with this change, as you now require the CPU to load inode->i_blkbits which, chances are, isn't hanging around handily in a register like blocksize obviously is. So, you've increased register pressure and added more fetches from memory instead of just doing a simple (and cheap) multiplication. Not good.

Check the generated code for both cases. Smaller is usually better. Benchmarking would be best, however, code changes that cause cache misses or register pressure can be hard to measure well.

Ray