Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2689075rdd; Fri, 12 Jan 2024 19:57:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKaeS81WgVjNb6gdFcHwfhXs5n9TxRBdopFxRzL5wiUXIUefgc0VfLcEjfS+ENHT5yjar2 X-Received: by 2002:a17:90a:9cb:b0:28c:1017:fbda with SMTP id 69-20020a17090a09cb00b0028c1017fbdamr4966220pjo.0.1705118250944; Fri, 12 Jan 2024 19:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705118250; cv=none; d=google.com; s=arc-20160816; b=buMsxLSKPrsdev9D90gSlQCZ5ykL7nOkrWgmQCpMux8DRf2WObVpXMIYFkuppiwWpD qDqTtKEjt78DeI4Yxd+DiDsN3wW7EoJLl7u+sBXA0kiLyhobl48ZiPt8KbE4ROL+fP2N 3n9MVis0+iiKLXUdjl/O/4hWwBksDW8Aqrx/b3GcsF8h3ChsMFUU05ln2JRHQX7isKA5 1B75Vdgmhu+a4c3eIXg3Pzq5PtYotd82SD86CLVYQrXAedv+FrGSjAe0zo4pbeAEoNTc 7lNTzQVKtfOMgQKPNfU4ZeAjXMyVUK3E0Q8nWPCCd/EsYGimERV4UJJFSOe+wwaF7Jm7 BxKQ== 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=YsigP+VaIBvZj36zwwwMZKpyH/Hp+LVscKGUsBZbaog=; fh=3gbPhre1OB9gPaTtmCq689W9XI462kLAqPsb9Z8n0A8=; b=Ixv3n8vOhPLHh88S6ve/2Qe3w8KCWUkpTsNMNRqlGrpkY8fzGgTXV0spNTfhkzHoxf e0EC9WfdfoVMlGUxea1G/RPP+y6KyvMzoBeuqnVfpFmNTCWnytEPD0+cDd1saaaUxaSb 3xZmOUR00S2hQmuxh0VrTxj7cMxhlk+6cJeCvVjkMlRz2dJtttXOrr5os8PVnXmwc1eP Ddr5WFwvvjfh3Aw0VDVFEIEv1G95aTSCWfpbVZHswxBMPG0QhYtKGFVOvJ0X4Vm3AV98 jDpONoqVY/3pHugQU9MMGtpS6WKge0zAlyD04461EePV0xAYIgW9qK+JRRbR19Xl/jWm TWeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQBXkuzY; spf=pass (google.com: domain of linux-kernel+bounces-25186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id oa16-20020a17090b1bd000b0028db455dab1si4749677pjb.27.2024.01.12.19.57.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 19:57:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQBXkuzY; spf=pass (google.com: domain of linux-kernel+bounces-25186-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25186-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AE9B286F69 for ; Sat, 13 Jan 2024 03:57:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08967DDD3; Sat, 13 Jan 2024 03:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hQBXkuzY" 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 1D80CCA68 for ; Sat, 13 Jan 2024 03:57:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 773A7C433C7; Sat, 13 Jan 2024 03:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705118242; bh=ywpF7M7D95zhHcwElxt0DfykbkE6hwAR+GppJ/4fpB0=; h=From:To:Cc:Subject:Date:From; b=hQBXkuzYfllzx+qIwwaNwncmmkXi0y4ESLWwb4bR55nooqz/eokfESkvYvMk5WtHi YNPLHBGN6oapFSvu3fTmqpKPtjHyZCdEL70q1BUnm+zS4OVbj9S5vAFVH/7c0QvP0G UtOlsosWRZkRebr243HNptLlyR7TA4DoUXw6nn8/01KfOVniJ7FcXcbHxF1fsFprBg zmK/EV9k2Wu00MQwLJFto9ifNqkb6acsRCI/23fCZtpfyg8lfoAGud73Tkef22dHFV 6LYW2F90Xfg7uIwKVFjW/m23MPi3iWSZo8RlcqaJ2FScv+GkiojS2nnfGGyhOzAJdz Q5uCx9yCF1o/w== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Daeho Jeong Subject: [PATCH v5 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP Date: Sat, 13 Jan 2024 03:41:27 +0800 Message-Id: <20240112194132.25637-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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") Reviewed-by: Daeho Jeong Signed-off-by: Chao Yu --- 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; 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