Skip to content

Commit 5c40d2e

Browse files
committed
erofs: clean up encoded map flags
- Remove EROFS_MAP_ENCODED since it was always set together with EROFS_MAP_MAPPED for compressed extents and checked redundantly; - Replace the EROFS_MAP_FULL_MAPPED flag with the opposite EROFS_MAP_PARTIAL_MAPPED flag so that extents are implicitly fully mapped initially to simplify the logic; - Make fragment extents independent of EROFS_MAP_MAPPED since they are not directly allocated on disk; thus fragment extents are no longer twisted with mapped extents. Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 21e161d commit 5c40d2e

4 files changed

Lines changed: 33 additions & 35 deletions

File tree

fs/erofs/internal.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,20 +360,19 @@ static inline struct folio *erofs_grab_folio_nowait(struct address_space *as,
360360
readahead_gfp_mask(as) & ~__GFP_RECLAIM);
361361
}
362362

363-
/* Has a disk mapping */
364-
#define EROFS_MAP_MAPPED 0x0001
363+
/* Allocated on disk at @m_pa (e.g. NOT a fragment extent) */
364+
#define EROFS_MAP_MAPPED 0x0001
365365
/* Located in metadata (could be copied from bd_inode) */
366-
#define EROFS_MAP_META 0x0002
367-
/* The extent is encoded */
368-
#define EROFS_MAP_ENCODED 0x0004
369-
/* The length of extent is full */
370-
#define EROFS_MAP_FULL_MAPPED 0x0008
366+
#define EROFS_MAP_META 0x0002
367+
/* @m_llen may be truncated by the runtime compared to the on-disk record */
368+
#define EROFS_MAP_PARTIAL_MAPPED 0x0004
369+
/* The on-disk @m_llen may cover only part of the encoded data */
370+
#define EROFS_MAP_PARTIAL_REF 0x0008
371371
/* Located in the special packed inode */
372-
#define __EROFS_MAP_FRAGMENT 0x0010
373-
/* The extent refers to partial decompressed data */
374-
#define EROFS_MAP_PARTIAL_REF 0x0020
375-
376-
#define EROFS_MAP_FRAGMENT (EROFS_MAP_MAPPED | __EROFS_MAP_FRAGMENT)
372+
#define EROFS_MAP_FRAGMENT 0x0010
373+
/* The encoded on-disk data will be fully handled (decompressed) */
374+
#define EROFS_MAP_FULL(f) (!((f) & (EROFS_MAP_PARTIAL_MAPPED | \
375+
EROFS_MAP_PARTIAL_REF)))
377376

