linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: Yongji Xie <xieyongji@bytedance.com>
Cc: linux-fsdevel@vger.kernel.org, 张佳辰 <zhangjiachen.jaycee@bytedance.com>
Subject: Re: [RFC] fuse: Avoid invalidating attrs if writeback_cache enabled
Date: Mon, 18 Oct 2021 13:45:47 +0200	[thread overview]
Message-ID: <CAJfpegv51cbjkD6BQ6wUZSbaTpnB1-827G++HQnWX7zGA5fmmA@mail.gmail.com> (raw)
In-Reply-To: <CACycT3s=aC6eWfo0LHMuE6sVVErjkZPScsgaBGn4QABbZE2a9g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2101 bytes --]

On Mon, 18 Oct 2021 at 13:25, Yongji Xie <xieyongji@bytedance.com> wrote:
>
> On Wed, Oct 13, 2021 at 9:52 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> >
> > On Mon, 11 Oct 2021 at 16:45, Yongji Xie <xieyongji@bytedance.com> wrote:
> > >
> > > On Mon, Oct 11, 2021 at 9:21 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
> > > >
> > > > On Mon, 11 Oct 2021 at 11:07, Xie Yongji <xieyongji@bytedance.com> wrote:
> > > > >
> > > > > Recently we found the performance of small direct writes is bad
> > > > > when writeback_cache enabled. This is because we need to get
> > > > > attrs from userspace in fuse_update_get_attr() on each write.
> > > > > The timeout for the attributes doesn't work since every direct write
> > > > > will invalidate the attrs in fuse_direct_IO().
> > > > >
> > > > > To fix it, this patch tries to avoid invalidating attrs if writeback_cache
> > > > > is enabled since we should trust local size/ctime/mtime in this case.
> > > >
> > > > Hi,
> > > >
> > > > Thanks for the patch.
> > > >
> > > > Just pushed an update to
> > > > git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.gitt#for-next
> > > > (9ca3f8697158 ("fuse: selective attribute invalidation")) that should
> > > > fix this behavior.
> > > >
> > >
> > > Looks like fuse_update_get_attr() will still get attrs from userspace
> > > each time with this commit applied.
> > >
> > > > Could you please test?
> > > >
> > >
> > > I applied the commit 9ca3f8697158 ("fuse: selective attribute
> > > invalidation")  and tested it. But the issue still exists.
> >
> > Yeah, my bad.  Pushed a more complete set of fixes to #for-next ending with
> >
> > e15a9a5fca6c ("fuse: take cache_mask into account in getattr")
> >
> > You should pull or cherry pick the complete branch.
> >
>
> I tested this branch, but it still doesn't fix this issue. The
> inval_mask = 0x6C0 and cache_mask = 0x2C0, so we still need to get
> attrs from userspace. Should we add STATX_BLOCKS to cache_mask?

Does the attach incremental ~/gupatch solve this?  Or is the
fuse_update_get_attr() coming from a stat* syscall?

Thanks,
Miklos

[-- Attachment #2: fuse-only-update-necessary-attributes.patch --]
[-- Type: text/x-patch, Size: 3387 bytes --]

Index: linux/fs/fuse/dir.c
===================================================================
--- linux.orig/fs/fuse/dir.c	2021-10-18 13:40:27.381801032 +0200
+++ linux/fs/fuse/dir.c	2021-10-18 13:37:26.798569496 +0200
@@ -1055,11 +1055,9 @@ static int fuse_update_get_attr(struct i
 	return err;
 }
 
-int fuse_update_attributes(struct inode *inode, struct file *file)
+int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask)
 {
-	/* Do *not* need to get atime for internal purposes */
-	return fuse_update_get_attr(inode, file, NULL,
-				    STATX_BASIC_STATS & ~STATX_ATIME, 0);
+	return fuse_update_get_attr(inode, file, NULL, mask, 0);
 }
 
 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
Index: linux/fs/fuse/file.c
===================================================================
--- linux.orig/fs/fuse/file.c	2021-10-18 13:40:27.382801044 +0200
+++ linux/fs/fuse/file.c	2021-10-18 13:40:14.504641904 +0200
@@ -996,7 +996,7 @@ static ssize_t fuse_cache_read_iter(stru
 	if (fc->auto_inval_data ||
 	    (iocb->ki_pos + iov_iter_count(to) > i_size_read(inode))) {
 		int err;
-		err = fuse_update_attributes(inode, iocb->ki_filp);
+		err = fuse_update_attributes(inode, iocb->ki_filp, STATX_SIZE);
 		if (err)
 			return err;
 	}
@@ -1282,7 +1282,8 @@ static ssize_t fuse_cache_write_iter(str
 
 	if (fc->writeback_cache) {
 		/* Update size (EOF optimization) and mode (SUID clearing) */
-		err = fuse_update_attributes(mapping->host, file);
+		err = fuse_update_attributes(mapping->host, file,
+					     STATX_SIZE | STATX_MODE);
 		if (err)
 			return err;
 
@@ -2633,7 +2634,7 @@ static loff_t fuse_lseek(struct file *fi
 	return vfs_setpos(file, outarg.offset, inode->i_sb->s_maxbytes);
 
 fallback:
-	err = fuse_update_attributes(inode, file);
+	err = fuse_update_attributes(inode, file, STATX_SIZE);
 	if (!err)
 		return generic_file_llseek(file, offset, whence);
 	else
@@ -2653,7 +2654,7 @@ static loff_t fuse_file_llseek(struct fi
 		break;
 	case SEEK_END:
 		inode_lock(inode);
-		retval = fuse_update_attributes(inode, file);
+		retval = fuse_update_attributes(inode, file, STATX_SIZE);
 		if (!retval)
 			retval = generic_file_llseek(file, offset, whence);
 		inode_unlock(inode);
Index: linux/fs/fuse/fuse_i.h
===================================================================
--- linux.orig/fs/fuse/fuse_i.h	2021-10-18 13:40:27.382801044 +0200
+++ linux/fs/fuse/fuse_i.h	2021-10-18 13:37:43.778779327 +0200
@@ -1161,7 +1161,7 @@ u64 fuse_lock_owner_id(struct fuse_conn
 void fuse_flush_time_update(struct inode *inode);
 void fuse_update_ctime(struct inode *inode);
 
-int fuse_update_attributes(struct inode *inode, struct file *file);
+int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask);
 
 void fuse_flush_writepages(struct inode *inode);
 
Index: linux/fs/fuse/readdir.c
===================================================================
--- linux.orig/fs/fuse/readdir.c	2021-10-18 13:41:02.365233336 +0200
+++ linux/fs/fuse/readdir.c	2021-10-18 13:38:03.413021954 +0200
@@ -454,7 +454,7 @@ static int fuse_readdir_cached(struct fi
 	 * cache; both cases require an up-to-date mtime value.
 	 */
 	if (!ctx->pos && fc->auto_inval_data) {
-		int err = fuse_update_attributes(inode, file);
+		int err = fuse_update_attributes(inode, file, STATX_MTIME);
 
 		if (err)
 			return err;

  reply	other threads:[~2021-10-18 11:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11  9:02 [RFC] fuse: Avoid invalidating attrs if writeback_cache enabled Xie Yongji
2021-10-11 13:21 ` Miklos Szeredi
2021-10-11 14:45   ` Yongji Xie
2021-10-13 13:52     ` Miklos Szeredi
2021-10-18 11:25       ` Yongji Xie
2021-10-18 11:45         ` Miklos Szeredi [this message]
2021-10-18 13:08           ` Yongji Xie

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=CAJfpegv51cbjkD6BQ6wUZSbaTpnB1-827G++HQnWX7zGA5fmmA@mail.gmail.com \
    --to=miklos@szeredi.hu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=xieyongji@bytedance.com \
    --cc=zhangjiachen.jaycee@bytedance.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;
as well as URLs for NNTP newsgroup(s).