linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Chinner <dgc@sgi.com>
To: Chris Mason <chris.mason@oracle.com>
Cc: linux-fsdevel@vger.kernel.org, akpm@osdl.org,
	zach.brown@oracle.com, Suparna Bhattacharya <suparna@in.ibm.com>
Subject: Re: [PATCH 2 of 7] Change O_DIRECT to use placeholders instead of i_mutex/i_alloc_sem locking
Date: Thu, 2 Nov 2006 09:44:20 +1100	[thread overview]
Message-ID: <20061101224420.GN8394166@melbourne.sgi.com> (raw)
In-Reply-To: <4486b1f7011adb925d90.1162397284@opti.oraclecorp.com>

On Wed, Nov 01, 2006 at 11:08:04AM -0400, Chris Mason wrote:
> All mutex and semaphore usage is removed from fs/direct-io.c.  Callers
> can ask for placeholder pages if they want help protecting against
> races with buffered io.
> 
> Signed-off-by: Chris Mason <chris.mason@oracle.com>
.....

> +static void unlock_page_range(struct dio *dio, unsigned long start,
> +			      unsigned long nr)
> +{
> +	if (dio->lock_type != DIO_NO_LOCKING) {
> +		remove_placeholder_pages(dio->inode->i_mapping, dio->tmppages,
> +					 &dio->fake,
> +					 start, start + nr,
> +					 ARRAY_SIZE(dio->tmppages));
> +	}
> +}
> +
> +static int lock_page_range(struct dio *dio, unsigned long start,
> +			   unsigned long nr)
> +{
> +	struct address_space *mapping = dio->inode->i_mapping;
> +	struct page *fake = &dio->fake;
> +	unsigned long end = start + nr;
> +
> +	if (dio->lock_type == DIO_NO_LOCKING)
> +		return 0;
> +	return find_or_insert_placeholders(mapping, dio->tmppages, start, end,
> +	                                  ARRAY_SIZE(dio->tmppages),
> +					  GFP_KERNEL, fake,
> +					  dio->rw == READ);
> +}

I'm not sure that these two function are well named -
lock_page_range() could be confused for an extenstion of lock_page()
and they are very different things. Something like dio_lock_range()
and dio_unlock_range() might be more appropriate...

> +
> +
>  /*
>   * Get another userspace page.  Returns an ERR_PTR on error.  Pages are
>   * buffered inside the dio so that we can call get_user_pages() against a
> @@ -219,9 +255,9 @@ static void dio_complete(struct dio *dio
>  {
>  	if (dio->end_io && dio->result)
>  		dio->end_io(dio->iocb, offset, bytes, dio->map_bh.b_private);
> -	if (dio->lock_type == DIO_LOCKING)
> -		/* lockdep: non-owner release */
> -		up_read_non_owner(&dio->inode->i_alloc_sem);
> +	unlock_page_range(dio, dio->fspages_start_off,
> +			  dio->fspages_end_off - dio->fspages_start_off);
> +	dio->fspages_end_off = dio->fspages_start_off;
>  }

dio->fspages_end_off and dio->fspages_start_off only seem to have
relevance to the DIO_PLACEHOLDER case - can this be wrapped up
inside dio_unlock_range()?

>  
>  /*
> @@ -517,6 +553,7 @@ static int get_more_blocks(struct dio *d
>  	unsigned long fs_count;	/* Number of filesystem-sized blocks */
>  	unsigned long dio_count;/* Number of dio_block-sized blocks */
>  	unsigned long blkmask;
> +	unsigned long index;
>  	int create;
>  
>  	/*
> @@ -544,7 +581,19 @@ static int get_more_blocks(struct dio *d
>  		} else if (dio->lock_type == DIO_NO_LOCKING) {
>  			create = 0;
>  		}
> -
> +	        index = fs_startblk >> (PAGE_CACHE_SHIFT -
> +		                        dio->inode->i_blkbits);
> +		end = (dio->final_block_in_request >> dio->blkfactor) >>
> +		      (PAGE_CACHE_SHIFT - dio->inode->i_blkbits);
> +		BUG_ON(index > end);
> +		while (index >= dio->fspages_end_off) {
> +			unsigned long nr;
> +			nr = min(end - index + 1, (unsigned long)DIO_PAGES);
> +			ret = lock_page_range(dio, dio->fspages_end_off, nr);
> +			if (ret)
> +				goto error;
> +			dio->fspages_end_off += nr;
> +		}

Ditto for this - if we are not using placeholders, then none of this
is needed and so could be wrapped in:

		if (dio->flags & DIO_PLACEHOLDER) {
			ret = dio_lock_range(dio, ...)
			if (ret)
				goto error;
		}

> @@ -1221,49 +1257,29 @@ __blockdev_direct_IO(int rw, struct kioc
>  				goto out;
>  		}
>  	}
> -
>  	dio = kmalloc(sizeof(*dio), GFP_KERNEL);
>  	retval = -ENOMEM;
>  	if (!dio)
>  		goto out;
>  
> +	set_page_placeholder(&dio->fake);
> +	dio->fspages_start_off = offset >> PAGE_CACHE_SHIFT;
> +	dio->fspages_end_off = dio->fspages_start_off;
> +

if (flags & DIO_PLACEHOLDER) ?

>  	/*
>  	 * For block device access DIO_NO_LOCKING is used,
>  	 *	neither readers nor writers do any locking at all
>  	 * For regular files using DIO_LOCKING,
> -	 *	readers need to grab i_mutex and i_alloc_sem
> -	 *	writers need to grab i_alloc_sem only (i_mutex is already held)
> +	 *	No locks are taken
>  	 * For regular files using DIO_OWN_LOCKING,
>  	 *	neither readers nor writers take any locks here
>  	 */

So nothing does any locking here - comment can be simplified/killed?

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

  reply	other threads:[~2006-11-01 22:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-01 15:08 [PATCH 0 of 7] O_DIRECT locking rework Chris Mason
2006-11-01 15:08 ` [PATCH 1 of 7] Introduce a place holder page for the pagecache Chris Mason
2006-11-01 15:08 ` [PATCH 2 of 7] Change O_DIRECT to use placeholders instead of i_mutex/i_alloc_sem locking Chris Mason
2006-11-01 22:44   ` David Chinner [this message]
2006-11-01 15:08 ` [PATCH 3 of 7] DIO: don't fall back to buffered writes Chris Mason
2006-11-01 15:08 ` [PATCH 4 of 7] Turn the DIO lock_type parameter into a flags field Chris Mason
2006-11-01 22:58   ` David Chinner
2006-11-02  1:02     ` Chris Mason
2006-11-02  2:16       ` David Chinner
2006-11-08 18:48     ` Chris Mason
2006-11-01 15:08 ` [PATCH 5 of 7] Make ext3 safe for the new DIO locking rules Chris Mason
2006-11-01 15:08 ` [PATCH 6 of 7] Make reiserfs safe for " Chris Mason
2006-11-01 15:08 ` [PATCH 7 of 7] Adapt XFS to the new blockdev_direct_IO calls Chris Mason
2006-11-01 23:00   ` David Chinner

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=20061101224420.GN8394166@melbourne.sgi.com \
    --to=dgc@sgi.com \
    --cc=akpm@osdl.org \
    --cc=chris.mason@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=suparna@in.ibm.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;
as well as URLs for NNTP newsgroup(s).