Skip to content

Commit

Permalink
dio: zero struct dio with kzalloc instead of manually
Browse files Browse the repository at this point in the history
This patch uses kzalloc to zero all of struct dio rather than manually
trying to track which fields we rely on being zero.  It passed aio+dio
stress testing and some bug regression testing on ext3.

This patch was introduced by Linus in the conversation that lead up to
Badari's minimal fix to manually zero .map_bh.b_state in commit:

  6a648fa

It makes the code a bit smaller.  Maybe a couple fewer cachelines to
load, if we're lucky:

   text    data     bss     dec     hex filename
3285925  568506 1304616 5159047  4eb887 vmlinux
3285797  568506 1304616 5158919  4eb807 vmlinux.patched

I was unable to measure a stable difference in the number of cpu cycles
spent in blockdev_direct_IO() when pushing aio+dio 256K reads at
~340MB/s.

So the resulting intent of the patch isn't a performance gain but to
avoid exposing ourselves to the risk of finding another field like
.map_bh.b_state where we rely on zeroing but don't enforce it in the
code.

Signed-off-by: Zach Brown <zach.brown@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Zach Brown authored and Linus Torvalds committed Aug 21, 2007
1 parent 38f061c commit 848c4dd
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions fs/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,45 +958,29 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
ssize_t ret2;
size_t bytes;

dio->bio = NULL;
dio->inode = inode;
dio->rw = rw;
dio->blkbits = blkbits;
dio->blkfactor = inode->i_blkbits - blkbits;
dio->start_zero_done = 0;
dio->size = 0;
dio->block_in_file = offset >> blkbits;
dio->blocks_available = 0;
dio->cur_page = NULL;

dio->boundary = 0;
dio->reap_counter = 0;
dio->get_block = get_block;
dio->end_io = end_io;
dio->map_bh.b_private = NULL;
dio->map_bh.b_state = 0;
dio->final_block_in_bio = -1;
dio->next_block_for_io = -1;

dio->page_errors = 0;
dio->io_error = 0;
dio->result = 0;
dio->iocb = iocb;
dio->i_size = i_size_read(inode);

spin_lock_init(&dio->bio_lock);
dio->refcount = 1;
dio->bio_list = NULL;
dio->waiter = NULL;

/*
* In case of non-aligned buffers, we may need 2 more
* pages since we need to zero out first and last block.
*/
if (unlikely(dio->blkfactor))
dio->pages_in_io = 2;
else
dio->pages_in_io = 0;

for (seg = 0; seg < nr_segs; seg++) {
user_addr = (unsigned long)iov[seg].iov_base;
Expand Down Expand Up @@ -1184,7 +1168,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
}
}

dio = kmalloc(sizeof(*dio), GFP_KERNEL);
dio = kzalloc(sizeof(*dio), GFP_KERNEL);
retval = -ENOMEM;
if (!dio)
goto out;
Expand Down

0 comments on commit 848c4dd

Please sign in to comment.