Skip to content

Commit 8f89926

Browse files
committed
erofs: get compression algorithms directly on mapping
Currently, z_erofs_map_blocks_iter() returns whether extents are compressed or not, and the decompression frontend gets the specific algorithms then. It works but not quite well in many aspests, for example: - The decompression frontend has to deal with whether extents are compressed or not again and lookup the algorithms if compressed. It's duplicated and too detailed about the on-disk mapping. - A new secondary compression head will be introduced later so that each file can have 2 compression algorithms at most for different type of data. It could increase the complexity of the decompression frontend if still handled in this way; - A new readmore decompression strategy will be introduced to get better performance for much bigger pcluster and lzma, which needs the specific algorithm in advance as well. Let's look up compression algorithms in z_erofs_map_blocks_iter() directly instead. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chao Yu <[email protected]> Reviewed-by: Yue Hu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent dfeab2e commit 8f89926

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

fs/erofs/compress.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
#include "internal.h"
1010

11-
enum {
12-
Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
13-
Z_EROFS_COMPRESSION_RUNTIME_MAX
14-
};
15-
1611
struct z_erofs_decompress_req {
1712
struct super_block *sb;
1813
struct page **in, **out;

fs/erofs/internal.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ extern const struct address_space_operations z_erofs_aops;
363363
* of the corresponding uncompressed data in the file.
364364
*/
365365
enum {
366-
BH_Zipped = BH_PrivateStart,
366+
BH_Encoded = BH_PrivateStart,
367367
BH_FullMapped,
368368
};
369369

370370
/* Has a disk mapping */
371371
#define EROFS_MAP_MAPPED (1 << BH_Mapped)
372372
/* Located in metadata (could be copied from bd_inode) */
373373
#define EROFS_MAP_META (1 << BH_Meta)
374-
/* The extent has been compressed */
375-
#define EROFS_MAP_ZIPPED (1 << BH_Zipped)
374+
/* The extent is encoded */
375+
#define EROFS_MAP_ENCODED (1 << BH_Encoded)
376376
/* The length of extent is full */
377377
#define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped)
378378

@@ -381,6 +381,7 @@ struct erofs_map_blocks {
381381
u64 m_plen, m_llen;
382382

383383
unsigned short m_deviceid;
384+
char m_algorithmformat;
384385
unsigned int m_flags;
385386

386387
struct page *mpage;
@@ -394,6 +395,11 @@ struct erofs_map_blocks {
394395
*/
395396
#define EROFS_GET_BLOCKS_FIEMAP 0x0002
396397

398+
enum {
399+
Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
400+
Z_EROFS_COMPRESSION_RUNTIME_MAX
401+
};
402+
397403
/* zmap.c */
398404
extern const struct iomap_ops z_erofs_iomap_report_ops;
399405

fs/erofs/zdata.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,23 +476,23 @@ static int z_erofs_register_collection(struct z_erofs_collector *clt,
476476
struct erofs_workgroup *grp;
477477
int err;
478478

479+
if (!(map->m_flags & EROFS_MAP_ENCODED)) {
480+
DBG_BUGON(1);
481+
return -EFSCORRUPTED;
482+
}
483+
479484
/* no available pcluster, let's allocate one */
480485
pcl = z_erofs_alloc_pcluster(map->m_plen >> PAGE_SHIFT);
481486
if (IS_ERR(pcl))
482487
return PTR_ERR(pcl);
483488

484489
atomic_set(&pcl->obj.refcount, 1);
485490
pcl->obj.index = map->m_pa >> PAGE_SHIFT;
486-
491+
pcl->algorithmformat = map->m_algorithmformat;
487492
pcl->length = (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) |
488493
(map->m_flags & EROFS_MAP_FULL_MAPPED ?
489494
Z_EROFS_PCLUSTER_FULL_LENGTH : 0);
490495

491-
if (map->m_flags & EROFS_MAP_ZIPPED)
492-
pcl->algorithmformat = Z_EROFS_COMPRESSION_LZ4;
493-
else
494-
pcl->algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
495-
496496
/* new pclusters should be claimed as type 1, primary and followed */
497497
pcl->next = clt->owned_head;
498498
clt->mode = COLLECT_PRIMARY_FOLLOWED;

fs/erofs/zmap.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct z_erofs_maprecorder {
111111

112112
unsigned long lcn;
113113
/* compression extent information gathered */
114-
u8 type;
114+
u8 type, headtype;
115115
u16 clusterofs;
116116
u16 delta[2];
117117
erofs_blk_t pblk, compressedlcs;
@@ -446,9 +446,8 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
446446
}
447447
return z_erofs_extent_lookback(m, m->delta[0]);
448448
case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
449-
map->m_flags &= ~EROFS_MAP_ZIPPED;
450-
fallthrough;
451449
case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
450+
m->headtype = m->type;
452451
map->m_la = (lcn << lclusterbits) | m->clusterofs;
453452
break;
454453
default:
@@ -472,7 +471,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
472471

473472
DBG_BUGON(m->type != Z_EROFS_VLE_CLUSTER_TYPE_PLAIN &&
474473
m->type != Z_EROFS_VLE_CLUSTER_TYPE_HEAD);
475-
if (!(map->m_flags & EROFS_MAP_ZIPPED) ||
474+
if (m->headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN ||
476475
!(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) {
477476
map->m_plen = 1 << lclusterbits;
478477
return 0;
@@ -609,16 +608,14 @@ int z_erofs_map_blocks_iter(struct inode *inode,
609608
if (err)
610609
goto unmap_out;
611610

612-
map->m_flags = EROFS_MAP_ZIPPED; /* by default, compressed */
611+
map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_ENCODED;
613612
end = (m.lcn + 1ULL) << lclusterbits;
614613

615614
switch (m.type) {
616615
case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
617-
if (endoff >= m.clusterofs)
618-
map->m_flags &= ~EROFS_MAP_ZIPPED;
619-
fallthrough;
620616
case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
621617
if (endoff >= m.clusterofs) {
618+
m.headtype = m.type;
622619
map->m_la = (m.lcn << lclusterbits) | m.clusterofs;
623620
break;
624621
}
@@ -650,12 +647,16 @@ int z_erofs_map_blocks_iter(struct inode *inode,
650647

651648
map->m_llen = end - map->m_la;
652649
map->m_pa = blknr_to_addr(m.pblk);
653-
map->m_flags |= EROFS_MAP_MAPPED;
654650

655651
err = z_erofs_get_extent_compressedlen(&m, initial_lcn);
656652
if (err)
657653
goto out;
658654

655+
if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN)
656+
map->m_algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
657+
else
658+
map->m_algorithmformat = vi->z_algorithmtype[0];
659+
659660
if (flags & EROFS_GET_BLOCKS_FIEMAP) {
660661
err = z_erofs_get_extent_decompressedlen(&m);
661662
if (!err)

include/trace/events/erofs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct erofs_map_blocks;
2424
#define show_mflags(flags) __print_flags(flags, "", \
2525
{ EROFS_MAP_MAPPED, "M" }, \
2626
{ EROFS_MAP_META, "I" }, \
27-
{ EROFS_MAP_ZIPPED, "Z" })
27+
{ EROFS_MAP_ENCODED, "E" })
2828

2929
TRACE_EVENT(erofs_lookup,
3030

0 commit comments

Comments
 (0)