Skip to contentSkip to conversation

erofs: fix small compressed files inlining

PATCH In review Gao Xiang 2 participants 2 messages Feb 3, 2022 – Feb 4, 2022 EROFS file system

lore
Share & tools
lore

Gao Xiang

author maintainer
#0 lore raw

PATCH 1/1 erofs: fix small compressed files inlining

From: Gao Xiang <[email protected]>

Prior to ztailpacking feature, it's enough that each lcluster has two pclusters at most, and the last pcluster should be turned into an uncompressed pcluster if necessary. For example,
_________________________________________________
|_ pcluster n-2 _|_ pcluster n-1 _|____ EOFed ____|

which should be converted into:
_________________________________________________
|_ pcluster n-2 _|_ pcluster n-1 (uncompressed)' _|

That is fine since either pcluster n-1 or (uncompressed)' takes one physical block.

However, after ztailpacking supported, the game is changed since the last pcluster can be inlined now. And such case above is quite common for inlining small files. Therefore, in order to inline such files more effectively, special EOF lclusters are now supported which can have three parts at most, as illustrated below:
_________________________________________________
|_ pcluster n-2 _|_ pcluster n-1 _|____ EOFed ____|
^ i_size

Actually similar code exists in Yue Hu's original patchset [1], but I removed this part on purpose. After evaluating more real cases with small files, I've changed my mind.

[1] https://lore.kernel.org/r/[email protected]

Fixes ab92184ff8f1 ("erofs: add on-disk compressed tail-packing inline support")
---
 fs/erofs/zmap.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/erofs/zmap.c +7 -0
index 18d7fd1a5064..723ebfa6a27d 100644
@@ -630,6 +630,13 @@ static int z_erofs_do_map_blocks(struct inode *inode,
 		if (endoff >= m.clusterofs) {
 			m.headtype = m.type;
 			map->m_la = (m.lcn << lclusterbits) | m.clusterofs;
+			/*
+			 * For ztailpacking files, in order to inline data more
+			 * effectively, special EOF lclusters are now supported
+			 * which can have three parts at most.
+			 */
+			if (ztailpacking && end >= inode->i_size)
+				end = inode->i_size;
 			break;
 		}
 		/* m.lcn should be >= 1 if endoff < m.clusterofs */
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Gao Xiang

From: Gao Xiang <[email protected]>

Prior to ztailpacking feature, it's enough that each lcluster has two pclusters at most, and the last pcluster should be turned into an uncompressed pcluster if necessary. For example,
_________________________________________________
|_ pcluster n-2 _|_ pcluster n-1 _|____ EOFed ____|

which should be converted into:

   _________________________________________________

|_ pcluster n-2 _|_ pcluster n-1 (uncompressed)' _|

That is fine since either pcluster n-1 or (uncompressed)' takes one physical block.

However, after ztailpacking supported, the game is changed since the last pcluster can be inlined now. And such case above is quite common for inlining small files. Therefore, in order to inline such files more effectively, special EOF lclusters are now supported which can have three parts at most, as illustrated below:

   _________________________________________________

|_ pcluster n-2 _|_ pcluster n-1 _|____ EOFed ____|
^ i_size

Quoted 7 lines

Actually similar code exists in Yue Hu's original patchset [1], but I removed this part on purpose. After evaluating more real cases with small files, I've changed my mind.

[1] https://lore.kernel.org/r/[email protected]

Fixes ab92184ff8f1 ("erofs: add on-disk compressed tail-packing inline support")

Thanks,