378377
struct erofs_map_blocks {
379378
struct erofs_buf buf;

fs/erofs/zdata.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static bool z_erofs_should_alloc_cache(struct z_erofs_frontend *fe)
520520
if (cachestrategy <= EROFS_ZIP_CACHE_DISABLED)
521521
return false;
522522

523-
if (!(fe->map.m_flags & EROFS_MAP_FULL_MAPPED))
523+
if (fe->map.m_flags & EROFS_MAP_PARTIAL_MAPPED)
524524
return true;
525525

526526
if (cachestrategy >= EROFS_ZIP_CACHE_READAROUND &&
@@ -1033,10 +1033,7 @@ static int z_erofs_scan_folio(struct z_erofs_frontend *f,
10331033
/* bump split parts first to avoid several separate cases */
10341034
++split;
10351035

1036-
if (!(map->m_flags & EROFS_MAP_MAPPED)) {
1037-
folio_zero_segment(folio, cur, end);
1038-
tight = false;
1039-
} else if (map->m_flags & __EROFS_MAP_FRAGMENT) {
1036+
if (map->m_flags & EROFS_MAP_FRAGMENT) {
10401037
erofs_off_t fpos = offset + cur - map->m_la;
10411038

10421039
err = z_erofs_read_fragment(inode->i_sb, folio, cur,
@@ -1045,6 +1042,9 @@ static int z_erofs_scan_folio(struct z_erofs_frontend *f,
10451042
if (err)
10461043
break;
10471044
tight = false;
1045+
} else if (!(map->m_flags & EROFS_MAP_MAPPED)) {
1046+
folio_zero_segment(folio, cur, end);
1047+
tight = false;
10481048
} else {
10491049
if (!f->pcl) {
10501050
err = z_erofs_pcluster_begin(f);
@@ -1080,14 +1080,13 @@ static int z_erofs_scan_folio(struct z_erofs_frontend *f,
10801080
f->pcl->length = offset + end - map->m_la;
10811081
f->pcl->pageofs_out = map->m_la & ~PAGE_MASK;
10821082
}
1083-
if ((map->m_flags & EROFS_MAP_FULL_MAPPED) &&
1084-
!(map->m_flags & EROFS_MAP_PARTIAL_REF) &&
1083+
if (EROFS_MAP_FULL(map->m_flags) &&
10851084
f->pcl->length == map->m_llen)
10861085
f->pcl->partial = false;
10871086
}
10881087
/* shorten the remaining extent to update progress */
10891088
map->m_llen = offset + cur - map->m_la;
1090-
map->m_flags &= ~EROFS_MAP_FULL_MAPPED;
1089+
map->m_flags |= EROFS_MAP_PARTIAL_MAPPED;
10911090
if (cur <= pgs) {
10921091
split = cur < pgs;
10931092
tight = (bs == PAGE_SIZE);
@@ -1841,7 +1840,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
18411840
map->m_la = end;
18421841
err = z_erofs_map_blocks_iter(inode, map,
18431842
EROFS_GET_BLOCKS_READMORE);
1844-
if (err || !(map->m_flags & EROFS_MAP_ENCODED))
1843+
if (err || !(map->m_flags & EROFS_MAP_MAPPED))
18451844
return;
18461845

18471846
/* expand ra for the trailing edge if readahead */
@@ -1853,7 +1852,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
18531852
end = round_up(end, PAGE_SIZE);
18541853
} else {
18551854
end = round_up(map->m_la, PAGE_SIZE);
1856-
if (!(map->m_flags & EROFS_MAP_ENCODED) || !map->m_llen)
1855+
if (!(map->m_flags & EROFS_MAP_MAPPED) || !map->m_llen)
18571856
return;
18581857
}
18591858

fs/erofs/zmap.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
419419

420420
if ((flags & EROFS_GET_BLOCKS_FINDTAIL) && ztailpacking)
421421
vi->z_fragmentoff = m.nextpackoff;
422-
map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_ENCODED;
422+
map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_PARTIAL_MAPPED;
423423
end = (m.lcn + 1ULL) << lclusterbits;
424424

425425
if (m.type != Z_EROFS_LCLUSTER_TYPE_NONHEAD && endoff >= m.clusterofs) {
@@ -435,7 +435,7 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
435435
} else {
436436
if (m.type != Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
437437
end = (m.lcn << lclusterbits) | m.clusterofs;
438-
map->m_flags |= EROFS_MAP_FULL_MAPPED;
438+
map->m_flags &= ~EROFS_MAP_PARTIAL_MAPPED;
439439
m.delta[0] = 1;
440440
}
441441
/* get the corresponding first chunk */
@@ -496,7 +496,7 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
496496
map->m_llen >= i_blocksize(inode))) {
497497
err = z_erofs_get_extent_decompressedlen(&m);
498498
if (!err)
499-
map->m_flags |= EROFS_MAP_FULL_MAPPED;
499+
map->m_flags &= ~EROFS_MAP_PARTIAL_MAPPED;
500500
}
501501

502502
unmap_out:
@@ -594,8 +594,7 @@ static int z_erofs_map_blocks_ext(struct inode *inode,
594594
if (recsz > offsetof(struct z_erofs_extent, pstart_lo))
595595
vi->z_fragmentoff |= map->m_pa << 32;
596596
} else if (map->m_plen & Z_EROFS_EXTENT_PLEN_MASK) {
597-
map->m_flags |= EROFS_MAP_MAPPED |
598-
EROFS_MAP_FULL_MAPPED | EROFS_MAP_ENCODED;
597+
map->m_flags |= EROFS_MAP_MAPPED;
599598
fmt = map->m_plen >> Z_EROFS_EXTENT_PLEN_FMT_BIT;
600599
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
601600
map->m_flags |= EROFS_MAP_PARTIAL_REF;
@@ -714,7 +713,7 @@ static int z_erofs_map_sanity_check(struct inode *inode,
714713
struct erofs_sb_info *sbi = EROFS_I_SB(inode);
715714
u64 pend;
716715

717-
if (!(map->m_flags & EROFS_MAP_ENCODED))
716+
if (!(map->m_flags & EROFS_MAP_MAPPED))
718717
return 0;
719718
if (unlikely(map->m_algorithmformat >= Z_EROFS_COMPRESSION_RUNTIME_MAX)) {
720719
erofs_err(inode->i_sb, "unknown algorithm %d @ pos %llu for nid %llu, please upgrade kernel",
@@ -781,10 +780,12 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
781780
iomap->bdev = inode->i_sb->s_bdev;
782781
iomap->offset = map.m_la;
783782
iomap->length = map.m_llen;
784-
if (map.m_flags & EROFS_MAP_MAPPED) {
783+
if (map.m_flags & EROFS_MAP_FRAGMENT) {
785784
iomap->type = IOMAP_MAPPED;
786-
iomap->addr = map.m_flags & __EROFS_MAP_FRAGMENT ?
787-
IOMAP_NULL_ADDR : map.m_pa;
785+
iomap->addr = IOMAP_NULL_ADDR;
786+
} else if (map.m_flags & EROFS_MAP_MAPPED) {
787+
iomap->type = IOMAP_MAPPED;
788+
iomap->addr = map.m_pa;
788789
} else {
789790
iomap->type = IOMAP_HOLE;
790791
iomap->addr = IOMAP_NULL_ADDR;

include/trace/events/erofs.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ struct erofs_map_blocks;
2626
#define show_mflags(flags) __print_flags(flags, "", \
2727
{ EROFS_MAP_MAPPED, "M" }, \
2828
{ EROFS_MAP_META, "I" }, \
29-
{ EROFS_MAP_ENCODED, "E" }, \
30-
{ EROFS_MAP_FULL_MAPPED, "F" }, \
31-
{ EROFS_MAP_FRAGMENT, "R" }, \
32-
{ EROFS_MAP_PARTIAL_REF, "P" })
29+
{ EROFS_MAP_PARTIAL_MAPPED, "T" }, \
30+
{ EROFS_MAP_PARTIAL_REF, "P" }, \
31+
{ EROFS_MAP_FRAGMENT, "R" })
3332

3433
TRACE_EVENT(erofs_lookup,
3534

0 commit comments

Comments
 (0)