Skip to content

Commit cc831ab

Browse files
committed
erofs: tidy up synchronous decompression
- Get rid of `sbi->opt.max_sync_decompress_pages` since it's fixed as 3 all the time; - Add Z_EROFS_MAX_SYNC_DECOMPRESS_BYTES in bytes instead of in pages, since for non-4K pages, 3-page limitation makes no sense; - Move `sync_decompress` to sbi to avoid unexpected remount impact; - Fold z_erofs_is_sync_decompress() into its caller; - Better description of sysfs entry `sync_decompress`. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 06e5c34 commit cc831ab

5 files changed

Lines changed: 25 additions & 34 deletions

File tree

Documentation/ABI/testing/sysfs-fs-erofs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ Description: Shows all enabled kernel features.
1010
What: /sys/fs/erofs/<disk>/sync_decompress
1111
Date: November 2021
1212
Contact: "Huang Jianan" <huangjianan@oppo.com>
13-
Description: Control strategy of sync decompression:
13+
Description: Control strategy of synchronous decompression. Synchronous
14+
decompression tries to decompress in the reader thread for
15+
synchronous reads and small asynchronous reads (<= 12 KiB):
1416

15-
- 0 (default, auto): enable for readpage, and enable for
16-
readahead on atomic contexts only.
17-
- 1 (force on): enable for readpage and readahead.
18-
- 2 (force off): disable for all situations.
17+
- 0 (auto, default): apply to synchronous reads only, but will
18+
switch to 1 (force on) if any decompression
19+
request is detected in atomic contexts;
20+
- 1 (force on): apply to synchronous reads and small
21+
asynchronous reads;
22+
- 2 (force off): disable synchronous decompression completely.
1923

2024
What: /sys/fs/erofs/<disk>/drop_caches
2125
Date: November 2024

fs/erofs/internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ enum {
5959
struct erofs_mount_opts {
6060
/* current strategy of how to use managed cache */
6161
unsigned char cache_strategy;
62-
/* strategy of sync decompression (0 - auto, 1 - force on, 2 - force off) */
63-
unsigned int sync_decompress;
64-
/* threshold for decompression synchronously */
65-
unsigned int max_sync_decompress_pages;
6662
unsigned int mount_opt;
6763
};
6864

@@ -116,6 +112,7 @@ struct erofs_sb_info {
116112
/* managed XArray arranged in physical block number */
117113
struct xarray managed_pslots;
118114

115+
unsigned int sync_decompress; /* strategy for sync decompression */
119116
unsigned int shrinker_run_no;
120117
u16 available_compr_algs;
121118

fs/erofs/super.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
375375
{
376376
#ifdef CONFIG_EROFS_FS_ZIP
377377
sbi->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
378-
sbi->opt.max_sync_decompress_pages = 3;
379-
sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
378+
sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
380379
#endif
381380
#ifdef CONFIG_EROFS_FS_XATTR
382381
set_opt(&sbi->opt, XATTR_USER);

fs/erofs/sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static struct erofs_attr erofs_attr_##_name = { \
5959
#define ATTR_LIST(name) (&erofs_attr_##name.attr)
6060

6161
#ifdef CONFIG_EROFS_FS_ZIP
62-
EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts);
62+
EROFS_ATTR_RW_UI(sync_decompress, erofs_sb_info);
6363
EROFS_ATTR_FUNC(drop_caches, 0200);
6464
#endif
6565
#ifdef CONFIG_EROFS_FS_ZIP_ACCEL

fs/erofs/zdata.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/cpuhotplug.h>
1010
#include <trace/events/erofs.h>
1111

12+
#define Z_EROFS_MAX_SYNC_DECOMPRESS_BYTES 12288
1213
#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE)
1314
#define Z_EROFS_INLINE_BVECS 2
1415

@@ -1095,21 +1096,6 @@ static int z_erofs_scan_folio(struct z_erofs_frontend *f,
10951096
return err;
10961097
}
10971098

1098-
static bool z_erofs_is_sync_decompress(struct erofs_sb_info *sbi,
1099-
unsigned int readahead_pages)
1100-
{
1101-
/* auto: enable for read_folio, disable for readahead */
1102-
if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO) &&
1103-
!readahead_pages)
1104-
return true;
1105-
1106-
if ((sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_FORCE_ON) &&
1107-
(readahead_pages <= sbi->opt.max_sync_decompress_pages))
1108-
return true;
1109-
1110-
return false;
1111-
}
1112-
11131099
static bool z_erofs_page_is_invalidated(struct page *page)
11141100
{
11151101
return !page_folio(page)->mapping && !z_erofs_is_shortlived_page(page);
@@ -1484,9 +1470,9 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
14841470
#else
14851471
queue_work(z_erofs_workqueue, &io->u.work);
14861472
#endif
1487-
/* enable sync decompression for readahead */
1488-
if (sbi->opt.sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
1489-
sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
1473+
/* See `sync_decompress` in sysfs-fs-erofs for more details */
1474+
if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
1475+
sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
14901476
return;
14911477
}
14921478
z_erofs_decompressqueue_work(&io->u.work);
@@ -1803,16 +1789,21 @@ static void z_erofs_submit_queue(struct z_erofs_frontend *f,
18031789
z_erofs_decompress_kickoff(q[JQ_SUBMIT], nr_bios);
18041790
}
18051791

1806-
static int z_erofs_runqueue(struct z_erofs_frontend *f, unsigned int rapages)
1792+
static int z_erofs_runqueue(struct z_erofs_frontend *f, unsigned int rabytes)
18071793
{
18081794
struct z_erofs_decompressqueue io[NR_JOBQUEUES];
18091795
struct erofs_sb_info *sbi = EROFS_I_SB(f->inode);
1810-
bool force_fg = z_erofs_is_sync_decompress(sbi, rapages);
1796+
int syncmode = sbi->sync_decompress;
1797+
bool force_fg;
18111798
int err;
18121799

1800+
force_fg = (syncmode == EROFS_SYNC_DECOMPRESS_AUTO && !rabytes) ||
1801+
(syncmode == EROFS_SYNC_DECOMPRESS_FORCE_ON &&
1802+
(rabytes <= Z_EROFS_MAX_SYNC_DECOMPRESS_BYTES));
1803+
18131804
if (f->head == Z_EROFS_PCLUSTER_TAIL)
18141805
return 0;
1815-
z_erofs_submit_queue(f, io, &force_fg, !!rapages);
1806+
z_erofs_submit_queue(f, io, &force_fg, !!rabytes);
18161807

18171808
/* handle bypass queue (no i/o pclusters) immediately */
18181809
err = z_erofs_decompress_queue(&io[JQ_BYPASS], &f->pagepool);
@@ -1933,7 +1924,7 @@ static void z_erofs_readahead(struct readahead_control *rac)
19331924
z_erofs_pcluster_readmore(&f, rac, false);
19341925
z_erofs_pcluster_end(&f);
19351926

1936-
(void)z_erofs_runqueue(&f, nrpages);
1927+
(void)z_erofs_runqueue(&f, nrpages << PAGE_SHIFT);
19371928
erofs_put_metabuf(&f.map.buf);
19381929
erofs_release_pages(&f.pagepool);
19391930
}

0 commit comments

Comments
 (0)