Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp646756rdh; Wed, 7 Feb 2024 16:07:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUdcK6w5RzgSo1U1ANgomcTtq41lrj+7Xtfv51jPp0J4F3qKUd45wqzBrd7SMfDkeAEQM0p/ch6PE3zIRww+3+z4zg8SS3buNowPiNNgg== X-Google-Smtp-Source: AGHT+IEoDr37+3dVfGiFyikjqptT11ZBiyzbiUajjtdB+o+a/y92Hh5qTDaKTY06uIA1Q6z04C0R X-Received: by 2002:a05:6402:c18:b0:560:f198:2487 with SMTP id co24-20020a0564020c1800b00560f1982487mr1306766edb.25.1707350866943; Wed, 07 Feb 2024 16:07:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707350866; cv=pass; d=google.com; s=arc-20160816; b=bMtMgbUkk/VBsESwFatoJG/f1mywA/fqe0zPrIoiT4fLcs+j6zpy2wItRtz2/8S5K5 SXB41TIYcfgZIX8ift70OhM4uOSA2TWjpA09aR/3SQq2BHASgvRYLO2P0uovtPlV8Zu7 CtTfo4Mt5sxaOyHC7ky9q6VhujzqU1J0i2/MXWsDFELpye0XmjVCRAW0KPDYQ0T9L208 2fF3LB8hqC3UzwdsbYfAdK2gHg4xM21ypGSjKCVEAiF61jnwqM0DO9zUAnnA+6kF3nk4 MgtzCdrV+DscxbPS22VpV4SKP2vVZhVaEsoIju+UhdUrvfOEKzUHc+SeokrCOPPRRHvE fMkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QcIggjTQa9I11zSG1qwOwfhOzJL3GE2BMVHIRlFlW0M=; fh=4C0vQtZe/mkD7PsnmjU/q6THLwtfHNreROTkoEkT8QY=; b=tBzfWITIa+h+Nfh1c2nNOu4njqUwv7Hr4DgXaIplwNqTYamZ9qwPa2bTACOoPdBz7u Qx/tmAF9EvLINKuwrn/gg1Bs8MBhlNKVMkHTVWE/jBBt70daVDMc5c7mm2b6MCqBhAL9 VUDV4LlcjBkoJDmXqDh7v07oBj5SNyx6HHvqUs3CCPfU+wF7/TqKkGKGwPNkWJLi3Kb3 ZkR698hTnkEta/RaiLhoUtaVNzkBOllApkcUWwiNVT61iQBLf3BuW8MmMcuAtzZbk+Rf th5ebMNIpOBIsjHgoAs2QqvIa4KZj0RtgDrGmRy+AvBIRUky9UnpL6I4Dykr6Yfb8UNY +1ww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KtrU3Kxk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57314-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVOYVpeh7N1NkZtKwAn3WzpsMVr1q8ZM4QKzmZ2miI6DeAgK7gTxv1+RV93H0RdO5uOvWZt0bC1PCjEFlMtslxJO6KjDFESivasi2wDbA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id de20-20020a056402309400b00560006e84bcsi240239edb.425.2024.02.07.16.07.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 16:07:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57314-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KtrU3Kxk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57314-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 823AF1F24389 for ; Thu, 8 Feb 2024 00:07:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3B0D11CAB; Thu, 8 Feb 2024 00:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KtrU3Kxk" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6118DF4EE for ; Thu, 8 Feb 2024 00:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707350857; cv=none; b=HkpCJ9LdMB6s4lXu7TDfd9y97aPeE1JIOSupY7LvF8aa4i/1aJdY+OY1ygG1PyprdIP/3MBLitdbLWTvR4HRTLx6ylbWFdNH1133KK/u2ILt4mJ5hznuVX72Ze86hj8BTjWmVvmkj37sdLYUVPVcMbGT5y1bqNl/HTkMRfo10g8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707350857; c=relaxed/simple; bh=hwkLdDMjJeQwe535I6mISaHdEEZ3S9N6jpToD65gvmU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PCQ4F0Y41FkeXdNeJoMC0PUnuSSJjr/pNQRpizRglVlubDHckEK+EsVZBYTa/40wtygiQleSAYiWzGVwYgx5Da9Z6LwRbdPDG77MTb92oJmNDlLC1dwZ1yJ3hCuzD0rv+Ej/o2uhNnNkHfvVhXK4e2xC8Og0T5HpbociRrB/2mg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KtrU3Kxk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA389C433F1; Thu, 8 Feb 2024 00:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707350856; bh=hwkLdDMjJeQwe535I6mISaHdEEZ3S9N6jpToD65gvmU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KtrU3KxkhLmfGxH8uAjs4oHMdgbGUSBQtiqE6eYi2bUb9JsGsqwopCKopTPysTpcY SPSF4fi/lEkoQvtH0pDBHPX3wCw6nvFNB07ixa+KAsPyD7iaRh/1ad82tZ4jM0ndqK /YF1UHo4vjxEF8rvITofPg/6ICAg7VYDwGEqLsytwpEq+OV7v15HYfMuXb3cD4K5a1 qM4HfRyDShTCva2y+O2Frpgp7S7lDNoKiadT2QkX7y8D+QpeaFp6iiZ7z1QqI4NdBr QZJLDWs+D5nEoKOQN8ED/JJzq8EXzUHxeKWupytZhPQJuc6ugtXxluQZZYPnvjWYeD ezF6WZtWv8p2w== Date: Wed, 7 Feb 2024 16:07:35 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sheng Yong Subject: Re: [PATCH] f2fs: support compress extension update via sysfs interface Message-ID: References: <20240207062546.3083870-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240207062546.3083870-1-chao@kernel.org> On 02/07, Chao Yu wrote: > Introduce /sys/fs/f2fs//compress_extension to support > adding/deleting compress extension via sysfs interface, in > comparison to mount option, it's more easy to use and less > authority issue for applications. > > Usage: > - Query: cat /sys/fs/f2fs//compress_extension > - Add: echo '[c|n]extension' > /sys/fs/f2fs//compress_extension > - Del: echo '[c|n]!extension' > /sys/fs/f2fs//compress_extension > - [c] means add/del compress extension > - [n] means add/del nocompress extension > > Signed-off-by: Sheng Yong > Signed-off-by: Chao Yu > --- > Documentation/ABI/testing/sysfs-fs-f2fs | 10 ++++ > Documentation/filesystems/f2fs.rst | 6 ++- > fs/f2fs/compress.c | 61 +++++++++++++++++++++++ > fs/f2fs/f2fs.h | 4 +- > fs/f2fs/sysfs.c | 65 +++++++++++++++++++++++-- > 5 files changed, 139 insertions(+), 7 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs > index 48c135e24eb5..1f2cc0913e45 100644 > --- a/Documentation/ABI/testing/sysfs-fs-f2fs > +++ b/Documentation/ABI/testing/sysfs-fs-f2fs > @@ -762,3 +762,13 @@ Date: November 2023 > Contact: "Chao Yu" > Description: It controls to enable/disable IO aware feature for background discard. > By default, the value is 1 which indicates IO aware is on. > + > +What: /sys/fs/f2fs//compress_extension > +Date: October 2023 > +Contact: "Chao Yu" > +Description: Used to control configure [|no]compress_extension list: > + - Query: cat /sys/fs/f2fs//compress_extension > + - Add: echo '[c|n]extension' > /sys/fs/f2fs//compress_extension > + - Del: echo '[c|n]!extension' > /sys/fs/f2fs//compress_extension > + - [c] means add/del compress extension > + - [n] means add/del nocompress extension > diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst > index 32cbfa864f38..c82a8fd7316b 100644 > --- a/Documentation/filesystems/f2fs.rst > +++ b/Documentation/filesystems/f2fs.rst > @@ -821,17 +821,19 @@ Compression implementation > all logical blocks in cluster contain valid data and compress ratio of > cluster data is lower than specified threshold. > > -- To enable compression on regular inode, there are four ways: > +- To enable compression on regular inode, there are five ways: > > * chattr +c file > * chattr +c dir; touch dir/file > * mount w/ -o compress_extension=ext; touch file.ext > * mount w/ -o compress_extension=*; touch any_file > + * echo '[c]ext' > /sys/fs/f2fs//compress_extension; touch file.ext > > -- To disable compression on regular inode, there are two ways: > +- To disable compression on regular inode, there are three ways: > > * chattr -c file > * mount w/ -o nocompress_extension=ext; touch file.ext > + * echo '[n]ext' > /sys/fs/f2fs//compress_extension; touch file.ext > > - Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions: > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 3dc488ce882b..a5257882c772 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -20,6 +20,67 @@ > #include "segment.h" > #include > > +static int is_compress_extension_exist(struct f2fs_sb_info *sbi, > + unsigned char (*ext)[F2FS_EXTENSION_LEN], > + int ext_cnt, unsigned char *new_ext) > +{ > + int i; > + > + for (i = 0; i < ext_cnt; i++) { > + if (!strcasecmp(new_ext, ext[i])) > + return i; > + } > + return -1; > +} > + > +int f2fs_update_compress_extension(struct f2fs_sb_info *sbi, > + unsigned char *new_ext, bool is_ext, bool set) > +{ > + unsigned char (*ext)[F2FS_EXTENSION_LEN]; > + unsigned char *ext_cnt; > + > + if (is_ext) { > + ext = F2FS_OPTION(sbi).extensions; > + ext_cnt = &F2FS_OPTION(sbi).compress_ext_cnt; > + } else { > + ext = F2FS_OPTION(sbi).noextensions; > + ext_cnt = &F2FS_OPTION(sbi).nocompress_ext_cnt; > + } > + > + if (set) { > + if (*ext_cnt >= COMPRESS_EXT_NUM) > + return -EINVAL; > + > + if (is_compress_extension_exist(sbi, > + F2FS_OPTION(sbi).extensions, > + F2FS_OPTION(sbi).compress_ext_cnt, > + new_ext) >= 0) > + return -EEXIST; > + > + if (is_compress_extension_exist(sbi, > + F2FS_OPTION(sbi).noextensions, > + F2FS_OPTION(sbi).nocompress_ext_cnt, > + new_ext) >= 0) > + return -EEXIST; > + > + strcpy(ext[*ext_cnt], new_ext); > + (*ext_cnt)++; > + } else { > + int pos = is_compress_extension_exist(sbi, ext, > + *ext_cnt, new_ext); > + if (pos < 0) > + return -ENOENT; > + > + if (pos < *ext_cnt - 1) > + memmove(ext + pos, ext + pos + 1, > + F2FS_EXTENSION_LEN * (*ext_cnt - pos - 1)); > + memset(ext + *ext_cnt - 1, 0, F2FS_EXTENSION_LEN); > + (*ext_cnt)--; > + } > + > + return 0; > +} > + > static struct kmem_cache *cic_entry_slab; > static struct kmem_cache *dic_entry_slab; > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index c5e7460d1a0a..d44e2c43d8ab 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -186,7 +186,7 @@ struct f2fs_mount_info { > unsigned char compress_level; /* compress level */ > bool compress_chksum; /* compressed data chksum */ > unsigned char compress_ext_cnt; /* extension count */ > - unsigned char nocompress_ext_cnt; /* nocompress extension count */ > + unsigned char nocompress_ext_cnt; /* nocompress extension count */ > int compress_mode; /* compression mode */ > unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ > unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ > @@ -4273,6 +4273,8 @@ static inline bool f2fs_post_read_required(struct inode *inode) > * compress.c > */ > #ifdef CONFIG_F2FS_FS_COMPRESSION > +int f2fs_update_compress_extension(struct f2fs_sb_info *sbi, > + unsigned char *new_ext, bool is_ext, bool set); > bool f2fs_is_compressed_page(struct page *page); > struct page *f2fs_compress_control_page(struct page *page); > int f2fs_prepare_compress_overwrite(struct inode *inode, > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c > index a7ec55c7bb20..a8f05a02e202 100644 > --- a/fs/f2fs/sysfs.c > +++ b/fs/f2fs/sysfs.c > @@ -39,6 +39,7 @@ enum { > RESERVED_BLOCKS, /* struct f2fs_sb_info */ > CPRC_INFO, /* struct ckpt_req_control */ > ATGC_INFO, /* struct atgc_management */ > + MOUNT_INFO, /* struct f2fs_mount_info */ > }; > > static const char *gc_mode_names[MAX_GC_MODE] = { > @@ -89,6 +90,8 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) > return (unsigned char *)&sbi->cprc_info; > else if (struct_type == ATGC_INFO) > return (unsigned char *)&sbi->am; > + else if (struct_type == MOUNT_INFO) > + return (unsigned char *)&F2FS_OPTION(sbi); > return NULL; > } > > @@ -358,6 +361,25 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a, > > if (!strcmp(a->attr.name, "compr_new_inode")) > return sysfs_emit(buf, "%u\n", sbi->compr_new_inode); > + > + if (!strcmp(a->attr.name, "compress_extension")) { > + int len = 0, i; > + > + f2fs_down_read(&sbi->sb_lock); > + len += scnprintf(buf + len, PAGE_SIZE - len, > + "compress extension:\n"); > + for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) > + len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n", > + F2FS_OPTION(sbi).extensions[i]); > + > + len += scnprintf(buf + len, PAGE_SIZE - len, > + "nocompress extension:\n"); > + for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) > + len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n", > + F2FS_OPTION(sbi).noextensions[i]); I don't think this is acceptable in sysfs. > + f2fs_up_read(&sbi->sb_lock); > + return len; > + } > #endif > > if (!strcmp(a->attr.name, "gc_segment_mode")) > @@ -446,6 +468,35 @@ static ssize_t __sbi_store(struct f2fs_attr *a, > return ret ? ret : count; > } > > +#ifdef CONFIG_F2FS_FS_COMPRESSION > + if (!strcmp(a->attr.name, "compress_extension")) { > + char *name = strim((char *)buf); > + bool set = true, cmpr; > + > + if (!strncmp(name, "[c]", 3)) > + cmpr = true; > + else if (!strncmp(name, "[n]", 3)) > + cmpr = false; > + else > + return -EINVAL; > + > + name += 3; > + > + if (*name == '!') { > + name++; > + set = false; > + } > + > + if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN) > + return -EINVAL; > + > + f2fs_down_write(&sbi->sb_lock); > + ret = f2fs_update_compress_extension(sbi, name, cmpr, set); > + f2fs_up_write(&sbi->sb_lock); > + return ret ? ret : count; > + } > +#endif > + > if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) { > const char *name = strim((char *)buf); > struct ckpt_req_control *cprc = &sbi->cprc_info; > @@ -785,15 +836,16 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a, > const char *buf, size_t count) > { > ssize_t ret; > - bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") || > - a->struct_type == GC_THREAD); > + bool need_lock = (!strcmp(a->attr.name, "gc_urgent") || > + a->struct_type == GC_THREAD || > + a->struct_type == MOUNT_INFO); > > - if (gc_entry) { > + if (need_lock) { > if (!down_read_trylock(&sbi->sb->s_umount)) > return -EAGAIN; > } > ret = __sbi_store(a, sbi, buf, count); > - if (gc_entry) > + if (need_lock) > up_read(&sbi->sb->s_umount); > > return ret; > @@ -942,6 +994,9 @@ static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) > #define ATGC_INFO_RW_ATTR(name, elname) \ > F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname) > > +#define MOUNT_INFO_RW_ATTR(name, elname) \ > + F2FS_RW_ATTR(MOUNT_INFO, f2fs_mount_info, name, elname) > + > /* GC_THREAD ATTR */ > GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time); > GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time); > @@ -1008,6 +1063,7 @@ F2FS_SBI_GENERAL_RW_ATTR(compr_saved_block); > F2FS_SBI_GENERAL_RW_ATTR(compr_new_inode); > F2FS_SBI_GENERAL_RW_ATTR(compress_percent); > F2FS_SBI_GENERAL_RW_ATTR(compress_watermark); > +MOUNT_INFO_RW_ATTR(compress_extension, extensions); > #endif > /* atomic write */ > F2FS_SBI_GENERAL_RO_ATTR(current_atomic_write); > @@ -1181,6 +1237,7 @@ static struct attribute *f2fs_attrs[] = { > ATTR_LIST(compr_new_inode), > ATTR_LIST(compress_percent), > ATTR_LIST(compress_watermark), > + ATTR_LIST(compress_extension), > #endif > /* For ATGC */ > ATTR_LIST(atgc_candidate_ratio), > -- > 2.40.1