Tiny optimization for large read operations
Subsystems (3)
cover Tiny optimization for large read operations
From: Chi Zhiling <[email protected]>
This series contains two patches,
1. Skip calling is_partially_uptodate for entire folio to save time, I have reviewed the mpage and iomap implementations and didn't spot any issues, but this change likely needs more thorough review.
2. Skip calling filemap_uptodate if there are ready folios in the batch, This might save a few milliseconds in practice, but I didn't observe measurable improvements in my tests.
Changes from rfc:
- update commits
- switch to the new solution which provided by Matthew Wilcox.
rfc:
https://lore.kernel.org/linux-fsdevel/[email protected]/
Chi Zhiling (2):
mm/filemap: Do not use is_partially_uptodate for entire folio mm/filemap: Skip non-uptodate folio if there are available folios
mm/filemap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 mm/filemap: Do not use is_partially_uptodate for entire folio
From: Chi Zhiling <[email protected]>
When a folio is marked as non-uptodate, it means the folio contains some non-uptodate data. Therefore, calling is_partially_uptodate() to recheck the entire folio is redundant.
If all data in a folio is actually up-to-date but the folio lacks the uptodate flag, it will still be treated as non-uptodate in many other places. Thus, there should be no special case handling for filemap.
--- mm/filemap.c | 3 +++ 1 file changed, 3 insertions(+)
mm/filemap.c +3 -0
@@ -2447,6 +2447,9 @@ static bool filemap_range_uptodate(struct address_space *mapping, pos -=folio_pos (folio); } +if (pos ==0 && count >=folio_size (folio)) +return false; +return mapping->a_ops->is_partially_uptodate (folio, pos, count); }
Signature · 1 line
2.43.0
PATCH 2/2 mm/filemap: Skip non-uptodate folio if there are available folios
In reply to Chi ZhilingFrom: Chi Zhiling <[email protected]>
When reading data exceeding the maximum IO size, the operation is split into multiple IO requests, but the data isn't immediately copied to userspace after each IO completion.
For example, when reading 2560k data from a device with 1280k maximum IO size, the following sequence occurs:
1. read 1280k
2. copy 41 pages and issue read ahead for next 1280k
3. copy 31 pages to user buffer
4. wait the next 1280k
5. copy 8 pages to user buffer
6. copy 20 folios(64k) to user buffer
The 8 pages in step 5 are copied after the second 1280k completes(step 4) due to waiting for a non-uptodate folio in filemap_update_page. We can copy the 8 pages before the second 1280k completes(step 4) to reduce the latency of this read operation.
After applying the patch, these 8 pages will be copied before the next IO completes:
1. read 1280k
2. copy 41 pages and issue read ahead for next 1280k
3. copy 31 pages to user buffer
4. copy 8 pages to user buffer
5. wait the next 1280k
6. copy 20 folios(64k) to user buffer
This patch drops a setting of IOCB_NOWAIT for AIO, which is fine because filemap_read will set it again for AIO.
The final solution provided by Matthew Wilcox:
--- mm/filemap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mm/filemap.c +4 -3
@@ -2623,9 +2623,10 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, goto err; }if (!folio_test_uptodate (folio)) { -if ((iocb->ki_flags &IOCB_WAITQ ) && -folio_batch_count (fbatch) >1 ) - iocb->ki_flags |=IOCB_NOWAIT ; +if (folio_batch_count (fbatch) >1 ) { + err = -EAGAIN ; + goto err; + } err =filemap_update_page (iocb, mapping, count, folio, need_uptodate);if (err)
Signature · 1 line
2.43.0