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>, Jens Axboe <axboe@kernel.dk>,
Matthew Wilcox <willy@infradead.org>
Subject: [PATCH 2/2] mm: allow read-ahead with IOCB_NOWAIT set
Date: Mon, 12 Aug 2024 17:05:25 +0800 [thread overview]
Message-ID: <20240812090525.80299-3-laoar.shao@gmail.com> (raw)
In-Reply-To: <20240812090525.80299-1-laoar.shao@gmail.com>
Readahead support for IOCB_NOWAIT was introduced in commit 2e85abf053b9
("mm: allow read-ahead with IOCB_NOWAIT set"). However, this behavior was
altered in commit efa8480a8316 ("fs: RWF_NOWAIT should imply IOCB_NOIO") to
prevent potential blocking during memory reclamation.
To address the blocking issue during memory reclamation, we can use
memalloc_nowait_{save,restore} to ensure non-blocking behavior. With this
change, we can restore the original functionality, allowing
preadv2(IOCB_NOWAIT) to read data directly from the disk if it's not
already in the page cache.
Link: https://lore.gnuweeb.org/io-uring/20200624164127.GP21350@casper.infradead.org/
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>
---
include/linux/fs.h | 1 -
mm/filemap.c | 6 ++++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fd34b5755c0b..ced74b1b350d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3455,7 +3455,6 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags,
if (flags & RWF_NOWAIT) {
if (!(ki->ki_filp->f_mode & FMODE_NOWAIT))
return -EOPNOTSUPP;
- kiocb_flags |= IOCB_NOIO;
}
if (flags & RWF_ATOMIC) {
if (rw_type != WRITE)
diff --git a/mm/filemap.c b/mm/filemap.c
index 657bcd887fdb..93c690e1d1fd 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -46,6 +46,7 @@
#include <linux/pipe_fs_i.h>
#include <linux/splice.h>
#include <linux/rcupdate_wait.h>
+#include <linux/sched/mm.h>
#include <asm/pgalloc.h>
#include <asm/tlbflush.h>
#include "internal.h"
@@ -2514,6 +2515,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count,
pgoff_t index = iocb->ki_pos >> PAGE_SHIFT;
pgoff_t last_index;
struct folio *folio;
+ unsigned int flags;
int err = 0;
/* "last_index" is the index of the page beyond the end of the read */
@@ -2526,8 +2528,12 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count,
if (!folio_batch_count(fbatch)) {
if (iocb->ki_flags & IOCB_NOIO)
return -EAGAIN;
+ if (iocb->ki_flags & IOCB_NOWAIT)
+ flags = memalloc_nowait_save();
page_cache_sync_readahead(mapping, ra, filp, index,
last_index - index);
+ if (iocb->ki_flags & IOCB_NOWAIT)
+ memalloc_nowait_restore(flags);
filemap_get_read_batch(mapping, index, last_index - 1, fbatch);
}
if (!folio_batch_count(fbatch)) {
--
2.43.5
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 ` [PATCH 1/2] mm: Add memalloc_nowait_{save,restore} Yafang Shao
2024-08-12 11:37 ` 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 ` Yafang Shao [this message]
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-3-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=david@fromorbit.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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).