From: Yafang Shao <laoar.shao@gmail.com>
To: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
brauner@kernel.org, jack@suse.cz, david@fromorbit.com
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
Yafang Shao <laoar.shao@gmail.com>,
Kent Overstreet <kent.overstreet@linux.dev>
Subject: [PATCH 1/2] mm: Add memalloc_nowait_{save,restore}
Date: Mon, 12 Aug 2024 17:05:24 +0800 [thread overview]
Message-ID: <20240812090525.80299-2-laoar.shao@gmail.com> (raw)
In-Reply-To: <20240812090525.80299-1-laoar.shao@gmail.com>
The PF_MEMALLOC_NORECLAIM flag was introduced in commit eab0af905bfc
("mm: introduce PF_MEMALLOC_NORECLAIM, PF_MEMALLOC_NOWARN"). To complement
this, let's add two helper functions, memalloc_nowait_{save,restore}, which
will be useful in scenarios where we want to avoid waiting for memory
reclamation.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
---
include/linux/sched/mm.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 91546493c43d..4fbae0013166 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -484,6 +484,36 @@ static inline void memalloc_pin_restore(unsigned int flags)
memalloc_flags_restore(flags);
}
+/**
+ * memalloc_nowait_save - Marks implicit ~__GFP_DIRECT_RECLAIM allocation scope.
+ *
+ * This functions marks the beginning of the ~__GFP_DIRECT_RECLAIM allocation
+ * scope. All further allocations will implicitly drop __GFP_DIRECT_RECLAIM flag
+ * and so they are won't wait for direct memory reclaiming. Use
+ * memalloc_nowait_restore to end the scope with flags returned by this
+ * function.
+ *
+ * Context: This function is safe to be used from any context.
+ * Return: The saved flags to be passed to memalloc_nowait_restore.
+ */
+static inline unsigned int memalloc_nowait_save(void)
+{
+ return memalloc_flags_save(PF_MEMALLOC_NORECLAIM);
+}
+
+/**
+ * memalloc_nofs_restore - Ends the implicit ~__GFP_DIRECT_RECLAIM scope.
+ * @flags: Flags to restore.
+ *
+ * Ends the implicit ~__GFP_DIRECT_RECLAIM scope started by memalloc_nowait_save
+ * function. Always make sure that the given flags is the return value from the
+ * pairing memalloc_nowait_save call.
+ */
+static inline void memalloc_nowait_restore(unsigned int flags)
+{
+ memalloc_flags_restore(flags);
+}
+
#ifdef CONFIG_MEMCG
DECLARE_PER_CPU(struct mem_cgroup *, int_active_memcg);
/**
--
2.43.5
next prev parent reply other threads:[~2024-08-12 9:08 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 9:05 [PATCH 0/2] mm: Add readahead support for IOCB_NOWAIT Yafang Shao
2024-08-12 9:05 ` Yafang Shao [this message]
2024-08-12 11:37 ` [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Christoph Hellwig
2024-08-12 12:59 ` Yafang Shao
2024-08-12 13:21 ` Christoph Hellwig
2024-08-13 2:09 ` Yafang Shao
2024-08-14 5:27 ` Christoph Hellwig
2024-08-14 7:33 ` Yafang Shao
2024-09-01 20:24 ` Vlastimil Babka
2024-09-01 20:42 ` Kent Overstreet
2024-08-14 7:42 ` Michal Hocko
2024-08-14 8:12 ` Yafang Shao
2024-08-14 12:43 ` Michal Hocko
2024-08-15 3:26 ` Yafang Shao
2024-08-15 6:22 ` Michal Hocko
2024-08-15 6:32 ` Yafang Shao
2024-08-15 6:51 ` Michal Hocko
2024-08-16 8:17 ` [PATCH] mm: document risk of PF_MEMALLOC_NORECLAIM Michal Hocko
2024-08-16 8:22 ` Christoph Hellwig
2024-08-16 8:54 ` Michal Hocko
2024-08-16 14:26 ` Christoph Hellwig
2024-08-16 15:57 ` Michal Hocko
2024-08-21 7:30 ` Michal Hocko
2024-08-21 11:44 ` Christoph Hellwig
2024-08-21 12:37 ` Michal Hocko
2024-08-22 9:09 ` Christian Brauner
2024-08-17 2:29 ` Yafang Shao
2024-08-19 7:57 ` Michal Hocko
2024-08-12 16:48 ` [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Kent Overstreet
2024-08-14 5:24 ` Christoph Hellwig
2024-08-14 0:28 ` Dave Chinner
2024-08-14 2:19 ` Yafang Shao
2024-08-14 5:42 ` Dave Chinner
2024-08-14 7:32 ` Yafang Shao
2024-08-15 2:54 ` Dave Chinner
2024-08-15 3:38 ` Yafang Shao
2024-08-12 9:05 ` [PATCH 2/2] mm: allow read-ahead with IOCB_NOWAIT set Yafang Shao
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=20240812090525.80299-2-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=david@fromorbit.com \
--cc=jack@suse.cz \
--cc=kent.overstreet@linux.dev \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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).