From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 9702626F2BE for ; Mon, 3 Aug 2026 02:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785724381; cv=none; b=agaShC0TPzGJjMeZW8F8RrNvDay+KF8Iz9UP3Awdh4m8EFXhiKDfwwcChgjZB72NMJaLhvN0cP9DT0rHJCyHHn3/NU9g34Jz6fm6wbHv3PnvH42n7uA1PkqL4KHTnZNqTCTaH8X6f2eytlMOEHi5kzYwpMttYtA8oYTSJJMREUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785724381; c=relaxed/simple; bh=vMoZOyN21yM8uuTxEK5bo50fz2Vb2LpSMwn1dib0CDQ=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=pygOLli6FiluU4yhmwcLfk0cbfAyklIM42SIESDnFb38n9hfFDNOvlm5PDN/QuWRXU4Vjzx3LTXqaDtri5KKmC/6YGCN5CXzXxAnjYwK0xHrmN/fRhzt5nF4/hbwr1O215noFjsQpchIXXVyihXrqqOX2I2H4O18gYLLAT1bd04= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ef3ViM9p; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ef3ViM9p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEF341F000E9; Mon, 3 Aug 2026 02:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785724380; bh=yUUdgUi+9aMNWWibyppTVdNTC32O/HmK8pKq6gK212Q=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=Ef3ViM9pSMIfreQIIEC9pPGLP+7/OPPV0udEOcit73/Uz+Yu9q3MVI9hR1sCX38A4 w0T4VWfguB2A+1pn1YgyHp21hz21RgbYQxvKGz10v/upc3SGkfbDk/0F0BNzFWCB+8 L2aXGLYSghrlEaCmAbD9Fb1L712TJnZgsBv7+MuSWD6ZmNzs9W5zRmTHQMK2FTvIGj rVbR2QUTgP/SfebomAOW0sSJUzwd9ZFIunpXru2vOTsKpWcdNXNCi8h0jRWsBx45wW 1JiZVbN0QahgHkHMBwpfTUoLdkfxcit7GT4TG7jCUa3Kz/yx38Pi9pociVOmpI+QPf fEJAVVwzz1Q4g== Message-ID: <4549a2d6-f512-4f34-a6bd-5e7324f037ad@kernel.org> Date: Mon, 3 Aug 2026 10:32:56 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com Subject: Re: [PATCH] f2fs: account compressed writeback by raw folio type To: Wenjie Qi , jaegeuk@kernel.org References: <20260616125219.1396871-1-qiwenjie@xiaomi.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260616125219.1396871-1-qiwenjie@xiaomi.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/16/26 20:52, Wenjie Qi wrote: > Compressed writeback is always charged as F2FS_WB_CP_DATA today because > WB_DATA_TYPE() is called with compressed_page set. That is wrong for > normal compressed file writeback; the CP guarantee belongs to the raw > pagecache folio, not the compressed bounce page. IIUC, I changed compressed writeback guaranteed by checkpoint to avoid compressed cluster corruption when encountering power off recovery after fsync/sync. I didn't get why it's wrong to set F2FS_WB_CP_DATA for compressed page, can you please explain more? Thanks, > > Use the raw folio for the writeback count type. Also keep one raw page > under writeback until the compressed end_io callback is done using sbi, > as normal compressed writeback is no longer protected by the CP-data > counter. > > Signed-off-by: Wenjie Qi > --- > QEMU/KASAN tested with compress_mode=fs and compress_mode=user, using > concurrent 1MiB compressed writes and a background sync loop. The user > mode case also ran F2FS_IOC_COMPRESS_FILE and fsync. No dmesg splat was > reported and fsck.f2fs passed after unmount. > > fs/f2fs/compress.c | 34 +++++++++++++++++++++++++++------- > fs/f2fs/data.c | 2 +- > 2 files changed, 28 insertions(+), 8 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 91855d91bbdd..be9483b9a401 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1487,9 +1487,19 @@ void f2fs_compress_write_end_io(struct bio *bio, struct folio *folio) > struct page *page = &folio->page; > struct f2fs_sb_info *sbi = bio->bi_private; > struct compress_io_ctx *cic = folio->private; > - enum count_type type = WB_DATA_TYPE(folio, true); > + unsigned int offset = folio->index & (cic->nr_rpages - 1); > + struct page *last_page = NULL; > + enum count_type type; > int i; > > + if (unlikely(!offset || offset >= cic->nr_rpages || > + !cic->rpages[offset])) { > + f2fs_bug_on(sbi, 1); > + type = F2FS_WB_CP_DATA; > + } else { > + type = WB_DATA_TYPE(page_folio(cic->rpages[offset]), false); > + } > + > if (unlikely(bio->bi_status != BLK_STS_OK)) > mapping_set_error(cic->inode->i_mapping, -EIO); > > @@ -1501,21 +1511,31 @@ void f2fs_compress_write_end_io(struct bio *bio, struct folio *folio) > } > > for (i = 0; i < cic->nr_rpages; i++) { > - WARN_ON(!cic->rpages[i]); > + if (WARN_ON(!cic->rpages[i])) > + continue; > + last_page = cic->rpages[i]; > + } > + > + for (i = 0; i < cic->nr_rpages; i++) { > + if (!cic->rpages[i]) > + continue; > clear_page_private_gcing(cic->rpages[i]); > - end_page_writeback(cic->rpages[i]); > + > + if (cic->rpages[i] != last_page) > + end_page_writeback(cic->rpages[i]); > } > > page_array_free(sbi, cic->rpages, cic->nr_rpages); > kmem_cache_free(cic_entry_slab, cic); > > /* > - * Make sure dec_page_count() is the last access to sbi. > - * Once it drops the F2FS_WB_CP_DATA counter to zero, the > - * unmount thread can proceed to destroy sbi and > - * sbi->page_array_slab. > + * Keep all sbi accesses before the last raw page writeback is > + * released, so an unmount thread cannot free sbi while this callback > + * is still using it. > */ > dec_page_count(sbi, type); > + if (last_page) > + end_page_writeback(last_page); > } > > static int f2fs_write_raw_pages(struct compress_ctx *cc, > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index a765fda71536..1466a7825dc5 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -1092,7 +1092,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) > /* set submitted = true as a return value */ > fio->submitted = 1; > > - type = WB_DATA_TYPE(bio_folio, fio->compressed_page); > + type = WB_DATA_TYPE(fio->compressed_page ? fio->folio : bio_folio, false); > inc_page_count(sbi, type); > > if (io->bio && > > base-commit: 7cc48ead1a8a96f2dd1eabd87c2f22947dc84cdf