Message ID | 20231220135934.3471407-1-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-7011-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2662723dyi; Wed, 20 Dec 2023 06:11:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0PYDJppmQU9KaVAsAZuVBoOpMERPtNxVyQRCWcUSuHmoPvu4cj4QI6zYe/AketkVEtuzt X-Received: by 2002:ac2:4211:0:b0:50e:54be:150b with SMTP id y17-20020ac24211000000b0050e54be150bmr390846lfh.122.1703081463270; Wed, 20 Dec 2023 06:11:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703081463; cv=none; d=google.com; s=arc-20160816; b=DQ//4j0TqeNVCF2qDZ0jXHwESMBpfIvIpFmQwFSgtohesU1cSZObscOVq//Uw/rgE8 KY4Pt4K3h5pBgYhdVjgPzb6kR1s+h4OZ7tdd+w/xlHa2zA0BW/dTTRsmOlZQkg/U1+WF Y3bz+6GWpWtRgwmuSoesphtfzLBIW/NCdMcTiBi2dKKp8kDVyEBd6XJzjPVTOGOBdIfx 6NfTjUH9qKotZjTvIeFStTZBUHNhUTkSYJGk6KOsJgXtuJwvY8CIpJAIwfHAeJ6m3cnF dX/LumRxfPOVI2QlWhx8OLvLLyGLYUFGFVOd/cSoF1NZoUngxbr+HBFhLuobPylA497W XkXw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=xscjI8hRCqb0TVF/ZPOmL17Fu99hTNWTrn2y8jLUfpo=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=HsENtSWLdhiTJa3SvISRobq6d3yjRU8kNd0IeDbC6ONTYR8HwyxnnhFwZpO3aTJgop ldSgPL87Sh2duzG6EOLgTLfa412EwUjWCpj0wmHX9xgJNGeeWfLUvK7YkW7x64WZ+grP ilOkfqeHYHXDENXSkZZl0QtTpFSFuZFf1qBEWQDgRd4xqmz2Jmo6fmRDvKGdYN/6n9VO Fkk8jADS0VRQt0bR53wktplRqzijfP8QgYRyQeNve8RIRbOVNtWiCf7LGVytkpvK8V7a D25sUNeb8yub3LRY3u6iZcayC+32itCFytkjRjE4oiTmO+nJcuT8RSDonC6pda3vF7jg L+Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LsflaQn/"; spf=pass (google.com: domain of linux-kernel+bounces-7011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7011-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 lr8-20020a170906fb8800b00a2353445209si3058673ejb.686.2023.12.20.06.11.03 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:11:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7011-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="LsflaQn/"; spf=pass (google.com: domain of linux-kernel+bounces-7011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7011-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 D53FF1F220C5 for <ouuuleilei@gmail.com>; Wed, 20 Dec 2023 14:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 105173B7B5; Wed, 20 Dec 2023 13:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LsflaQn/" 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 765A53A1B3 for <linux-kernel@vger.kernel.org>; Wed, 20 Dec 2023 13:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C1FAC433C9; Wed, 20 Dec 2023 13:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080781; bh=1NoN4vHX+F5B0WJZK8QqQakY9pc1N432/Yr899L6umA=; h=From:To:Cc:Subject:Date:From; b=LsflaQn/Rpi1r63bTcKQzLAw6EfRwK9cBsHYh2in+KK6g6cuNWDLwdAppjiihuRPE DUh1q6tb8kH/p+aNjHZGtKNGSH47k8IPkYzKP1KYu9+0v6RJW9cTl6gIw36PkVv7lw VcsmWYBHfZG++2ANDm7PwM6g65zOvG4hJTdrQnghgTb9b4WYEfLk3Qu0OhvwA43clV Av9IjNnnAYkKuVB9Mrhv/RPZ1MisWBUU3Mqe2X18y/hrGur6vgPHhJLLSAqG4yf/fk mAlr/bWMlcn5tyW61vmyqOfPqRrpT4HS2QuDhkI1ZzpaIhtg/qFQ/3qogGw6ItMCVg QFUKONcK8dPLA== From: Chao Yu <chao@kernel.org> To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org> Subject: [PATCH 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP Date: Wed, 20 Dec 2023 21:59:29 +0800 Message-Id: <20231220135934.3471407-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 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: 1785810348376268121 X-GMAIL-MSGID: 1785810348376268121 |
Series |
[1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP
|
|
Commit Message
Chao Yu
Dec. 20, 2023, 1:59 p.m. UTC
If data block in compressed cluster is not persisted with metadata
during checkpoint, after SPOR, the data may be corrupted, let's
guarantee to write compressed page by checkpoint.
Fixes: 4c8ff7095bef ("f2fs: support data compression")
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/compress.c | 3 ++-
fs/f2fs/data.c | 12 +++++++++---
fs/f2fs/f2fs.h | 3 ++-
3 files changed, 13 insertions(+), 5 deletions(-)
Comments
On 12/20, Chao Yu wrote: > If data block in compressed cluster is not persisted with metadata > during checkpoint, after SPOR, the data may be corrupted, let's > guarantee to write compressed page by checkpoint. > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fs/f2fs/compress.c | 3 ++- > fs/f2fs/data.c | 12 +++++++++--- > fs/f2fs/f2fs.h | 3 ++- > 3 files changed, 13 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 5b076329e9bf..1122db8cc0b0 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) > struct f2fs_sb_info *sbi = bio->bi_private; > struct compress_io_ctx *cic = > (struct compress_io_ctx *)page_private(page); > + enum count_type type = WB_DATA_TYPE(page); > int i; > > if (unlikely(bio->bi_status)) > @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) > > f2fs_compress_free_page(page); > > - dec_page_count(sbi, F2FS_WB_DATA); > + dec_page_count(sbi, type); > > if (atomic_dec_return(&cic->pending_pages)) > return; > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index d28c97282e68..6c72a6e86ba8 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) > bioset_exit(&f2fs_bioset); > } > > -static bool __is_cp_guaranteed(struct page *page) > +bool f2fs_is_cp_guaranteed(struct page *page) > { > struct address_space *mapping = page->mapping; > struct inode *inode; > @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) > return true; > > if (f2fs_is_compressed_page(page)) > - return false; > + return true; > if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || > page_private_gcing(page)) > return true; > @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); > struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; > struct page *bio_page; > + enum count_type type; > > f2fs_bug_on(sbi, is_read_io(fio->op)); > > @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > /* set submitted = true as a return value */ > fio->submitted = 1; > > - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); > + type = WB_DATA_TYPE(bio_page); > + /* override count type if page is compressed one */ > + if (fio->compressed_page) > + type = WB_DATA_TYPE(fio->compressed_page); Doesn't bio_page already point fio->compressed_page? > + > + inc_page_count(sbi, type); > > if (io->bio && > (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 76e9a8682e38..bcb3940ab5ba 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { > * f2fs monitors the number of several block types such as on-writeback, > * dirty dentry blocks, dirty node blocks, and dirty meta blocks. > */ > -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > enum count_type { > F2FS_DIRTY_DENTS, > F2FS_DIRTY_DATA, > @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); > */ > int __init f2fs_init_bioset(void); > void f2fs_destroy_bioset(void); > +bool f2fs_is_cp_guaranteed(struct page *page); > int f2fs_init_bio_entry_cache(void); > void f2fs_destroy_bio_entry_cache(void); > void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, > -- > 2.40.1
On 2023/12/27 5:02, Jaegeuk Kim wrote: > On 12/20, Chao Yu wrote: >> If data block in compressed cluster is not persisted with metadata >> during checkpoint, after SPOR, the data may be corrupted, let's >> guarantee to write compressed page by checkpoint. >> >> Fixes: 4c8ff7095bef ("f2fs: support data compression") >> Signed-off-by: Chao Yu <chao@kernel.org> >> --- >> fs/f2fs/compress.c | 3 ++- >> fs/f2fs/data.c | 12 +++++++++--- >> fs/f2fs/f2fs.h | 3 ++- >> 3 files changed, 13 insertions(+), 5 deletions(-) >> >> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c >> index 5b076329e9bf..1122db8cc0b0 100644 >> --- a/fs/f2fs/compress.c >> +++ b/fs/f2fs/compress.c >> @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) >> struct f2fs_sb_info *sbi = bio->bi_private; >> struct compress_io_ctx *cic = >> (struct compress_io_ctx *)page_private(page); >> + enum count_type type = WB_DATA_TYPE(page); >> int i; >> >> if (unlikely(bio->bi_status)) >> @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) >> >> f2fs_compress_free_page(page); >> >> - dec_page_count(sbi, F2FS_WB_DATA); >> + dec_page_count(sbi, type); >> >> if (atomic_dec_return(&cic->pending_pages)) >> return; >> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >> index d28c97282e68..6c72a6e86ba8 100644 >> --- a/fs/f2fs/data.c >> +++ b/fs/f2fs/data.c >> @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) >> bioset_exit(&f2fs_bioset); >> } >> >> -static bool __is_cp_guaranteed(struct page *page) >> +bool f2fs_is_cp_guaranteed(struct page *page) >> { >> struct address_space *mapping = page->mapping; >> struct inode *inode; >> @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) >> return true; >> >> if (f2fs_is_compressed_page(page)) >> - return false; >> + return true; >> if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || >> page_private_gcing(page)) >> return true; >> @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) >> enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); >> struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; >> struct page *bio_page; >> + enum count_type type; >> >> f2fs_bug_on(sbi, is_read_io(fio->op)); >> >> @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) >> /* set submitted = true as a return value */ >> fio->submitted = 1; >> >> - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); >> + type = WB_DATA_TYPE(bio_page); >> + /* override count type if page is compressed one */ >> + if (fio->compressed_page) >> + type = WB_DATA_TYPE(fio->compressed_page); > > Doesn't bio_page already point fio->compressed_page? Please check below codes, bio_page will point to fio->encrypted_page if both software encryption feature and compression feature are on, for this case, we still need to account F2FS_WB_CP_DATA. if (fio->encrypted_page) bio_page = fio->encrypted_page; else if (fio->compressed_page) bio_page = fio->compressed_page; else bio_page = fio->page; Thanks, > >> + >> + inc_page_count(sbi, type); >> >> if (io->bio && >> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >> index 76e9a8682e38..bcb3940ab5ba 100644 >> --- a/fs/f2fs/f2fs.h >> +++ b/fs/f2fs/f2fs.h >> @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { >> * f2fs monitors the number of several block types such as on-writeback, >> * dirty dentry blocks, dirty node blocks, and dirty meta blocks. >> */ >> -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) >> +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) >> enum count_type { >> F2FS_DIRTY_DENTS, >> F2FS_DIRTY_DATA, >> @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); >> */ >> int __init f2fs_init_bioset(void); >> void f2fs_destroy_bioset(void); >> +bool f2fs_is_cp_guaranteed(struct page *page); >> int f2fs_init_bio_entry_cache(void); >> void f2fs_destroy_bio_entry_cache(void); >> void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, >> -- >> 2.40.1
On 12/27, Chao Yu wrote: > On 2023/12/27 5:02, Jaegeuk Kim wrote: > > On 12/20, Chao Yu wrote: > > > If data block in compressed cluster is not persisted with metadata > > > during checkpoint, after SPOR, the data may be corrupted, let's > > > guarantee to write compressed page by checkpoint. > > > > > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > > > Signed-off-by: Chao Yu <chao@kernel.org> > > > --- > > > fs/f2fs/compress.c | 3 ++- > > > fs/f2fs/data.c | 12 +++++++++--- > > > fs/f2fs/f2fs.h | 3 ++- > > > 3 files changed, 13 insertions(+), 5 deletions(-) > > > > > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > > > index 5b076329e9bf..1122db8cc0b0 100644 > > > --- a/fs/f2fs/compress.c > > > +++ b/fs/f2fs/compress.c > > > @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) > > > struct f2fs_sb_info *sbi = bio->bi_private; > > > struct compress_io_ctx *cic = > > > (struct compress_io_ctx *)page_private(page); > > > + enum count_type type = WB_DATA_TYPE(page); > > > int i; > > > if (unlikely(bio->bi_status)) > > > @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) > > > f2fs_compress_free_page(page); > > > - dec_page_count(sbi, F2FS_WB_DATA); > > > + dec_page_count(sbi, type); > > > if (atomic_dec_return(&cic->pending_pages)) > > > return; > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > > > index d28c97282e68..6c72a6e86ba8 100644 > > > --- a/fs/f2fs/data.c > > > +++ b/fs/f2fs/data.c > > > @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) > > > bioset_exit(&f2fs_bioset); > > > } > > > -static bool __is_cp_guaranteed(struct page *page) > > > +bool f2fs_is_cp_guaranteed(struct page *page) > > > { > > > struct address_space *mapping = page->mapping; > > > struct inode *inode; > > > @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) > > > return true; > > > if (f2fs_is_compressed_page(page)) > > > - return false; > > > + return true; > > > if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || > > > page_private_gcing(page)) > > > return true; > > > @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > > > enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); > > > struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; > > > struct page *bio_page; > > > + enum count_type type; > > > f2fs_bug_on(sbi, is_read_io(fio->op)); > > > @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > > > /* set submitted = true as a return value */ > > > fio->submitted = 1; > > > - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); > > > + type = WB_DATA_TYPE(bio_page); > > > + /* override count type if page is compressed one */ > > > + if (fio->compressed_page) > > > + type = WB_DATA_TYPE(fio->compressed_page); > > > > Doesn't bio_page already point fio->compressed_page? > > Please check below codes, bio_page will point to fio->encrypted_page if > both software encryption feature and compression feature are on, for this > case, we still need to account F2FS_WB_CP_DATA. So, it seems you want to make F2FS_WB_CP_DATA regardless of conditions. Then, how about making this explictly instead of implicit condition check of the page? #define WB_DATA_TYPE(p, f) (f || __is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) inc_page_count(sbi, WB_DATA_TYPE(bio_page, bio_page == fio->compressed_page)); dec_page_count(sbi, WB_DATA_TYPE(page, f2fs_is_compressed_page(page))); > > if (fio->encrypted_page) > bio_page = fio->encrypted_page; > else if (fio->compressed_page) > bio_page = fio->compressed_page; > else > bio_page = fio->page; > > Thanks, > > > > > > + > > > + inc_page_count(sbi, type); > > > if (io->bio && > > > (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, > > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > > index 76e9a8682e38..bcb3940ab5ba 100644 > > > --- a/fs/f2fs/f2fs.h > > > +++ b/fs/f2fs/f2fs.h > > > @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { > > > * f2fs monitors the number of several block types such as on-writeback, > > > * dirty dentry blocks, dirty node blocks, and dirty meta blocks. > > > */ > > > -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > > > +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > > > enum count_type { > > > F2FS_DIRTY_DENTS, > > > F2FS_DIRTY_DATA, > > > @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); > > > */ > > > int __init f2fs_init_bioset(void); > > > void f2fs_destroy_bioset(void); > > > +bool f2fs_is_cp_guaranteed(struct page *page); > > > int f2fs_init_bio_entry_cache(void); > > > void f2fs_destroy_bio_entry_cache(void); > > > void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, > > > -- > > > 2.40.1
On 2023/12/28 6:55, Jaegeuk Kim wrote: > On 12/27, Chao Yu wrote: >> On 2023/12/27 5:02, Jaegeuk Kim wrote: >>> On 12/20, Chao Yu wrote: >>>> If data block in compressed cluster is not persisted with metadata >>>> during checkpoint, after SPOR, the data may be corrupted, let's >>>> guarantee to write compressed page by checkpoint. >>>> >>>> Fixes: 4c8ff7095bef ("f2fs: support data compression") >>>> Signed-off-by: Chao Yu <chao@kernel.org> >>>> --- >>>> fs/f2fs/compress.c | 3 ++- >>>> fs/f2fs/data.c | 12 +++++++++--- >>>> fs/f2fs/f2fs.h | 3 ++- >>>> 3 files changed, 13 insertions(+), 5 deletions(-) >>>> >>>> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c >>>> index 5b076329e9bf..1122db8cc0b0 100644 >>>> --- a/fs/f2fs/compress.c >>>> +++ b/fs/f2fs/compress.c >>>> @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) >>>> struct f2fs_sb_info *sbi = bio->bi_private; >>>> struct compress_io_ctx *cic = >>>> (struct compress_io_ctx *)page_private(page); >>>> + enum count_type type = WB_DATA_TYPE(page); >>>> int i; >>>> if (unlikely(bio->bi_status)) >>>> @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) >>>> f2fs_compress_free_page(page); >>>> - dec_page_count(sbi, F2FS_WB_DATA); >>>> + dec_page_count(sbi, type); >>>> if (atomic_dec_return(&cic->pending_pages)) >>>> return; >>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >>>> index d28c97282e68..6c72a6e86ba8 100644 >>>> --- a/fs/f2fs/data.c >>>> +++ b/fs/f2fs/data.c >>>> @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) >>>> bioset_exit(&f2fs_bioset); >>>> } >>>> -static bool __is_cp_guaranteed(struct page *page) >>>> +bool f2fs_is_cp_guaranteed(struct page *page) >>>> { >>>> struct address_space *mapping = page->mapping; >>>> struct inode *inode; >>>> @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) >>>> return true; >>>> if (f2fs_is_compressed_page(page)) >>>> - return false; >>>> + return true; >>>> if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || >>>> page_private_gcing(page)) >>>> return true; >>>> @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) >>>> enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); >>>> struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; >>>> struct page *bio_page; >>>> + enum count_type type; >>>> f2fs_bug_on(sbi, is_read_io(fio->op)); >>>> @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) >>>> /* set submitted = true as a return value */ >>>> fio->submitted = 1; >>>> - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); >>>> + type = WB_DATA_TYPE(bio_page); >>>> + /* override count type if page is compressed one */ >>>> + if (fio->compressed_page) >>>> + type = WB_DATA_TYPE(fio->compressed_page); >>> >>> Doesn't bio_page already point fio->compressed_page? >> >> Please check below codes, bio_page will point to fio->encrypted_page if >> both software encryption feature and compression feature are on, for this >> case, we still need to account F2FS_WB_CP_DATA. > > So, it seems you want to make F2FS_WB_CP_DATA regardless of conditions. Then, > how about making this explictly instead of implicit condition check of the page? > > #define WB_DATA_TYPE(p, f) (f || __is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > > inc_page_count(sbi, WB_DATA_TYPE(bio_page, bio_page == fio->compressed_page)); Do you mean inc_page_count(sbi, WB_DATA_TYPE(bio_page, fio->compressed_page));? If we use inc_page_count(sbi, WB_DATA_TYPE(bio_page, bio_page == fio->compressed_page)); if bio_page points to fio->encrypted_page, but fio->compressed_page is valid, then WB_DATA_TYPE() will return F2FS_WB_DATA, it doesn't as expect. Or am I missing something? Thanks, > > dec_page_count(sbi, WB_DATA_TYPE(page, f2fs_is_compressed_page(page))); > >> >> if (fio->encrypted_page) >> bio_page = fio->encrypted_page; >> else if (fio->compressed_page) >> bio_page = fio->compressed_page; >> else >> bio_page = fio->page; >> >> Thanks, >> >>> >>>> + >>>> + inc_page_count(sbi, type); >>>> if (io->bio && >>>> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, >>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>>> index 76e9a8682e38..bcb3940ab5ba 100644 >>>> --- a/fs/f2fs/f2fs.h >>>> +++ b/fs/f2fs/f2fs.h >>>> @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { >>>> * f2fs monitors the number of several block types such as on-writeback, >>>> * dirty dentry blocks, dirty node blocks, and dirty meta blocks. >>>> */ >>>> -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) >>>> +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) >>>> enum count_type { >>>> F2FS_DIRTY_DENTS, >>>> F2FS_DIRTY_DATA, >>>> @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); >>>> */ >>>> int __init f2fs_init_bioset(void); >>>> void f2fs_destroy_bioset(void); >>>> +bool f2fs_is_cp_guaranteed(struct page *page); >>>> int f2fs_init_bio_entry_cache(void); >>>> void f2fs_destroy_bio_entry_cache(void); >>>> void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, >>>> -- >>>> 2.40.1
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 5b076329e9bf..1122db8cc0b0 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1442,6 +1442,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) struct f2fs_sb_info *sbi = bio->bi_private; struct compress_io_ctx *cic = (struct compress_io_ctx *)page_private(page); + enum count_type type = WB_DATA_TYPE(page); int i; if (unlikely(bio->bi_status)) @@ -1449,7 +1450,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) f2fs_compress_free_page(page); - dec_page_count(sbi, F2FS_WB_DATA); + dec_page_count(sbi, type); if (atomic_dec_return(&cic->pending_pages)) return; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d28c97282e68..6c72a6e86ba8 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) bioset_exit(&f2fs_bioset); } -static bool __is_cp_guaranteed(struct page *page) +bool f2fs_is_cp_guaranteed(struct page *page) { struct address_space *mapping = page->mapping; struct inode *inode; @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) return true; if (f2fs_is_compressed_page(page)) - return false; + return true; if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || page_private_gcing(page)) return true; @@ -1007,6 +1007,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; struct page *bio_page; + enum count_type type; f2fs_bug_on(sbi, is_read_io(fio->op)); @@ -1046,7 +1047,12 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) /* set submitted = true as a return value */ fio->submitted = 1; - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); + type = WB_DATA_TYPE(bio_page); + /* override count type if page is compressed one */ + if (fio->compressed_page) + type = WB_DATA_TYPE(fio->compressed_page); + + inc_page_count(sbi, type); if (io->bio && (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 76e9a8682e38..bcb3940ab5ba 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1092,7 +1092,7 @@ struct f2fs_sm_info { * f2fs monitors the number of several block types such as on-writeback, * dirty dentry blocks, dirty node blocks, and dirty meta blocks. */ -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) +#define WB_DATA_TYPE(p) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) enum count_type { F2FS_DIRTY_DENTS, F2FS_DIRTY_DATA, @@ -3824,6 +3824,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); */ int __init f2fs_init_bioset(void); void f2fs_destroy_bioset(void); +bool f2fs_is_cp_guaranteed(struct page *page); int f2fs_init_bio_entry_cache(void); void f2fs_destroy_bio_entry_cache(void); void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,