Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013AbdHRPQz (ORCPT ); Fri, 18 Aug 2017 11:16:55 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4081 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750709AbdHRPQx (ORCPT ); Fri, 18 Aug 2017 11:16:53 -0400 Subject: Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs To: Chao Yu , , , CC: , , , , References: <1502199825-15218-1-git-send-email-yunlong.song@huawei.com> <1502451826-45453-1-git-send-email-yunlong.song@huawei.com> <2e1652f9-5e3a-4f38-5736-54b1a89ac02a@huawei.com> <3ef856f1-4155-4821-4cf8-25f5872257e5@huawei.com> From: Yunlong Song Message-ID: Date: Fri, 18 Aug 2017 23:16:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.111.220.140] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.599704DB.008C,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 96b9d0bfd27b6a6fc7cfea6ba380a7a9 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6513 Lines: 166 I send a v3 patch, please review, and the main difference is shown below. On 2017/8/18 18:20, Chao Yu wrote: > Hi Yunlong, > > IMO, we don't need additional sysfs entry, how about changing a bit as below? > > >From 3fc8206871fe457859f1537c9dc8918b45f14601 Mon Sep 17 00:00:00 2001 > From: Yunlong Song > Date: Wed, 16 Aug 2017 23:01:56 +0800 > Subject: [PATCH] f2fs: support soft block reservation > > It supports to extend reserved_blocks sysfs interface to be soft > threshold, which allows user configure it exceeding current available > user space. > > Signed-off-by: Yunlong Song > Signed-off-by: Chao Yu > --- > Documentation/ABI/testing/sysfs-fs-f2fs | 3 ++- > fs/f2fs/f2fs.h | 12 ++++++++++-- > fs/f2fs/super.c | 3 ++- > fs/f2fs/sysfs.c | 16 ++++++++++++++-- > 4 files changed, 28 insertions(+), 6 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs > index 11b7f4ebea7c..45c3d92f77c8 100644 > --- a/Documentation/ABI/testing/sysfs-fs-f2fs > +++ b/Documentation/ABI/testing/sysfs-fs-f2fs > @@ -138,7 +138,8 @@ What: /sys/fs/f2fs//reserved_blocks > Date: June 2017 > Contact: "Chao Yu" > Description: > - Controls current reserved blocks in system. > + Controls current reserved blocks in system, the threshold > + is soft, it could exceed current avaible user space. > > What: /sys/fs/f2fs//gc_urgent > Date: August 2017 > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 336021b9b93e..a7b2d257e8ee 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1046,6 +1046,7 @@ struct f2fs_sb_info { > block_t discard_blks; /* discard command candidats */ > block_t last_valid_block_count; /* for recovery */ > block_t reserved_blocks; /* configurable reserved blocks */ > + block_t current_reserved_blocks; /* current reserved blocks */ > > u32 s_next_generation; /* for NFS support */ > > @@ -1520,7 +1521,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, > > spin_lock(&sbi->stat_lock); > sbi->total_valid_block_count += (block_t)(*count); > - avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; > + avail_user_block_count = sbi->user_block_count - > + sbi->current_reserved_blocks; > if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { > diff = sbi->total_valid_block_count - avail_user_block_count; > *count -= diff; > @@ -1554,6 +1556,9 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, > f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); > f2fs_bug_on(sbi, inode->i_blocks < sectors); > sbi->total_valid_block_count -= (block_t)count; > + if (sbi->reserved_blocks) Add sbi->reserved_blocks != sbi->cur_reserved_blocks check > + sbi->current_reserved_blocks = min(sbi->reserved_blocks, > + sbi->current_reserved_blocks + count); > spin_unlock(&sbi->stat_lock); > f2fs_i_blocks_write(inode, count, false, true); > } > @@ -1700,7 +1705,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, > spin_lock(&sbi->stat_lock); > > valid_block_count = sbi->total_valid_block_count + 1; > - if (unlikely(valid_block_count + sbi->reserved_blocks > > + if (unlikely(valid_block_count + sbi->current_reserved_blocks > > sbi->user_block_count)) { > spin_unlock(&sbi->stat_lock); > goto enospc; > @@ -1743,6 +1748,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, > > sbi->total_valid_node_count--; > sbi->total_valid_block_count--; > + if (sbi->reserved_blocks) > + sbi->current_reserved_blocks = min(sbi->reserved_blocks, > + sbi->current_reserved_blocks + 1); change to sbi->cur_reserved_blocks++; > > spin_unlock(&sbi->stat_lock); > > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index 4c1bdcb94133..036f083bbf56 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -957,7 +957,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) > buf->f_blocks = total_count - start_count; > buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count; > buf->f_bavail = user_block_count - valid_user_blocks(sbi) - > - sbi->reserved_blocks; > + sbi->current_reserved_blocks; > > avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; > > @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) > le64_to_cpu(sbi->ckpt->valid_block_count); > sbi->last_valid_block_count = sbi->total_valid_block_count; > sbi->reserved_blocks = 0; > + sbi->current_reserved_blocks = 0; > > for (i = 0; i < NR_INODE_TYPE; i++) { > INIT_LIST_HEAD(&sbi->inode_list[i]); > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c > index 4bcaa9059026..3173a272fe7c 100644 > --- a/fs/f2fs/sysfs.c > +++ b/fs/f2fs/sysfs.c > @@ -104,12 +104,23 @@ static ssize_t features_show(struct f2fs_attr *a, > return len; > } > > +static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a, > + struct f2fs_sb_info *sbi, char *buf) > +{ > + return snprintf(buf, PAGE_SIZE, > + "expected: %u\ncurrent: %u\n", > + sbi->reserved_blocks, sbi->current_reserved_blocks); > +} > + > static ssize_t f2fs_sbi_show(struct f2fs_attr *a, > struct f2fs_sb_info *sbi, char *buf) > { > unsigned char *ptr = NULL; > unsigned int *ui; > > + if (a->struct_type == RESERVED_BLOCKS) > + return f2fs_reserved_blocks_show(a, sbi, buf); > + > ptr = __struct_ptr(sbi, a->struct_type); > if (!ptr) > return -EINVAL; > @@ -143,12 +154,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a, > #endif > if (a->struct_type == RESERVED_BLOCKS) { > spin_lock(&sbi->stat_lock); > - if ((unsigned long)sbi->total_valid_block_count + t > > - (unsigned long)sbi->user_block_count) { > + if (t > (unsigned long)sbi->user_block_count) { > spin_unlock(&sbi->stat_lock); > return -EINVAL; > } > *ui = t; > + sbi->current_reserved_blocks = min(sbi->reserved_blocks, > + sbi->user_block_count - valid_user_blocks(sbi)); This is not safe for support system's activation, since the user available space can be suddenly zero! So I change this to only admit t < sbi->cur_reserved_blocks then change its value. > spin_unlock(&sbi->stat_lock); > return count; > } -- Thanks, Yunlong Song