Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbdHOHOu (ORCPT ); Tue, 15 Aug 2017 03:14:50 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3531 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753059AbdHOHOt (ORCPT ); Tue, 15 Aug 2017 03:14:49 -0400 From: Yunlong Song To: , , , , CC: , , , , Subject: [PATCH v2] f2fs: free_user_blocks should use reserved_segments instead Date: Tue, 15 Aug 2017 15:14:33 +0800 Message-ID: <1502781273-97035-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1502702552-78497-1-git-send-email-yunlong.song@huawei.com> References: <1502702552-78497-1-git-send-email-yunlong.song@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.59929F67.007C,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: 56e17174344d1a5986b13ff74facbb46 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1616 Lines: 44 The part (overprovision_segments - reserved_segments) can still be used for LFS in some case, e.g., there are lots of invalid block from dirty segments, then the part (overprovision_segments - reserved_segments) can be safely used. So free_use_blocks should use reserved_segments instead, rather than directly use overprovision_segments. BTW, we also add the constraint of sbi->reserved_blocks. Signed-off-by: Yunlong Song --- fs/f2fs/gc.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index 9325191..542612a 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h @@ -49,11 +49,23 @@ struct gc_inode_list { */ static inline block_t free_user_blocks(struct f2fs_sb_info *sbi) { - if (free_segments(sbi) < overprovision_segments(sbi)) + block_t avail_user_block_count, free_blocks, avail_free_blocks; + block_t reserved_blocks; + + avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; + + if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) + return 0; + + free_blocks = free_segments(sbi) << sbi->log_blocks_per_seg; + avail_free_blocks = min(free_blocks, avail_user_block_count - + sbi->total_valid_block_count); + reserved_blocks = reserved_segments(sbi) << sbi->log_blocks_per_seg; + + if (avail_free_blocks < reserved_blocks) return 0; else - return (free_segments(sbi) - overprovision_segments(sbi)) - << sbi->log_blocks_per_seg; + return avail_free_blocks - reserved_blocks; } static inline block_t limit_invalid_user_blocks(struct f2fs_sb_info *sbi) -- 1.8.5.2