From nobody Thu Apr 9 11:16:25 2026 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 58DC922759C for ; Mon, 9 Mar 2026 10:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052665; cv=none; b=u6WPbhUKi61vbp9sElPp+kgYYmpZJUXEnNpyUEgr+XRPUTVpazrXD+n73zbHWsKuIXoiO1+OPlg/2f71CWAdj6VZBmt7PvY1JTI5mmP2QN8ysQM2k9fvfHZZjfthSnPjlaQC5xFYQ2fPfp+2abVsR0zqj3AlkeNsEE+N3uGqGUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052665; c=relaxed/simple; bh=TripupM9s+k8BLa2yEfptDjAbsH+UDWd3+a03oWoFvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UIdBEjg7qMrAMxVaWbBAc1p2GyOgBrmwEpm5ZE/XmxWCuJ3PxVGuBqcGBG/NvenL3ucCNHIsDKE0g/1yNCJqc/PyISYx/Ke1uf3GvsWX1p7gWUU8DoauxfCO80cH74Te5r5P6hX21LHbJGzDufwGcTUchy7CGx8trnR6rzXB6ng= 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=Cn/ZBUW4; arc=none smtp.client-ip=209.85.210.51 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="Cn/ZBUW4" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7d74dbfe84cso391304a34.1 for ; Mon, 09 Mar 2026 03:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773052663; x=1773657463; 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; bh=dBuOUGVLEw4nznHpBENauX1eomvy7I2QzIe17Bzs21Q=; b=Cn/ZBUW4P5grkR5w5C9hLx6Wqivu1fdEk4XS5Q7tpIwsHeITxJX9MnmHrBbqG+oFk8 eC1CJZzdOl7BydiMlgQMhbAUcNKMbxPmUuXSMwatDzxGSS9aacq2aUObS3EI7NVDOiSN VxD7Oi31wUjempMoEL5SeuBJzqHSIDSaS15ebpw9PJmT/gX5Nt8mEEcL8xqcCjTBo/ge IrwS0hitlRl5SaBp1924FqGP7Od+2hxFL+kDt+bhzwv454/IKyDcK3FDnExw4mUO6nIo +bo6L+IP3a2Zav8MWYChFrHzE0/WWUbMpCCbnzzMJYuBaIJiDezVXLwYBi2LNLNtNVP4 jJaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773052663; x=1773657463; 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; bh=dBuOUGVLEw4nznHpBENauX1eomvy7I2QzIe17Bzs21Q=; b=ShxkQr9S69ybazrQBvu23ED+vK0dQJKOvNpDT+bFAwVtt1c9B1NNipYU6qJnShn1QE Lbj7553Ki8k6B7bGrAknVnnqCDVw6dfvDJ/lcoN83Gb1M2MPqn8605/b/MNrh5+417dX q+6lajE8AhBaN5IJHPnJiNk0oETDwrTSmPwod3geqKaI7xQbv51f2b4PsHUXgNgUihjP WWH5p7aB4QOYDMDHJ06o/80ZV9v4ie9F3a7fLprYqEgBkaet3UvqdoisV6Zjnc6GrGst hjn0w8Kn0O3rqrqHBf9qJkkavOEKgKEFFDQXCBxBfmtwIwOsfrtZzCXEFo4ho7LINBbj pTiw== X-Forwarded-Encrypted: i=1; AJvYcCW/3t/gLR5L5O4fki0IF1rTXHF/iK+J/u2j9Y17Jvt+2rQWUlf2dpACgdI0ffLDkm5sCOV6G6hq15voB1w=@vger.kernel.org X-Gm-Message-State: AOJu0YzV02BQIS+gnC3ASbKgf1biW/9GP10XEleDmdmNTWqD6w2ouSig fQPkt6/gBcxo/DIj02P4xwQ8hLuLoEev5bHFVE0FCcZ0n+TNIJQtamKh X-Gm-Gg: ATEYQzyqTtyF5prgUjRw8IdgZp1LkEfQu6GKGBTBnh2Pt07YAYM4uIjYL+pnegOzdyo dVrtDwevB7qu+ptJTCy93pdJO5ScPGtJacbTRUyrZrMZ/dE5NBkN+MD7wrZvqs1u2bTy5kOdI2z ZFUDfy40TCWSbpwI6dovudrofhTZI+B+2bGTOsbF4kI+OoUBw4mWQm4UrWa0EdH7evc/8TTWhid 2lRkkdMkmvq1yqbuPieQhrw+IXeFXdj4hrdcCYXoCaJQCF13Zjw3zPxGui92gFX97GWA+WzN1KR r7VUZQifP3uFcKU452Beoj8r4XwnwasFn8WuSDLJf2aPA9d9vnqxIE2hmmvxzUGd9AzDGooDv8s kRsKAOfAzuiF0E3RkG1xpxlFkN+959iMdRCm8q2UlQSdMAu8UC/5cWPDhG5j3yqpVY40ol5clY/ bec17a78upAyw63WwUKDxNOz1htrMH8sddC1yWXmiTQdaUaFsJczo= X-Received: by 2002:a05:6830:828e:b0:7d7:45ff:dcfd with SMTP id 46e09a7af769-7d745ffe497mr2836864a34.12.1773052663327; Mon, 09 Mar 2026 03:37:43 -0700 (PDT) Received: from starman.tricat-industries.com ([136.49.86.72]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d755603798sm231247a34.29.2026.03.09.03.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 03:37:42 -0700 (PDT) From: 'wallentx To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org, wallentx Subject: [RFC PATCH 1/3] f2fs: prepare cur_valid_map for safe lockless access Date: Mon, 9 Mar 2026 05:36:58 -0500 Message-ID: <20260309103700.489932-2-william.allentx@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309103700.489932-1-william.allentx@gmail.com> References: <20260309103700.489932-1-william.allentx@gmail.com> 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" From: wallentx checkpoint validation and segment_bits_seq_show() can read cur_valid_map without taking the segment lock. A following patch will allow zoned LFS segments to switch between shared and private SIT valid maps, so those readers need to tolerate pointer publication safely. Prepare for that by reading cur_valid_map under RCU in the lockless paths and by publishing the initial map pointer with RCU semantics. This is preparatory and does not change the SIT layout or allocation policy yet. Signed-off-by: wallentx --- fs/f2fs/checkpoint.c | 4 +++- fs/f2fs/segment.c | 3 ++- fs/f2fs/sysfs.c | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 6dd39b7de11a..7b196d9df0f7 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -354,7 +354,9 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi,= block_t blkaddr, offset =3D GET_BLKOFF_FROM_SEG0(sbi, blkaddr); se =3D get_seg_entry(sbi, segno); =20 - exist =3D f2fs_test_bit(offset, se->cur_valid_map); + rcu_read_lock(); + exist =3D f2fs_test_bit(offset, rcu_dereference(se->cur_valid_map)); + rcu_read_unlock(); =20 /* skip data, if we already have an error in checkpoint. */ if (unlikely(f2fs_cp_error(sbi))) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 23faf6725632..c9cfc8f17698 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4845,7 +4845,8 @@ static int build_sit_info(struct f2fs_sb_info *sbi) bitmap =3D sit_i->bitmap; =20 for (start =3D 0; start < MAIN_SEGS(sbi); start++) { - sit_i->sentries[start].cur_valid_map =3D bitmap; + rcu_assign_pointer(sit_i->sentries[start].cur_valid_map, + bitmap); bitmap +=3D SIT_VBLOCK_MAP_SIZE; =20 sit_i->sentries[start].ckpt_valid_map =3D bitmap; diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 969e06b65b04..9c79f7b63583 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1782,11 +1782,18 @@ static int __maybe_unused segment_bits_seq_show(str= uct seq_file *seq, =20 for (i =3D 0; i < total_segs; i++) { struct seg_entry *se =3D get_seg_entry(sbi, i); + unsigned char map[SIT_VBLOCK_MAP_SIZE]; =20 seq_printf(seq, "%-10d", i); seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks); + + rcu_read_lock(); + memcpy(map, rcu_dereference(se->cur_valid_map), + SIT_VBLOCK_MAP_SIZE); + rcu_read_unlock(); + for (j =3D 0; j < SIT_VBLOCK_MAP_SIZE; j++) - seq_printf(seq, " %.2x", se->cur_valid_map[j]); + seq_printf(seq, " %.2x", map[j]); seq_printf(seq, "| %llx", se->mtime); seq_putc(seq, '\n'); } --=20 2.53.0 From nobody Thu Apr 9 11:16:25 2026 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 83CBB22759C for ; Mon, 9 Mar 2026 10:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052670; cv=none; b=uK3lhln9TsQmRC9f1T5Dnd5tEu/hx80Y6IVT9+sszjcs1/llZMqgEUlgSTtH3FUjF9nFNMnUnFjf4DXTG/vX/fJxHyilVd+AEN/vZjB2G9UtiE7UyfxH2rsf+1lvWY5CIvV9PHOMh05WbP1OfcSPe1IBpmywl2B78yJkdaa2LpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052670; c=relaxed/simple; bh=m0zEb4F26BwQG0VoCr42ygexL4Svps/s6BGllOnVX0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=atVvg6ehzUaHxwQX0cxJJ6fK/ZN8DBy4Wd/e/AWtk9vU/ofvgeOyHfphlKSPdNcVeWmnwfMTFAVWOhFNEwY/9aiF4zFU7ehjsGgbtvPr5LYPUSmQaq89e3SUFIxBmzT+rpzQr27ECdP8MbH5Hc9pvyUopsv0TCdajni0jXkDF7A= 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=CWTgT1MZ; arc=none smtp.client-ip=209.85.210.46 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="CWTgT1MZ" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-7d754c7c150so97516a34.0 for ; Mon, 09 Mar 2026 03:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773052667; x=1773657467; 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; bh=ocFSNy72gpBYTyqbLTn5+BD/eUt6UO2paTu1vwXpU5E=; b=CWTgT1MZuqdRDvsoyEAkpUQXDaDzkXWLUY9cj/0HXxBaX2uPl6bJTeYrWMYTIAd3W/ ehOAe412E2pix4frWa71hux3XWz21w4vhuktX1hqUDPjsflwUJIOyyswsRfjeLZSCS5a qeaofGf/ApBcTzbrX1XFoD1sjWp729yrq8avOqoEQo2SUoc7rbk90FLOwFZ1RlvKg/jF rPeQf6eAGXqWdgQQ1vYT0JblCHeLl6ETbBuHrQSRQalZsPFnrJEEe6UDe7IaHQnnuTzb +ctBXo5SM10Ru0Y1NUmMErYURaC03SdqRzGbRR7GstKuOuG20HtvS8HSbRueU/baDx1w JSMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773052667; x=1773657467; 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; bh=ocFSNy72gpBYTyqbLTn5+BD/eUt6UO2paTu1vwXpU5E=; b=ZQ5EcEzhU/3LvWs483wKXnURoGPn97sLwofOkT9wuUz96Ta6DxLbriQIjNgJvxaBHk Y84KIsVHsLNJieEcPc2b3R5ne/MAHnpZlysdHj+z6/H6D5cE/b0Z+BH1L36rMI/kpNm6 u3ubdVUVKiOi6SzOZP8m8zFJLqqGbtyvDGgq+2XihUzozOf8GG0CZGC8dKAjrvpiwALQ EZhib4+FkE1DyBWtwuI6SGhdh7rxGS4bifSfqBDVqkzzrjIjIzaiAh+O3HSMhYBeE8P1 QpRiEHhdEPTcfdH514Cx3LEXRyrPDkt/1kezWauR1Gyb3P2vtvrcJ4BmFQtjqusSdCdY FTaA== X-Forwarded-Encrypted: i=1; AJvYcCXFWjR1Lj2VCvPwHl1opAYQ/0D14erOO30S3MLc8BCGT9aSabc9UyRdq8KmE+EyqWKqFISiCzmVScTxevQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2vAZUbgRO5V+xH674bKUK9uRnpOf3JxopBuoOsqOMj4s2nW9s NsiO2WMZOM6b4i9RKqDzpdqjhfmIsYNgZeC6a2nYfLE4LfRQDXIKcTVV X-Gm-Gg: ATEYQzwGGChbxrtcVZFSc5evrHfKcFCIt857Uuzq48TVypIh9gezXEg90zKZkNhBOUs oxOnjUTtCnldEwnulVeQLPJTrGDwxQNM6Ca0LhQPtq3WmOqR3x20nzHzzKetZ5qgN0uQzlU39rd JE5v9wr7Fb2A4CCd/EJtX/YzV+PcAf5IXzaOhRD6LIKYrbqDFK9vKYDWucjmPi9egLfXnoHTFbe j3FgQvHRr3MqxBmLcYRSbAZEcQeIvy7Aki4bZ9BwayWo/fcQhfQyrZh4R9iqRQie++FDNltMZSK LKFOpvGLdKfc0ouH9h/LxaCqt2ojmomiT9hf853BHyonqz2xRG52MZuEIe/2/kKGPPb1IsYXjK3 pb0sMbBEmlU09V9AVScxbAdMR9IpaxeiGa2KE4tUwmlENXdi3jrGh/Rmdc0eiisFHVw0CRcVGCp XEP1AC/F+Dn1xrJGkgieEDG4bblc2meZH0MxOTOUDebWI1ulSv/eY= X-Received: by 2002:a05:6830:d18:b0:7ab:e111:1a57 with SMTP id 46e09a7af769-7d72705c2fcmr6133858a34.31.1773052667312; Mon, 09 Mar 2026 03:37:47 -0700 (PDT) Received: from starman.tricat-industries.com ([136.49.86.72]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d755603798sm231247a34.29.2026.03.09.03.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 03:37:46 -0700 (PDT) From: 'wallentx To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org, wallentx Subject: [RFC PATCH 2/3] f2fs: reduce zoned LFS memory by sharing SIT valid maps Date: Mon, 9 Mar 2026 05:36:59 -0500 Message-ID: <20260309103700.489932-3-william.allentx@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309103700.489932-1-william.allentx@gmail.com> References: <20260309103700.489932-1-william.allentx@gmail.com> 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" From: wallentx For zoned devices, F2FS only allows LFS mode. In that configuration SSR is not used, IPU is not allowed, and discard defaults to section granularity. Even so, F2FS still allocates per-segment cur/ckpt valid maps for every segment, including the common cases where a segment is trivially empty or trivially full. Reduce that overhead by introducing shared zero/full SIT valid maps for zoned LFS. Empty inactive segments point at the shared zero map, full inactive segments point at the shared full map, and only active or partially valid segments keep private maps. Update SIT rebuild and runtime updates to move segments between shared and private maps safely, and retire replaced private maps with RCU. Also invalidate scanned SIT metadata pages after mount-time rebuild so META_MAPPING does not retain the full SIT scan, update memory reporting to reflect the new layout, and reject checkpoint=3Ddisable because its checkpoint-era validity accounting does not fit the collapsed shared-SIT representation. On a test system with 43 HM-SMR zoned volumes (~550 TB total), CONFIG_F2FS_CHECK_FS=3Dy, and this patch applied on top of jaegeuk/f2fs dev at 5f04e90eedd0, static F2FS memory dropped from 58.91 GiB to 27.70 GiB. Signed-off-by: wallentx --- fs/f2fs/debug.c | 20 ++- fs/f2fs/f2fs.h | 6 + fs/f2fs/segment.c | 338 ++++++++++++++++++++++++++++++++++++++++++---- fs/f2fs/segment.h | 3 + fs/f2fs/super.c | 4 + fs/f2fs/sysfs.c | 3 +- 6 files changed, 341 insertions(+), 33 deletions(-) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index af88db8fdb71..d8bfdac5c1e4 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -319,9 +319,23 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=3D sizeof(struct sit_info); si->base_mem +=3D MAIN_SEGS(sbi) * sizeof(struct seg_entry); si->base_mem +=3D f2fs_bitmap_size(MAIN_SEGS(sbi)); - si->base_mem +=3D 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); - si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); - si->base_mem +=3D SIT_VBLOCK_MAP_SIZE; + + if (f2fs_use_shared_sit_map(sbi)) { + /* shared cur/ckpt maps (zero + full bitmaps) */ + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * 2; + /* Approximate private bitmaps for active logs */ + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * NR_CURSEG_TYPE; +#ifdef CONFIG_F2FS_CHECK_FS + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); +#endif + if (f2fs_block_unit_discard(sbi)) + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); + } else { + si->base_mem +=3D 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE; + } + if (__is_large_section(sbi)) si->base_mem +=3D MAIN_SECS(sbi) * sizeof(struct sec_entry); si->base_mem +=3D __bitmap_size(sbi, SIT_BITMAP); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8942b2a63cfd..11f3601ffd34 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4914,6 +4914,12 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info= *sbi) return F2FS_OPTION(sbi).fs_mode =3D=3D FS_MODE_LFS; } =20 +/* Share SIT valid maps only for zoned LFS. */ +static inline bool f2fs_use_shared_sit_map(struct f2fs_sb_info *sbi) +{ + return f2fs_sb_has_blkzoned(sbi) && f2fs_lfs_mode(sbi); +} + static inline bool f2fs_is_sequential_zone_area(struct f2fs_sb_info *sbi, block_t blkaddr) { diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c9cfc8f17698..0dab6b16ba56 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -31,6 +31,24 @@ static struct kmem_cache *discard_entry_slab; static struct kmem_cache *discard_cmd_slab; static struct kmem_cache *sit_entry_set_slab; static struct kmem_cache *revoke_entry_slab; +static struct kmem_cache *sit_bitmap_slab; + +struct f2fs_sit_bitmap { + struct rcu_head rcu; + unsigned char map[SIT_VBLOCK_MAP_SIZE]; +}; + +static void f2fs_free_sit_bitmap_rcu(struct rcu_head *rcu) +{ + struct f2fs_sit_bitmap *b =3D container_of(rcu, struct f2fs_sit_bitmap, r= cu); + + kmem_cache_free(sit_bitmap_slab, b); +} + +static struct f2fs_sit_bitmap *f2fs_sit_bitmap_from_map(void *map) +{ + return container_of(map, struct f2fs_sit_bitmap, map); +} =20 static unsigned long __reverse_ulong(unsigned char *str) { @@ -2444,6 +2462,31 @@ static int update_sit_entry_for_release(struct f2fs_= sb_info *sbi, struct seg_ent =20 f2fs_bug_on(sbi, GET_SEGNO(sbi, blkaddr) !=3D GET_SEGNO(sbi, blkaddr + de= l_count - 1)); =20 + if (f2fs_use_shared_sit_map(sbi)) { + struct sit_info *sit_i =3D SIT_I(sbi); + + if (se->cur_valid_map =3D=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_NOFS, true, sbi); + memset(b->map, 0xff, SIT_VBLOCK_MAP_SIZE); + rcu_assign_pointer(se->cur_valid_map, b->map); + se->ckpt_valid_map =3D b->map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); +#endif + } else if (se->cur_valid_map =3D=3D sit_i->bitmap_zero) { + /* Should not happen, freeing empty segment */ + struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_NOFS, true, sbi); + memset(b->map, 0, SIT_VBLOCK_MAP_SIZE); + rcu_assign_pointer(se->cur_valid_map, b->map); + se->ckpt_valid_map =3D b->map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); +#endif + } + } + for (i =3D 0; i < del_count; i++) { exist =3D f2fs_test_and_clear_bit(offset + i, se->cur_valid_map); #ifdef CONFIG_F2FS_CHECK_FS @@ -2478,10 +2521,18 @@ static int update_sit_entry_for_release(struct f2fs= _sb_info *sbi, struct seg_ent f2fs_test_and_clear_bit(offset + i, se->discard_map)) sbi->discard_blks++; =20 - if (!f2fs_test_bit(offset + i, se->ckpt_valid_map)) { - se->ckpt_valid_blocks -=3D 1; - if (__is_large_section(sbi)) - get_sec_entry(sbi, segno)->ckpt_valid_blocks -=3D 1; + if (se->cur_valid_map !=3D se->ckpt_valid_map) { + if (!f2fs_test_bit(offset + i, se->ckpt_valid_map)) { + se->ckpt_valid_blocks -=3D 1; + if (__is_large_section(sbi)) + get_sec_entry(sbi, segno)->ckpt_valid_blocks -=3D 1; + } + } else { + if (exist) { + se->ckpt_valid_blocks -=3D 1; + if (__is_large_section(sbi)) + get_sec_entry(sbi, segno)->ckpt_valid_blocks -=3D 1; + } } } =20 @@ -2499,6 +2550,31 @@ static int update_sit_entry_for_alloc(struct f2fs_sb= _info *sbi, struct seg_entry bool mir_exist; #endif =20 + if (f2fs_use_shared_sit_map(sbi)) { + struct sit_info *sit_i =3D SIT_I(sbi); + + if (se->cur_valid_map =3D=3D sit_i->bitmap_zero) { + struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_NOFS, true, sbi); + memset(b->map, 0, SIT_VBLOCK_MAP_SIZE); + rcu_assign_pointer(se->cur_valid_map, b->map); + se->ckpt_valid_map =3D b->map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); +#endif + } else if (se->cur_valid_map =3D=3D sit_i->bitmap_full) { + /* Should not happen in LFS alloc, but for safety */ + struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_NOFS, true, sbi); + memset(b->map, 0xff, SIT_VBLOCK_MAP_SIZE); + rcu_assign_pointer(se->cur_valid_map, b->map); + se->ckpt_valid_map =3D b->map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); +#endif + } + } + exist =3D f2fs_test_and_set_bit(offset, se->cur_valid_map); #ifdef CONFIG_F2FS_CHECK_FS mir_exist =3D f2fs_test_and_set_bit(offset, @@ -2525,14 +2601,23 @@ static int update_sit_entry_for_alloc(struct f2fs_s= b_info *sbi, struct seg_entry * or newly invalidated. */ if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { - if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) { - se->ckpt_valid_blocks++; - if (__is_large_section(sbi)) - get_sec_entry(sbi, segno)->ckpt_valid_blocks++; + if (se->cur_valid_map !=3D se->ckpt_valid_map) { + if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) { + se->ckpt_valid_blocks++; + if (__is_large_section(sbi)) + get_sec_entry(sbi, segno)->ckpt_valid_blocks++; + } + } else { + if (!exist) { + se->ckpt_valid_blocks++; + if (__is_large_section(sbi)) + get_sec_entry(sbi, segno)->ckpt_valid_blocks++; + } } } =20 - if (!f2fs_test_bit(offset, se->ckpt_valid_map)) { + if (se->cur_valid_map !=3D se->ckpt_valid_map && + !f2fs_test_bit(offset, se->ckpt_valid_map)) { se->ckpt_valid_blocks +=3D del; if (__is_large_section(sbi)) get_sec_entry(sbi, segno)->ckpt_valid_blocks +=3D del; @@ -2582,6 +2667,40 @@ static void update_sit_entry(struct f2fs_sb_info *sb= i, block_t blkaddr, int del) =20 if (__is_large_section(sbi)) get_sec_entry(sbi, segno)->valid_blocks +=3D del; + + if (f2fs_use_shared_sit_map(sbi)) { + struct sit_info *sit_i =3D SIT_I(sbi); + + if (new_vblocks =3D=3D 0 && + se->cur_valid_map !=3D sit_i->bitmap_zero) { + void *old_map =3D se->cur_valid_map; + + rcu_assign_pointer(se->cur_valid_map, sit_i->bitmap_zero); + se->ckpt_valid_map =3D sit_i->bitmap_zero; +#ifdef CONFIG_F2FS_CHECK_FS + memset(se->cur_valid_map_mir, 0, SIT_VBLOCK_MAP_SIZE); +#endif + if (old_map !=3D sit_i->bitmap_zero && + old_map !=3D sit_i->bitmap_full) { + call_rcu(&f2fs_sit_bitmap_from_map(old_map)->rcu, + f2fs_free_sit_bitmap_rcu); + } + } else if (new_vblocks =3D=3D BLKS_PER_SEG(sbi) && + se->cur_valid_map !=3D sit_i->bitmap_full) { + void *old_map =3D se->cur_valid_map; + + rcu_assign_pointer(se->cur_valid_map, sit_i->bitmap_full); + se->ckpt_valid_map =3D sit_i->bitmap_full; +#ifdef CONFIG_F2FS_CHECK_FS + memset(se->cur_valid_map_mir, 0xff, SIT_VBLOCK_MAP_SIZE); +#endif + if (old_map !=3D sit_i->bitmap_zero && + old_map !=3D sit_i->bitmap_full) { + call_rcu(&f2fs_sit_bitmap_from_map(old_map)->rcu, + f2fs_free_sit_bitmap_rcu); + } + } + } } =20 void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr, @@ -4812,6 +4931,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) char *src_bitmap, *bitmap; unsigned int bitmap_size, main_bitmap_size, sit_bitmap_size; unsigned int discard_map =3D f2fs_block_unit_discard(sbi) ? 1 : 0; + bool share_map =3D f2fs_use_shared_sit_map(sbi); =20 /* allocate memory for SIT information */ sit_i =3D f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL); @@ -4838,28 +4958,73 @@ static int build_sit_info(struct f2fs_sb_info *sbi) #else bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (2 + discard_map); #endif - sit_i->bitmap =3D f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); - if (!sit_i->bitmap) - return -ENOMEM; - - bitmap =3D sit_i->bitmap; =20 - for (start =3D 0; start < MAIN_SEGS(sbi); start++) { - rcu_assign_pointer(sit_i->sentries[start].cur_valid_map, - bitmap); - bitmap +=3D SIT_VBLOCK_MAP_SIZE; + if (share_map) { + sit_i->bitmap_zero =3D f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL= ); + if (!sit_i->bitmap_zero) + return -ENOMEM; + sit_i->bitmap_full =3D f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL= ); + if (!sit_i->bitmap_full) { + kfree(sit_i->bitmap_zero); + sit_i->bitmap_zero =3D NULL; + return -ENOMEM; + } + memset(sit_i->bitmap_full, 0xff, SIT_VBLOCK_MAP_SIZE); =20 - sit_i->sentries[start].ckpt_valid_map =3D bitmap; - bitmap +=3D SIT_VBLOCK_MAP_SIZE; + bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * discard_map; +#ifdef CONFIG_F2FS_CHECK_FS + bitmap_size +=3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE; +#endif + if (bitmap_size) { + sit_i->bitmap =3D f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); + if (!sit_i->bitmap) { + kfree(sit_i->bitmap_full); + kfree(sit_i->bitmap_zero); + sit_i->bitmap_full =3D NULL; + sit_i->bitmap_zero =3D NULL; + return -ENOMEM; + } + bitmap =3D sit_i->bitmap; + } =20 + for (start =3D 0; start < MAIN_SEGS(sbi); start++) { + rcu_assign_pointer(sit_i->sentries[start].cur_valid_map, + sit_i->bitmap_zero); + sit_i->sentries[start].ckpt_valid_map =3D + sit_i->bitmap_zero; #ifdef CONFIG_F2FS_CHECK_FS - sit_i->sentries[start].cur_valid_map_mir =3D bitmap; - bitmap +=3D SIT_VBLOCK_MAP_SIZE; + sit_i->sentries[start].cur_valid_map_mir =3D + bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; #endif + if (discard_map) { + sit_i->sentries[start].discard_map =3D bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; + } + } + } else { + sit_i->bitmap =3D f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); + if (!sit_i->bitmap) + return -ENOMEM; + + bitmap =3D sit_i->bitmap; + + for (start =3D 0; start < MAIN_SEGS(sbi); start++) { + rcu_assign_pointer(sit_i->sentries[start].cur_valid_map, bitmap); + bitmap +=3D SIT_VBLOCK_MAP_SIZE; =20 - if (discard_map) { - sit_i->sentries[start].discard_map =3D bitmap; + sit_i->sentries[start].ckpt_valid_map =3D bitmap; bitmap +=3D SIT_VBLOCK_MAP_SIZE; + +#ifdef CONFIG_F2FS_CHECK_FS + sit_i->sentries[start].cur_valid_map_mir =3D bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; +#endif + + if (discard_map) { + sit_i->sentries[start].discard_map =3D bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; + } } } =20 @@ -5009,7 +5174,39 @@ static int build_sit_entries(struct f2fs_sb_info *sb= i) err =3D check_block_count(sbi, start, &sit); if (err) return err; - seg_info_from_raw_sit(se, &sit); + + if (f2fs_use_shared_sit_map(sbi)) { + unsigned int vblocks =3D GET_SIT_VBLOCKS(&sit); + unsigned char *map =3D NULL; + bool is_active =3D is_curseg(sbi, start); + + if (vblocks =3D=3D 0 && !is_active) { + map =3D sit_i->bitmap_zero; + } else if (vblocks =3D=3D BLKS_PER_SEG(sbi) && !is_active) { + map =3D sit_i->bitmap_full; + } else { + struct f2fs_sit_bitmap *b =3D + f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_KERNEL, + false, sbi); + if (!b) + return -ENOMEM; + map =3D b->map; + memcpy(map, sit.valid_map, SIT_VBLOCK_MAP_SIZE); + } + + se->valid_blocks =3D vblocks; + se->ckpt_valid_blocks =3D vblocks; + rcu_assign_pointer(se->cur_valid_map, map); + se->ckpt_valid_map =3D map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); +#endif + se->type =3D GET_SIT_TYPE(&sit); + se->mtime =3D le64_to_cpu(sit.mtime); + } else { + seg_info_from_raw_sit(se, &sit); + } =20 if (se->type >=3D NR_PERSISTENT_LOG) { f2fs_err(sbi, "Invalid segment type: %u, segno: %u", @@ -5039,6 +5236,15 @@ static int build_sit_entries(struct f2fs_sb_info *sb= i) get_sec_entry(sbi, start)->valid_blocks +=3D se->valid_blocks; } + if (f2fs_use_shared_sit_map(sbi)) { + pgoff_t start_addr =3D sit_i->sit_base_addr + start_blk; + pgoff_t end_addr =3D start_addr + readed - 1; + pgoff_t alt_start_addr =3D start_addr + sit_i->sit_blocks; + pgoff_t alt_end_addr =3D alt_start_addr + readed - 1; + + invalidate_mapping_pages(META_MAPPING(sbi), start_addr, end_addr); + invalidate_mapping_pages(META_MAPPING(sbi), alt_start_addr, alt_end_add= r); + } start_blk +=3D readed; } while (start_blk < sit_blk_cnt); =20 @@ -5065,7 +5271,52 @@ static int build_sit_entries(struct f2fs_sb_info *sb= i) err =3D check_block_count(sbi, start, &sit); if (err) break; - seg_info_from_raw_sit(se, &sit); + + if (f2fs_use_shared_sit_map(sbi)) { + unsigned int vblocks =3D GET_SIT_VBLOCKS(&sit); + unsigned char *map =3D se->cur_valid_map; + bool is_active =3D is_curseg(sbi, start); + + if (vblocks =3D=3D 0 && !is_active) { + if (map !=3D sit_i->bitmap_zero && + map !=3D sit_i->bitmap_full) + kmem_cache_free(sit_bitmap_slab, + f2fs_sit_bitmap_from_map(map)); + map =3D sit_i->bitmap_zero; + } else if (vblocks =3D=3D BLKS_PER_SEG(sbi) && !is_active) { + if (map !=3D sit_i->bitmap_zero && + map !=3D sit_i->bitmap_full) + kmem_cache_free(sit_bitmap_slab, + f2fs_sit_bitmap_from_map(map)); + map =3D sit_i->bitmap_full; + } else { + if (map =3D=3D sit_i->bitmap_zero || + map =3D=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b =3D + f2fs_kmem_cache_alloc(sit_bitmap_slab, + GFP_KERNEL, + false, sbi); + if (!b) { + up_read(&curseg->journal_rwsem); + return -ENOMEM; + } + map =3D b->map; + } + memcpy(map, sit.valid_map, SIT_VBLOCK_MAP_SIZE); + } + + se->valid_blocks =3D vblocks; + se->ckpt_valid_blocks =3D vblocks; + rcu_assign_pointer(se->cur_valid_map, map); + se->ckpt_valid_map =3D map; +#ifdef CONFIG_F2FS_CHECK_FS + memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); +#endif + se->type =3D GET_SIT_TYPE(&sit); + se->mtime =3D le64_to_cpu(sit.mtime); + } else { + seg_info_from_raw_sit(se, &sit); + } =20 if (se->type >=3D NR_PERSISTENT_LOG) { f2fs_err(sbi, "Invalid segment type: %u, segno: %u", @@ -5844,8 +6095,30 @@ static void destroy_sit_info(struct f2fs_sb_info *sb= i) if (!sit_i) return; =20 - if (sit_i->sentries) - kvfree(sit_i->bitmap); + if (sit_i->sentries) { + if (f2fs_use_shared_sit_map(sbi)) { + unsigned int start; + + for (start =3D 0; start < MAIN_SEGS(sbi); start++) { + struct seg_entry *se =3D &sit_i->sentries[start]; + + if (se->cur_valid_map && + se->cur_valid_map !=3D sit_i->bitmap_zero && + se->cur_valid_map !=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b; + + b =3D f2fs_sit_bitmap_from_map(se->cur_valid_map); + kmem_cache_free(sit_bitmap_slab, b); + } + } + kfree(sit_i->bitmap_zero); + kfree(sit_i->bitmap_full); + if (sit_i->bitmap) + kvfree(sit_i->bitmap); + } else { + kvfree(sit_i->bitmap); + } + } kfree(sit_i->tmp_map); =20 kvfree(sit_i->sentries); @@ -5898,8 +6171,16 @@ int __init f2fs_create_segment_manager_caches(void) sizeof(struct revoke_entry)); if (!revoke_entry_slab) goto destroy_sit_entry_set; + + sit_bitmap_slab =3D f2fs_kmem_cache_create("f2fs_sit_bitmap", + sizeof(struct f2fs_sit_bitmap)); + if (!sit_bitmap_slab) + goto destroy_revoke_entry; + return 0; =20 +destroy_revoke_entry: + kmem_cache_destroy(revoke_entry_slab); destroy_sit_entry_set: kmem_cache_destroy(sit_entry_set_slab); destroy_discard_cmd: @@ -5916,4 +6197,5 @@ void f2fs_destroy_segment_manager_caches(void) kmem_cache_destroy(discard_cmd_slab); kmem_cache_destroy(discard_entry_slab); kmem_cache_destroy(revoke_entry_slab); + kmem_cache_destroy(sit_bitmap_slab); } diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 068845660b0f..cb45cfa7a658 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -233,6 +233,9 @@ struct sit_info { unsigned long long dirty_max_mtime; /* rerange candidates in GC_AT */ =20 unsigned int last_victim[MAX_GC_POLICY]; /* last victim segment # */ + + unsigned char *bitmap_zero; /* shared zero bitmap */ + unsigned char *bitmap_full; /* shared full bitmap */ }; =20 struct free_segmap_info { diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 8774c60b4be4..83ce88ce12cb 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2617,6 +2617,10 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_in= fo *sbi) f2fs_err(sbi, "checkpoint=3Ddisable on readonly fs"); return -EINVAL; } + if (f2fs_use_shared_sit_map(sbi)) { + f2fs_err(sbi, "checkpoint=3Ddisable is not supported in zoned shared SIT= mode"); + return -EOPNOTSUPP; + } sbi->sb->s_flags |=3D SB_ACTIVE; =20 /* check if we need more GC first */ diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 9c79f7b63583..2baf349721c9 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1788,8 +1788,7 @@ static int __maybe_unused segment_bits_seq_show(struc= t seq_file *seq, seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks); =20 rcu_read_lock(); - memcpy(map, rcu_dereference(se->cur_valid_map), - SIT_VBLOCK_MAP_SIZE); + memcpy(map, rcu_dereference(se->cur_valid_map), SIT_VBLOCK_MAP_SIZE); rcu_read_unlock(); =20 for (j =3D 0; j < SIT_VBLOCK_MAP_SIZE; j++) --=20 2.53.0 From nobody Thu Apr 9 11:16:25 2026 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 65A8438F246 for ; Mon, 9 Mar 2026 10:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052671; cv=none; b=U2ZR8N7pcpKCIBCsKRw5MkcOOnKlR3mdEzqt8YJxafaS5+7w8hmKdsbba/STrPfbxTQa4XKzpQgklypv2Ds7veC/nVXc9zeVacTNfor+at5Z9qOJzmA08RdYXv9YYZNNFmQI1NY+1ZS77dohLKB5xZjI7cScq47xzO0SCghopSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773052671; c=relaxed/simple; bh=qt5t1/emrS46onB3YmmEZ6IIOIey3P2ogr8O6ImMkhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sudRr9E7N6e54uiSH9mxXJvfmk1FLp+CljGjp7DstrsN2kzFmdAQ9FIegFS3ccWrn82LKSLs4lrCbfQe8sMhLCp4uVZc34G3ObxIeKGSpA4XRv2YdEalMjqpMT6iORLTVh29AF+m/RYpf+WpTJKi19LP+RHO4v9gVNEKgdPD8yE= 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=J/Og1nE/; arc=none smtp.client-ip=209.85.210.41 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="J/Og1nE/" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7d556c1a79eso12861661a34.3 for ; Mon, 09 Mar 2026 03:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773052668; x=1773657468; 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; bh=C40mOQiFhCho9b1ncDKXUwUmuyOAb3ID3hm31CJf4pM=; b=J/Og1nE/tpbsoVdd4iZZl8YVG/zewLVsqtAh4HxnVV1YDStA9FETbD0SjemBdfkBJE 3JS3XwZxgZXs4ieE7ZDfAZq9INuol6HuV4zGl6khUoxx1p6eTAfgvRrwj0rjdnbSgYbO ZAmfBFTo2Q75zh3FJgJYnvUMwch1c2+iFxxvbn1bdLL18veHvDszmLFO1YGrD0r8QPUd uTOmibIrd9G8/dcJKAx2LHX1NJ5cfnEDYLDiy5W1M8SUpwa4lt006jj/7/kP/jrycNKG /5s8BWzW4ZaBL5UiIwAR8v3VxhqD526md8xxqoE/0jyuH9Bz/klssn1etBpBS0hJSK+g xNVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773052668; x=1773657468; 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; bh=C40mOQiFhCho9b1ncDKXUwUmuyOAb3ID3hm31CJf4pM=; b=iorBDUvjHdoRdYZsKggidmODCBnDg7PruKwd3KE4ELKLa6L0sJQKxSkJn79YwSXFc3 IxF3F7ApL8uVr9FuwKU9FO8zPmgOwhvixXP9cikNErLBetkOU9Bg/sdByH5rGsdnTV4x VWTa+DAPprD4WCD12gm3eaMNynElOgFZ+T95CeIOJI462VHqBF0xmYb22R378dEBef9j fb96dg4BKXCcWBOwQC3wX222M1V3yVYCE7Z+SbkoX3JzlXL0KzIKCODYc68vpZo4JAjD KVXD0ZcRcSouOgAL1Oorq5E/f9GDohoBTts4f05bXftv+Gc7WsHytvimlpzXohZKJrWD lqnQ== X-Forwarded-Encrypted: i=1; AJvYcCWiuaO4FWVc1PijL9ss9TYj8tS65kCUb0y4DMjDPLAXZmGRyZBgPSD4G4mHVPjHt5qO42i1eeSQ2hmSeqY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/J8LFrrHxF8is/pMV9gpmCEYEu/JZS33VWp47LlrUcY72CY6o zxlu6YBlj2ysTHbAr5W8r/BF3kcHLiNvgfAJ004I6Yfr7OXheDQ/MjbkHuwyHrm6 X-Gm-Gg: ATEYQzzG+BvoxZw8ChKg2x+8vIDmTCVOB5agxVZ1OuZESx1Rtpa2KOU0c34yy9ZAihF TX2HGAgNbPgaHn55CC9i/p/Z+5O8XoQl4he62R3aReoWH/DcEUrqS2NWPJrwcbkvDY3LPbG8XwC eEkV4noBIviG+zGpWo4P/bcBkvuSntHlIdjRiuUk0o/OdrfBUPkmGLFnzlB5c0jLJhpzt2vzFIx oLZHIaDI7yzePtWwa7wQG8ueFQ4dR1B1bCS2HEpFArMDbBOuL8m1dEFkUUqbLFasyOF5nS0oS7R WDLPMD1taOVaTZDNO62eX3nX44lavQjvseOklUeB9XuuD8shydJLz7okehnW1vPCIUhcBNUY2ER dWd4PoL1zJmNm09B1A0Db3VJfh7CCz/WeWrQELJ3tC2U+pxzMbMS+3+W7yYI8I2Fuz/0fDrjcKJ zhrL44+3MdiHSKc1X44Knm74HJIXnFLT+jAQtsTJIJYAaR49TTj6d+E+nJxH567Q== X-Received: by 2002:a05:6830:838b:b0:7d7:5460:49cd with SMTP id 46e09a7af769-7d7546055e6mr389579a34.14.1773052668303; Mon, 09 Mar 2026 03:37:48 -0700 (PDT) Received: from starman.tricat-industries.com ([136.49.86.72]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d755603798sm231247a34.29.2026.03.09.03.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 03:37:47 -0700 (PDT) From: 'wallentx To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org, wallentx Subject: [RFC PATCH 3/3] f2fs: add mount option to disable shared SIT mirror checks Date: Mon, 9 Mar 2026 05:37:00 -0500 Message-ID: <20260309103700.489932-4-william.allentx@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309103700.489932-1-william.allentx@gmail.com> References: <20260309103700.489932-1-william.allentx@gmail.com> 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" From: wallentx When CONFIG_F2FS_CHECK_FS=3Dy, zoned shared-SIT mode still keeps per-segment cur_valid_map_mir together with auxiliary SIT mirror state for runtime consistency checks. After shared SIT maps are introduced, that mirror path becomes the next major static memory cost on large zoned systems. Add shared_sit_check/noshared_sit_check to control that extra mirror tracking explicitly. Keep shared_sit_check as the default, limit the option to zoned shared-SIT mounts, and reject changing it by remount because the mirror state is built at mount time. With noshared_sit_check, shared-SIT mode skips cur_valid_map_mir, sit_bitmap_mir, and invalid_segmap allocation and their associated check paths. This does not disable all CONFIG_F2FS_CHECK_FS behavior; it only disables the extra shared-SIT mirror tracking. On the same 43-volume HM-SMR test system (~550 TB total) with CONFIG_F2FS_CHECK_FS=3Dy, shared SIT with the default mirror path enabled reported 27.70 GiB of static F2FS memory. Mounting with noshared_sit_check reduced that to 12.10 GiB. Signed-off-by: wallentx --- Documentation/filesystems/f2fs.rst | 11 ++ fs/f2fs/debug.c | 7 +- fs/f2fs/f2fs.h | 16 +++ fs/f2fs/gc.c | 29 ++-- fs/f2fs/segment.c | 213 ++++++++++++++++------------- fs/f2fs/segment.h | 28 ++-- fs/f2fs/super.c | 21 +++ 7 files changed, 204 insertions(+), 121 deletions(-) diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems= /f2fs.rst index 7e4031631286..3ca191f92309 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -363,6 +363,17 @@ memory=3D%s Control memory mode. This supports "norm= al" and "low" modes. Because of the nature of low memory devices, in this mode, f2fs will try to save memory sometimes by sacrificing performance. "normal" mode is the default mode and same as before. +shared_sit_check/ +noshared_sit_check Enable or disable extra SIT mirror consistency checks = in + zoned shared-SIT mode. This only affects zoned devices + mounted with ``mode=3Dlfs``, where shared SIT valid maps are + used. ``shared_sit_check`` is enabled by default. Setting + ``noshared_sit_check`` reduces memory usage when the kernel + is built with ``CONFIG_F2FS_CHECK_FS=3Dy`` by skipping the + per-segment SIT mirror tracking. This option has no effect + when shared SIT maps are not in use and cannot be changed + by remount. To use a different setting, unmount and + mount again with the new option. age_extent_cache Enable an age extent cache based on rb-tree. It records data block update frequency of the extent per inode, in order to provide better temperature hints for data block diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index d8bfdac5c1e4..ed6e03b42836 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -325,9 +325,10 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * 2; /* Approximate private bitmaps for active logs */ si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * NR_CURSEG_TYPE; -#ifdef CONFIG_F2FS_CHECK_FS - si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); + #endif if (f2fs_block_unit_discard(sbi)) si->base_mem +=3D SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); } else { diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 11f3601ffd34..d8526103d86a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -130,6 +130,7 @@ enum f2fs_mount_opt { F2FS_MOUNT_COMPRESS_CACHE, F2FS_MOUNT_AGE_EXTENT_CACHE, F2FS_MOUNT_NAT_BITS, + F2FS_MOUNT_SHARED_SIT_CHECK, F2FS_MOUNT_INLINECRYPT, /* * Some f2fs environments expect to be able to pass the "lazytime" option @@ -4920,6 +4921,21 @@ static inline bool f2fs_use_shared_sit_map(struct f2= fs_sb_info *sbi) return f2fs_sb_has_blkzoned(sbi) && f2fs_lfs_mode(sbi); } =20 +/* + * shared_sit_check is a mount-time escape hatch for the extra SIT mirror + * tracking kept by CONFIG_F2FS_CHECK_FS in zoned shared-SIT mode. + */ +static inline bool f2fs_sit_check_enabled(struct f2fs_sb_info *sbi) +{ + if (!IS_ENABLED(CONFIG_F2FS_CHECK_FS)) + return false; + + if (!f2fs_use_shared_sit_map(sbi)) + return true; + + return test_opt(sbi, SHARED_SIT_CHECK); +} + static inline bool f2fs_is_sequential_zone_area(struct f2fs_sb_info *sbi, block_t blkaddr) { diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 80b8500fa987..1decb0caea1b 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -877,15 +877,16 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigne= d int *result, p.offset =3D segno + p.ofs_unit; nsearched++; =20 -#ifdef CONFIG_F2FS_CHECK_FS - /* - * skip selecting the invalid segno (that is failed due to block - * validity check failure during GC) to avoid endless GC loop in - * such cases. - */ - if (test_bit(segno, sm->invalid_segmap)) - goto next; -#endif + #ifdef CONFIG_F2FS_CHECK_FS + /* + * skip selecting the invalid segno (that is failed due to block + * validity check failure during GC) to avoid endless GC loop in + * such cases. + */ + if (f2fs_sit_check_enabled(sbi) && + test_bit(segno, sm->invalid_segmap)) + goto next; + #endif =20 secno =3D GET_SEC_FROM_SEG(sbi, segno); =20 @@ -1197,18 +1198,20 @@ static bool is_alive(struct f2fs_sb_info *sbi, stru= ct f2fs_summary *sum, f2fs_folio_put(node_folio, true); =20 if (source_blkaddr !=3D blkaddr) { -#ifdef CONFIG_F2FS_CHECK_FS + #ifdef CONFIG_F2FS_CHECK_FS unsigned int segno =3D GET_SEGNO(sbi, blkaddr); unsigned long offset =3D GET_BLKOFF_FROM_SEG0(sbi, blkaddr); =20 - if (unlikely(check_valid_map(sbi, segno, offset))) { + if (f2fs_sit_check_enabled(sbi) && + unlikely(check_valid_map(sbi, segno, offset))) { if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { - f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u", + f2fs_err(sbi, + "mismatched blkaddr %u (source_blkaddr %u) in seg %u", blkaddr, source_blkaddr, segno); set_sbi_flag(sbi, SBI_NEED_FSCK); } } -#endif + #endif return false; } return true; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 0dab6b16ba56..dce66eec2a5f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -38,6 +38,11 @@ struct f2fs_sit_bitmap { unsigned char map[SIT_VBLOCK_MAP_SIZE]; }; =20 +static inline struct f2fs_sit_bitmap *f2fs_sit_bitmap_from_map(void *map) +{ + return container_of(map, struct f2fs_sit_bitmap, map); +} + static void f2fs_free_sit_bitmap_rcu(struct rcu_head *rcu) { struct f2fs_sit_bitmap *b =3D container_of(rcu, struct f2fs_sit_bitmap, r= cu); @@ -45,11 +50,6 @@ static void f2fs_free_sit_bitmap_rcu(struct rcu_head *rc= u) kmem_cache_free(sit_bitmap_slab, b); } =20 -static struct f2fs_sit_bitmap *f2fs_sit_bitmap_from_map(void *map) -{ - return container_of(map, struct f2fs_sit_bitmap, map); -} - static unsigned long __reverse_ulong(unsigned char *str) { unsigned long tmp =3D 0; @@ -845,9 +845,10 @@ static void __remove_dirty_segment(struct f2fs_sb_info= *sbi, unsigned int segno, if (valid_blocks =3D=3D 0) { clear_bit(GET_SEC_FROM_SEG(sbi, segno), dirty_i->victim_secmap); -#ifdef CONFIG_F2FS_CHECK_FS - clear_bit(segno, SIT_I(sbi)->invalid_segmap); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + clear_bit(segno, SIT_I(sbi)->invalid_segmap); + #endif } if (__is_large_section(sbi)) { unsigned int secno =3D GET_SEC_FROM_SEG(sbi, segno); @@ -2471,9 +2472,10 @@ static int update_sit_entry_for_release(struct f2fs_= sb_info *sbi, struct seg_ent memset(b->map, 0xff, SIT_VBLOCK_MAP_SIZE); rcu_assign_pointer(se->cur_valid_map, b->map); se->ckpt_valid_map =3D b->map; -#ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); + #endif } else if (se->cur_valid_map =3D=3D sit_i->bitmap_zero) { /* Should not happen, freeing empty segment */ struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, @@ -2481,23 +2483,27 @@ static int update_sit_entry_for_release(struct f2fs= _sb_info *sbi, struct seg_ent memset(b->map, 0, SIT_VBLOCK_MAP_SIZE); rcu_assign_pointer(se->cur_valid_map, b->map); se->ckpt_valid_map =3D b->map; -#ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); + #endif } } =20 for (i =3D 0; i < del_count; i++) { exist =3D f2fs_test_and_clear_bit(offset + i, se->cur_valid_map); -#ifdef CONFIG_F2FS_CHECK_FS - mir_exist =3D f2fs_test_and_clear_bit(offset + i, - se->cur_valid_map_mir); - if (unlikely(exist !=3D mir_exist)) { - f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit= :%d", - blkaddr + i, exist); - f2fs_bug_on(sbi, 1); - } -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) { + mir_exist =3D f2fs_test_and_clear_bit(offset + i, + se->cur_valid_map_mir); + if (unlikely(exist !=3D mir_exist)) { + f2fs_err(sbi, + "Inconsistent error when clearing bitmap, blk:%u, old bit:%d", + blkaddr + i, exist); + f2fs_bug_on(sbi, 1); + } + } + #endif if (unlikely(!exist)) { f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u", blkaddr + i); f2fs_bug_on(sbi, 1); @@ -2559,9 +2565,10 @@ static int update_sit_entry_for_alloc(struct f2fs_sb= _info *sbi, struct seg_entry memset(b->map, 0, SIT_VBLOCK_MAP_SIZE); rcu_assign_pointer(se->cur_valid_map, b->map); se->ckpt_valid_map =3D b->map; -#ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); + #endif } else if (se->cur_valid_map =3D=3D sit_i->bitmap_full) { /* Should not happen in LFS alloc, but for safety */ struct f2fs_sit_bitmap *b =3D f2fs_kmem_cache_alloc(sit_bitmap_slab, @@ -2569,22 +2576,26 @@ static int update_sit_entry_for_alloc(struct f2fs_s= b_info *sbi, struct seg_entry memset(b->map, 0xff, SIT_VBLOCK_MAP_SIZE); rcu_assign_pointer(se->cur_valid_map, b->map); se->ckpt_valid_map =3D b->map; -#ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, b->map, SIT_VBLOCK_MAP_SIZE); + #endif } } =20 exist =3D f2fs_test_and_set_bit(offset, se->cur_valid_map); -#ifdef CONFIG_F2FS_CHECK_FS - mir_exist =3D f2fs_test_and_set_bit(offset, - se->cur_valid_map_mir); - if (unlikely(exist !=3D mir_exist)) { - f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%= d", - blkaddr, exist); - f2fs_bug_on(sbi, 1); + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) { + mir_exist =3D f2fs_test_and_set_bit(offset, + se->cur_valid_map_mir); + if (unlikely(exist !=3D mir_exist)) { + f2fs_err(sbi, + "Inconsistent error when setting bitmap, blk:%u, old bit:%d", + blkaddr, exist); + f2fs_bug_on(sbi, 1); + } } -#endif + #endif if (unlikely(exist)) { f2fs_err(sbi, "Bitmap was wrongly set, blk:%u", blkaddr); f2fs_bug_on(sbi, 1); @@ -2677,13 +2688,15 @@ static void update_sit_entry(struct f2fs_sb_info *s= bi, block_t blkaddr, int del) =20 rcu_assign_pointer(se->cur_valid_map, sit_i->bitmap_zero); se->ckpt_valid_map =3D sit_i->bitmap_zero; -#ifdef CONFIG_F2FS_CHECK_FS - memset(se->cur_valid_map_mir, 0, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memset(se->cur_valid_map_mir, 0, SIT_VBLOCK_MAP_SIZE); + #endif if (old_map !=3D sit_i->bitmap_zero && old_map !=3D sit_i->bitmap_full) { - call_rcu(&f2fs_sit_bitmap_from_map(old_map)->rcu, - f2fs_free_sit_bitmap_rcu); + struct f2fs_sit_bitmap *b =3D + f2fs_sit_bitmap_from_map(old_map); + call_rcu(&b->rcu, f2fs_free_sit_bitmap_rcu); } } else if (new_vblocks =3D=3D BLKS_PER_SEG(sbi) && se->cur_valid_map !=3D sit_i->bitmap_full) { @@ -2691,13 +2704,15 @@ static void update_sit_entry(struct f2fs_sb_info *s= bi, block_t blkaddr, int del) =20 rcu_assign_pointer(se->cur_valid_map, sit_i->bitmap_full); se->ckpt_valid_map =3D sit_i->bitmap_full; -#ifdef CONFIG_F2FS_CHECK_FS - memset(se->cur_valid_map_mir, 0xff, SIT_VBLOCK_MAP_SIZE); -#endif + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) + memset(se->cur_valid_map_mir, 0xff, SIT_VBLOCK_MAP_SIZE); + #endif if (old_map !=3D sit_i->bitmap_zero && old_map !=3D sit_i->bitmap_full) { - call_rcu(&f2fs_sit_bitmap_from_map(old_map)->rcu, - f2fs_free_sit_bitmap_rcu); + struct f2fs_sit_bitmap *b =3D + f2fs_sit_bitmap_from_map(old_map); + call_rcu(&b->rcu, f2fs_free_sit_bitmap_rcu); } } } @@ -4701,7 +4716,7 @@ static struct folio *get_next_sit_folio(struct f2fs_s= b_info *sbi, seg_info_to_sit_folio(sbi, folio, start); =20 folio_mark_dirty(folio); - set_to_next_sit(sit_i, start); + set_to_next_sit(sbi, sit_i, start); =20 return folio; } @@ -4857,11 +4872,12 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sb= i, struct cp_control *cpc) int offset, sit_offset; =20 se =3D get_seg_entry(sbi, segno); -#ifdef CONFIG_F2FS_CHECK_FS - if (memcmp(se->cur_valid_map, se->cur_valid_map_mir, - SIT_VBLOCK_MAP_SIZE)) + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi) && + memcmp(se->cur_valid_map, se->cur_valid_map_mir, + SIT_VBLOCK_MAP_SIZE)) f2fs_bug_on(sbi, 1); -#endif + #endif =20 /* add discard candidates */ if (!(cpc->reason & CP_DISCARD)) { @@ -4953,11 +4969,8 @@ static int build_sit_info(struct f2fs_sb_info *sbi) if (!sit_i->dirty_sentries_bitmap) return -ENOMEM; =20 -#ifdef CONFIG_F2FS_CHECK_FS - bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (3 + discard_map); -#else - bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (2 + discard_map); -#endif + bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * + (2 + discard_map + f2fs_sit_check_enabled(sbi)); =20 if (share_map) { sit_i->bitmap_zero =3D f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL= ); @@ -4971,10 +4984,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi) } memset(sit_i->bitmap_full, 0xff, SIT_VBLOCK_MAP_SIZE); =20 - bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * discard_map; -#ifdef CONFIG_F2FS_CHECK_FS - bitmap_size +=3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE; -#endif + bitmap_size =3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * discard_map; + if (f2fs_sit_check_enabled(sbi)) + bitmap_size +=3D MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE; if (bitmap_size) { sit_i->bitmap =3D f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); if (!sit_i->bitmap) { @@ -4993,9 +5005,10 @@ static int build_sit_info(struct f2fs_sb_info *sbi) sit_i->sentries[start].ckpt_valid_map =3D sit_i->bitmap_zero; #ifdef CONFIG_F2FS_CHECK_FS - sit_i->sentries[start].cur_valid_map_mir =3D - bitmap; - bitmap +=3D SIT_VBLOCK_MAP_SIZE; + if (f2fs_sit_check_enabled(sbi)) { + sit_i->sentries[start].cur_valid_map_mir =3D bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; + } #endif if (discard_map) { sit_i->sentries[start].discard_map =3D bitmap; @@ -5017,8 +5030,10 @@ static int build_sit_info(struct f2fs_sb_info *sbi) bitmap +=3D SIT_VBLOCK_MAP_SIZE; =20 #ifdef CONFIG_F2FS_CHECK_FS - sit_i->sentries[start].cur_valid_map_mir =3D bitmap; - bitmap +=3D SIT_VBLOCK_MAP_SIZE; + if (f2fs_sit_check_enabled(sbi)) { + sit_i->sentries[start].cur_valid_map_mir =3D bitmap; + bitmap +=3D SIT_VBLOCK_MAP_SIZE; + } #endif =20 if (discard_map) { @@ -5052,16 +5067,20 @@ static int build_sit_info(struct f2fs_sb_info *sbi) if (!sit_i->sit_bitmap) return -ENOMEM; =20 -#ifdef CONFIG_F2FS_CHECK_FS - sit_i->sit_bitmap_mir =3D kmemdup(src_bitmap, - sit_bitmap_size, GFP_KERNEL); - if (!sit_i->sit_bitmap_mir) - return -ENOMEM; + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi)) { + sit_i->sit_bitmap_mir =3D kmemdup(src_bitmap, + sit_bitmap_size, + GFP_KERNEL); + if (!sit_i->sit_bitmap_mir) + return -ENOMEM; =20 - sit_i->invalid_segmap =3D f2fs_kvzalloc(sbi, - main_bitmap_size, GFP_KERNEL); - if (!sit_i->invalid_segmap) - return -ENOMEM; + sit_i->invalid_segmap =3D f2fs_kvzalloc(sbi, + main_bitmap_size, + GFP_KERNEL); + if (!sit_i->invalid_segmap) + return -ENOMEM; + } #endif =20 sit_i->sit_base_addr =3D le32_to_cpu(raw_super->sit_blkaddr); @@ -5200,12 +5219,13 @@ static int build_sit_entries(struct f2fs_sb_info *s= bi) rcu_assign_pointer(se->cur_valid_map, map); se->ckpt_valid_map =3D map; #ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); #endif se->type =3D GET_SIT_TYPE(&sit); se->mtime =3D le64_to_cpu(sit.mtime); } else { - seg_info_from_raw_sit(se, &sit); + seg_info_from_raw_sit(sbi, se, &sit); } =20 if (se->type >=3D NR_PERSISTENT_LOG) { @@ -5279,15 +5299,19 @@ static int build_sit_entries(struct f2fs_sb_info *s= bi) =20 if (vblocks =3D=3D 0 && !is_active) { if (map !=3D sit_i->bitmap_zero && - map !=3D sit_i->bitmap_full) - kmem_cache_free(sit_bitmap_slab, - f2fs_sit_bitmap_from_map(map)); + map !=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b =3D + f2fs_sit_bitmap_from_map(map); + kmem_cache_free(sit_bitmap_slab, b); + } map =3D sit_i->bitmap_zero; } else if (vblocks =3D=3D BLKS_PER_SEG(sbi) && !is_active) { if (map !=3D sit_i->bitmap_zero && - map !=3D sit_i->bitmap_full) - kmem_cache_free(sit_bitmap_slab, - f2fs_sit_bitmap_from_map(map)); + map !=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b =3D + f2fs_sit_bitmap_from_map(map); + kmem_cache_free(sit_bitmap_slab, b); + } map =3D sit_i->bitmap_full; } else { if (map =3D=3D sit_i->bitmap_zero || @@ -5310,12 +5334,13 @@ static int build_sit_entries(struct f2fs_sb_info *s= bi) rcu_assign_pointer(se->cur_valid_map, map); se->ckpt_valid_map =3D map; #ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, map, SIT_VBLOCK_MAP_SIZE); #endif se->type =3D GET_SIT_TYPE(&sit); se->mtime =3D le64_to_cpu(sit.mtime); } else { - seg_info_from_raw_sit(se, &sit); + seg_info_from_raw_sit(sbi, se, &sit); } =20 if (se->type >=3D NR_PERSISTENT_LOG) { @@ -6099,18 +6124,18 @@ static void destroy_sit_info(struct f2fs_sb_info *s= bi) if (f2fs_use_shared_sit_map(sbi)) { unsigned int start; =20 - for (start =3D 0; start < MAIN_SEGS(sbi); start++) { - struct seg_entry *se =3D &sit_i->sentries[start]; + for (start =3D 0; start < MAIN_SEGS(sbi); start++) { + struct seg_entry *se =3D &sit_i->sentries[start]; =20 - if (se->cur_valid_map && - se->cur_valid_map !=3D sit_i->bitmap_zero && - se->cur_valid_map !=3D sit_i->bitmap_full) { - struct f2fs_sit_bitmap *b; + if (se->cur_valid_map && + se->cur_valid_map !=3D sit_i->bitmap_zero && + se->cur_valid_map !=3D sit_i->bitmap_full) { + struct f2fs_sit_bitmap *b; =20 - b =3D f2fs_sit_bitmap_from_map(se->cur_valid_map); - kmem_cache_free(sit_bitmap_slab, b); + b =3D f2fs_sit_bitmap_from_map(se->cur_valid_map); + kmem_cache_free(sit_bitmap_slab, b); + } } - } kfree(sit_i->bitmap_zero); kfree(sit_i->bitmap_full); if (sit_i->bitmap) diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index cb45cfa7a658..0f4445375ed1 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -404,15 +404,17 @@ static inline void sanity_check_valid_blocks(struct f= 2fs_sb_info *sbi, { } #endif -static inline void seg_info_from_raw_sit(struct seg_entry *se, - struct f2fs_sit_entry *rs) +static inline void seg_info_from_raw_sit(struct f2fs_sb_info *sbi, + struct seg_entry *se, + struct f2fs_sit_entry *rs) { se->valid_blocks =3D GET_SIT_VBLOCKS(rs); se->ckpt_valid_blocks =3D GET_SIT_VBLOCKS(rs); memcpy(se->cur_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); #ifdef CONFIG_F2FS_CHECK_FS - memcpy(se->cur_valid_map_mir, rs->valid_map, SIT_VBLOCK_MAP_SIZE); + if (f2fs_sit_check_enabled(sbi)) + memcpy(se->cur_valid_map_mir, rs->valid_map, SIT_VBLOCK_MAP_SIZE); #endif se->type =3D GET_SIT_TYPE(rs); se->mtime =3D le64_to_cpu(rs->mtime); @@ -558,11 +560,12 @@ static inline void get_sit_bitmap(struct f2fs_sb_info= *sbi, { struct sit_info *sit_i =3D SIT_I(sbi); =20 -#ifdef CONFIG_F2FS_CHECK_FS - if (memcmp(sit_i->sit_bitmap, sit_i->sit_bitmap_mir, - sit_i->bitmap_size)) + #ifdef CONFIG_F2FS_CHECK_FS + if (f2fs_sit_check_enabled(sbi) && + memcmp(sit_i->sit_bitmap, sit_i->sit_bitmap_mir, + sit_i->bitmap_size)) f2fs_bug_on(sbi, 1); -#endif + #endif memcpy(dst_addr, sit_i->sit_bitmap, sit_i->bitmap_size); } =20 @@ -904,8 +907,9 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_i= nfo *sbi, f2fs_bug_on(sbi, !valid_main_segno(sbi, start)); =20 #ifdef CONFIG_F2FS_CHECK_FS - if (f2fs_test_bit(offset, sit_i->sit_bitmap) !=3D - f2fs_test_bit(offset, sit_i->sit_bitmap_mir)) + if (f2fs_sit_check_enabled(sbi) && + f2fs_test_bit(offset, sit_i->sit_bitmap) !=3D + f2fs_test_bit(offset, sit_i->sit_bitmap_mir)) f2fs_bug_on(sbi, 1); #endif =20 @@ -929,13 +933,15 @@ static inline pgoff_t next_sit_addr(struct f2fs_sb_in= fo *sbi, return block_addr + sit_i->sit_base_addr; } =20 -static inline void set_to_next_sit(struct sit_info *sit_i, unsigned int st= art) +static inline void set_to_next_sit(struct f2fs_sb_info *sbi, + struct sit_info *sit_i, unsigned int start) { unsigned int block_off =3D SIT_BLOCK_OFFSET(start); =20 f2fs_change_bit(block_off, sit_i->sit_bitmap); #ifdef CONFIG_F2FS_CHECK_FS - f2fs_change_bit(block_off, sit_i->sit_bitmap_mir); + if (f2fs_sit_check_enabled(sbi)) + f2fs_change_bit(block_off, sit_i->sit_bitmap_mir); #endif } =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 83ce88ce12cb..e2bb5d0ab3e1 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -228,6 +228,7 @@ enum { Opt_gc_merge, Opt_discard_unit, Opt_memory_mode, + Opt_shared_sit_check, Opt_age_extent_cache, Opt_errors, Opt_nat_bits, @@ -359,6 +360,7 @@ static const struct fs_parameter_spec f2fs_param_specs[= ] =3D { fsparam_flag_no("gc_merge", Opt_gc_merge), fsparam_enum("discard_unit", Opt_discard_unit, f2fs_param_discard_unit), fsparam_enum("memory", Opt_memory_mode, f2fs_param_memory_mode), + fsparam_flag_no("shared_sit_check", Opt_shared_sit_check), fsparam_flag("age_extent_cache", Opt_age_extent_cache), fsparam_enum("errors", Opt_errors, f2fs_param_errors), fsparam_enum("lookup_mode", Opt_lookup_mode, f2fs_param_lookup_mode), @@ -1217,6 +1219,12 @@ static int f2fs_parse_param(struct fs_context *fc, s= truct fs_parameter *param) F2FS_CTX_INFO(ctx).memory_mode =3D result.uint_32; ctx->spec_mask |=3D F2FS_SPEC_memory_mode; break; + case Opt_shared_sit_check: + if (result.negated) + ctx_clear_opt(ctx, F2FS_MOUNT_SHARED_SIT_CHECK); + else + ctx_set_opt(ctx, F2FS_MOUNT_SHARED_SIT_CHECK); + break; case Opt_age_extent_cache: ctx_set_opt(ctx, F2FS_MOUNT_AGE_EXTENT_CACHE); break; @@ -2514,6 +2522,11 @@ static int f2fs_show_options(struct seq_file *seq, s= truct dentry *root) else if (F2FS_OPTION(sbi).memory_mode =3D=3D MEMORY_MODE_LOW) seq_printf(seq, ",memory=3D%s", "low"); =20 + if (test_opt(sbi, SHARED_SIT_CHECK)) + seq_puts(seq, ",shared_sit_check"); + else + seq_puts(seq, ",noshared_sit_check"); + if (F2FS_OPTION(sbi).errors =3D=3D MOUNT_ERRORS_READONLY) seq_printf(seq, ",errors=3D%s", "remount-ro"); else if (F2FS_OPTION(sbi).errors =3D=3D MOUNT_ERRORS_CONTINUE) @@ -2573,6 +2586,7 @@ static void default_options(struct f2fs_sb_info *sbi,= bool remount) F2FS_OPTION(sbi).bggc_mode =3D BGGC_MODE_ON; F2FS_OPTION(sbi).memory_mode =3D MEMORY_MODE_NORMAL; F2FS_OPTION(sbi).errors =3D MOUNT_ERRORS_CONTINUE; + set_opt(sbi, SHARED_SIT_CHECK); =20 set_opt(sbi, INLINE_XATTR); set_opt(sbi, INLINE_DATA); @@ -2782,6 +2796,7 @@ static int __f2fs_remount(struct fs_context *fc, stru= ct super_block *sb) bool no_compress_cache =3D !test_opt(sbi, COMPRESS_CACHE); bool block_unit_discard =3D f2fs_block_unit_discard(sbi); bool no_nat_bits =3D !test_opt(sbi, NAT_BITS); + bool shared_sit_check =3D test_opt(sbi, SHARED_SIT_CHECK); #ifdef CONFIG_QUOTA int i, j; #endif @@ -2904,6 +2919,12 @@ static int __f2fs_remount(struct fs_context *fc, str= uct super_block *sb) goto restore_opts; } =20 + if (shared_sit_check !=3D !!test_opt(sbi, SHARED_SIT_CHECK)) { + err =3D -EINVAL; + f2fs_warn(sbi, "switch shared_sit_check option is not allowed"); + goto restore_opts; + } + if ((flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { err =3D -EINVAL; f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); --=20 2.53.0