Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp593692pxh; Tue, 9 Nov 2021 15:51:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrYfJ/egEFPCCMRSCc4uaHn3JysWj7OO/A/mAvAyaPbDqjRV/fgHxNQWtO9nfcDyw+h2+U X-Received: by 2002:a17:906:3d32:: with SMTP id l18mr15085483ejf.393.1636501907832; Tue, 09 Nov 2021 15:51:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636501907; cv=none; d=google.com; s=arc-20160816; b=LRh2ZJ27vVhmZ6cNtvqsyfdz4SUVZClovMIe9eeowkKJ6jIIVFcL8+enrWX9K4eL9a 1CD9zb7YGMRXMFE4x8mgWGzFBxNRT0Ks8uH0kNIrSbQ4aNIlJ7Qxykpi0z1vyB9aoeIx 0nrobdM5O7vqg4hD8ZdFjmsOohG+bwzDJScLlRS+iFcOoJ//REcxmFuHoR9X11dFB4Ul vsFJwNz5/1gBB+0J2fTroA5heeL3iF0DEZf0bbKvwGOfsZKfjb4srhvCfJ8kdQLWCd7Z Fv6IUwZi3/U3c6ZPxxqLLLujobmoBvWcOFY/eKmKccPB8XMHLXe1Sp2ganYZ9RoQmdbP RdFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=K2T/zWpo0GQGspV/SMu2/VqMcQIaXg/NwddRB2dGTWk=; b=bjVoBTFzm9PHqkIEQ5dxp2vyRZ6Q0psBoHAlb0rPLFGMQHbFO6sfyafxrFDgdqC1yQ 2bBjHTWHQaFNnqNNwzRhLt7B5pIaUr3Ey9+i7SuVkVBwR5u40vWMU8i81IhgupgcofHS yAF1oKD9aBRhOvTnwcXsYsAEdKJYRST4vbBuoTFdydlCAHDoRrFdfBkX13PJgmuHZ+Ro FmOAf8f/GPWRCWNfYvNoJ8SBW6wOVBX1tWCqteyWEtCPD7aB/YzSUFp5L2Xk6ui1MyLH yg/J/34Y4+t6IMlSYWDoTQEFhjZtIqH9veBJXO0KO8WbLrHlv0uaOcZFkgLUvpvuT9Cj k6xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AX81colq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si15246711edu.169.2021.11.09.15.51.24; Tue, 09 Nov 2021 15:51:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AX81colq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235612AbhKINaQ (ORCPT + 97 others); Tue, 9 Nov 2021 08:30:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:41344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235585AbhKINaP (ORCPT ); Tue, 9 Nov 2021 08:30:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E2E2261159; Tue, 9 Nov 2021 13:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636464449; bh=HpU5yMi3I0oRYexnSAUrBIMuTdc6OxR7OPbDG9kAIA8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AX81colqHSy015btlOq0G9JRoqwJgYyvl98sQy0zDgeZzWU5Rj1LX1HmPyjAwzJfT IP6hJaz58WeEw3Zv/9gP4fHPTd8T108+D2KQqFRUM+8h07s6p+iieUIxI//weoHc45 14cJ2CMmbfN7NY3NAjN2f0u77isy8iha6vAaiEGiySKER1OFCxgA4xDHf5VGJtNanp MeeHYc6KVNebHfgMw0nX/PK/ar2bDxmtRFRM90GqxAX/yXpKVXRrE8XT7wMYq0LV/h k0Pz7hsw0adizpsrSJrrRtuuBqBxqhILNqAfGqjYPEhwUZnqKvaO04DVNRA7WEffdo 6asVz4yyD1CUg== Message-ID: Date: Tue, 9 Nov 2021 21:27:25 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH v2 2/2] erofs: add sysfs node to control sync decompression strategy Content-Language: en-US To: Huang Jianan , linux-erofs@lists.ozlabs.org Cc: zhangshiming@oppo.com, linux-kernel@vger.kernel.org, yh@oppo.com, guanyuwei@oppo.com, guoweichao@oppo.com References: <82f7c99e-b83f-90b7-fceb-b8436da94339@oppo.com> <20211109074536.23137-1-huangjianan@oppo.com> <20211109074536.23137-2-huangjianan@oppo.com> From: Chao Yu In-Reply-To: <20211109074536.23137-2-huangjianan@oppo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/11/9 15:45, Huang Jianan via Linux-erofs wrote: > Although readpage is a synchronous path, there will be no additional > kworker scheduling overhead in non-atomic contexts. So add a sysfs > node to allow disable sync decompression. > > Signed-off-by: Huang Jianan > --- > changes since v1: > - leave auto default > - add a disable strategy for sync_decompress > > Documentation/ABI/testing/sysfs-fs-erofs | 9 +++++++++ > fs/erofs/internal.h | 4 ++-- > fs/erofs/super.c | 2 +- > fs/erofs/sysfs.c | 10 ++++++++++ > fs/erofs/zdata.c | 19 ++++++++++++++----- > 5 files changed, 36 insertions(+), 8 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/testing/sysfs-fs-erofs > index 86d0d0234473..c84f12004f02 100644 > --- a/Documentation/ABI/testing/sysfs-fs-erofs > +++ b/Documentation/ABI/testing/sysfs-fs-erofs > @@ -5,3 +5,12 @@ Description: Shows all enabled kernel features. > Supported features: > lz4_0padding, compr_cfgs, big_pcluster, device_table, > sb_chksum. > + > +What: /sys/fs/erofs//sync_decompress > +Date: November 2021 > +Contact: "Huang Jianan" > +Description: Control strategy of sync decompression > + - 0 (defalut, auto): enable for readpage, and enable for > + readahead on atomic contexts only, > + - 1 (force on): enable for readpage and readahead. > + - 2 (disable): disable for all situations. 1 (force on) 2 (force off) > diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h > index d0cd712dc222..06a8bbdb378f 100644 > --- a/fs/erofs/internal.h > +++ b/fs/erofs/internal.h > @@ -60,8 +60,8 @@ 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) */ > - bool readahead_sync_decompress; > + /* strategy of sync decompression (0 - auto, 1 - force on, 2 - disable) */ Ditto, > + unsigned int sync_decompress; > > /* threshold for decompression synchronously */ > unsigned int max_sync_decompress_pages; > diff --git a/fs/erofs/super.c b/fs/erofs/super.c > index abc1da5d1719..ea223d6c7985 100644 > --- a/fs/erofs/super.c > +++ b/fs/erofs/super.c > @@ -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.sync_decompress = 0; > #endif > #ifdef CONFIG_EROFS_FS_XATTR > set_opt(&ctx->opt, XATTR_USER); > diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c > index dd328d20c451..a8889b2b65f3 100644 > --- a/fs/erofs/sysfs.c > +++ b/fs/erofs/sysfs.c > @@ -16,6 +16,7 @@ enum { > > enum { > struct_erofs_sb_info, > + struct_erofs_mount_opts, > }; > > struct erofs_attr { > @@ -55,7 +56,10 @@ static struct erofs_attr erofs_attr_##_name = { \ > > #define ATTR_LIST(name) (&erofs_attr_##name.attr) > > +EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts); > + > static struct attribute *erofs_attrs[] = { > + ATTR_LIST(sync_decompress), > NULL, > }; > ATTRIBUTE_GROUPS(erofs); > @@ -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; > } > > @@ -126,6 +132,10 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr, > ret = kstrtoul(skip_spaces(buf), 0, &t); > if (ret) > return ret; > + > + if (!strcmp(a->attr.name, "sync_decompress") && (t > 2)) if (!strcmp()) { if (t > 2) return -EINVAL; *((unsigned int *) ptr) = t; return len; } How about adding enum instead of raw numbers to improve readability? Thanks, > + return -EINVAL; > + > *((unsigned int *) ptr) = t; > return len; > case attr_pointer_bool: > diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c > index bcb1b91b234f..70ec51fa7131 100644 > --- a/fs/erofs/zdata.c > +++ b/fs/erofs/zdata.c > @@ -794,7 +794,8 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io, > /* Use workqueue and sync decompression for atomic contexts only */ > if (in_atomic() || irqs_disabled()) { > queue_work(z_erofs_workqueue, &io->u.work); > - sbi->opt.readahead_sync_decompress = true; > + if (sbi->opt.sync_decompress == 0) > + sbi->opt.sync_decompress = 1; > return; > } > z_erofs_decompressqueue_work(&io->u.work); > @@ -1454,9 +1455,11 @@ 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; > + bool force_fg = true; > > trace_erofs_readpage(page, false); > f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT; > @@ -1468,8 +1471,11 @@ static int z_erofs_readpage(struct file *file, struct page *page) > > (void)z_erofs_collector_end(&f.clt); > > + if (sbi->opt.sync_decompress == 2) > + force_fg = false; > + > /* 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, force_fg); > > if (err) > erofs_err(inode->i_sb, "failed to read, err [%d]", err); > @@ -1488,6 +1494,7 @@ static void z_erofs_readahead(struct readahead_control *rac) > struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode); > struct page *pagepool = NULL, *head = NULL, *page; > unsigned int nr_pages; > + bool force_fg = false; > > f.readahead = true; > f.headoffset = readahead_pos(rac); > @@ -1519,9 +1526,11 @@ static void z_erofs_readahead(struct readahead_control *rac) > z_erofs_pcluster_readmore(&f, rac, 0, &pagepool, false); > (void)z_erofs_collector_end(&f.clt); > > - z_erofs_runqueue(inode->i_sb, &f, &pagepool, > - sbi->opt.readahead_sync_decompress && > - nr_pages <= sbi->opt.max_sync_decompress_pages); > + if (sbi->opt.sync_decompress == 1) > + force_fg = true; > + > + z_erofs_runqueue(inode->i_sb, &f, &pagepool, force_fg > + && nr_pages <= sbi->opt.max_sync_decompress_pages); > if (f.map.mpage) > put_page(f.map.mpage); > erofs_release_pages(&pagepool); >