From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF78AC433DB for ; Wed, 24 Mar 2021 01:24:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A735619B2 for ; Wed, 24 Mar 2021 01:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234440AbhCXBXx (ORCPT ); Tue, 23 Mar 2021 21:23:53 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:14511 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234404AbhCXBXe (ORCPT ); Tue, 23 Mar 2021 21:23:34 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F4r646kJxzPlSH; Wed, 24 Mar 2021 09:21:00 +0800 (CST) Received: from [10.136.110.154] (10.136.110.154) by smtp.huawei.com (10.3.19.208) with Microsoft SMTP Server (TLS) id 14.3.498.0; Wed, 24 Mar 2021 09:23:29 +0800 Subject: Re: [PATCH] f2fs: fix to align to section for fallocate() on pinned file To: Jaegeuk Kim , Chao Yu CC: , References: <20210305095601.96591-1-yuchao0@huawei.com> From: Chao Yu Message-ID: Date: Wed, 24 Mar 2021 09:23:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.136.110.154] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/24 2:32, Jaegeuk Kim wrote: > On 03/23, Chao Yu wrote: >> On 2021/3/5 17:56, Chao Yu wrote: >>> Now, fallocate() on a pinned file only allocates blocks which aligns >>> to segment rather than section, so GC may try to migrate pinned file's >>> block, and after several times of failure, pinned file's block could >>> be migrated to other place, however user won't be aware of such >>> condition, and then old obsolete block address may be readed/written >>> incorrectly. >>> >>> To avoid such condition, let's try to allocate pinned file's blocks >>> with section alignment. >>> >>> Signed-off-by: Chao Yu >> >> Jaegeuk, >> >> Could you please check and apply below diff into original patch? >> >> --- >> fs/f2fs/file.c | 10 +++++----- >> 1 file changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index 236f3f69681a..24fa68fdcaa0 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -1648,13 +1648,13 @@ static int expand_inode_data(struct inode *inode, loff_t offset, >> return 0; >> >> if (f2fs_is_pinned_file(inode)) { >> - block_t len = (map.m_len >> sbi->log_blocks_per_seg) << >> - sbi->log_blocks_per_seg; >> + block_t sec_blks = BLKS_PER_SEC(sbi); >> + block_t len = rounddown(map.m_len, sec_blks); > > len is declared above, so let me rephrase this as well. Oh, right. > >> >> - if (map.m_len % sbi->blocks_per_seg) >> - len += sbi->blocks_per_seg; >> + if (map.m_len % sec_blks) >> + len += sec_blks; > > is this roundup()? More clean. > > Could you check this? > https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev&id=e1175f02291141bbd924fc578299305fcde35855 Looks good to me. :) Thanks, > >> >> - map.m_len = sbi->blocks_per_seg; >> + map.m_len = sec_blks; >> next_alloc: >> if (has_not_enough_free_secs(sbi, 0, >> GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) { >> -- >> 2.22.1 >> > . >