linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Wei <liuwei09@cestc.cn>
To: willy@infradead.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	liuwei09@cestc.cn
Subject: [PATCH] mm/filemap: invalidating pages is still necessary when io with IOCB_NOWAIT
Date: Mon, 13 May 2024 21:23:39 +0800	[thread overview]
Message-ID: <20240513132339.26269-1-liuwei09@cestc.cn> (raw)

After commit (6be96d3ad3 fs: return if direct I/O will trigger writeback),
when we issuing AIO with direct I/O and IOCB_NOWAIT on a block device, the
process context will not be blocked.

However, if the device already has page cache in memory, EAGAIN will be
returned. And even when trying to reissue the AIO with direct I/O and
IOCB_NOWAIT again, we consistently receive EAGAIN.

Maybe a better way to deal with it: filemap_fdatawrite_range dirty pages
with WB_SYNC_NONE flag, and invalidate_mapping_pages unmapped pages at
the same time.

Signed-off-by: Liu Wei <liuwei09@cestc.cn>
---
 mm/filemap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 30de18c4fd28..1852a00caf31 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2697,8 +2697,15 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count)
 
 	if (iocb->ki_flags & IOCB_NOWAIT) {
 		/* we could block if there are any pages in the range */
-		if (filemap_range_has_page(mapping, pos, end))
+		if (filemap_range_has_page(mapping, pos, end)) {
+			if (mapping_needs_writeback(mapping)) {
+				__filemap_fdatawrite_range(mapping,
+						pos, end, WB_SYNC_NONE);
+			}
+			invalidate_mapping_pages(mapping,
+					pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
 			return -EAGAIN;
+		}
 	} else {
 		ret = filemap_write_and_wait_range(mapping, pos, end);
 		if (ret)
-- 
2.42.1




             reply	other threads:[~2024-05-13 13:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-13 13:23 Liu Wei [this message]
2024-05-23 20:08 ` [PATCH] mm/filemap: invalidating pages is still necessary when io with IOCB_NOWAIT Andrew Morton
2024-05-23 21:11   ` Matthew Wilcox
2024-05-23 21:17     ` Jens Axboe
2024-05-23 21:08 ` Matthew Wilcox
2024-05-23 21:16   ` Jens Axboe
2024-05-27 10:09     ` Liu Wei
2024-05-27 15:36       ` Jens Axboe

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=20240513132339.26269-1-liuwei09@cestc.cn \
    --to=liuwei09@cestc.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --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).