Messages in this thread Patch in this message | | | From | Mikael Starvik <> | Subject | [PATCH 2.4.20] alloc_kiovec performance improvement | Date | Mon, 5 May 2003 18:54:39 +0200 |
| |
alloc_kiovec always allocates 1024 buffer heads which is a waste with performance in the cases when the buffers aren't used.
The patch below adds variants that doesn't allocate the buffer heads.
A similar approach would be to introduce a common function with a flag that indicates if buffer heads should be allocated.
/Mikael
diff -Nurp linux-2.4.20/fs/iobuf.c linux-2.4.20-local/fs/iobuf.c --- linux-2.4.20/fs/iobuf.c Fri Nov 29 00:53:15 2002 +++ linux-2.4.20-local/fs/iobuf.c Mon May 5 18:35:12 2003 @@ -114,6 +114,29 @@ nomem: return -ENOMEM; } +int alloc_kiovec_nobhs(int nr, struct kiobuf **bufp) +{ + int i; + struct kiobuf *iobuf; + + for (i = 0; i < nr; i++) { + iobuf = kmem_cache_alloc(kiobuf_cachep, GFP_KERNEL); + if (unlikely(!iobuf)) + goto nomem; + if (unlikely(kiobuf_init(iobuf))) + goto nomem2; + bufp[i] = iobuf; + } + + return 0; + +nomem2: + kmem_cache_free(kiobuf_cachep, iobuf); +nomem: + free_kiovec_nobhs(i, bufp); + return -ENOMEM; +} + void free_kiovec(int nr, struct kiobuf **bufp) { int i; @@ -128,6 +151,20 @@ void free_kiovec(int nr, struct kiobuf * kmem_cache_free(kiobuf_cachep, bufp[i]); } } + +void free_kiovec_nobhs(int nr, struct kiobuf **bufp) +{ + int i; + struct kiobuf *iobuf; + + for (i = 0; i < nr; i++) { + iobuf = bufp[i]; + if (iobuf->locked) + unlock_kiovec(1, &iobuf); + kfree(iobuf->maplist); + kmem_cache_free(kiobuf_cachep, bufp[i]); + } +} int expand_kiobuf(struct kiobuf *iobuf, int wanted) { diff -Nurp linux-2.4.20/include/linux/iobuf.h linux-2.4.20-local/include/linux/iobuf.h --- linux-2.4.20/include/linux/iobuf.h Fri Nov 29 00:53:15 2002 +++ linux-2.4.20-local/include/linux/iobuf.h Mon May 5 18:35:51 2003 @@ -64,7 +64,9 @@ void mark_dirty_kiobuf(struct kiobuf *io void end_kio_request(struct kiobuf *, int); void simple_wakeup_kiobuf(struct kiobuf *); int alloc_kiovec(int nr, struct kiobuf **); +int alloc_kiovec_nobhs(int nr, struct kiobuf **); void free_kiovec(int nr, struct kiobuf **); +void free_kiovec_nobhs(int nr, struct kiobuf **); int expand_kiobuf(struct kiobuf *, int); void kiobuf_wait_for_io(struct kiobuf *); extern int alloc_kiobuf_bhs(struct kiobuf *); diff -Nurp linux-2.4.20/kernel/ksyms.c linux-2.4.20-local/kernel/ksyms.c --- linux-2.4.20/kernel/ksyms.c Fri Nov 29 00:53:15 2002 +++ linux-2.4.20-local/kernel/ksyms.c Mon May 5 18:36:25 2003 @@ -410,7 +410,9 @@ EXPORT_SYMBOL(__br_write_unlock); /* Kiobufs */ EXPORT_SYMBOL(alloc_kiovec); +EXPORT_SYMBOL(alloc_kiovec_nobhs); EXPORT_SYMBOL(free_kiovec); +EXPORT_SYMBOL(free_kiovec_nobhs); EXPORT_SYMBOL(expand_kiobuf); EXPORT_SYMBOL(map_user_kiobuf); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |