[PATCH 11/16] squashfs: zero the tail of the last folio up to folio_size()
From: Tal Zussman
Date: Tue Nov 03 2026 - 08:29:54 EST
Add squashfs_actor_zero_tail(), which zeroes from the end of the data
in the last folio to folio_size(), and use it in the three places that
zeroed from the data length modulo PAGE_SIZE.
squashfs only uses order-0 folios, so no functional change. This is a
step towards enabling large folios.
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/squashfs/file.c | 13 +++++--------
fs/squashfs/file_direct.c | 10 +++++-----
fs/squashfs/page_actor.h | 16 ++++++++++++++++
3 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index e024d2e21246..b34f2ac75e16 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -549,9 +549,8 @@ static int squashfs_readahead_fragment(struct inode *inode,
ok = copied == expected && !IS_ERR(last_folio);
/* Last folio (if present) may have trailing bytes not filled */
- bytes = copied % PAGE_SIZE;
- if (ok && last_folio && bytes)
- folio_zero_segment(last_folio, bytes, PAGE_SIZE);
+ if (ok && last_folio)
+ squashfs_actor_zero_tail(last_folio, start, copied);
for (i = 0; i < nr_folios; i++) {
if (ok)
@@ -591,7 +590,7 @@ static void squashfs_readahead(struct readahead_control *ractl)
return;
for (;;) {
- int res, bsize, bytes;
+ int res, bsize;
u64 index, block = 0;
unsigned int expected;
struct folio *last_folio;
@@ -641,10 +640,8 @@ static void squashfs_readahead(struct readahead_control *ractl)
ok = res == expected && !IS_ERR(last_folio);
/* Last folio (if present) may have trailing bytes not filled */
- bytes = res % PAGE_SIZE;
- if (ok && index == file_end && last_folio &&
- bytes)
- folio_zero_segment(last_folio, bytes, PAGE_SIZE);
+ if (ok && index == file_end && last_folio)
+ squashfs_actor_zero_tail(last_folio, start, res);
for (i = 0; i < nr_folios; i++) {
if (ok)
diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c
index 266b5fdea67a..ef522923e6a9 100644
--- a/fs/squashfs/file_direct.c
+++ b/fs/squashfs/file_direct.c
@@ -28,8 +28,9 @@ int squashfs_readpage_block(struct folio *folio, u64 block, int bsize,
unsigned int nr = squashfs_pages_per_block(msblk);
loff_t start_index = squashfs_block_first_index(msblk, folio->index);
loff_t end_index = start_index + nr - 1;
+ loff_t start = start_index << PAGE_SHIFT;
loff_t index;
- int i, nr_folios, bytes, res = -ENOMEM;
+ int i, nr_folios, res = -ENOMEM;
struct folio **folios, *last_folio;
struct squashfs_page_actor *actor;
@@ -72,7 +73,7 @@ int squashfs_readpage_block(struct folio *folio, u64 block, int bsize,
* page cache folios appropriately within the decompressor.
*/
actor = squashfs_page_actor_init_folios(msblk, folios, nr_folios,
- expected, start_index << PAGE_SHIFT);
+ expected, start);
if (actor == NULL)
goto mark_errored;
@@ -90,9 +91,8 @@ int squashfs_readpage_block(struct folio *folio, u64 block, int bsize,
}
/* Last folio (if present) may have trailing bytes not filled */
- bytes = res % PAGE_SIZE;
- if (end_index == file_end && last_folio && bytes)
- folio_zero_segment(last_folio, bytes, PAGE_SIZE);
+ if (end_index == file_end && last_folio)
+ squashfs_actor_zero_tail(last_folio, start, res);
/* Mark folios as uptodate, unlock and release */
for (i = 0; i < nr_folios; i++) {
diff --git a/fs/squashfs/page_actor.h b/fs/squashfs/page_actor.h
index e188e807350b..6d8cf7798f69 100644
--- a/fs/squashfs/page_actor.h
+++ b/fs/squashfs/page_actor.h
@@ -6,6 +6,9 @@
* Phillip Lougher <phillip@xxxxxxxxxxxxxxx>
*/
+#include <linux/highmem.h>
+#include <linux/pagemap.h>
+
struct squashfs_page_actor {
union {
void **buffer;
@@ -58,4 +61,17 @@ static inline void squashfs_actor_nobuff(struct squashfs_page_actor *actor)
{
actor->alloc_buffer = 0;
}
+
+/*
+ * Zero whatever is left of @folio past the data, which starts at @start and
+ * is @length bytes long. Meant for the last folio the actor filled.
+ */
+static inline void squashfs_actor_zero_tail(struct folio *folio, loff_t start,
+ size_t length)
+{
+ size_t end = length - (folio_pos(folio) - start);
+
+ if (end < folio_size(folio))
+ folio_zero_segment(folio, end, folio_size(folio));
+}
#endif
--
2.39.5