}
 
 /* Copy data into page cache  */
-void squashfs_copy_cache(struct page *page, struct squashfs_cache_entry *buffer,
-       int bytes, int offset)
+void squashfs_copy_cache(struct folio *folio,
+               struct squashfs_cache_entry *buffer, size_t bytes,
+               size_t offset)
 {
-       struct inode *inode = page->mapping->host;
+       struct address_space *mapping = folio->mapping;
+       struct inode *inode = mapping->host;
        struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
        int i, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
-       int start_index = page->index & ~mask, end_index = start_index | mask;
+       int start_index = folio->index & ~mask, end_index = start_index | mask;
 
        /*
         * Loop copying datablock into pages.  As the datablock likely covers
         */
        for (i = start_index; i <= end_index && bytes > 0; i++,
                        bytes -= PAGE_SIZE, offset += PAGE_SIZE) {
-               struct page *push_page;
-               int avail = buffer ? min_t(int, bytes, PAGE_SIZE) : 0;
+               struct folio *push_folio;
+               size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0;
 
-               TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
+               TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail);
 
-               push_page = (i == page->index) ? page :
-                       grab_cache_page_nowait(page->mapping, i);
+               push_folio = (i == folio->index) ? folio :
+                       __filemap_get_folio(mapping, i,
+                                       FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
+                                       mapping_gfp_mask(mapping));
 
-               if (!push_page)
+               if (IS_ERR(push_folio))
                        continue;
 
-               if (PageUptodate(push_page))
-                       goto skip_page;
+               if (folio_test_uptodate(push_folio))
+                       goto skip_folio;
 
-               squashfs_fill_page(push_page, buffer, offset, avail);
-skip_page:
-               unlock_page(push_page);
-               if (i != page->index)
-                       put_page(push_page);
+               squashfs_fill_page(&push_folio->page, buffer, offset, avail);
+skip_folio:
+               folio_unlock(push_folio);
+               if (i != folio->index)
+                       folio_put(push_folio);
        }
 }
 
                        squashfs_i(inode)->fragment_block,
                        squashfs_i(inode)->fragment_size);
        else
-               squashfs_copy_cache(&folio->page, buffer, expected,
+               squashfs_copy_cache(folio, buffer, expected,
                        squashfs_i(inode)->fragment_offset);
 
        squashfs_cache_put(buffer);
        return res;
 }
 
-static int squashfs_readpage_sparse(struct page *page, int expected)
+static int squashfs_readpage_sparse(struct folio *folio, int expected)
 {
-       squashfs_copy_cache(page, NULL, expected, 0);
+       squashfs_copy_cache(folio, NULL, expected, 0);
        return 0;
 }
 
                        goto out;
 
                if (res == 0)
-                       res = squashfs_readpage_sparse(&folio->page, expected);
+                       res = squashfs_readpage_sparse(folio, expected);
                else
                        res = squashfs_readpage_block(folio, block, res, expected);
        } else