Skip to content

Commit

Permalink
erofs: add sysfs node to control sync decompression strategy
Browse files Browse the repository at this point in the history
Although readpage is a synchronous path, there will be no additional
kworker scheduling overhead in non-atomic contexts. So we can add a
sysfs node to allow disable sync decompression.

Signed-off-by: Huang Jianan <huangjianan@oppo.com>
  • Loading branch information
hjn-1 authored and intel-lab-lkp committed Nov 9, 2021
1 parent 508c472 commit d6bf9ed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fs/erofs/internal.h
Expand Up @@ -60,7 +60,7 @@ struct erofs_mount_opts {
#ifdef CONFIG_EROFS_FS_ZIP
/* current strategy of how to use managed cache */
unsigned char cache_strategy;
/* strategy of sync decompression (false - auto, true - force on) */
/* strategy of sync decompression (false - disable, true - force on) */
bool readahead_sync_decompress;

/* threshold for decompression synchronously */
Expand Down
2 changes: 1 addition & 1 deletion fs/erofs/super.c
Expand Up @@ -423,7 +423,7 @@ static void erofs_default_options(struct erofs_fs_context *ctx)
#ifdef CONFIG_EROFS_FS_ZIP
ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
ctx->opt.max_sync_decompress_pages = 3;
ctx->opt.readahead_sync_decompress = false;
ctx->opt.readahead_sync_decompress = true;
#endif
#ifdef CONFIG_EROFS_FS_XATTR
set_opt(&ctx->opt, XATTR_USER);
Expand Down
6 changes: 6 additions & 0 deletions fs/erofs/sysfs.c
Expand Up @@ -16,6 +16,7 @@ enum {

enum {
struct_erofs_sb_info,
struct_erofs_mount_opts,
};

struct erofs_attr {
Expand Down Expand Up @@ -55,7 +56,10 @@ static struct erofs_attr erofs_attr_##_name = { \

#define ATTR_LIST(name) (&erofs_attr_##name.attr)

EROFS_RW_ATTR_BOOL(readahead_sync_decompress, erofs_mount_opts);

static struct attribute *erofs_attrs[] = {
ATTR_LIST(readahead_sync_decompress),
NULL,
};
ATTRIBUTE_GROUPS(erofs);
Expand All @@ -82,6 +86,8 @@ static unsigned char *__struct_ptr(struct erofs_sb_info *sbi,
{
if (struct_type == struct_erofs_sb_info)
return (unsigned char *)sbi + offset;
if (struct_type == struct_erofs_mount_opts)
return (unsigned char *)&sbi->opt + offset;
return NULL;
}

Expand Down
9 changes: 4 additions & 5 deletions fs/erofs/zdata.c
Expand Up @@ -776,8 +776,6 @@ static void z_erofs_decompressqueue_work(struct work_struct *work);
static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
bool sync, int bios)
{
struct erofs_sb_info *const sbi = EROFS_SB(io->sb);

/* wake up the caller thread for sync decompression */
if (sync) {
unsigned long flags;
Expand All @@ -791,10 +789,9 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,

if (atomic_add_return(bios, &io->pending_bios))
return;
/* Use workqueue and sync decompression for atomic contexts only */
/* Use workqueue decompression for atomic contexts only */
if (in_atomic() || irqs_disabled()) {
queue_work(z_erofs_workqueue, &io->u.work);
sbi->opt.readahead_sync_decompress = true;
return;
}
z_erofs_decompressqueue_work(&io->u.work);
Expand Down Expand Up @@ -1454,6 +1451,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
static int z_erofs_readpage(struct file *file, struct page *page)
{
struct inode *const inode = page->mapping->host;
struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
struct page *pagepool = NULL;
int err;
Expand All @@ -1469,7 +1467,8 @@ static int z_erofs_readpage(struct file *file, struct page *page)
(void)z_erofs_collector_end(&f.clt);

/* if some compressed cluster ready, need submit them anyway */
z_erofs_runqueue(inode->i_sb, &f, &pagepool, true);
z_erofs_runqueue(inode->i_sb, &f, &pagepool,
sbi->opt.readahead_sync_decompress);

if (err)
erofs_err(inode->i_sb, "failed to read, err [%d]", err);
Expand Down

0 comments on commit d6bf9ed

Please sign in to comment.