Message ID | 20231228143152.1543509-1-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028277dyb; Thu, 28 Dec 2023 06:32:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKe3ZKiKKJqTQSKVuyCagpfX0qmXrBCqa1n0cFK9twYK3r9Thc+tUryvsxBz18+emq5oRn X-Received: by 2002:a05:622a:1043:b0:427:fb2b:8386 with SMTP id f3-20020a05622a104300b00427fb2b8386mr934518qte.99.1703773953038; Thu, 28 Dec 2023 06:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773953; cv=none; d=google.com; s=arc-20160816; b=PpgkWZGcaEjPMEdgLxCItV3dAAccNPHv21S6Bn+vdY+kqPjcYTV7dOarmKOB0c3pix Fb6idy7dlmuDfGTWMsTcMGo31LmdNXZy2UcZXASh2lqrq2nq5x0JZI8VuAeeooY8uZjb gfuEslnPr9ozS6ytxZRupCeX2zkD4xZexbqvi7fb92LOjUTJ8/b823aG7747moDORPDj M4cpjC7Dru4xqI4JoB6hfeXkLxMx3H8OlOc2D8R3L99db1A0w46U0E3Xe/3yis+fEJF0 6U9uRjSisHRmpXtCdNq0jxVop4fE9Acsg1XawvHXVw5RvIqgPQLHfPoq5atsQlXEUDjN 8E+g== 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=vPmh+CaS4FPJva8LA9C/gsUBD6xjJSAL5DH+nN3NUa8=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=DO7hS+hM8n4BZsxo+To9k6eHn4KudB8Qnsenxe3pSYXDOVBPkxwL6yHlMs/ZPagvlk ys0VX7izJYYyZzXZea7uTkA2zN55GwrQpYOF9mbTjHEnu+4WVYJnchkeOw0ROdOx2IEN 3RIPQwW3TWWhL/E4S1QdVO+UApL59FAi34hRZ6baz87ouiGV0F3Xtv+834ZVy0myhXwx iXZ1vpSNAsOgsvHKIuUOCp5fCHYugafZD60ETGhqK6Gl19OjuZqLgHC38xwgYlbstHXI db5VPQOgP3QjRlerv8OMTmrH0jI4VqSlX15SVtI5qae9kcftdmYub8yjXo0ecZqUeUbn IWQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MCLXEq5O; spf=pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e20-20020ac84e54000000b00427e936d13bsi4360920qtw.558.2023.12.28.06.32.32 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:32:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MCLXEq5O; spf=pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12702-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BED871C21C74 for <ouuuleilei@gmail.com>; Thu, 28 Dec 2023 14:32:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 352FAF9D1; Thu, 28 Dec 2023 14:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MCLXEq5O" 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 8D6BAE54C for <linux-kernel@vger.kernel.org>; Thu, 28 Dec 2023 14:32:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B96FC433C7; Thu, 28 Dec 2023 14:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773924; bh=9bgjtozDzWABSz5MpQDd5yOqAUr2mxUTvlK3pdYj7L8=; h=From:To:Cc:Subject:Date:From; b=MCLXEq5O89CRbk4jUqbDm2omlafRC6JTlg9vTcyDq6vLRBP3dpI9QgRtGvnIWNG4v 8J0hxmFQC3cSQyR1IIvWWdpCRuWAfa5Vg35cD82kZTumr3EtHIsg3XGjhC5qmWlpk3 bZy5U5nXuqVdB2+7/Kk/FYYDt3EAmJzJluGoupnrvrk2PJRVNlTqO+5aNIKfN0d2wT 2YBb4wcHt7+vtjkA9ihFzlL+JhHT8AbeOJT4blGyuAH2siqJCQPrjKwREbt4g2Xr3o o27PWy9GvTg/OjyqfwJU8cblWTyPOna1+fuzIfacQmVzACfHYBr7dc2T69M1vv3npl PwyTFH5EjzI3g== 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 v3 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP Date: Thu, 28 Dec 2023 22:31:47 +0800 Message-Id: <20231228143152.1543509-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: 1786536476981084621 |
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
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>
---
v3:
- treat compressed page as CP guaranteed data explictly.
fs/f2fs/compress.c | 4 +++-
fs/f2fs/data.c | 17 +++++++++--------
fs/f2fs/f2fs.h | 4 +++-
3 files changed, 15 insertions(+), 10 deletions(-)
Comments
On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> 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> > --- > v3: > - treat compressed page as CP guaranteed data explictly. > fs/f2fs/compress.c | 4 +++- > fs/f2fs/data.c | 17 +++++++++-------- > fs/f2fs/f2fs.h | 4 +++- > 3 files changed, 15 insertions(+), 10 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index c5a4364c4482..9940b7886e5d 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1418,6 +1418,8 @@ 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, > + f2fs_is_compressed_page(page)); > int i; > > if (unlikely(bio->bi_status)) > @@ -1425,7 +1427,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 dce8defdf4c7..81f9e2cc49e2 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; > @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) > S_ISDIR(inode->i_mode)) > return true; > > - if (f2fs_is_compressed_page(page)) > - return false; Out of curiosity, why don't we simply change the above to "return true"? > if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || > page_private_gcing(page)) > return true; > @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) > > bio_for_each_segment_all(bvec, bio, iter_all) { > struct page *page = bvec->bv_page; > - enum count_type type = WB_DATA_TYPE(page); > + enum count_type type = WB_DATA_TYPE(page, false); > > if (page_private_dummy(page)) { > clear_page_private_dummy(page); > @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) > wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > > inc_page_count(fio->sbi, is_read_io(fio->op) ? > - __read_io_type(page) : WB_DATA_TYPE(fio->page)); > + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); > > if (is_read_io(bio_op(bio))) > f2fs_submit_read_bio(fio->sbi, bio, fio->type); > @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) > if (fio->io_wbc) > wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > > - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); > + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); > > *fio->last_block = fio->new_blkaddr; > *fio->bio = bio; > @@ -1007,6 +1005,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 +1045,8 @@ 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, fio->compressed_page); > + inc_page_count(sbi, type); > > if (io->bio && > (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, > @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > if (F2FS_IO_ALIGNED(sbi) && > (fio->type == DATA || fio->type == NODE) && > fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { > - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); > + dec_page_count(sbi, WB_DATA_TYPE(bio_page, > + fio->compressed_page)); > fio->retry = 1; > goto skip; > } > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 65294e3b0bef..50f3d546ded8 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1080,7 +1080,8 @@ 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, f) \ > + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > enum count_type { > F2FS_DIRTY_DENTS, > F2FS_DIRTY_DATA, > @@ -3804,6 +3805,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 > > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On 2024/1/11 8:55, Daeho Jeong wrote: > On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> 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> >> --- >> v3: >> - treat compressed page as CP guaranteed data explictly. >> fs/f2fs/compress.c | 4 +++- >> fs/f2fs/data.c | 17 +++++++++-------- >> fs/f2fs/f2fs.h | 4 +++- >> 3 files changed, 15 insertions(+), 10 deletions(-) >> >> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c >> index c5a4364c4482..9940b7886e5d 100644 >> --- a/fs/f2fs/compress.c >> +++ b/fs/f2fs/compress.c >> @@ -1418,6 +1418,8 @@ 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, >> + f2fs_is_compressed_page(page)); >> int i; >> >> if (unlikely(bio->bi_status)) >> @@ -1425,7 +1427,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 dce8defdf4c7..81f9e2cc49e2 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; >> @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) >> S_ISDIR(inode->i_mode)) >> return true; >> >> - if (f2fs_is_compressed_page(page)) >> - return false; > > Out of curiosity, why don't we simply change the above to "return true"? Daeho, I used the implementation, please check v1 and related comments from Jaegeuk and me, let me know if that was not clear enough. :) https://lore.kernel.org/linux-f2fs-devel/aae654e7-8a7e-478d-9f5a-65807a0e0343@kernel.org/ > >> if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || >> page_private_gcing(page)) >> return true; >> @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) >> >> bio_for_each_segment_all(bvec, bio, iter_all) { >> struct page *page = bvec->bv_page; >> - enum count_type type = WB_DATA_TYPE(page); >> + enum count_type type = WB_DATA_TYPE(page, false); >> >> if (page_private_dummy(page)) { >> clear_page_private_dummy(page); >> @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); >> >> inc_page_count(fio->sbi, is_read_io(fio->op) ? >> - __read_io_type(page) : WB_DATA_TYPE(fio->page)); >> + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); >> >> if (is_read_io(bio_op(bio))) >> f2fs_submit_read_bio(fio->sbi, bio, fio->type); >> @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) >> if (fio->io_wbc) >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); >> >> - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); >> + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); >> >> *fio->last_block = fio->new_blkaddr; >> *fio->bio = bio; >> @@ -1007,6 +1005,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 +1045,8 @@ 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, fio->compressed_page); >> + inc_page_count(sbi, type); >> >> if (io->bio && >> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, >> @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) >> if (F2FS_IO_ALIGNED(sbi) && >> (fio->type == DATA || fio->type == NODE) && >> fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { >> - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); >> + dec_page_count(sbi, WB_DATA_TYPE(bio_page, >> + fio->compressed_page)); >> fio->retry = 1; >> goto skip; >> } >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >> index 65294e3b0bef..50f3d546ded8 100644 >> --- a/fs/f2fs/f2fs.h >> +++ b/fs/f2fs/f2fs.h >> @@ -1080,7 +1080,8 @@ 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, f) \ >> + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) >> enum count_type { >> F2FS_DIRTY_DENTS, >> F2FS_DIRTY_DATA, >> @@ -3804,6 +3805,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 >> >> >> >> _______________________________________________ >> 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:26 PM Chao Yu <chao@kernel.org> wrote: > > On 2024/1/11 8:55, Daeho Jeong wrote: > > On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> 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> > >> --- > >> v3: > >> - treat compressed page as CP guaranteed data explictly. > >> fs/f2fs/compress.c | 4 +++- > >> fs/f2fs/data.c | 17 +++++++++-------- > >> fs/f2fs/f2fs.h | 4 +++- > >> 3 files changed, 15 insertions(+), 10 deletions(-) > >> > >> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > >> index c5a4364c4482..9940b7886e5d 100644 > >> --- a/fs/f2fs/compress.c > >> +++ b/fs/f2fs/compress.c > >> @@ -1418,6 +1418,8 @@ 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, > >> + f2fs_is_compressed_page(page)); > >> int i; > >> > >> if (unlikely(bio->bi_status)) > >> @@ -1425,7 +1427,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 dce8defdf4c7..81f9e2cc49e2 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; > >> @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) > >> S_ISDIR(inode->i_mode)) > >> return true; > >> > >> - if (f2fs_is_compressed_page(page)) > >> - return false; > > > > Out of curiosity, why don't we simply change the above to "return true"? > > Daeho, > > I used the implementation, please check v1 and related comments > from Jaegeuk and me, let me know if that was not clear enough. :) > > https://lore.kernel.org/linux-f2fs-devel/aae654e7-8a7e-478d-9f5a-65807a0e0343@kernel.org/ Oh, I missed it. Sorry~ > > > > >> if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || > >> page_private_gcing(page)) > >> return true; > >> @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) > >> > >> bio_for_each_segment_all(bvec, bio, iter_all) { > >> struct page *page = bvec->bv_page; > >> - enum count_type type = WB_DATA_TYPE(page); > >> + enum count_type type = WB_DATA_TYPE(page, false); > >> > >> if (page_private_dummy(page)) { > >> clear_page_private_dummy(page); > >> @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) > >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > >> > >> inc_page_count(fio->sbi, is_read_io(fio->op) ? > >> - __read_io_type(page) : WB_DATA_TYPE(fio->page)); > >> + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); > >> > >> if (is_read_io(bio_op(bio))) > >> f2fs_submit_read_bio(fio->sbi, bio, fio->type); > >> @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) > >> if (fio->io_wbc) > >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > >> > >> - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); > >> + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); > >> > >> *fio->last_block = fio->new_blkaddr; > >> *fio->bio = bio; > >> @@ -1007,6 +1005,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 +1045,8 @@ 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, fio->compressed_page); > >> + inc_page_count(sbi, type); > >> > >> if (io->bio && > >> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, > >> @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > >> if (F2FS_IO_ALIGNED(sbi) && > >> (fio->type == DATA || fio->type == NODE) && > >> fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { > >> - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); > >> + dec_page_count(sbi, WB_DATA_TYPE(bio_page, > >> + fio->compressed_page)); > >> fio->retry = 1; > >> goto skip; > >> } > >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > >> index 65294e3b0bef..50f3d546ded8 100644 > >> --- a/fs/f2fs/f2fs.h > >> +++ b/fs/f2fs/f2fs.h > >> @@ -1080,7 +1080,8 @@ 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, f) \ > >> + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > >> enum count_type { > >> F2FS_DIRTY_DENTS, > >> F2FS_DIRTY_DATA, > >> @@ -3804,6 +3805,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 > >> > >> > >> > >> _______________________________________________ > >> Linux-f2fs-devel mailing list > >> Linux-f2fs-devel@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by: Daeho Jeong <daehojeong@google.com> On Thu, Jan 11, 2024 at 9:17 AM Daeho Jeong <daeho43@gmail.com> wrote: > > On Wed, Jan 10, 2024 at 5:26 PM Chao Yu <chao@kernel.org> wrote: > > > > On 2024/1/11 8:55, Daeho Jeong wrote: > > > On Thu, Dec 28, 2023 at 6:33 AM Chao Yu <chao@kernel.org> 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> > > >> --- > > >> v3: > > >> - treat compressed page as CP guaranteed data explictly. > > >> fs/f2fs/compress.c | 4 +++- > > >> fs/f2fs/data.c | 17 +++++++++-------- > > >> fs/f2fs/f2fs.h | 4 +++- > > >> 3 files changed, 15 insertions(+), 10 deletions(-) > > >> > > >> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > > >> index c5a4364c4482..9940b7886e5d 100644 > > >> --- a/fs/f2fs/compress.c > > >> +++ b/fs/f2fs/compress.c > > >> @@ -1418,6 +1418,8 @@ 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, > > >> + f2fs_is_compressed_page(page)); > > >> int i; > > >> > > >> if (unlikely(bio->bi_status)) > > >> @@ -1425,7 +1427,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 dce8defdf4c7..81f9e2cc49e2 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; > > >> @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) > > >> S_ISDIR(inode->i_mode)) > > >> return true; > > >> > > >> - if (f2fs_is_compressed_page(page)) > > >> - return false; > > > > > > Out of curiosity, why don't we simply change the above to "return true"? > > > > Daeho, > > > > I used the implementation, please check v1 and related comments > > from Jaegeuk and me, let me know if that was not clear enough. :) > > > > https://lore.kernel.org/linux-f2fs-devel/aae654e7-8a7e-478d-9f5a-65807a0e0343@kernel.org/ > > Oh, I missed it. Sorry~ > > > > > > > > >> if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || > > >> page_private_gcing(page)) > > >> return true; > > >> @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) > > >> > > >> bio_for_each_segment_all(bvec, bio, iter_all) { > > >> struct page *page = bvec->bv_page; > > >> - enum count_type type = WB_DATA_TYPE(page); > > >> + enum count_type type = WB_DATA_TYPE(page, false); > > >> > > >> if (page_private_dummy(page)) { > > >> clear_page_private_dummy(page); > > >> @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) > > >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > > >> > > >> inc_page_count(fio->sbi, is_read_io(fio->op) ? > > >> - __read_io_type(page) : WB_DATA_TYPE(fio->page)); > > >> + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); > > >> > > >> if (is_read_io(bio_op(bio))) > > >> f2fs_submit_read_bio(fio->sbi, bio, fio->type); > > >> @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) > > >> if (fio->io_wbc) > > >> wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); > > >> > > >> - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); > > >> + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); > > >> > > >> *fio->last_block = fio->new_blkaddr; > > >> *fio->bio = bio; > > >> @@ -1007,6 +1005,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 +1045,8 @@ 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, fio->compressed_page); > > >> + inc_page_count(sbi, type); > > >> > > >> if (io->bio && > > >> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, > > >> @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > > >> if (F2FS_IO_ALIGNED(sbi) && > > >> (fio->type == DATA || fio->type == NODE) && > > >> fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { > > >> - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); > > >> + dec_page_count(sbi, WB_DATA_TYPE(bio_page, > > >> + fio->compressed_page)); > > >> fio->retry = 1; > > >> goto skip; > > >> } > > >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > >> index 65294e3b0bef..50f3d546ded8 100644 > > >> --- a/fs/f2fs/f2fs.h > > >> +++ b/fs/f2fs/f2fs.h > > >> @@ -1080,7 +1080,8 @@ 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, f) \ > > >> + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) > > >> enum count_type { > > >> F2FS_DIRTY_DENTS, > > >> F2FS_DIRTY_DATA, > > >> @@ -3804,6 +3805,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 > > >> > > >> > > >> > > >> _______________________________________________ > > >> 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/compress.c b/fs/f2fs/compress.c index c5a4364c4482..9940b7886e5d 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1418,6 +1418,8 @@ 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, + f2fs_is_compressed_page(page)); int i; if (unlikely(bio->bi_status)) @@ -1425,7 +1427,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 dce8defdf4c7..81f9e2cc49e2 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; @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) S_ISDIR(inode->i_mode)) return true; - if (f2fs_is_compressed_page(page)) - return false; if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || page_private_gcing(page)) return true; @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) bio_for_each_segment_all(bvec, bio, iter_all) { struct page *page = bvec->bv_page; - enum count_type type = WB_DATA_TYPE(page); + enum count_type type = WB_DATA_TYPE(page, false); if (page_private_dummy(page)) { clear_page_private_dummy(page); @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); inc_page_count(fio->sbi, is_read_io(fio->op) ? - __read_io_type(page) : WB_DATA_TYPE(fio->page)); + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); if (is_read_io(bio_op(bio))) f2fs_submit_read_bio(fio->sbi, bio, fio->type); @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) if (fio->io_wbc) wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); *fio->last_block = fio->new_blkaddr; *fio->bio = bio; @@ -1007,6 +1005,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 +1045,8 @@ 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, fio->compressed_page); + inc_page_count(sbi, type); if (io->bio && (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE) && fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); + dec_page_count(sbi, WB_DATA_TYPE(bio_page, + fio->compressed_page)); fio->retry = 1; goto skip; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 65294e3b0bef..50f3d546ded8 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1080,7 +1080,8 @@ 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, f) \ + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) enum count_type { F2FS_DIRTY_DENTS, F2FS_DIRTY_DATA, @@ -3804,6 +3805,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,