[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240514131711.379322-29-wedsonaf@gmail.com>
Date: Tue, 14 May 2024 10:17:09 -0300
From: Wedson Almeida Filho <wedsonaf@...il.com>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Dave Chinner <david@...morbit.com>
Cc: Kent Overstreet <kent.overstreet@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-fsdevel@...r.kernel.org,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
Wedson Almeida Filho <walmeida@...rosoft.com>,
Wedson Almeida Filho <wedsonaf@...il.com>
Subject: [RFC PATCH v2 28/30] rust: fs: add memalloc_nofs support
From: Wedson Almeida Filho <walmeida@...rosoft.com>
When used in filesystems obviates the need for GFP_NOFS.
Signed-off-by: Wedson Almeida Filho <wedsonaf@...il.com>
---
rust/helpers.c | 12 ++++++++++++
rust/kernel/fs.rs | 12 ++++++++++++
2 files changed, 24 insertions(+)
diff --git a/rust/helpers.c b/rust/helpers.c
index edf12868962c..c26aa07cb20f 100644
--- a/rust/helpers.c
+++ b/rust/helpers.c
@@ -273,6 +273,18 @@ void *rust_helper_alloc_inode_sb(struct super_block *sb,
}
EXPORT_SYMBOL_GPL(rust_helper_alloc_inode_sb);
+unsigned int rust_helper_memalloc_nofs_save(void)
+{
+ return memalloc_nofs_save();
+}
+EXPORT_SYMBOL_GPL(rust_helper_memalloc_nofs_save);
+
+void rust_helper_memalloc_nofs_restore(unsigned int flags)
+{
+ memalloc_nofs_restore(flags);
+}
+EXPORT_SYMBOL_GPL(rust_helper_memalloc_nofs_restore);
+
void rust_helper_i_uid_write(struct inode *inode, uid_t uid)
{
i_uid_write(inode, uid);
diff --git a/rust/kernel/fs.rs b/rust/kernel/fs.rs
index 7a1c4884c370..b7a654546d23 100644
--- a/rust/kernel/fs.rs
+++ b/rust/kernel/fs.rs
@@ -417,6 +417,18 @@ impl<T: FileSystem + ?Sized> Tables<T> {
}
}
+/// Calls `cb` in a nofs allocation context.
+///
+/// That is, if an allocation happens within `cb`, it will have the `__GFP_FS` bit cleared.
+pub fn memalloc_nofs<T>(cb: impl FnOnce() -> T) -> T {
+ // SAFETY: Function is safe to be called from any context.
+ let flags = unsafe { bindings::memalloc_nofs_save() };
+ let ret = cb();
+ // SAFETY: Function is safe to be called from any context.
+ unsafe { bindings::memalloc_nofs_restore(flags) };
+ ret
+}
+
/// Kernel module that exposes a single file system implemented by `T`.
#[pin_data]
pub struct Module<T: FileSystem + ?Sized> {
--
2.34.1
Powered by blists - more mailing lists