From patchwork Sat Aug 26 12:49:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunlong Song X-Patchwork-Id: 9923511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C98E602BD for ; Sat, 26 Aug 2017 12:50:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 146A928587 for ; Sat, 26 Aug 2017 12:50:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09748285CB; Sat, 26 Aug 2017 12:50:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA4CC28587 for ; Sat, 26 Aug 2017 12:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754279AbdHZMtt (ORCPT ); Sat, 26 Aug 2017 08:49:49 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4581 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbdHZMtt (ORCPT ); Sat, 26 Aug 2017 08:49:49 -0400 Received: from 172.30.72.58 (EHLO DGGEMS409-HUB.china.huawei.com) ([172.30.72.58]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGA06658; Sat, 26 Aug 2017 20:49:46 +0800 (CST) Received: from huawei.com (10.107.193.250) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.301.0; Sat, 26 Aug 2017 20:49:39 +0800 From: Yunlong Song To: , , , , CC: , , , , Subject: [PATCH] f2fs: discard small invalid blocks in current active segments Date: Sat, 26 Aug 2017 20:49:32 +0800 Message-ID: <1503751772-158812-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.5.2 MIME-Version: 1.0 X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0201.59A16E6B.003A, 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: af6988db321fe2cfbe496415045eb2f5 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1. write file A with 5 blocks to current empty active segment 2. remove file A 3. write checkpoint 4. write file B with 507 blocks to the same active segment If file B is alive all the time, the blocks used by file A will never be discarded. So current active segment should also be treated as a candidate for small discards. Signed-off-by: Yunlong Song --- fs/f2fs/segment.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8375257..a2e7c8f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1339,7 +1339,9 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc, return false; if (!force) { - if (!test_opt(sbi, DISCARD) || !se->valid_blocks || + if (!test_opt(sbi, DISCARD) || + (!se->valid_blocks && + !IS_CURSEG(sbi, cpc->trim_start)) || SM_I(sbi)->dcc_info->nr_discards >= SM_I(sbi)->dcc_info->max_discards) return false;