mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Badari Pulavarty <pbadari@us.ibm.com>,
	Joe Jin <joe.jin@oracle.com>, Zach Brown <zach.brown@oracle.com>,
	gurudas pai <gurudas.pai@oracle.com>,
	jens.axboe@oracle.com, lkml <linux-kernel@vger.kernel.org>,
	wen.gang.wang@oracle.com
Subject: Re: [PATCH] add check do_direct_IO() return val
Date: Tue, 31 Jul 2007 15:59:45 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.0.999.0707311555410.4161@woody.linux-foundation.org> (raw)
In-Reply-To: <20070731153410.fcbf9a1b.akpm@linux-foundation.org>



On Tue, 31 Jul 2007, Andrew Morton wrote:
> 
> We zero out so many fields in there now that a kzalloc() might yield
> a net gain.  0.000001% in an unnamed benchmark!

Indeed. That's *especially* true since right now it passes a mostly 
totally uninitialized structure pointer down to direct_io_worker(), but it 
has actually initialized a _few_ fields. Ie the "die" pointer is almost 
totally filled with random crap, except for two members: dio->lock_type 
and dio->is_async have been initialized the rest is random crud.

That kind of mixing of totally-but-not-entirely-uninitialized pointer 
passing is just a recipe for disaster.

Does a patch like this work? I don't have any test-cases, but it would be 
good to have something like this tested and passed back with proper 
explanations and sign-offs.

		Linus

---
 fs/direct-io.c |   17 +----------------
 1 files changed, 1 insertions(+), 16 deletions(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index 52bb263..901dc55 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -958,35 +958,22 @@ 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->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
@@ -994,8 +981,6 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
 	 */
 	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;
@@ -1183,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;


  reply	other threads:[~2007-07-31 23:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-26  9:04 Joe Jin
2007-07-27  5:13 ` Andrew Morton
2007-07-27  7:15   ` Joe Jin
2007-07-27  7:31     ` Dave Young
2007-07-27  7:44       ` Joe Jin
2007-07-27 12:37     ` gurudas pai
2007-07-28  3:47       ` Joe Jin
2007-07-30 20:53         ` Andrew Morton
2007-07-30 21:09           ` Zach Brown
2007-07-30 21:24           ` Badari Pulavarty
2007-07-30 21:45             ` Zach Brown
2007-07-30 21:58               ` Badari Pulavarty
2007-07-30 21:58                 ` Zach Brown
2007-07-30 23:38                 ` Zach Brown
2007-07-31  0:15                   ` Badari Pulavarty
2007-07-31  0:17                   ` Badari Pulavarty
2007-07-31  0:53                   ` Joe Jin
2007-07-31  3:45                     ` Badari
2007-07-31  4:35                       ` Joe Jin
2007-07-31  5:01                         ` Badari
2007-07-31 22:25                         ` Badari Pulavarty
2007-07-31 22:34                           ` Andrew Morton
2007-07-31 22:59                             ` Linus Torvalds [this message]
2007-07-31 23:16                               ` Zach Brown
2007-08-01  1:36                               ` Joe Jin
2007-08-01 11:40                                 ` gurudas pai
2007-07-31 23:04                             ` Badari Pulavarty
2007-07-31 23:14                           ` Zach Brown
2007-08-01  1:11                           ` Joe Jin
2007-07-27  8:09   ` gurudas pai
2007-07-27  5:13 ` wengang wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.999.0707311555410.4161@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=gurudas.pai@oracle.com \
    --cc=jens.axboe@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbadari@us.ibm.com \
    --cc=wen.gang.wang@oracle.com \
    --cc=zach.brown@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®