Skip to content

Commit 1ff28f3

Browse files
fs/ntfs3: disable readahead for compressed files
Reading large compressed files is extremely slow when readahead is enabled. For example, reading a 4 GB XPRESS-4K compressed file (compression ratio ≈ 4:1) takes about 230 minutes with readahead enabled, but only around 3 minutes when readahead is disabled. The issue was first observed in January 2025 and is reproducible with large compressed NTFS files. Disabling readahead for compressed files avoids this performance regression, although this may not be the ideal long-term fix. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 9948dcb commit 1ff28f3

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

fs/ntfs3/file.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,14 @@ static int ntfs_file_mmap_prepare(struct vm_area_desc *desc)
325325
return -EOPNOTSUPP;
326326
}
327327

328-
if (is_compressed(ni) && rw) {
329-
ntfs_inode_warn(inode, "mmap(write) compressed not supported");
330-
return -EOPNOTSUPP;
328+
if (is_compressed(ni)) {
329+
if (rw) {
330+
ntfs_inode_warn(inode,
331+
"mmap(write) compressed not supported");
332+
return -EOPNOTSUPP;
333+
}
334+
/* Turn off readahead for compressed files. */
335+
file->f_ra.ra_pages = 0;
331336
}
332337

333338
if (rw) {
@@ -884,9 +889,14 @@ static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
884889
if (err)
885890
return err;
886891

887-
if (is_compressed(ni) && (iocb->ki_flags & IOCB_DIRECT)) {
888-
ntfs_inode_warn(inode, "direct i/o + compressed not supported");
889-
return -EOPNOTSUPP;
892+
if (is_compressed(ni)) {
893+
if (iocb->ki_flags & IOCB_DIRECT) {
894+
ntfs_inode_warn(
895+
inode, "direct i/o + compressed not supported");
896+
return -EOPNOTSUPP;
897+
}
898+
/* Turn off readahead for compressed files. */
899+
file->f_ra.ra_pages = 0;
890900
}
891901

892902
return generic_file_read_iter(iocb, iter);
@@ -906,6 +916,11 @@ static ssize_t ntfs_file_splice_read(struct file *in, loff_t *ppos,
906916
if (err)
907917
return err;
908918

919+
if (is_compressed(ntfs_i(inode))) {
920+
/* Turn off readahead for compressed files. */
921+
in->f_ra.ra_pages = 0;
922+
}
923+
909924
return filemap_splice_read(in, ppos, pipe, len, flags);
910925
}
911926

0 commit comments

Comments
 (0)