Re: [PATCH 09/11] ntfs: skip reads for full compression unit overwrites
Hyunchul Lee <[email protected]> Thu, 23 Jul 2026 11:16:41 +0900
| Newsgroups | dev.linux.lists.ntfs |
|---|---|
| Message-ID | <CANFS6bbOBBVvmY-KfqBVJDVfk3oi7Qb2zW0MSHtBVL_jt_sPdg@mail.gmail.com> |
2026=EB=85=84 7=EC=9B=94 21=EC=9D=BC (=ED=99=94) =EC=98=A4=ED=9B=84 6:55, N= amjae Jeon <[email protected]>=EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > ntfs_compress_write() reads every page in a compression unit before copyi= ng > new data into it. The read is unnecessary when an aligned write replaces > every byte covered by the page-cache folios. > > Detect full page-aligned compression unit overwrites and grab locked cach= e > folios without reading them. Keep the read-modify-write path for partial > units and units that cover only part of a large page. > > Signed-off-by: Namjae Jeon <[email protected]> Looks good to me. Reviewed-by: Hyunchul Lee <[email protected]> > --- > fs/ntfs/compress.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c > index a3af669b1008..ea29fade9b9b 100644 > --- a/fs/ntfs/compress.c > +++ b/fs/ntfs/compress.c > @@ -1501,6 +1501,7 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff= _t pos, size_t count, > pgoff_t index; > size_t copied, bytes; > unsigned int page_offset; > + bool full_cb; > int off; > > off =3D pos & (cb_size - 1); > @@ -1512,6 +1513,8 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff= _t pos, size_t count, > page_offset =3D offset_in_page(cb_off); > pages_per_cb =3D DIV_ROUND_UP(page_offset + cb_size, PAGE= _SIZE); > index =3D cb_off >> PAGE_SHIFT; > + full_cb =3D !off && bytes =3D=3D cb_size && !page_offset = && > + !(cb_size & (PAGE_SIZE - 1)); > > if (unlikely(fault_in_iov_iter_readable(from, bytes))) { > err =3D -EFAULT; > @@ -1519,7 +1522,10 @@ int ntfs_compress_write(struct ntfs_inode *ni, lof= f_t pos, size_t count, > } > > for (i =3D 0; i < pages_per_cb; i++) { > - folio =3D read_mapping_folio(mapping, index + i, = NULL); > + if (full_cb) > + folio =3D filemap_grab_folio(mapping, ind= ex + i); > + else > + folio =3D read_mapping_folio(mapping, ind= ex + i, NULL); > if (IS_ERR(folio)) { > for (ip =3D 0; ip < i; ip++) { > folio_unlock(page_folio(pages[ip]= )); > @@ -1529,7 +1535,8 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff= _t pos, size_t count, > goto out; > } > > - folio_lock(folio); > + if (!full_cb) > + folio_lock(folio); > pages[i] =3D folio_page(folio, 0); > } > > -- > 2.34.1 > --=20 Thanks, Hyunchul