From patchwork Tue Jan 3 09:01:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunlong Song X-Patchwork-Id: 9494645 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 65608606B4 for ; Tue, 3 Jan 2017 08:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E57920008 for ; Tue, 3 Jan 2017 08:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 530652679B; Tue, 3 Jan 2017 08:52:13 +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=ham 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 7D87B20008 for ; Tue, 3 Jan 2017 08:52:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934792AbdACIv5 (ORCPT ); Tue, 3 Jan 2017 03:51:57 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:19298 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754964AbdACIv4 (ORCPT ); Tue, 3 Jan 2017 03:51:56 -0500 Received: from 172.24.1.36 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DXJ00404; Tue, 03 Jan 2017 16:51:11 +0800 (CST) Received: from s00293685.huawei.com (10.108.111.190) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Tue, 3 Jan 2017 16:51:00 +0800 From: Yunlong Song To: , , , , , CC: , , , Subject: [PATCH] f2fs: fix small discards when se->valid_blocks is zero Date: Tue, 3 Jan 2017 17:01:57 +0800 Message-ID: <1483434117-24427-1-git-send-email-yunlong.song@huawei.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 X-Originating-IP: [10.108.111.190] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.586B661F.0196, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 0ee9417122c091b482342696073b0f58 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 In the small discard case, when se->valid_blocks is zero, the add_discard_addrs will directly return without __add_discard_entry. This will cause the file delete have no small discard. The case is like this: 1. Allocate free 2M segment 2. Write a file (size n blocks < 512) in that 2M segment, se->valid_blocks = n 3. Delete that file, se->valid_blocks = 0, add_discard_addrs will return without sending any discard of that file, and forever due to cur_map[i] ^ ckpt_map[i] = 0 after that checkpoint Signed-off-by: Yunlong Song --- fs/f2fs/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 0738f48..8610f14 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -838,7 +838,7 @@ static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc) return; if (!force) { - if (!test_opt(sbi, DISCARD) || !se->valid_blocks || + if (!test_opt(sbi, DISCARD) || SM_I(sbi)->nr_discards >= SM_I(sbi)->max_discards) return; }