Skip to contentSkip to conversation

FUSE: allow drivers to increase readahead.

RFC PATCH In review Kevin Vigor 2 participants 3 messages Mar 2, 2022 – Mar 10, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover FUSE: allow drivers to increase readahead.

Summary:

Allow FUSE drivers to increase readahead setting.

Details:

FUSE drivers can set a max_readahead value in the fuse_init_out value.

However, this value can currently only decrease the readahead setting from the default, which is set to VM_READAHEAD_PAGES in bdi_alloc().

Add a flag which causes the kernel driver to accept whatever max_readahead value the user provides in fuse_init_out. Note that read_ahead_kb_store() similarly allows users to set arbitrary ra_pages values.

Kevin Vigor (1):
FUSE: Add FUSE_TRUST_MAX_RA flag enabling readahead settings >128KB.

 fs/fuse/inode.c           | 8 ++++++--
 include/uapi/linux/fuse.h | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

RFC PATCH 1/1 FUSE: Add FUSE_TRUST_MAX_RA flag enabling readahead settings >128KB.

The existing process_init_reply() in fs/fuse/inode.c sets the ra_pages value to the minimum of the max_readahead value provided by the user and the pre-existing ra_pages value, which is initialized to VM_READAHEAD_PAGES. This makes it impossible to increase the readahead value to larger values.

Add a new flag which causes us to blindly accept the user-provided value. Note that the existing read_ahead_kb sysfs entry for normal block devices does the same (simply accepts user-provided values directly with no checks).

---
 fs/fuse/inode.c           | 8 ++++++--
 include/uapi/linux/fuse.h | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
fs/fuse/inode.c +6 -2
index 8b89e3ba7df3..81c96c404a76 100644
@@ -1182,8 +1182,12 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 			fc->no_flock = 1;
 		}
 
-		fm->sb->s_bdi->ra_pages =
+		if (arg->flags & FUSE_TRUST_MAX_RA) {
+			fm->sb->s_bdi->ra_pages = ra_pages;
+		} else {
+			fm->sb->s_bdi->ra_pages =
 				min(fm->sb->s_bdi->ra_pages, ra_pages);
+		}
 		fc->minor = arg->minor;
 		fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
 		fc->max_write = max_t(unsigned, 4096, fc->max_write);
@@ -1219,7 +1223,7 @@ void fuse_send_init(struct fuse_mount *fm)
 		FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL |
 		FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS |
 		FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
-		FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT;
+		FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_TRUST_MAX_RA;
 #ifdef CONFIG_FUSE_DAX
 	if (fm->fc->dax)
 		ia->in.flags |= FUSE_MAP_ALIGNMENT;
include/uapi/linux/fuse.h +3 -0
index a1dc3ee1d17c..df9840f4642f 100644
@@ -341,6 +341,8 @@ struct fuse_file_lock {
  *			write/truncate sgid is killed only if file has group
  *			execute permission. (Same as Linux VFS behavior).
  * FUSE_SETXATTR_EXT:	Server supports extended struct fuse_setxattr_in
+ * FUSE_TRUST_MAX_RA:	Accept the user-provided max_readahead value instead
+ *			of clamping to <= VM_READAHEAD_PAGES.
  */
 #define FUSE_ASYNC_READ		(1 << 0)
 #define FUSE_POSIX_LOCKS	(1 << 1)
@@ -372,6 +374,7 @@ struct fuse_file_lock {
 #define FUSE_SUBMOUNTS		(1 << 27)
 #define FUSE_HANDLE_KILLPRIV_V2	(1 << 28)
 #define FUSE_SETXATTR_EXT	(1 << 29)
+#define FUSE_TRUST_MAX_RA	(1 << 30)
 
 /**
  * CUSE INIT request/reply flags
Signature · 1 line
2.33.1
maintainer
#2 lore raw

Re: [RFC PATCH 1/1] FUSE: Add FUSE_TRUST_MAX_RA flag enabling readahead settings >128KB.

Quoted 11 lines · Kevin Vigor

The existing process_init_reply() in fs/fuse/inode.c sets the ra_pages value to the minimum of the max_readahead value provided by the user and the pre-existing ra_pages value, which is initialized to VM_READAHEAD_PAGES. This makes it impossible to increase the readahead value to larger values.

Add a new flag which causes us to blindly accept the user-provided value. Note that the existing read_ahead_kb sysfs entry for normal block devices does the same (simply accepts user-provided values directly with no checks).

read_ahead_kb only allows root to open for write. Allowing non-root arbitrary read ahead window size is not a good idea, IMO.

Thanks,
Miklos