linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] mm/filemap.c: fix the timing of asignment of prev_pos
@ 2022-08-17 13:51 Guixin Liu
  2022-08-17 15:16 ` Andrew Morton
  2022-08-17 15:25 ` Matthew Wilcox
  0 siblings, 2 replies; 5+ messages in thread
From: Guixin Liu @ 2022-08-17 13:51 UTC (permalink / raw)
  To: willy, akpm; +Cc: linux-fsdevel, linux-mm

The prev_pos should be assigned before the iocb->ki_pos is incremented,
so that the prev_pos is the exact location of the last visit.

Fixes: 06c0444290cec ("mm/filemap.c: generic_file_buffered_read() now
uses find_get_pages_contig")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>

---
Hi guys,
    When I`m running repetitive 4k read io which has same offset,
I find that access to folio_mark_accessed is inevitable in the
read process, the reason is that the prev_pos is assigned after the
iocb->ki_pos is incremented, so that the prev_pos is always not equal
to the position currently visited.
    Is this a bug that needs fixing?

 mm/filemap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 660490c..68fd987 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2703,8 +2703,8 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
 			copied = copy_folio_to_iter(folio, offset, bytes, iter);
 
 			already_read += copied;
-			iocb->ki_pos += copied;
 			ra->prev_pos = iocb->ki_pos;
+			iocb->ki_pos += copied;
 
 			if (copied < bytes) {
 				error = -EFAULT;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-18  3:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-17 13:51 [RFC PATCH] mm/filemap.c: fix the timing of asignment of prev_pos Guixin Liu
2022-08-17 15:16 ` Andrew Morton
2022-08-17 15:30   ` Matthew Wilcox
2022-08-17 15:25 ` Matthew Wilcox
2022-08-18  3:13   ` Guixin Liu

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).