Re: [PATCH v14 05/21] fsverity: improve flushing performance of fsverity_fill_zerohash

"Darrick J. Wong via Linux-f2fs-devel" <[email protected]> Tue, 4 Aug 2026 11:01:19 -0700
Newsgroups gmane.linux.file-systems.f2fs,gmane.linux.file-systems,gmane.comp.file-systems.ext4,gmane.comp.file-systems.btrfs
Message-ID <20260804180119.GJ3556460@frogsfrogsfrogs>
On Mon, Aug 03, 2026 at 10:07:55PM +0200, Andrey Albershteyn wrote:
> The current version calls flush_dcache_folio(), in memcpy_to_folio(), to
> flush whole folio on every digest (which is 128 for 4k) on the HIGHMEM
> systems. Open code folio mapping and flushing to copy all digests at
> once.

Do we really have to care about HIGHMEM performance?  I thought that
was going soon anyway[1].  The code change *looks* reasonable but ugh
it adds more complexity and how many 32-bit phones and servers are
there?

(For Andrey: Why is this bolted onto an XFS patchset?  Nobody
should run XFS on 32-bit at all these days.)

--D

[1] https://lwn.net/Articles/1051010/

> Reported-by: Eric Biggers <[email protected]>
> Link: https://lore.kernel.org/linux-fsdevel/20260401222717.GH2466@quark/
> Signed-off-by: Andrey Albershteyn <[email protected]>
> ---
>  fs/verity/pagecache.c | 28 ++++++++++++++++++++++++++--
>  1 file changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c
> index 9d82e6b74ba1..911207dc0ef7 100644
> --- a/fs/verity/pagecache.c
> +++ b/fs/verity/pagecache.c
> @@ -68,14 +68,38 @@ EXPORT_SYMBOL_GPL(generic_readahead_merkle_tree);
>  void fsverity_fill_zerohash(struct folio *folio, size_t offset, size_t len,
>  			      struct fsverity_info *vi)
>  {
> -	size_t off = offset;
> +	size_t off;
>  
>  	WARN_ON_ONCE(!IS_ALIGNED(offset, vi->tree_params.digest_size));
>  	WARN_ON_ONCE(!IS_ALIGNED(len, vi->tree_params.digest_size));
> +#ifdef CONFIG_HIGHMEM
> +	WARN_ON_ONCE(offset + len > folio_size(folio));
>  
> -	for (; off < (offset + len); off += vi->tree_params.digest_size)
> +	do {
> +		void *vaddr = kmap_local_folio(folio, offset);
> +		void *to = vaddr;
> +
> +		off = len;
> +
> +		if (folio_test_partial_kmap(folio) &&
> +		    off > PAGE_SIZE - offset_in_page(offset))
> +			off = PAGE_SIZE - offset_in_page(offset);
> +		for (; to < (vaddr + off); to += vi->tree_params.digest_size)
> +			memcpy(to, vi->tree_params.zero_digest,
> +				vi->tree_params.digest_size);
> +		kunmap_local(vaddr);
> +
> +		offset += off;
> +		len -= off;
> +	} while (len > 0);
> +
> +	flush_dcache_folio(folio);
> +#else
> +	for (off = offset; off < (offset + len);
> +			off += vi->tree_params.digest_size)
>  		memcpy_to_folio(folio, off, vi->tree_params.zero_digest,
>  				vi->tree_params.digest_size);
> +#endif
>  }
>  EXPORT_SYMBOL_GPL(fsverity_fill_zerohash);
>  
> -- 
> 2.54.0
> 
>