From: Jeff Layton <jlayton@redhat.com>
To: Jeff Layton <jlayton@redhat.com>
Cc: viro@zeniv.linux.org.uk, matthew@wil.cx, bfields@fieldses.org,
dhowells@redhat.com, sage@inktank.com, smfrench@gmail.com,
swhiteho@redhat.com, Trond.Myklebust@netapp.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
cluster-devel@redhat.com, linux-nfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org, piastryyy@gmail.com
Subject: Re: [PATCH v3 06/13] locks: protect most of the file_lock handling with i_lock
Date: Mon, 17 Jun 2013 11:49:38 -0400 [thread overview]
Message-ID: <20130617114938.447a8d81@tlielax.poochiereds.net> (raw)
In-Reply-To: <20130617114609.708a336b@tlielax.poochiereds.net>
On Mon, 17 Jun 2013 11:46:09 -0400
Jeff Layton <jlayton@redhat.com> wrote:
> On Mon, 17 Jun 2013 11:13:49 -0400
> Jeff Layton <jlayton@redhat.com> wrote:
>
> > Having a global lock that protects all of this code is a clear
> > scalability problem. Instead of doing that, move most of the code to be
> > protected by the i_lock instead. The exceptions are the global lists
> > that the ->fl_link sits on, and the ->fl_block list.
> >
> > ->fl_link is what connects these structures to the
> > global lists, so we must ensure that we hold those locks when iterating
> > over or updating these lists.
> >
> > Furthermore, sound deadlock detection requires that we hold the
> > blocked_list state steady while checking for loops. We also must ensure
> > that the search and update to the list are atomic.
> >
> > For the checking and insertion side of the blocked_list, push the
> > acquisition of the global lock into __posix_lock_file and ensure that
> > checking and update of the blocked_list is done without dropping the
> > lock in between.
> >
> > On the removal side, when waking up blocked lock waiters, take the
> > global lock before walking the blocked list and dequeue the waiters from
> > the global list prior to removal from the fl_block list.
> >
> > With this, deadlock detection should be race free while we minimize
> > excessive file_lock_lock thrashing.
> >
> > Finally, in order to avoid a lock inversion problem when handling
> > /proc/locks output we must ensure that manipulations of the fl_block
> > list are also protected by the file_lock_lock.
> >
> > Signed-off-by: Jeff Layton <jlayton@redhat.com>
> > ---
> > Documentation/filesystems/Locking | 21 ++++--
> > fs/afs/flock.c | 5 +-
> > fs/ceph/locks.c | 2 +-
> > fs/ceph/mds_client.c | 8 +-
> > fs/cifs/cifsfs.c | 2 +-
> > fs/cifs/file.c | 13 ++--
> > fs/gfs2/file.c | 2 +-
> > fs/lockd/svcsubs.c | 12 ++--
> > fs/locks.c | 151 ++++++++++++++++++++++---------------
> > fs/nfs/delegation.c | 10 +-
> > fs/nfs/nfs4state.c | 8 +-
> > fs/nfsd/nfs4state.c | 8 +-
> > include/linux/fs.h | 11 ---
> > 13 files changed, 140 insertions(+), 113 deletions(-)
> >
>
> [...]
>
> > @@ -1231,7 +1254,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
> > if (IS_ERR(new_fl))
> > return PTR_ERR(new_fl);
> >
> > - lock_flocks();
> > + spin_lock(&inode->i_lock);
> >
> > time_out_leases(inode);
> >
> > @@ -1281,11 +1304,11 @@ restart:
> > break_time++;
> > }
> > locks_insert_block(flock, new_fl);
> > - unlock_flocks();
> > + spin_unlock(&inode->i_lock);
> > error = wait_event_interruptible_timeout(new_fl->fl_wait,
> > !new_fl->fl_next, break_time);
> > - lock_flocks();
> > - __locks_delete_block(new_fl);
> > + spin_lock(&inode->i_lock);
> > + locks_delete_block(new_fl);
>
> Doh -- bug here. This should not have been changed to
> locks_delete_block(). My apologies.
>
> > if (error >= 0) {
> > if (error == 0)
> > time_out_leases(inode);
>
> [...]
>
> > posix_unblock_lock(struct file *filp, struct file_lock *waiter)
> > {
> > + struct inode *inode = file_inode(filp);
> > int status = 0;
> >
> > - lock_flocks();
> > + spin_lock(&inode->i_lock);
> > if (waiter->fl_next)
> > - __locks_delete_block(waiter);
> > + locks_delete_block(waiter);
>
>
> Ditto here...
>
> > else
> > status = -ENOENT;
> > - unlock_flocks();
> > + spin_unlock(&inode->i_lock);
> > return status;
> > }
> >
>
Bah, scratch that -- this patch is actually fine. We hold the i_lock
here and locks_delete_block takes the file_lock_lock, which is correct.
There is a potential race in patch 7 though. I'll reply to that patch
to point it out in a minute.
--
Jeff Layton <jlayton@redhat.com>
next prev parent reply other threads:[~2013-06-17 15:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-17 15:13 [PATCH v3 00/13] locks: scalability improvements for file locking Jeff Layton
2013-06-17 15:13 ` [PATCH v3 01/13] cifs: use posix_unblock_lock instead of locks_delete_block Jeff Layton
2013-06-17 15:13 ` [PATCH v3 02/13] locks: make generic_add_lease and generic_delete_lease static Jeff Layton
2013-06-17 15:13 ` [PATCH v3 03/13] locks: comment cleanups and clarifications Jeff Layton
2013-06-17 15:13 ` [PATCH v3 04/13] locks: make "added" in __posix_lock_file a bool Jeff Layton
2013-06-17 15:13 ` [PATCH v3 05/13] locks: encapsulate the fl_link list handling Jeff Layton
2013-06-17 15:13 ` [PATCH v3 06/13] locks: protect most of the file_lock handling with i_lock Jeff Layton
2013-06-17 15:46 ` Jeff Layton
2013-06-17 15:49 ` Jeff Layton [this message]
2013-06-18 17:43 ` Jeff Layton
2013-06-17 15:13 ` [PATCH v3 07/13] locks: avoid taking global lock if possible when waking up blocked waiters Jeff Layton
2013-06-17 15:55 ` Jeff Layton
2013-06-17 15:13 ` [PATCH v3 08/13] locks: convert fl_link to a hlist_node Jeff Layton
2013-06-17 15:13 ` [PATCH v3 09/13] locks: turn the blocked_list into a hashtable Jeff Layton
2013-06-17 15:13 ` [PATCH v3 10/13] locks: add a new "lm_owner_key" lock operation Jeff Layton
2013-06-17 15:13 ` [PATCH v3 11/13] locks: give the blocked_hash its own spinlock Jeff Layton
2013-06-17 15:13 ` [PATCH v3 12/13] seq_file: add seq_list_*_percpu helpers Jeff Layton
2013-06-17 15:13 ` [PATCH v3 13/13] locks: move file_lock_list to a set of percpu hlist_heads and convert file_lock_lock to an lglock Jeff Layton
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=20130617114938.447a8d81@tlielax.poochiereds.net \
--to=jlayton@redhat.com \
--cc=Trond.Myklebust@netapp.com \
--cc=akpm@linux-foundation.org \
--cc=bfields@fieldses.org \
--cc=ceph-devel@vger.kernel.org \
--cc=cluster-devel@redhat.com \
--cc=dhowells@redhat.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=piastryyy@gmail.com \
--cc=sage@inktank.com \
--cc=samba-technical@lists.samba.org \
--cc=smfrench@gmail.com \
--cc=swhiteho@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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®