Message ID | 20231228143152.1543509-3-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028601dyb; Thu, 28 Dec 2023 06:33:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZONq48Y33EHqc+1HXnX8FF1lxF0Zh+/jsq8akJVo8kHb6KVe7WWbW7kEauvm686nzZeGz X-Received: by 2002:ac2:4882:0:b0:50e:39b3:d43e with SMTP id x2-20020ac24882000000b0050e39b3d43emr4027142lfc.66.1703773982307; Thu, 28 Dec 2023 06:33:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773982; cv=none; d=google.com; s=arc-20160816; b=o9O8XP1IcnL2zJTF4CTOfJo4W6DzZjShpZRra+0l5BiCipsTjdAP9T4j19j2eVuecj UaP0KNJ0qB4Nljl96xG+TT/YBG3lY2rq4NutRXzimlRogLnfr0mV2gSVlCOZt6RXizS5 wtJE+8pgjrNTx6yuev0vPijs7ygBbJYXtJtyNa1WNSn0kQlBWCqX7y4HpnM5jwlW3aC2 zVOWb2LwNnUfglia+Pyp4lHEVzu+96/OW/JphlcqIMnWGM7LMvAvxQoG/mpDKotm9EZ8 SGP3yM+HQz/m4l01c6BIjIGyJ9z9kwxL5UxqaccZY9nDccpSMu3/08Quy++RQviDbB7W 0Vnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KsSgDPeE3D2PWDe+9Cjxa1TXEgtZW4xW4czqHA4SKmM=; fh=2w0/+7CnNSrmHtbae1hR3pLuwOJRubjB5ynbCr7QyGo=; b=TVDOF+JfFmS7lvrMCzBpYkxq+aTdN+x4SUrfDoS58kXaJ6aMe+lP1hRQLZbzSE5o/3 dBi8ByUS7gfyn7QDEvaFXQcG+5DuLSinGVjRBetWpcFgpRyEcDtvPvrR1aErfPpgvohd NIdaBmbxcucIxWX3EQ8ELS4zcCj7N9Mv+B8MpFSw4bJEecxG2e5Q0tiLXeuuWCqC8oxC 6Y3m77rK+6UVLXj9fgqlWkLFUvxr9XhFGiwwvy/Q7A0hV6O6pGSt8lIrADM1CqMZJjtQ 8Kys1EcOOu7kvHMKcVBfIDUqA+m6pt0QudMK11J9DgVORyIjzGDzJV/M7l03oyqLzN1W UlRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UmvBck; spf=pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id vz16-20020a17090704d000b00a234530a56csi6353453ejb.393.2023.12.28.06.33.02 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:33:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UmvBck; spf=pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E27211F233EB for <ouuuleilei@gmail.com>; Thu, 28 Dec 2023 14:33:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51D93107B4; Thu, 28 Dec 2023 14:32:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r3UmvBck" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F69101DE for <linux-kernel@vger.kernel.org>; Thu, 28 Dec 2023 14:32:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90591C433C9; Thu, 28 Dec 2023 14:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773928; bh=PlqlUk5bd+3fk4WKcXVwPKIXLZLKGpamNP0JtbEVizc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3UmvBckldbFBMtcyi3xBTx28VUw1mf8I7YeImoXPWLb1YsrbuwkMEUL8dHxnC/QH tUu+7M+5kN1T0M4IQWEo3M7Y31SJeeLGc4v5jIjFOLbTPH0LcGSA8fbhA57yX4bn2f vaIzuIfnzXCGIZoKJiqwpLSdjxsv86uofKZ6zMVLqFa1II3ycsn+HRNzIc+LI3tY8L PuQR6tWdMqErdbCa9J1nfYVRfE9OTooB4PYZO8hoXRRvie7f3FIJxJJcBH7hR+ANRD v2/3CMDmlDZy4h6wHZhIa73FxBCl0vCtSSQV8y6ppQlUyHejH+382f2nMTCExoHAhP inT/5EXcK82aA== From: Chao Yu <chao@kernel.org> To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sheng Yong <shengyong@oppo.com>, Chao Yu <chao@kernel.org> Subject: [PATCH v3 3/6] f2fs: compress: fix to check unreleased compressed cluster Date: Thu, 28 Dec 2023 22:31:49 +0800 Message-Id: <20231228143152.1543509-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536507444678393 X-GMAIL-MSGID: 1786536507444678393 |
Series |
[v3,1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP
|
|
Commit Message
Chao Yu
Dec. 28, 2023, 2:31 p.m. UTC
From: Sheng Yong <shengyong@oppo.com> Compressed cluster may not be released due to we can fail in release_compress_blocks(), fix to handle reserved compressed cluster correctly in reserve_compress_blocks(). Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Sheng Yong <shengyong@oppo.com> Signed-off-by: Chao Yu <chao@kernel.org> --- fs/f2fs/file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Comments
On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> wrote: > > From: Sheng Yong <shengyong@oppo.com> > > Compressed cluster may not be released due to we can fail in > release_compress_blocks(), fix to handle reserved compressed > cluster correctly in reserve_compress_blocks(). > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Sheng Yong <shengyong@oppo.com> > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fs/f2fs/file.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 026d05a7edd8..782ae3be48f6 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > goto next; > } > > + /* > + * compressed cluster was not released due to > + * it fails in release_compress_blocks(). > + */ > + if (blkaddr == NEW_ADDR) { > + compr_blocks++; > + continue; > + } > + > if (__is_valid_data_blkaddr(blkaddr)) { > compr_blocks++; > continue; How about merging two conditions like "blkaddr == NEW_ADDR || __is_valid_data_blkaddr(blkaddr)"? > @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > } > > reserved = cluster_size - compr_blocks; > + if (!reserved) > + goto next; > + How can the reserved variable be zero? > ret = inc_valid_block_count(sbi, dn->inode, &reserved); > if (ret) > return ret; > -- > 2.40.1 > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On 2024/1/11 9:18, Daeho Jeong wrote: > On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> wrote: >> >> From: Sheng Yong <shengyong@oppo.com> >> >> Compressed cluster may not be released due to we can fail in >> release_compress_blocks(), fix to handle reserved compressed >> cluster correctly in reserve_compress_blocks(). >> >> Fixes: 4c8ff7095bef ("f2fs: support data compression") >> Signed-off-by: Sheng Yong <shengyong@oppo.com> >> Signed-off-by: Chao Yu <chao@kernel.org> >> --- >> fs/f2fs/file.c | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index 026d05a7edd8..782ae3be48f6 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) >> goto next; >> } >> >> + /* >> + * compressed cluster was not released due to >> + * it fails in release_compress_blocks(). >> + */ >> + if (blkaddr == NEW_ADDR) { >> + compr_blocks++; >> + continue; >> + } >> + >> if (__is_valid_data_blkaddr(blkaddr)) { >> compr_blocks++; >> continue; > > How about merging two conditions like "blkaddr == NEW_ADDR || > __is_valid_data_blkaddr(blkaddr)"? Oh, sure. > >> @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) >> } >> >> reserved = cluster_size - compr_blocks; >> + if (!reserved) >> + goto next; >> + > > How can the reserved variable be zero? I guess it can happen if a cluster was not released during release_compress_blocks(), then all blocks in the cluster should has been reserved, so, in this round of reserving, it needs to skip reserve blocks, right? Thanks, > >> ret = inc_valid_block_count(sbi, dn->inode, &reserved); >> if (ret) >> return ret; >> -- >> 2.40.1 >> >> >> >> _______________________________________________ >> Linux-f2fs-devel mailing list >> Linux-f2fs-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On Wed, Jan 10, 2024 at 5:33 PM Chao Yu <chao@kernel.org> wrote: > > On 2024/1/11 9:18, Daeho Jeong wrote: > > On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> wrote: > >> > >> From: Sheng Yong <shengyong@oppo.com> > >> > >> Compressed cluster may not be released due to we can fail in > >> release_compress_blocks(), fix to handle reserved compressed > >> cluster correctly in reserve_compress_blocks(). > >> > >> Fixes: 4c8ff7095bef ("f2fs: support data compression") > >> Signed-off-by: Sheng Yong <shengyong@oppo.com> > >> Signed-off-by: Chao Yu <chao@kernel.org> > >> --- > >> fs/f2fs/file.c | 12 ++++++++++++ > >> 1 file changed, 12 insertions(+) > >> > >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > >> index 026d05a7edd8..782ae3be48f6 100644 > >> --- a/fs/f2fs/file.c > >> +++ b/fs/f2fs/file.c > >> @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > >> goto next; > >> } > >> > >> + /* > >> + * compressed cluster was not released due to > >> + * it fails in release_compress_blocks(). > >> + */ > >> + if (blkaddr == NEW_ADDR) { > >> + compr_blocks++; > >> + continue; > >> + } > >> + > >> if (__is_valid_data_blkaddr(blkaddr)) { > >> compr_blocks++; > >> continue; > > > > How about merging two conditions like "blkaddr == NEW_ADDR || > > __is_valid_data_blkaddr(blkaddr)"? > > Oh, sure. > > > > >> @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > >> } > >> > >> reserved = cluster_size - compr_blocks; > >> + if (!reserved) > >> + goto next; > >> + > > > > How can the reserved variable be zero? > > I guess it can happen if a cluster was not released during > release_compress_blocks(), then all blocks in the cluster should > has been reserved, so, in this round of reserving, it needs to skip > reserve blocks, right? Let's assume cluster_size is 4. How can compr_blocks be 4? if (i == 0) { if (blkaddr == COMPRESS_ADDR) continue; dn->ofs_in_node += cluster_size; goto next; } We skip the block having COMPRESS_ADDR when counting compr_blocks. So, the maximum value of compr_blocks should be 3, right? > > Thanks, > > > > >> ret = inc_valid_block_count(sbi, dn->inode, &reserved); > >> if (ret) > >> return ret; > >> -- > >> 2.40.1 > >> > >> > >> > >> _______________________________________________ > >> Linux-f2fs-devel mailing list > >> Linux-f2fs-devel@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On 2024/1/12 1:15, Daeho Jeong wrote: > On Wed, Jan 10, 2024 at 5:33 PM Chao Yu <chao@kernel.org> wrote: >> >> On 2024/1/11 9:18, Daeho Jeong wrote: >>> On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> wrote: >>>> >>>> From: Sheng Yong <shengyong@oppo.com> >>>> >>>> Compressed cluster may not be released due to we can fail in >>>> release_compress_blocks(), fix to handle reserved compressed >>>> cluster correctly in reserve_compress_blocks(). >>>> >>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>> Signed-off-by: Sheng Yong <shengyong@oppo.com> >>>> Signed-off-by: Chao Yu <chao@kernel.org> >>>> --- >>>> fs/f2fs/file.c | 12 ++++++++++++ >>>> 1 file changed, 12 insertions(+) >>>> >>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>> index 026d05a7edd8..782ae3be48f6 100644 >>>> --- a/fs/f2fs/file.c >>>> +++ b/fs/f2fs/file.c >>>> @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) >>>> goto next; >>>> } >>>> >>>> + /* >>>> + * compressed cluster was not released due to >>>> + * it fails in release_compress_blocks(). >>>> + */ >>>> + if (blkaddr == NEW_ADDR) { >>>> + compr_blocks++; >>>> + continue; >>>> + } >>>> + >>>> if (__is_valid_data_blkaddr(blkaddr)) { >>>> compr_blocks++; >>>> continue; >>> >>> How about merging two conditions like "blkaddr == NEW_ADDR || >>> __is_valid_data_blkaddr(blkaddr)"? >> >> Oh, sure. >> >>> >>>> @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) >>>> } >>>> >>>> reserved = cluster_size - compr_blocks; >>>> + if (!reserved) >>>> + goto next; >>>> + >>> >>> How can the reserved variable be zero? >> >> I guess it can happen if a cluster was not released during >> release_compress_blocks(), then all blocks in the cluster should >> has been reserved, so, in this round of reserving, it needs to skip >> reserve blocks, right? > > Let's assume cluster_size is 4. How can compr_blocks be 4? > > if (i == 0) { > if (blkaddr == COMPRESS_ADDR) > continue; > dn->ofs_in_node += cluster_size; > goto next; > } > > We skip the block having COMPRESS_ADDR when counting compr_blocks. > So, the maximum value of compr_blocks should be 3, right? Ah, got it, and I think you're right. Should fix the condition as below? /* for the case all blocks in cluster were reserved */ if (reserved == 1) goto next; Thanks, > >> >> Thanks, >> >>> >>>> ret = inc_valid_block_count(sbi, dn->inode, &reserved); >>>> if (ret) >>>> return ret; >>>> -- >>>> 2.40.1 >>>> >>>> >>>> >>>> _______________________________________________ >>>> Linux-f2fs-devel mailing list >>>> Linux-f2fs-devel@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On Thu, Jan 11, 2024 at 5:06 PM Chao Yu <chao@kernel.org> wrote: > > On 2024/1/12 1:15, Daeho Jeong wrote: > > On Wed, Jan 10, 2024 at 5:33 PM Chao Yu <chao@kernel.org> wrote: > >> > >> On 2024/1/11 9:18, Daeho Jeong wrote: > >>> On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> wrote: > >>>> > >>>> From: Sheng Yong <shengyong@oppo.com> > >>>> > >>>> Compressed cluster may not be released due to we can fail in > >>>> release_compress_blocks(), fix to handle reserved compressed > >>>> cluster correctly in reserve_compress_blocks(). > >>>> > >>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") > >>>> Signed-off-by: Sheng Yong <shengyong@oppo.com> > >>>> Signed-off-by: Chao Yu <chao@kernel.org> > >>>> --- > >>>> fs/f2fs/file.c | 12 ++++++++++++ > >>>> 1 file changed, 12 insertions(+) > >>>> > >>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > >>>> index 026d05a7edd8..782ae3be48f6 100644 > >>>> --- a/fs/f2fs/file.c > >>>> +++ b/fs/f2fs/file.c > >>>> @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > >>>> goto next; > >>>> } > >>>> > >>>> + /* > >>>> + * compressed cluster was not released due to > >>>> + * it fails in release_compress_blocks(). > >>>> + */ > >>>> + if (blkaddr == NEW_ADDR) { > >>>> + compr_blocks++; > >>>> + continue; > >>>> + } > >>>> + > >>>> if (__is_valid_data_blkaddr(blkaddr)) { > >>>> compr_blocks++; > >>>> continue; > >>> > >>> How about merging two conditions like "blkaddr == NEW_ADDR || > >>> __is_valid_data_blkaddr(blkaddr)"? > >> > >> Oh, sure. > >> > >>> > >>>> @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > >>>> } > >>>> > >>>> reserved = cluster_size - compr_blocks; > >>>> + if (!reserved) > >>>> + goto next; > >>>> + > >>> > >>> How can the reserved variable be zero? > >> > >> I guess it can happen if a cluster was not released during > >> release_compress_blocks(), then all blocks in the cluster should > >> has been reserved, so, in this round of reserving, it needs to skip > >> reserve blocks, right? > > > > Let's assume cluster_size is 4. How can compr_blocks be 4? > > > > if (i == 0) { > > if (blkaddr == COMPRESS_ADDR) > > continue; > > dn->ofs_in_node += cluster_size; > > goto next; > > } > > > > We skip the block having COMPRESS_ADDR when counting compr_blocks. > > So, the maximum value of compr_blocks should be 3, right? > > Ah, got it, and I think you're right. > > Should fix the condition as below? > > /* for the case all blocks in cluster were reserved */ > if (reserved == 1) > goto next; It looks good to me. > > Thanks, > > > > >> > >> Thanks, > >> > >>> > >>>> ret = inc_valid_block_count(sbi, dn->inode, &reserved); > >>>> if (ret) > >>>> return ret; > >>>> -- > >>>> 2.40.1 > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> Linux-f2fs-devel mailing list > >>>> Linux-f2fs-devel@lists.sourceforge.net > >>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 026d05a7edd8..782ae3be48f6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) goto next; } + /* + * compressed cluster was not released due to + * it fails in release_compress_blocks(). + */ + if (blkaddr == NEW_ADDR) { + compr_blocks++; + continue; + } + if (__is_valid_data_blkaddr(blkaddr)) { compr_blocks++; continue; @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } reserved = cluster_size - compr_blocks; + if (!reserved) + goto next; + ret = inc_valid_block_count(sbi, dn->inode, &reserved); if (ret) return ret;