Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp165967pxf; Wed, 24 Mar 2021 01:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/baYfd03jX0ssfvXEad7JZk8IfuAzMLSpg422/AQzh2M0XDWu17fRbYKPXzuUkWaouiMp X-Received: by 2002:a17:906:4d85:: with SMTP id s5mr2491232eju.43.1616576307739; Wed, 24 Mar 2021 01:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616576307; cv=none; d=google.com; s=arc-20160816; b=0ub0y4e6BE7JR+iTNR4FOAbwY7eZvcQe0uof+EVq/UKRyr/AM4yPQlAM7143w6ZOCl EJJDr6UzDJjaXnyMHVu/9qUaFli/B/Rz+xg7kvZCRuqB/jlKMv1cAxiY77JsE9hV6Iw1 KCYTUxO/cdaFVja1x1Z1UzKmu4hLaPqxglP2RsWvnk39FCbpCD5KhPxdQcg2AM8/NNQ0 blYZyEO6D4FUIA1skRl4c2bHFTCmoavpyjPYd0Fh+ojSAc0iwJ91++2gsjhU+u7J1nZl TL2IAE1e7KmIeW9Hb6cSo9NG/s0K7zLxIqr6qOoQFIqf9EDU6timHm8vXUAfqFswpsIQ pO/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=keEeRPK/Vuep/4VY0oJCmIK8EKrQvQjhGKXtZ94R9cA=; b=mxa/3nx311CpEUZhBjmxolQk8xngRu983opp8txGMjWdkiS/zqHAHLqc2T9+bw7r1c V/XCm7k4y6gkvrSwffhBb0khQl6fbSUAk8HKWYmI4JLzjwQOynGd+UbhTZsFYaIG3lHa RF7whZz3ocU2PpZkyni1FMGAzfSJ8YJoYvnkXQ6eOHCgPWaMkPKIAhXE2iDcRArPCGXg 1DCY6y98Am/SkS2HJDJ98KM3C8gbhL3/Dg+ygrDQu8RPFG4+NbMTQDQ+KIR0F9VcMiFn uZg7lDOc2u3PrzwvaMP3zjEaaHI87glSklh64P5+xqierFj4jt7vS32rFNfgeU0InIj8 5bBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si1193425ejb.289.2021.03.24.01.58.04; Wed, 24 Mar 2021 01:58:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234202AbhCXBXw (ORCPT + 99 others); Tue, 23 Mar 2021 21:23:52 -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 >> > . >