mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ed Tsai <ed.tsai@mediatek.com>
To: <miklos@szeredi.hu>
Cc: <linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<fuse-devel@lists.sourceforge.net>, <chenguanyou9338@gmail.com>,
	<stanley.chu@mediatek.com>, <Yong-xuan.Wang@mediatek.com>,
	<wsd_upstream@mediatek.com>, Ed Tsai <ed.tsai@mediatek.com>
Subject: [PATCH 1/1] fuse: add fuse_d_iput to postponed the iput
Date: Tue, 5 Jul 2022 16:53:08 +0800	[thread overview]
Message-ID: <20220705085308.32518-1-ed.tsai@mediatek.com> (raw)
In-Reply-To: <490be4e0b984e146c93586507442de3dad8694bb.camel@mediatek.com>

When all the references of an inode are dropped, and write of its dirty
pages is serving in Daemon, reclaim may deadlock on a regular allocation
in Daemon.

Add fuse_dentry_iput and some FI_* flags to postponed the iput for the
inodes be using in fuse_write_inode.

Signed-off-by: Ed Tsai <ed.tsai@mediatek.com>
---
Hi Miklos,
I define d_iput for fuse to postpone the iput until the fuse_write_inode
is done. This works fine at our platform. Please help to check this.

 fs/fuse/dir.c    | 17 +++++++++++++++++
 fs/fuse/file.c   | 15 +++++++++++++++
 fs/fuse/fuse_i.h |  4 ++++
 3 files changed, 36 insertions(+)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 74303d6e987b..37d768088c87 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -331,6 +331,22 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)
 	return mnt;
 }
 
+static void fuse_dentry_iput(struct dentry *dentry, struct inode *inode)
+{
+	struct fuse_inode *fi = get_fuse_inode(inode);
+	int need_iput = true;
+
+	spin_lock(&fi->lock);
+	if (test_bit(FUSE_I_WRITING, &fi->state)) {
+		set_bit(FUSE_I_NEED_IPUT, &fi->state);
+		need_iput = false;
+	}
+	spin_unlock(&fi->lock);
+
+	if (need_iput)
+		iput(inode);
+}
+
 const struct dentry_operations fuse_dentry_operations = {
 	.d_revalidate	= fuse_dentry_revalidate,
 	.d_delete	= fuse_dentry_delete,
@@ -339,6 +355,7 @@ const struct dentry_operations fuse_dentry_operations = {
 	.d_release	= fuse_dentry_release,
 #endif
 	.d_automount	= fuse_dentry_automount,
+	.d_iput		= fuse_dentry_iput,
 };
 
 const struct dentry_operations fuse_root_dentry_operations = {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 05caa2b9272e..a291784d42bc 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1848,6 +1848,7 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc)
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	struct fuse_file *ff;
+	int need_iput = false;
 	int err;
 
 	/*
@@ -1862,10 +1863,24 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc)
 	WARN_ON(wbc->for_reclaim);
 
 	ff = __fuse_write_file_get(fi);
+
+	spin_lock(&fi->lock);
+	set_bit(FUSE_I_WRITING, &fi->state);
+	spin_unlock(&fi->lock);
+
 	err = fuse_flush_times(inode, ff);
 	if (ff)
 		fuse_file_put(ff, false, false);
 
+	spin_lock(&fi->lock);
+	clear_bit(FUSE_I_WRITING, &fi->state);
+	if (test_and_clear_bit(FUSE_I_NEED_IPUT, &fi->state))
+		need_iput = true;
+	spin_unlock(&fi->lock);
+
+	if (need_iput)
+		iput(inode);
+
 	return err;
 }
 
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 488b460e046f..f5851e5397ce 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -167,6 +167,10 @@ enum {
 	FUSE_I_SIZE_UNSTABLE,
 	/* Bad inode */
 	FUSE_I_BAD,
+	/* inode is writing */
+	FUSE_I_WRITING,
+	/* inode need iput() after writing */
+	FUSE_I_NEED_IPUT,
 };
 
 struct fuse_conn;
-- 
2.18.0


  reply	other threads:[~2022-07-05  8:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 12:52 [PATCH] [fuse] alloc_page nofs avoid deadlock chenguanyou
2021-06-08 14:54 ` Re:[PATCH] fuse: " chenguanyou
2021-06-08 15:30 ` [PATCH] [fuse] " Miklos Szeredi
2021-06-11 12:14   ` Re:[PATCH] fuse: " chenguanyou
2021-07-13  2:42   ` [PATCH] [fuse] " Ed Tsai
2021-08-18  9:24     ` Miklos Szeredi
2021-09-24  3:52       ` Ed Tsai
2021-09-24  7:52         ` Miklos Szeredi
2021-09-28 15:25           ` Miklos Szeredi
2021-09-29  3:31             ` Re:[PATCH] fuse: " chenguanyou
2021-12-14  9:25             ` [PATCH] [fuse] " Ed Tsai
2021-12-14  9:38               ` Greg Kroah-Hartman
2021-12-15  8:22                 ` Ed Tsai
2021-12-15 13:52                   ` Greg Kroah-Hartman
     [not found]             ` <SI2PR03MB5545E0B76E54013678B9FEEC8BA99@SI2PR03MB5545.apcprd03.prod.outlook.com>
2022-06-10  7:48               ` Ed Tsai
2022-06-13  8:45                 ` Miklos Szeredi
2022-06-13  9:29                   ` Ed Tsai
2022-07-05  8:53                     ` Ed Tsai [this message]
2022-07-18 13:57                       ` [PATCH 1/1] fuse: add fuse_d_iput to postponed the iput Miklos Szeredi
2022-07-11  7:49                     ` [PATCH] [fuse] alloc_page nofs avoid deadlock Miklos Szeredi
2022-07-12  1:16                       ` Ed Tsai

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=20220705085308.32518-1-ed.tsai@mediatek.com \
    --to=ed.tsai@mediatek.com \
    --cc=Yong-xuan.Wang@mediatek.com \
    --cc=chenguanyou9338@gmail.com \
    --cc=fuse-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=stanley.chu@mediatek.com \
    --cc=wsd_upstream@mediatek.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

all inboxes | Powered by JetHome®