linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	Theodore Ts'o <tytso@mit.edu>,
	linux-kernel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: David Howells <dhowells@redhat.com>,
	Andreas Dilger <adilger@dilger.ca>,
	Dmitry Monakhov <dmtrmonakhov@yandex-team.ru>
Subject: [PATCH v2 1/2] vfs: add non-blocking mode for function find_inode_nowait()
Date: Thu, 30 Jan 2020 20:40:32 +0300	[thread overview]
Message-ID: <158040603214.1879.6549790415691475804.stgit@buzz> (raw)

Currently concurrent inode lookup by number does not scale well because
inode hash table is protected with single spinlock. Someday inode hash
will become searchable under RCU (see linked patchset by David Howells).

For now main user of this function: ext4_update_other_inodes_time()
could live with optimistic non-blocking try-lock/try-find semantics.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Suggested-by: Theodore Ts'o <tytso@mit.edu>
Link: https://lore.kernel.org/lkml/158031264567.6836.126132376018905207.stgit@buzz/T/#m83e4432ea81bc6c0ec0d1cca87e97bd89ff671d9
Link: https://lore.kernel.org/lkml/155620449631.4720.8762546550728087460.stgit@warthog.procyon.org.uk/ (RCU)
---
 fs/ext4/inode.c    |    2 +-
 fs/f2fs/node.c     |    2 +-
 fs/inode.c         |    9 +++++++--
 include/linux/fs.h |    2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 629a25d999f0..9512eb771820 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4865,7 +4865,7 @@ static void ext4_update_other_inodes_time(struct super_block *sb,
 		if (ino == orig_ino)
 			continue;
 		oi.raw_inode = (struct ext4_inode *) buf;
-		(void) find_inode_nowait(sb, ino, other_inode_match, &oi);
+		(void)find_inode_nowait(sb, ino, other_inode_match, &oi, false);
 	}
 }
 
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 3314a0f3405e..1b8515e4f451 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1793,7 +1793,7 @@ static bool flush_dirty_inode(struct page *page)
 	struct inode *inode;
 	nid_t ino = ino_of_node(page);
 
-	inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL);
+	inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL, false);
 	if (!inode)
 		return false;
 
diff --git a/fs/inode.c b/fs/inode.c
index ea15c6d9f274..6e52ee027b88 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1411,6 +1411,7 @@ EXPORT_SYMBOL(ilookup);
  * @hashval:	hash value (usually inode number) to search for
  * @match:	callback used for comparisons between inodes
  * @data:	opaque data pointer to pass to @match
+ * @nonblock:	if true do not wait for lock and fail with EAGAIN
  *
  * Search for the inode specified by @hashval and @data in the inode
  * cache, where the helper function @match will return 0 if the inode
@@ -1432,13 +1433,17 @@ struct inode *find_inode_nowait(struct super_block *sb,
 				unsigned long hashval,
 				int (*match)(struct inode *, unsigned long,
 					     void *),
-				void *data)
+				void *data, bool nonblock)
 {
 	struct hlist_head *head = inode_hashtable + hash(sb, hashval);
 	struct inode *inode, *ret_inode = NULL;
 	int mval;
 
-	spin_lock(&inode_hash_lock);
+	if (!nonblock)
+		spin_lock(&inode_hash_lock);
+	else if (!spin_trylock(&inode_hash_lock))
+		return ERR_PTR(-EAGAIN);
+
 	hlist_for_each_entry(inode, head, i_hash) {
 		if (inode->i_sb != sb)
 			continue;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 40be2ccb87f3..8eef77dbf0af 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3039,7 +3039,7 @@ extern struct inode *find_inode_nowait(struct super_block *,
 				       unsigned long,
 				       int (*match)(struct inode *,
 						    unsigned long, void *),
-				       void *data);
+				       void *data, bool nonblock);
 extern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *);
 extern int insert_inode_locked(struct inode *);
 #ifdef CONFIG_DEBUG_LOCK_ALLOC


             reply	other threads:[~2020-01-30 17:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 17:40 Konstantin Khlebnikov [this message]
2020-01-30 17:40 ` [PATCH v2 2/2] ext4: avoid spinlock congestion in lazytime optimization Konstantin Khlebnikov
2020-03-09 16:12 ` [PATCH v2 1/2] vfs: add non-blocking mode for function find_inode_nowait() David Howells

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=158040603214.1879.6549790415691475804.stgit@buzz \
    --to=khlebnikov@yandex-team.ru \
    --cc=adilger@dilger.ca \
    --cc=dhowells@redhat.com \
    --cc=dmtrmonakhov@yandex-team.ru \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --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;
as well as URLs for NNTP newsgroup(s).