From: Jeff Layton <jeff.layton@primarydata.com>
To: linux-fsdevel@vger.kernel.org
Cc: bfields@fieldses.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] locks: use cmpxchg to assign i_flctx pointer
Date: Sat, 7 Mar 2015 11:09:59 -0500 [thread overview]
Message-ID: <1425744599-4934-5-git-send-email-jeff.layton@primarydata.com> (raw)
In-Reply-To: <1425744599-4934-1-git-send-email-jeff.layton@primarydata.com>
During the v3.20/v4.0 cycle, I had originally had the code manage the
inode->i_flctx pointer using a compare-and-swap operation instead of
the i_lock.
Sasha Levin though hit a problem while testing trinity that made me
believe that that wasn't safe. I now think though that I completely
misread the problem, even though it seemed like it went away when
we started using the i_lock to protect this pointer.
The issue was likely the same race that Kirill Shutemov hit while
testing the pre-rc1 v4.0 kernel and that Linus spotted. Due to the
way that the spinlock was dropped in the middle of flock_lock_file,
you could end up with multiple flock locks for the same struct file
on the inode.
Reinstate the use of a CAS operation to assign this pointer since it's
likely to be more efficient and gets the i_lock completely out of the
file locking business.
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
---
fs/locks.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index 4347f3dc17cc..22c0785c00ed 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -223,14 +223,7 @@ locks_get_lock_context(struct inode *inode, int type)
* Assign the pointer if it's not already assigned. If it is, then
* free the context we just allocated.
*/
- spin_lock(&inode->i_lock);
- if (likely(!inode->i_flctx)) {
- inode->i_flctx = new;
- new = NULL;
- }
- spin_unlock(&inode->i_lock);
-
- if (new)
+ if (cmpxchg(&inode->i_flctx, NULL, new))
kmem_cache_free(flctx_cache, new);
out:
return inode->i_flctx;
--
2.1.0
prev parent reply other threads:[~2015-03-07 16:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-07 16:09 [PATCH 0/4] locks: locks related cleanups for v4.1 Jeff Layton
2015-03-07 16:09 ` [PATCH 1/4] locks: don't allocate a lock context for an F_UNLCK request Jeff Layton
2015-03-07 16:09 ` [PATCH 2/4] locks: change lm_get_owner and lm_put_owner prototypes Jeff Layton
2015-03-07 16:09 ` [PATCH 3/4] locks: get rid of WE_CAN_BREAK_LSLK_NOW dead code Jeff Layton
2015-03-07 16:09 ` Jeff Layton [this message]
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=1425744599-4934-5-git-send-email-jeff.layton@primarydata.com \
--to=jeff.layton@primarydata.com \
--cc=bfields@fieldses.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
Powered by JetHome