mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Al Viro <viro@ZenIV.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Chris Mason <clm@fb.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	David Howells <dhowells@redhat.com>,
	elena.reshetova@intel.com, ishkamiel@gmail.com,
	dwindsor@gmail.com, gregkh@linuxfoundation.org,
	peterz@infradead.org
Subject: [RFC][PATCH 10/10] fs: Convert i_count over to refcount_t
Date: Fri, 24 Feb 2017 16:43:39 +0100	[thread overview]
Message-ID: <20170224162044.548813302@infradead.org> (raw)
In-Reply-To: <20170224154329.478276481@infradead.org>

[-- Attachment #1: peterz-fs-inode-4.patch --]
[-- Type: text/plain, Size: 5366 bytes --]

Now that i_count is a proper refcount, convert it to refcount_t.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 fs/btrfs/inode.c   |    2 +-
 fs/f2fs/super.c    |    4 ++--
 fs/inode.c         |   16 ++++++++--------
 fs/xfs/xfs_inode.c |    2 +-
 fs/xfs/xfs_inode.h |    2 +-
 include/linux/fs.h |    5 +++--
 kernel/futex.c     |    2 +-
 7 files changed, 17 insertions(+), 16 deletions(-)

--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3172,7 +3172,7 @@ void btrfs_add_delayed_iput(struct inode
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct btrfs_inode *binode = BTRFS_I(inode);
 
-	if (atomic_add_unless(&inode->i_count, -1, 2))
+	if (refcount_dec_unless(&inode->i_count, 2))
 		return;
 
 	spin_lock(&fs_info->delayed_iput_lock);
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -601,7 +601,7 @@ static int f2fs_drop_inode(struct inode
 	if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) {
 		if (!inode->i_nlink && !is_bad_inode(inode)) {
 			/* to avoid evict_inode call simultaneously */
-			atomic_inc(&inode->i_count);
+			refcount_inc(&inode->i_count);
 			spin_unlock(&inode->i_lock);
 
 			/* some remained atomic pages should discarded */
@@ -621,7 +621,7 @@ static int f2fs_drop_inode(struct inode
 
 			fscrypt_put_encryption_info(inode, NULL);
 			spin_lock(&inode->i_lock);
-			atomic_dec(&inode->i_count);
+			refcount_dec(&inode->i_count);
 		}
 		return 0;
 	}
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -135,7 +135,7 @@ int inode_init_always(struct super_block
 	inode->i_sb = sb;
 	inode->i_blkbits = sb->s_blocksize_bits;
 	inode->i_flags = 0;
-	atomic_set(&inode->i_count, 2); /* hashed and ref */
+	refcount_set(&inode->i_count, 2); /* hashed and ref */
 	inode->i_op = &empty_iops;
 	inode->i_fop = &no_open_fops;
 	inode->__i_nlink = 1;
@@ -387,7 +387,7 @@ static void init_once(void *foo)
 void __iget(struct inode *inode)
 {
 	lockdep_assert_held(&inode->i_lock);
-	WARN_ON(!atomic_inc_not_zero(&inode->i_count));
+	refcount_inc(&inode->i_count); /* must not be 0 */
 }
 
 /*
@@ -395,7 +395,7 @@ void __iget(struct inode *inode)
  */
 void ihold(struct inode *inode)
 {
-	WARN_ON(atomic_inc_return(&inode->i_count) < 3);
+	refcount_inc(&inode->i_count);
 }
 EXPORT_SYMBOL(ihold);
 
@@ -818,7 +818,7 @@ static struct inode *find_inode(struct s
 			continue;
 		if (!test(inode, data))
 			continue;
-		if (atomic_inc_not_zero(&inode->i_count))
+		if (refcount_inc_not_zero(&inode->i_count))
 			goto out_unlock;
 		goto slow;
 	}
@@ -875,7 +875,7 @@ static struct inode *find_inode_fast(str
 			continue;
 		if (inode->i_sb != sb)
 			continue;
-		if (atomic_inc_not_zero(&inode->i_count))
+		if (refcount_inc_not_zero(&inode->i_count))
 			goto out_unlock;
 		goto slow;
 	}
@@ -1538,7 +1538,7 @@ void iput(struct inode *inode)
 
 	BUG_ON(inode->i_state & I_CLEAR);
 retry:
-	if (atomic_add_unless(&inode->i_count, -1, 2))
+	if (refcount_dec_unless(&inode->i_count, 2))
 		return;
 
 	spin_lock(&inode->i_lock);
@@ -1551,7 +1551,7 @@ void iput(struct inode *inode)
 		goto retry;
 	}
 
-	atomic_dec(&inode->i_count); /* 2 -> 1 */
+	refcount_dec(&inode->i_count); /* 2 -> 1 */
 	WARN_ON(inode->i_state & I_NEW);
 
 	/*
@@ -1578,7 +1578,7 @@ void iput(struct inode *inode)
 	 * continue to take the inode out, otherwise someone got a ref
 	 * while we weren't looking.
 	 */
-	if (atomic_cmpxchg(&inode->i_count, 1, 0) != 1) {
+	if (!refcount_dec_if_one(&inode->i_count)) {
 		spin_unlock(&inode->i_lock);
 		return;
 	}
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1563,7 +1563,7 @@ xfs_itruncate_extents(
 	int			done = 0;
 
 	ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
-	ASSERT(!atomic_read(&VFS_I(ip)->i_count) ||
+	ASSERT(!refcount_read(&VFS_I(ip)->i_count) ||
 	       xfs_isilocked(ip, XFS_IOLOCK_EXCL));
 	ASSERT(new_size <= XFS_ISIZE(ip));
 	ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -475,7 +475,7 @@ static inline void xfs_setup_existing_in
 
 #define IHOLD(ip) \
 do { \
-	ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
+	ASSERT(refcount_read(&VFS_I(ip)->i_count) > 0) ; \
 	ihold(VFS_I(ip)); \
 	trace_xfs_ihold(ip, _THIS_IP_); \
 } while (0)
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -23,6 +23,7 @@
 #include <linux/fiemap.h>
 #include <linux/rculist_bl.h>
 #include <linux/atomic.h>
+#include <linux/refcount.h>
 #include <linux/shrinker.h>
 #include <linux/migrate_mode.h>
 #include <linux/uidgid.h>
@@ -622,7 +623,7 @@ struct inode {
 		struct rcu_head		i_rcu;
 	};
 	u64			i_version;
-	atomic_t		i_count;
+	refcount_t		i_count;
 	atomic_t		i_dio_count;
 	atomic_t		i_writecount;
 #ifdef CONFIG_IMA
@@ -2713,7 +2714,7 @@ extern unsigned int get_next_ino(void);
 
 static inline int i_count(struct inode *inode)
 {
-	int i_count = atomic_read(&inode->i_count);
+	int i_count = refcount_read(&inode->i_count);
 
 	/*
 	 * In order to preserve the 'old' usage-count semantics, remove the
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -676,7 +676,7 @@ get_futex_key(u32 __user *uaddr, int fsh
 		 * cases, therefore a successful atomic_inc return below will
 		 * guarantee that get_futex_key() will still imply smp_mb(); (B).
 		 */
-		if (WARN_ON_ONCE(!atomic_inc_not_zero(&inode->i_count))) {
+		if (WARN_ON_ONCE(!refcount_inc_not_zero(&inode->i_count))) {
 			rcu_read_unlock();
 			put_page(page);
 

  parent reply	other threads:[~2017-02-24 18:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 15:43 [RFC][PATCH 00/10] On inode::i_count and the usage vs reference count issue Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 01/10] fs: Use lockdep_assert_held() instead of comments Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 02/10] fs: Avoid looking at i_count without i_lock held Peter Zijlstra
     [not found]   ` <CA+55aFxLw8FXf61rsGYDjA1tS=joDeaF7OSgaepLWwcz4zt=dg@mail.gmail.com>
2017-02-24 17:06     ` Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 03/10] fs: Introduce i_count() Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 04/10] fs: Restructure iput() Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 05/10] fs: Remove iput_final() Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 06/10] fs: Rework i_count Peter Zijlstra
2017-02-24 20:49   ` Al Viro
2017-02-24 15:43 ` [RFC][PATCH 07/10] orangefs: Use RCU for destroy_inode Peter Zijlstra
2017-02-24 20:52   ` Al Viro
2017-02-24 23:00     ` Mike Marshall
2017-02-25 20:31       ` Mike Marshall
2017-02-27  0:34         ` Mike Marshall
2017-02-27  1:20           ` Linus Torvalds
2017-02-27  8:44         ` David Howells
2017-02-27 14:44           ` Mike Marshall
2017-02-24 15:43 ` [RFC][PATCH 08/10] fs: Do RCU versions for find_inode() Peter Zijlstra
2017-02-24 15:43 ` [RFC][PATCH 09/10] locking/refcount: Provide refcount_dec_unless() Peter Zijlstra
2017-02-27  9:28   ` Reshetova, Elena
2017-02-24 15:43 ` Peter Zijlstra [this message]
2017-02-24 16:43 ` [RFC][PATCH 00/10] On inode::i_count and the usage vs reference count issue Christoph Hellwig
2017-02-24 17:07   ` Peter Zijlstra
2017-02-24 20:59   ` David Windsor
     [not found] ` <CA+55aFy1bNbsX_3T-s_EUwTP-r_SmJJMvB3=-2nffehFVP=EdQ@mail.gmail.com>
     [not found]   ` <CA+55aFz0DbAGZ8gc+s35nm1N5frXjK_NOh7QzuSfZeJbjsT6Sg@mail.gmail.com>
     [not found]     ` <CA+55aFyR8wkHps5_AqUqzx8MDMNxRZZ7+MYH9g=ZCUi=4Oey8w@mail.gmail.com>
2017-02-24 19:24       ` Fwd: " Linus Torvalds
2017-02-24 20:42 ` Al Viro

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=20170224162044.548813302@infradead.org \
    --to=peterz@infradead.org \
    --cc=clm@fb.com \
    --cc=dhowells@redhat.com \
    --cc=dwindsor@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ishkamiel@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --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

Powered by JetHome