From nobody Mon Sep 28 08:45:52 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E57F44078D9 for ; Mon, 24 Aug 2026 10:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787568710; cv=none; b=PZz01TdEClPjaJyjGJ+lctphTCc4EwGXD3ObF3pfuM4pEYFdXLvnbGorTkxhavu+44eLu8glCbN8TrthseWcpt0BvlrhUWOBrYDgJljgs7ZTDkwOCDHosv0joS0fwMSfZvdCrUC0eBmQnUuxnbBTgHZByWgSQbbNMwxZVuRJ2xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787568710; c=relaxed/simple; bh=4l8oMR5aXVNXALkhuKjHiDg3zhd77lNY+7C7QN0eWXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mziST+CJypZ7zjv3pTb/2yCLQydcqia9/JeV9IvU4DwMB74XD6vVLz7fTurcM6Z9thfzw5wSQpC0kUVHE/Lj8TU27LCW0G5pCey6u0iOjV2mG2xM3/X5V1AVOdo0RFmoyBZ2XRS7UXsnx1Q++GNooUEBQwQHWVl2bVDts2ivu4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ro+Re7iF; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ro+Re7iF" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38e88b60121so2544221a91.3 for ; Mon, 24 Aug 2026 03:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787568708; x=1788173508; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hJJbk4tPuMZ/n5IgnZpbMmRDFynIgVeuM9Ohf0uhx24=; b=ro+Re7iFydzwU5CZCDLRoCSIKLkFfYgzedajR46O1IszVkJIUAakyaf0ksrv/1IOIJ xJjYubjBoGGZp9lXTbEi040ow0vJiKZvtiL2hoGQ+q3dG7hw02Rywno7EEp6e1m215Cn 0I0NBEfiUM8qlag0ZUazzXAGi76LdLea7XGwuXm0wluruzdravYghTc1EaNrNGV1NbLJ CNcIsoB5tnxSQH81cNKGk+PMcQDGTaS/a4csZubj83yjg2xtHdaePSIfjoOwg62KizQW 7KN/oy1kuH6tNX76qnXafr6Z++bt8dfJbSvu2lN+JYiRUaUZF2ZDapGdFs9QvCD/RWpp w7mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787568708; x=1788173508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=hJJbk4tPuMZ/n5IgnZpbMmRDFynIgVeuM9Ohf0uhx24=; b=RgF9KN5Ogb6xpPvvPFSDBebss4DStfEILS3jz00uMQi37kBR+z6E/mRmxTb8xlYn5l dz9uCNcmzgQ+W9lk1WCvQRtKK4QSAwYM5OztzP3QgAbn1iBtBpt1eDrc/0INbRxKKEWs czMWNFS+YiOrZP8p4cBQ0znm6oyI0Tmx8kvmXZMkx8yi+5I6QJ8N7KRTPVqtvP1GnjSV 5mVbABONNfer/2XT/cbt1L7xoY031tbJ7OOz5CLACej5DUvtsNe4n2VqQJlTkPUzvrcA pXdnpjGpper+ZktftoSRCRaPBp93U25k4rUXiCNGJWzJEFhTtghrGR+kVFaA3ZYC5vKC dSzw== X-Forwarded-Encrypted: i=1; AHgh+RqGylwJ2mJ42BPtnlHb5V/5vXtwT8RptM2SfIz1P9YgCyn4elzStn/9Ecu6HJX/TwtMyPGKcv/LSqoamJg=@vger.kernel.org X-Gm-Message-State: AFuF++ksjoZDT66gtLx62+oZNGO/BX7sSU0bMd5exmH6YesOhRVVFty5 9lwJOR1UrQ4KLgl6hXRW8EWxSv8mcY0pKVlz4soQq1f66MoL0lTp6OEy X-Gm-Gg: AR+sD10WGiJ5wX4zrqHw7NpBZ7IMOT14WfWBeIaIjwzG4TBVWuuvUFfWkWRt3I10oX2 pnlYEzOv+sDU02huF+extZCnXUCoTr1I5x/rSaF3raQhc3964op9B1PBd0ffi8y+DXiRnfkposa NB6u8d42VhUZcs1vFTbDZ8QQiGTJYQF8+0MsIcZ5Tp1Gtz3TFlPMzRuSDWhGii+AKz0j31f3l3W oCVKwny79IBUoRAyhZFySyC3CD5i0Bhug80BzvMv4/kH2bppJ3L4O+663xMpSf5GP5GQN1nhUWH EJLItngqEbWNhXz2UBD7fQGx/saphOXmfF0WCR6JoBKTR29D263vLmj+r+0bJmPfDrU+nCKCipl LCIFqSKD4FgNjxzlUpW9ZsxgpPYdWZhZyJBpGTzTvsArWQ17e+TtrSSv9kYLWM08jdVL5dj+OdZ q2mA+oP+DieiDrO7hyM8JsFTJj54MtPAklr5C5e05347netLFm2yPEFT39PVvszTkQN60tWYFB7 fgGGevKiFG9/JOwqjftM0kV X-Received: by 2002:a17:90b:5112:b0:37f:c22a:c188 with SMTP id 98e67ed59e1d1-395dee8a5c5mr34369423a91.4.1787568707684; Mon, 24 Aug 2026 03:51:47 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-395e4af6e88sm9708996a91.9.2026.08.24.03.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 03:51:47 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com Subject: [PATCH v3 RESEND 1/2] f2fs: complete dropbehind write bios in safe task context Date: Mon, 24 Aug 2026 18:51:36 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Buffered RWF_DONTCACHE writes invalidate dropbehind folios from writeback completion. Keep normal and dropbehind folios in separate write bios, and defer dropbehind bios to sbi->wq unless completion runs in preemptible task context. Use an F2FS-local context check for this decision. Task context alone is not sufficient: preemption may still be disabled, or completion may run in a preemptible RCU read-side critical section. Keep the existing large-ATC deferral unchanged. Signed-off-by: Wenjie Qi --- fs/f2fs/data.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6ae0eb37d20..774a3e2d8e3 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include "f2fs.h" #include "node.h" @@ -43,9 +44,29 @@ struct f2fs_folio_state { =20 struct f2fs_bio { struct work_struct work; + bool dropbehind; struct bio bio; }; =20 +static struct f2fs_bio *to_f2fs_bio(struct bio *bio) +{ + return container_of(bio, struct f2fs_bio, bio); +} + +/* Keep in sync with the proposed block-layer bio_in_atomic(). */ +static bool f2fs_bio_in_atomic(void) +{ +#ifdef CONFIG_PREEMPTION + if (rcu_preempt_depth()) + return true; +#endif +#ifndef CONFIG_PREEMPT_COUNT + return true; +#else + return !preemptible(); +#endif +} + #define F2FS_BIO_POOL_SIZE NR_CURSEG_TYPE =20 int __init f2fs_init_bioset(void) @@ -426,12 +447,13 @@ static void f2fs_write_end_io(struct bio *bio) =20 sbi =3D bio->bi_private; =20 - if (in_atomic() && bio->bi_iter.bi_size > sbi->max_atc_write_bio_size) { - struct work_struct *w; + if ((to_f2fs_bio(bio)->dropbehind && f2fs_bio_in_atomic()) || + (in_atomic() && + bio->bi_iter.bi_size > sbi->max_atc_write_bio_size)) { + struct work_struct *work =3D &to_f2fs_bio(bio)->work; =20 - w =3D &container_of(bio, struct f2fs_bio, bio)->work; - INIT_WORK(w, f2fs_write_end_io_work); - queue_work(sbi->wq, w); + INIT_WORK(work, f2fs_write_end_io_work); + queue_work(sbi->wq, work); } else { f2fs_write_end_bio(bio); } @@ -530,6 +552,8 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio= , int npages) bio =3D bio_alloc_bioset(bdev, npages, fio->op | fio->op_flags | f2fs_io_flags(fio), GFP_NOIO, &f2fs_bioset); + to_f2fs_bio(bio)->dropbehind =3D + !is_read_io(fio->op) && folio_test_dropbehind(fio->folio); bio->bi_iter.bi_sector =3D sector; if (is_read_io(fio->op)) { bio->bi_end_io =3D f2fs_read_end_io; @@ -825,6 +849,13 @@ static bool page_is_mergeable(struct f2fs_sb_info *sbi= , struct bio *bio, return bio->bi_bdev =3D=3D f2fs_target_device(sbi, cur_blkaddr, NULL); } =20 +static bool f2fs_bio_dropbehind_mergeable(struct bio *bio, + struct f2fs_io_info *fio) +{ + return to_f2fs_bio(bio)->dropbehind =3D=3D + folio_test_dropbehind(fio->folio); +} + static bool io_type_is_mergeable(struct f2fs_bio_info *io, struct f2fs_io_info *fio) { @@ -1017,8 +1048,10 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) =20 trace_f2fs_submit_folio_bio(data_folio, fio); =20 - if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block, - fio->new_blkaddr)) + if (bio && + (!page_is_mergeable(fio->sbi, bio, *fio->last_block, + fio->new_blkaddr) || + !f2fs_bio_dropbehind_mergeable(bio, fio))) f2fs_submit_merged_ipu_write(fio->sbi, &bio, NULL); alloc_new: if (!bio) { @@ -1118,7 +1151,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, fio->new_blkaddr) || !f2fs_crypt_mergeable_bio(io->bio, fio_inode(fio), - bio_folio->index, fio))) + bio_folio->index, fio) || + !f2fs_bio_dropbehind_mergeable(io->bio, fio))) __submit_merged_bio(io); alloc_new: if (io->bio =3D=3D NULL) { --=20 2.43.0 From nobody Mon Sep 28 08:45:52 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15D064048B1 for ; Mon, 24 Aug 2026 10:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787568713; cv=none; b=Ey4Q09YOFVMbQwCYZBBIh/rO3YANMw1psaw4PgpVEY/kNrNn32h5jL18KxHSJLWDMp1UDtJ20VDyTo2GPMOTwCAqrb9vOeODs6WOm2D0cZ6dhSIFFQWKPKW9FS8x0ZAXr8b41dVjdWgDXUi4vbKddlogY5ymxU0WSNdh9HGtwAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787568713; c=relaxed/simple; bh=hjq0pQiBsaHl8KYYoi3rulZLOGXynkRSkoeGa7w61MY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EfRXNKRcTvgOzbUL9D8b8vxQGmmhWmZmHMIOqJ52mNk1znd3t7lDCE5Eo9EN1Lo/JSMR74yE2ImEBmZ1/eSkPDfYicEJC8NvMVGQLLoKHMN6MWhGAYRbs+EtSEJUk73/RrNdKXCcKCIxPHvnXRBDTT2Vcylh6OIsIZxOy/P9NhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HAR6RuHx; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HAR6RuHx" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2d049069377so27644055ad.0 for ; Mon, 24 Aug 2026 03:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787568711; x=1788173511; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gAe9u96jNxE6H3oZgwbxQpRnQm+N+LumGnkEUW5jR6Q=; b=HAR6RuHxleQBJVdoSKqm13Uxm5irBrri5y1oFwudDglwKQqHlL3F8xZxbpAgxFQ4oe dlFScqzKK7J1KPSuezbUY99Z9GNJUpl0CkA662zUkkxyzGqlTM3uSp9Msdc/0DbfUyrR EgL6RQQ7rA22IRKLjb9oVlXXNmWtraWXaY88mgLDZzfEXU7HLW6yYeOk1cNR2l0xyGdd BYFiZXSyhwyutBCa1Ct9yj0SC8hwlZXnlP5/Qwp/n5blbpTRbJb4urKFUN4Z1qAet5m0 IUQo2OS5y/oyAzaTyCzUltfPQkf5Eix+T3dFcyTWojzQckflzS46+YrS0o73w/0U1sSC 7Aiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787568711; x=1788173511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gAe9u96jNxE6H3oZgwbxQpRnQm+N+LumGnkEUW5jR6Q=; b=cuEwSOjIjW00OGSRS8uS5SlKKnkNdoO3P9ja032g7MAh4YEas1Glv5n82T2ELaG4nW kSM5rbRyFBPtRscUqP2GUu2efmMcI7CB/GIlJBnAROLot/34lBSY7Ir6QkKBiBywxGIn Em+nC/iftq9sikZZH6lSG53uPK8LtUXKkJ7s5ncOy0H7f9B+fkWuOlrsGMafDMWh2qGH F580EGh1oqEBBjtmHooixApzO7EhEvrxoDpS9uVEYTAqbpFS0oFb5v9TjbfSB7MLNnuC bS3QWiHWigmcE4ipMC9opFRKF4y38F/09+cfpwTufw2QC2DnQXKkuJt11WFKPQKQTrs3 x4nw== X-Forwarded-Encrypted: i=1; AHgh+RovEPeSHAUFm0C9lLkRsz9bW+LMLvFwBWA31nB7xOZrwzQyr9rzMF0FM3Q2DuE7eHE91Z5PCEeoiJIR/qg=@vger.kernel.org X-Gm-Message-State: AFuF++kHkBEepQGuYEG+q3vMBANXKGSiR4IcOuJw9sq0Eyi4O+rUjjYI lfJnfwRZqzqQN3BmwZeue6rlZer6npkY/8e1swWAazjhWg4RBwLxaMd2zse8alfw X-Gm-Gg: AR+sD116DSe3hqwj7a2HXhwafswfGwkl8KF3/2CRhCuTzpEu1+v0ghcvblh2ooaGtV4 adMQndDKCsmVIM4DIFjgirqG7qd1vj3wrNGKhag6Zh4DzAY0P3CCQLMCx9K034sCs7WAl/s0Kxe h7u6o0NabTldaWa34XiYdk4JKzBYZ6WxBhUMAVxvp1uSYQE6ziNmHnXQU6ylT1XLGK7S9T4CJL/ eW2IQKczfHStBeX1Aara1/QzzCsCLyIsDrE1mXsOmRda5of0UI4tRpbRphlnQuhNBp0ppp5kN0y yv5ZNh4/0zryzIXPCPa+NAuj/yXE99Y57sOz43h5isPNSlSvlBqnaeZNMpJzr4wN+W5RIpykXpZ m+kPpSgHWWIxzC+5V7nO8k4kmjXt2N9VLIYO1RcDYFwHtPnRrchaQHPWGaSxv9P6bEHA1sNfxHc VXkLIsVuj5B7BWdCPt7WLYB3BJLQOdhDk/psY9eKgdU92mY3X/+nxnZ7Jzeda+0wnt2ogRY8evO Jw8TUv9JbBSj9oGcUbhu8QI X-Received: by 2002:a17:90b:2d91:b0:38e:2e86:ed02 with SMTP id 98e67ed59e1d1-395c39cd288mr49656738a91.14.1787568711410; Mon, 24 Aug 2026 03:51:51 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-395e4af6e88sm9708996a91.9.2026.08.24.03.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 03:51:50 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com Subject: [PATCH v3 RESEND 2/2] f2fs: enable buffered RWF_DONTCACHE Date: Mon, 24 Aug 2026 18:51:37 +0800 Message-ID: <03790070c828924d98ba6d78e909391fb0014c7a.1787568046.git.qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass FGP_DONTCACHE to f2fs_filemap_get_folio() for IOCB_DONTCACHE writes and advertise FOP_DONTCACHE. Keep the F2FS-specific lookup flags because write_begin_get_folio() adds FGP_STABLE, which can deadlock here. Signed-off-by: Wenjie Qi --- fs/f2fs/data.c | 9 ++++++--- fs/f2fs/file.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 774a3e2d8e3..ebd9dc582f9 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3981,11 +3981,15 @@ static int f2fs_write_begin(const struct kiocb *ioc= b, struct inode *inode =3D mapping->host; struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct folio *folio; + fgf_t fgp_flags =3D FGP_LOCK | FGP_WRITE | FGP_CREAT; pgoff_t index =3D pos >> PAGE_SHIFT; bool need_balance =3D false; block_t blkaddr =3D NULL_ADDR; int err =3D 0; =20 + if (iocb->ki_flags & IOCB_DONTCACHE) + fgp_flags |=3D FGP_DONTCACHE; + trace_f2fs_write_begin(inode, pos, len); =20 if (!f2fs_is_checkpoint_ready(sbi)) { @@ -4031,9 +4035,8 @@ static int f2fs_write_begin(const struct kiocb *iocb, * Do not use FGP_STABLE to avoid deadlock. * Will wait that below with our IO control. */ - folio =3D f2fs_filemap_get_folio(mapping, index, - FGP_LOCK | FGP_WRITE | FGP_CREAT, - mapping_gfp_mask(mapping)); + folio =3D f2fs_filemap_get_folio(mapping, index, fgp_flags, + mapping_gfp_mask(mapping)); if (IS_ERR(folio)) { err =3D PTR_ERR(folio); goto fail; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d82be8c1502..8e9d86dd42c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -5912,6 +5912,6 @@ const struct file_operations f2fs_file_operations =3D= { .splice_read =3D f2fs_file_splice_read, .splice_write =3D iter_file_splice_write, .fadvise =3D f2fs_file_fadvise, - .fop_flags =3D FOP_BUFFER_RASYNC, + .fop_flags =3D FOP_BUFFER_RASYNC | FOP_DONTCACHE, .setlease =3D generic_setlease, }; --=20 2.43.0