From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 1CBA12AD37 for ; Thu, 3 Sep 2026 23:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788476770; cv=none; b=GuzQkDkCWcU7byGVpbfPWzNyGwqq9FSiErQhZMcCPuGbS/ihhEREpp0rNh/YqgMXNEG3YW3ERvuxSHR+clH9urITXZyCaDgt0xNd8zENT8ACko9sSrYIvLDohD9GrkOZtIHiihQQO32OGdNR6SPCCEKbEpWRJ/wU8Kp6sva9YAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788476770; c=relaxed/simple; bh=MxdONtZ4qXs9+6weX7FcBID+xHRxM7khKMFZJyMwTzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SKhR3gmij/Yr1Lru1Lt8qM4SZ9v0VQllwwnhWBtkUQMdbrnR5EeNyfZ0ZKcXxL7CRcx0uP+mJPBbJ8TOFac/eXMP04/qCbGhVQhz8IZoap578dFLeNqwEBSn4EeQl9nrDaYcAsU13LxI1xl71X0unN4XnMe4GL14V2FyB/RCGyo= 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=T3ifP4Z2; arc=none smtp.client-ip=209.85.215.170 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="T3ifP4Z2" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-cb5b8572b70so554834a12.2 for ; Thu, 03 Sep 2026 16:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788476768; x=1789081568; 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=0byPuk5ss0w8gPStks6iC7C9A3PMDT/7QIWY5qOJydM=; b=T3ifP4Z2lNR6LZAWa3NuWlrmI46XwTwcQwEtmTI8/gVpjcIEg7qgrkA+R9zlbmnfRU RYR1QRt5blB64HGZw9vdavyQbUbHA/lGHpadjl5CumESi/QsXxPjXc/K4FgW96QQbMwf xljiju9N8OPxqm5KgPNnYui4+nPqS3ZddmnXk9zSb1bgaiKLh6AT1YZRkQYXOd8XVcCv 9zjePY5iT8peblB1b4z8Ue/087RwHLSvqD2SVZciB/GzPAMP8hjhG73XUJDlvX9t7Ag4 WMWtPUyxsp0fQ+vE4InvpXnQH6T2WZM7HXoQUvVR+PnY8+ZIiOXyrzO2pZdCvU9KePdc 07ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788476768; x=1789081568; 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=0byPuk5ss0w8gPStks6iC7C9A3PMDT/7QIWY5qOJydM=; b=sVm3ptSiiMqg5EiA9yZbCJt0wo5BtqL4R8Ff4RB7U/jlmvM/1dWH+eqgYYip5TBvrc EoJl694DG/a2xkUB9EsJDrw2GR0NMRyV/lO+EZGyX/TszzY1XR1T/ojiyvMuo8du6hCv g2dj5MWsxpkjKjOLXo6QwqwM9vlKHzCJ7Il+LlnjJvbOI4sgoBQPN9oZL0KNR0XIVO9e 8qZJDCLP60cIUZY+YIdveBUodoFmpu518zbsPt/MIcQ7NXjc6tYhh72qpfNgyDo/B0Q2 WKOScomJQUilNc7GhTT8HoAM+hon55EiVUaKc5TaUqqScF77s6UjN8JR8xdfb5Xjex2t Ll8A== X-Forwarded-Encrypted: i=1; AKwUvBzVOn/xzqX8IjPgbWOzk133IK1OgjS2zIgEY+H8eawS0vJfiSjWkoM9r3QtAnFDAgkcgGYdbDTD/4GY7bk=@vger.kernel.org X-Gm-Message-State: AFuF++ml2RFS2kI2vxMPtb1bS9KFZr692GfyycMxGGerCUuBx+hb4FH5 30wNWGIGgcfkSvIE0yNrq3R4OK7qVmr2G9pWQueEbDQYhtvs5gH3T6U5 X-Gm-Gg: AYBFou2tqc2iqtomLuGKu7JZZN3IFojPHdvV0ZH/Pcilv6SVpM6PQ+1KcFNVFQT1CK7 GjiQfxtpkzilCfsDPsAnkCbp37AqvSk0yhBEDMC2A7OnWNTCIknjqh3BxNR84ujwN7TPIVCWGPt 5HbZiBihNEl+xJYzPKhXeNTZEF9fBI+w68+e6Hs6qvU4YlX2n+1wLPin/3NGtB95HNfvWAGeGmD cHnaqFVhd1fpxEbDniZlrF7My+o39AMFuVbfb4j0VisrbYcgUA/lj1WhJ8SjeBvgBhC3Ly9UKyA 9CslHgjX6bwO8KuUHFDwBqWyN5kDMiEQqI/JDAM9NgmPZQm2JLAZ2JhVUnJ/rqk3y0K4Kc70Q/q lZ19B33u9YImf3nzdU3m16UvJoku3GJZd3We4kUGFkoF/mGxmkJ6XgIdKnDq7+TdHqk/fhwkD3h mBisFSmme4aEdlR2lxmi1uwCYNUhgE9stYqaQTO/daLAWdgdoqqdBJSpzmtQNkf8vGykfeOA+6t DUH8A== X-Received: by 2002:a05:6a00:2289:b0:857:726d:2e99 with SMTP id d2e1a72fcca58-8616af5b1aemr3118130b3a.22.1788476768342; Thu, 03 Sep 2026 16:06:08 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-86152c2a536sm429263b3a.31.2026.09.03.16.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:06:07 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 01/11] f2fs: initialize sb_info early in f2fs_fill_super Date: Thu, 3 Sep 2026 16:06:05 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" Previously, init_sb_info() was invoked late in f2fs_fill_super(), after processing superblock error tracking, mount options, and sb->s_maxbytes. However, read_raw_super_block() reads the superblock folio directly from the block device mapping using folio page offsets. This makes the initial static sb_set_blocksize(sb, F2FS_BLKSIZE) call redundant. Move init_sb_info() to execute immediately after sbi->raw_super is attached, allowing the block device block size to be set dynamically via sb_set_blocksize(sb, sbi->blocksize). This early initialization also prepares for upcoming patches that add dynamically computed filesystem geometry fields, such as sbi->addrs_per_block and sbi->nids_per_block, to init_sb_info(). These fields are required by earlier initialization steps, including mount option consistency checks and sb->s_maxbytes computation. Signed-off-by: Kelvin Zhang --- fs/f2fs/super.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 253a579e9d5b..c48acfb30a0d 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5125,12 +5125,6 @@ static int f2fs_fill_super(struct super_block *sb, s= truct fs_context *fc) } mutex_init(&sbi->flush_lock); =20 - /* set a block size */ - if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { - f2fs_err(sbi, "unable to set blocksize"); - goto free_sbi; - } - err =3D read_raw_super_block(sbi, &raw_super, &valid_super_block, &recovery); if (err) @@ -5138,6 +5132,14 @@ static int f2fs_fill_super(struct super_block *sb, s= truct fs_context *fc) =20 sb->s_fs_info =3D sbi; sbi->raw_super =3D raw_super; + init_sb_info(sbi); + + /* set a block size */ + if (unlikely(!sb_set_blocksize(sb, sbi->blocksize))) { + f2fs_err(sbi, "unable to set blocksize %u", sbi->blocksize); + err =3D -EINVAL; + goto free_sb_buf; + } sbi->max_atc_write_bio_size =3D UINT_MAX; =20 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); @@ -5217,8 +5219,6 @@ static int f2fs_fill_super(struct super_block *sb, st= ruct fs_context *fc) if (err) goto free_bio_info; =20 - init_sb_info(sbi); - err =3D f2fs_init_iostat(sbi); if (err) goto free_bio_info; --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 2A6ED35AC37 for ; Thu, 3 Sep 2026 23:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477102; cv=none; b=i/T7WxoTU3UYJkx5BFsBpprmk2GMqMSjzokhnm+Hay4o93p19EurFDXjGkqgzoOLMxWdopo8XMP7vhXYFCfCI2j4wn9fVBn+KWOZBtLvHH3dzO6z3Z8MaobFTJVUw1rgPZopqFYoxjxxr1kZQ5DNv9BjWbLm3WfBDDHy6l8TBvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477102; c=relaxed/simple; bh=/eKzcUYqtqi6ZyS8O2gK/artlZUxLrE3srKDRDStQ3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kdotEib7EGalmpqH9xTJ/bkh+T6ff44ecQNUgJNfFnFFchuMr6EGYTm0yFkDNZximse0BvUMrmeXT9c2xuijR6F+92BsKV0YgsKKSz6mJK3Ws6HftvpScW1FEGUeoQosFAyil3ZKDg2R2xmYJBZ3krbJHqiJBQ/wkJisTMCLmgI= 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=ERTw8D9a; arc=none smtp.client-ip=209.85.214.171 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="ERTw8D9a" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2d6fe26ef1cso4445345ad.2 for ; Thu, 03 Sep 2026 16:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477100; x=1789081900; 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=DGyg1WPPMyMXADIi43RQoQz+6jMKkRiaeE4Vks1ETOg=; b=ERTw8D9ahRV7+MF2xz0Ioi/hhDuL4WUB5YmSRppMFxPz2vabKR/kGqFXJetWciGyY4 3qsgLehX3HjwZ0uOr/aH1ZW9bKeQ9/vujOXOI0kBoCydkIh7vTFRA+WB1oFezXD4aOcH 7kmKjXJU6gjex61zV+v2wttTApbnhn3pDMkcPJfhJlUsb99loPf7X9HKCb7NHjmsNutC krQxQTGZeeP1Lt7dVh6kqJPI8K7XvuTmihcTKe2YL5ztFBkT0TKW9zNVo+Bfd4K8aIdb TYBwNEEi16e3lk5oUO5tcU35MQHKitjvG2O8qntT5pbXYGGrIA5IDw76orrVnZvc4WZW YFOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477100; x=1789081900; 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=DGyg1WPPMyMXADIi43RQoQz+6jMKkRiaeE4Vks1ETOg=; b=kUFg27VwO/Vru4aOj+UDFM7tz+R047eXRT4p8wzlYuRf0V5mUZ+XzrQprORVbyvsHt dS/5UfKnCF5pgXaSzfRyXR/xi3ubk51g0Rs7cIkonxFKNsVFsW6MdqxzCJPceZgOMhS4 SyZgCnA3u1Wdep1ylKxOVm52q5t18vqWFjOAe1dpGfOpwSemZAijjbZ88zasXgTXfkIx 9COV4+2Bfz3FcuXdq3smB5bOP5AUAqa3Vx1V0Tbr632qlshpxDVa3YXeuALeVQMLUnwy cQa0dbS5HB8RY+QDP4M3xyzySOB3FPhngdIHFsuH00prnjw+nHgBMZQstT0MLnG0HWEY Vhsw== X-Forwarded-Encrypted: i=1; AKwUvBxEXZwpntnznl+yNvgEh3aitVZNJdVXlaL9NJbOamCCgkqrt/caNiBKVG4q0il1USWdWLsTY1ai2DNtvSM=@vger.kernel.org X-Gm-Message-State: AFuF++nj2+w7V2b7MuLGgvc/wU3vFmMTcchrU3pdzDnpTaFc3B/pYqf6 XkYMhKR37z5/bBfCqJg4NPje2VKB77KYcv3NJ4uRGbUQHmY/tjbfrSq/aFb4g8DZTz0= X-Gm-Gg: AYBFou0Tn/KaS1OLCJLOPO1MoUMyy3JwR4/F9Vrw8pxoT617i9TSScyhco1ce36fJBx e1p9+dZnXatyRLudRG2eqVuybpOBPH/mXp4un5U836mSD6axrmU8jd0z3riOfI2hOVPWREO+c6Q dV6MnB3NdmOFoGwJqRw8fDGPBIS5TesqtJJRC5iZ8nPPnxC8IuXRCjJ1Ltujobn/MFdACrK+zwY dlrVQG2+6coKihcALkY76UNzpGX0IxQYjpvr+EPcT9Bj3r9PWAxMxM/TYmb2rOdcNhX7ft4q2g4 YUdMAX2xXztX6aEGBJR7+S1JiOdkEh+UUapKPjMV1DCYpCXuTxWPDfYjnmTaloVfGFDu+2UFG1T WgetYu1XUUvltfj46icdpTo/yurPowxf3qamjav2Fn7Ad5ZGnaL9F6L3Q/EdPaxUEGZ8uVhV9Dw Gw/MdYbuNfZ0u4lvPFCHntfKFCmConG/8chQmmbBmhUdNegk+xRmRkHT4f7EP2vhmTDQ== X-Received: by 2002:a17:903:1ae3:b0:2d9:54:fc69 with SMTP id d9443c01a7336-2db1247f4d0mr36480165ad.7.1788477100298; Thu, 03 Sep 2026 16:11:40 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db149ca6c2sm1713495ad.70.2026.09.03.16.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:39 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 02/11] f2fs: describe SIT block layout dynamically Date: Thu, 3 Sep 2026 16:11:29 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" An SIT block consists of an on-disk array of struct f2fs_sit_entry elements whose total capacity depends on the filesystem block size. The existing fixed SIT_ENTRY_PER_BLOCK macro hardcodes a 4KB block size. Convert the entries array in struct f2fs_sit_block into a C flexible array member, and calculate sbi->sit_entries_per_block dynamically in init_sb_info(). Parameterize SIT indexing helpers (SIT_ENTRY_PER_BLOCK, SIT_BLOCK_OFFSET, SIT_BLK_CNT, and f2fs_start_segno) to take struct f2fs_sb_info *sbi, and update all call sites across segment management, checkpointing, and mount. This is a layout-only change; valid 4KB filesystems retain identical runtime geometry and behavior. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/segment.c | 15 ++++++++------- fs/f2fs/segment.h | 22 +++++++++++++--------- fs/f2fs/super.c | 4 +++- include/linux/f2fs_fs.h | 9 ++++++--- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4b59f30ef45d..47c4a5c83a70 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -487,7 +487,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_= t start, int nrpages, goto out; /* get sit block addr */ fio.new_blkaddr =3D current_sit_addr(sbi, - blkno * SIT_ENTRY_PER_BLOCK); + blkno * SIT_ENTRY_PER_BLOCK(sbi)); break; case META_SSA: case META_CP: diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 16720f1f0a9c..035863d513ab 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1863,6 +1863,7 @@ struct f2fs_sb_info { unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ + unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2251,6 +2252,8 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) return F2FS_M_SB(folio->mapping); } =20 +#define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) + static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { return (struct f2fs_super_block *)(sbi->raw_super); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 1e7e745be71d..b3bf1b62cdad 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4708,7 +4708,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; } @@ -4747,10 +4747,11 @@ static void adjust_sit_entry_set(struct sit_entry_s= et *ses, list_move_tail(&ses->set_list, head); } =20 -static void add_sit_entry(unsigned int segno, struct list_head *head) +static void add_sit_entry(struct f2fs_sb_info *sbi, unsigned int segno, + struct list_head *head) { struct sit_entry_set *ses; - unsigned int start_segno =3D START_SEGNO(segno); + unsigned int start_segno =3D f2fs_start_segno(sbi, segno); =20 list_for_each_entry(ses, head, set_list) { if (ses->start_segno =3D=3D start_segno) { @@ -4775,7 +4776,7 @@ static void add_sits_in_set(struct f2fs_sb_info *sbi) unsigned int segno; =20 for_each_set_bit(segno, bitmap, MAIN_SEGS(sbi)) - add_sit_entry(segno, set_list); + add_sit_entry(sbi, segno, set_list); } =20 static void remove_sits_in_journal(struct f2fs_sb_info *sbi) @@ -4793,7 +4794,7 @@ static void remove_sits_in_journal(struct f2fs_sb_inf= o *sbi) dirtied =3D __mark_sit_entry_dirty(sbi, segno); =20 if (!dirtied) - add_sit_entry(segno, &SM_I(sbi)->sit_entry_set); + add_sit_entry(sbi, segno, &SM_I(sbi)->sit_entry_set); } update_sits_in_cursum(journal, -i); up_write(&curseg->journal_rwsem); @@ -4843,7 +4844,7 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi,= struct cp_control *cpc) struct folio *folio =3D NULL; struct f2fs_sit_block *raw_sit =3D NULL; unsigned int start_segno =3D ses->start_segno; - unsigned int end =3D min(start_segno + SIT_ENTRY_PER_BLOCK, + unsigned int end =3D min(start_segno + SIT_ENTRY_PER_BLOCK(sbi), (unsigned long)MAIN_SEGS(sbi)); unsigned int segno =3D start_segno; =20 @@ -5008,7 +5009,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) sit_i->written_valid_blocks =3D 0; sit_i->bitmap_size =3D sit_bitmap_size; sit_i->dirty_sentries =3D 0; - sit_i->sents_per_block =3D SIT_ENTRY_PER_BLOCK; + sit_i->sents_per_block =3D SIT_ENTRY_PER_BLOCK(sbi); sit_i->elapsed_time =3D le64_to_cpu(sbi->ckpt->elapsed_time); sit_i->mounted_time =3D ktime_get_boottime_seconds(); init_rwsem(&sit_i->sentry_lock); diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 5949aa5200ac..534e376cbc92 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -102,12 +102,15 @@ static inline void sanity_check_seg_type(struct f2fs_= sb_info *sbi, =20 #define SIT_ENTRY_OFFSET(sit_i, segno) \ ((segno) % (sit_i)->sents_per_block) -#define SIT_BLOCK_OFFSET(segno) \ - ((segno) / SIT_ENTRY_PER_BLOCK) -#define START_SEGNO(segno) \ - (SIT_BLOCK_OFFSET(segno) * SIT_ENTRY_PER_BLOCK) +#define SIT_BLOCK_OFFSET(sbi, segno) \ + ((segno) / SIT_ENTRY_PER_BLOCK(sbi)) +static inline unsigned int +f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno) +{ + return SIT_BLOCK_OFFSET(sbi, segno) * SIT_ENTRY_PER_BLOCK(sbi); +} #define SIT_BLK_CNT(sbi) \ - DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK) + DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK(sbi)) #define f2fs_bitmap_size(nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long)) =20 @@ -424,7 +427,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb= _info *sbi, struct f2fs_sit_block *raw_sit; struct seg_entry *se; struct f2fs_sit_entry *rs; - unsigned int end =3D min(start + SIT_ENTRY_PER_BLOCK, + unsigned int end =3D min(start + SIT_ENTRY_PER_BLOCK(sbi), (unsigned long)MAIN_SEGS(sbi)); int i; =20 @@ -869,7 +872,7 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_i= nfo *sbi, unsigned int start) { struct sit_info *sit_i =3D SIT_I(sbi); - unsigned int offset =3D SIT_BLOCK_OFFSET(start); + unsigned int offset =3D SIT_BLOCK_OFFSET(sbi, start); block_t blk_addr =3D sit_i->sit_base_addr + offset; =20 f2fs_bug_on(sbi, !valid_main_segno(sbi, start)); @@ -894,9 +897,10 @@ static inline pgoff_t next_sit_addr(struct f2fs_sb_inf= o *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); + unsigned int block_off =3D SIT_BLOCK_OFFSET(sbi, start); =20 f2fs_change_bit(block_off, sit_i->sit_bitmap); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c48acfb30a0d..ad88ce8d40a7 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4329,7 +4329,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) return 1; } =20 - sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK); + sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK(sbi)); if (sit_bitmap_size * 8 < sit_blk_cnt) { f2fs_err(sbi, "Wrong bitmap size: sit: %u, sit_blk_cnt:%u", sit_bitmap_size, sit_blk_cnt); @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->sit_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bb2b6cd5d507..ecd6694af572 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -396,8 +396,6 @@ struct f2fs_nat_block { * Not allow to change this. */ #define SIT_VBLOCK_MAP_SIZE 64 -#define SIT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_sit_entry)) - /* * F2FS uses 4 bytes to represent block address. As a result, supported si= ze of * disk is 16 TB for a 4K page size and 64 TB for a 16K page size and it e= quals @@ -424,8 +422,13 @@ struct f2fs_sit_entry { __le64 mtime; /* segment age for cleaning */ } __packed; =20 +/* + * The on-disk SIT block is a filesystem-block-sized array of SIT entries. + * Its entry count depends on the filesystem block size, so it must be + * calculated by the caller rather than implied by this C structure. + */ struct f2fs_sit_block { - struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; + DECLARE_FLEX_ARRAY(struct f2fs_sit_entry, entries); } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 F0C9A385D64 for ; Thu, 3 Sep 2026 23:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477105; cv=none; b=sgaDsP/TO91H/K0o1wS0yULM/PIVh02tpnBmZRO6tY+i5cJLP4CO0ltN0+39IN6wDBdJ461rkKv5ApQA1LTtl7LcybzmSe/UhFzidvf/F9Crn5jv9Gw9v9a+lCyjnGxP2xkRIz46StafBL00FMGKL/wEnJIkb9hWVkMoy85zffc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477105; c=relaxed/simple; bh=GaOaLh2/7SNoMtmpWmo+1ZpppdTzB2ZNmmePT4EVrB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RbC6ZtlDJ4OcYRwGSXr8s4A52uS6rrI2rZRFjQ4a3c7vCP7uGmoIsJqVGmj8fImkJJjlgtU+Sxa9QaMbWVB7zJLeuBJ0xlzipZcDxK1AyI9iWnvsCZXNC4hzkfHOJwDLPR/KVhSa7nQ8iq5X1g8tduFnRtjbmW65Htp3Ub7VkSk= 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=NYyaN3Bl; arc=none smtp.client-ip=209.85.215.171 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="NYyaN3Bl" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-cc439bfb2d8so376631a12.2 for ; Thu, 03 Sep 2026 16:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477102; x=1789081902; 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=d2iFOywns5b68ZCP8DbhAwKFN2nvF+iRMA6fHbOlcpc=; b=NYyaN3Blzs7TZOyY3B1KUPx/jqCXtSk0Ue7/yEvXeHgghRSWaoux6N5AV3eSF953MM GGRoaC+iK6t4s+iz+6Da6e3pcA0p9lyOyp3+2bugbyZ+LzINcmULJWiA0mhditxRbZBE mgM4qHTZSvIcPW4VF2NK14PdqBjKnvh91mgJQUHO4zQT6hxq1+/23/ZIelvuW7DTN/Ng HIH7N6OEFlta+Mluwj8CmB7ChffRMtjYwvWi65zqPzy1hBqgc0RQs1o7V0QDKe6LIFVR JaUEes0Itv/sghgxXKT/pOazxFfbSQVC6F9Oq3iR9h9zRnEwjMKRyR9/lr9/Yn1VMFTR pLng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477102; x=1789081902; 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=d2iFOywns5b68ZCP8DbhAwKFN2nvF+iRMA6fHbOlcpc=; b=YXKAdIpTo8DL2Bphq8Khls3gYnySPXA0XlF2Z6JkV/AcoQY93rCJXip0wRfyZQxbBE Fh1QLssEtquKgmalzhl9OkxS1laCMkibVWIOPESf3gwVHL6HXLbRl5xi5xStn9b+u60Z hawtQS5exwTxnbT4tWdigESWdsHi+UkOXTjNhJXD1Xa5EnVJVSpfN/Q5OJshS7NUssUV iPTAAKXfxDF+637AoFQbPShkR3zT6vBiRclaEVhnVDFNUnzkh7/wHo8PxQdFaz8u0Du/ kGH5+KDDhLHihx0SNpeBJMXl2v1G4JT92QJLTwzymjDWzA2Uh9JciNz9wlue1HzO4Uwn LuUg== X-Forwarded-Encrypted: i=1; AKwUvBzDVTGjCRS+e/75FgkksSDptCnKStbXbQ0CJqG0xBax6tCKUy/AjoovTYi7ir9bhd0wD2BDnsBZ57RNYss=@vger.kernel.org X-Gm-Message-State: AFuF++nGTQV7DQ/BByS++CUYdKG+Z2XXxSS597EzpxVotmVGRE6Bfs4I mgGlfplLqahtZz878QaAgCfgDMs7tTxKXhVDQyQ0TDWVdjMIs/7htycI X-Gm-Gg: AYBFou14zrxojLKIdJbQyDF6vVhqwjG1V/BOCuTmU/1dPzn2Xhet53SOHLyE+nZ5r/a HmXT6py0e3CuAtknWsRtdfhwiatLURV+CyI7u3yTzpqaIqPTHmrlGH1/kMdwJlezppfNpQ98pxM VG82SyhM7YJgW8SEmF/z1dVG8q9/RJcUMqt21oxxF3BJznjMO2h8gJEt9pO7Z1KdOE8lJ8S6kld Z2Ini9MXl2JIj1Kd3ibOp8DGfn6Gz0sa6bI7j2k3mA3m5G6wbLuX1++Q2V7TrjpROVzsislEdC1 bXNvzCuNN+BjxceNlGc6eWL5a4XyJc9cMSfNRENAqpPW3iPdj06bFAqGWnJp61yvNQkjklt0l9h hd67Hmy5WdT6rf83iki8K1Nc0nAI7fN1YaRHjrdxwH98D99VABNnf1bR1kEy0Laaoed0qgq4LZ8 yq/gFv/XipyNcl8L2EVkG0eD56ZbssfQN7TzHwNvvrtLmNthOLu93j5CsYtVr6x+RNPg== X-Received: by 2002:a17:90b:39a7:b0:398:9bd1:3211 with SMTP id 98e67ed59e1d1-39b262ab182mr2643958a91.18.1788477101852; Thu, 03 Sep 2026 16:11:41 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b08bcd243sm7534603a91.5.2026.09.03.16.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:41 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 03/11] f2fs: describe NAT block layout dynamically Date: Thu, 3 Sep 2026 16:11:30 -0700 Message-ID: <5fbe294c7c2da62778b060c353dcbf238591d1b4.1788476500.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.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" A NAT block is a filesystem-block-sized array of struct f2fs_nat_entry elements. The compile-time NAT_ENTRY_PER_BLOCK definition hardcodes the NAT capacity to a 4KB block size. Replace the fixed array in struct f2fs_nat_block with a C flexible array member, and calculate sbi->nat_entries_per_block dynamically in init_sb_info(). Parameterize NAT geometry helpers (NAT_ENTRY_PER_BLOCK, NAT_BLOCK_OFFSET, f2fs_start_nid, NAT_BLK_CNT, and f2fs_nat_bitmap_size) with sbi. Update call sites across node management, checkpointing, GC, and sysfs. This is a layout-only change without behavioral differences for 4KB blocks. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 4 +-- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/gc.c | 4 +-- fs/f2fs/node.c | 77 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 20 +++++++---- fs/f2fs/segment.c | 4 +-- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 4 ++- include/linux/f2fs_fs.h | 5 ++- 10 files changed, 69 insertions(+), 55 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 47c4a5c83a70..3ecced9b4d57 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -476,11 +476,11 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, bloc= k_t start, int nrpages, switch (type) { case META_NAT: if (unlikely(blkno >=3D - NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid))) + NAT_BLOCK_OFFSET(sbi, NM_I(sbi)->max_nid))) blkno =3D 0; /* get nat block addr */ fio.new_blkaddr =3D current_nat_addr(sbi, - blkno * NAT_ENTRY_PER_BLOCK); + blkno * NAT_ENTRY_PER_BLOCK(sbi)); break; case META_SIT: if (unlikely(blkno >=3D TOTAL_SEGS(sbi))) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index ff379aff4472..5980b9d79afb 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -345,7 +345,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=3D __bitmap_size(sbi, NAT_BITMAP); si->base_mem +=3D F2FS_BLK_TO_BYTES(NM_I(sbi)->nat_bits_blocks); si->base_mem +=3D NM_I(sbi)->nat_blocks * - f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK); + f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)); si->base_mem +=3D NM_I(sbi)->nat_blocks / 8; si->base_mem +=3D NM_I(sbi)->nat_blocks * sizeof(unsigned short); =20 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 035863d513ab..8e6000e7d766 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1863,6 +1863,7 @@ struct f2fs_sb_info { unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ + unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ @@ -2253,6 +2254,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) } =20 #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) +#define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) =20 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 0a00180c21dc..c15c6ba91597 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1066,7 +1066,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, continue; =20 if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } @@ -1614,7 +1614,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, = struct f2fs_summary *sum, continue; =20 if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 86c2e67e43b6..960c6657d0d6 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -169,7 +169,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_= info *sbi, nid_t nid) folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); =20 - set_to_next_nat(nm_i, nid); + set_to_next_nat(sbi, nm_i, nid); =20 return dst_folio; } @@ -254,10 +254,11 @@ static void __del_from_nat_cache(struct f2fs_nm_info = *nm_i, struct nat_entry *e) __free_nat_entry(e); } =20 -static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_= i, +static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne) { - nid_t set =3D NAT_BLOCK_OFFSET(ne->ni.nid); + nid_t set =3D NAT_BLOCK_OFFSET(sbi, ne->ni.nid); struct nat_entry_set *head; =20 head =3D radix_tree_lookup(&nm_i->nat_set_root, set); @@ -274,14 +275,15 @@ static struct nat_entry_set *__grab_nat_entry_set(str= uct f2fs_nm_info *nm_i, return head; } =20 -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne, bool init_dirty) { struct nat_entry_set *head; bool new_ne =3D nat_get_blkaddr(ne) =3D=3D NEW_ADDR; =20 if (!new_ne) - head =3D __grab_nat_entry_set(nm_i, ne); + head =3D __grab_nat_entry_set(sbi, nm_i, ne); =20 /* * update entry_cnt in below condition: @@ -527,7 +529,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, str= uct node_info *ni, nat_set_blkaddr(e, new_blkaddr); if (!__is_valid_data_blkaddr(new_blkaddr)) set_nat_flag(e, IS_CHECKPOINTED, false); - __set_nat_cache_dirty(nm_i, e, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, e, init_dirty); =20 /* update fsync_mark if its inode nat entry is still alive */ if (ni->nid !=3D ni->ino) @@ -578,7 +580,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t = nid, struct f2fs_nm_info *nm_i =3D NM_I(sbi); struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D START_NID(nid); + nid_t start_nid =3D f2fs_start_nid(sbi, nid); struct f2fs_nat_block *nat_blk; struct folio *folio =3D NULL; struct f2fs_nat_entry ne; @@ -2403,8 +2405,8 @@ static void update_free_nid_bitmap(struct f2fs_sb_inf= o *sbi, nid_t nid, bool set, bool build) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(nid); - unsigned int nid_ofs =3D nid - START_NID(nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, nid); + unsigned int nid_ofs =3D nid - f2fs_start_nid(sbi, nid); =20 if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) return; @@ -2524,14 +2526,14 @@ static int scan_nat_page(struct f2fs_sb_info *sbi, { struct f2fs_nm_info *nm_i =3D NM_I(sbi); block_t blk_addr; - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, start_nid); int i; =20 __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); =20 - i =3D start_nid % NAT_ENTRY_PER_BLOCK; + i =3D start_nid % NAT_ENTRY_PER_BLOCK(sbi); =20 - for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++, start_nid++) { if (unlikely(start_nid >=3D nm_i->max_nid)) break; =20 @@ -2587,16 +2589,16 @@ static void scan_free_nid_bits(struct f2fs_sb_info = *sbi) continue; if (!nm_i->free_nid_count[i]) continue; - for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { + for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK(sbi); idx++) { idx =3D find_next_bit_le(nm_i->free_nid_bitmap[i], - NAT_ENTRY_PER_BLOCK, idx); - if (idx >=3D NAT_ENTRY_PER_BLOCK) + NAT_ENTRY_PER_BLOCK(sbi), idx); + if (idx >=3D NAT_ENTRY_PER_BLOCK(sbi)) break; =20 - nid =3D i * NAT_ENTRY_PER_BLOCK + idx; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi) + idx; add_free_nid(sbi, nid, true, false); =20 - if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS(sbi)) goto out; } } @@ -2617,11 +2619,11 @@ static int __f2fs_build_free_nids(struct f2fs_sb_in= fo *sbi, if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; =20 - if (unlikely(nid % NAT_ENTRY_PER_BLOCK)) - nid =3D NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK; + if (unlikely(nid % NAT_ENTRY_PER_BLOCK(sbi))) + nid =3D NAT_BLOCK_OFFSET(sbi, nid) * NAT_ENTRY_PER_BLOCK(sbi); =20 /* Enough entries */ - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; =20 if (!sync && !f2fs_available_free_memory(sbi, FREE_NIDS)) @@ -2631,18 +2633,18 @@ static int __f2fs_build_free_nids(struct f2fs_sb_in= fo *sbi, /* try to find free nids in free_nid_bitmap */ scan_free_nid_bits(sbi); =20 - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; } =20 /* readahead nat pages to be scanned */ - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), FREE_NID_PAGES, META_NAT, true); =20 f2fs_down_read_trace(&nm_i->nat_tree_lock, &lc); =20 while (1) { - if (!test_bit_le(NAT_BLOCK_OFFSET(nid), + if (!test_bit_le(NAT_BLOCK_OFFSET(sbi, nid), nm_i->nat_block_bitmap)) { struct folio *folio =3D get_current_nat_folio(sbi, nid); =20 @@ -2668,7 +2670,8 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info= *sbi, } } =20 - nid +=3D (NAT_ENTRY_PER_BLOCK - (nid % NAT_ENTRY_PER_BLOCK)); + nid +=3D NAT_ENTRY_PER_BLOCK(sbi) - + (nid % NAT_ENTRY_PER_BLOCK(sbi)); if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; =20 @@ -2684,7 +2687,7 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info= *sbi, =20 f2fs_up_read_trace(&nm_i->nat_tree_lock, &lc); =20 - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nm_i->next_scan_nid), nm_i->ra_nid_pages, META_NAT, false); =20 return 0; @@ -2811,20 +2814,20 @@ int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi,= int nr_shrink) struct f2fs_nm_info *nm_i =3D NM_I(sbi); int nr =3D nr_shrink; =20 - if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) return 0; =20 if (!mutex_trylock(&nm_i->build_lock)) return 0; =20 - while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS) { + while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS(sbi)) { struct free_nid *i, *next; unsigned int batch =3D SHRINK_NID_BATCH_SIZE; =20 spin_lock(&nm_i->nid_list_lock); list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) { if (!nr_shrink || !batch || - nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) break; __remove_free_nid(sbi, i, FREE_NID); kmem_cache_free(free_nid_slab, i); @@ -3074,7 +3077,7 @@ static void remove_nats_in_journal(struct f2fs_sb_inf= o *sbi) spin_unlock(&nm_i->nid_list_lock); } =20 - __set_nat_cache_dirty(nm_i, ne, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, ne, init_dirty); } update_nats_in_cursum(journal, -i); up_write(&curseg->journal_rwsem); @@ -3102,7 +3105,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, const struct f2fs_nat_block *nat_blk) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK; + unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK(sbi); int valid =3D 0; int i =3D 0; =20 @@ -3113,7 +3116,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, valid =3D 1; i =3D 1; } - for (; i < NAT_ENTRY_PER_BLOCK; i++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++) { if (le32_to_cpu(nat_blk->entries[i].block_addr) !=3D NULL_ADDR) valid++; } @@ -3124,7 +3127,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, } =20 __clear_bit_le(nat_index, nm_i->empty_nat_bits); - if (valid =3D=3D NAT_ENTRY_PER_BLOCK) + if (valid =3D=3D NAT_ENTRY_PER_BLOCK(sbi)) __set_bit_le(nat_index, nm_i->full_nat_bits); else __clear_bit_le(nat_index, nm_i->full_nat_bits); @@ -3135,7 +3138,7 @@ static int __flush_nat_entry_set(struct f2fs_sb_info = *sbi, { struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK; + nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK(sbi); bool to_journal =3D true; struct f2fs_nat_block *nat_blk; struct nat_entry *ne, *cur; @@ -3342,8 +3345,8 @@ static inline void load_free_nid_bitmap(struct f2fs_s= b_info *sbi) =20 __set_bit_le(i, nm_i->nat_block_bitmap); =20 - nid =3D i * NAT_ENTRY_PER_BLOCK; - last_nid =3D nid + NAT_ENTRY_PER_BLOCK; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi); + last_nid =3D nid + NAT_ENTRY_PER_BLOCK(sbi); =20 spin_lock(&NM_I(sbi)->nid_list_lock); for (; nid < last_nid; nid++) @@ -3373,7 +3376,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) /* segment_count_nat includes pair segment so divide to 2. */ nat_segs =3D le32_to_cpu(sb_raw->segment_count_nat) >> 1; nm_i->nat_blocks =3D nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); - nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks; + nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK(sbi) * nm_i->nat_blocks; =20 /* not used nids: 0, node, meta, (and root counted as valid node) */ nm_i->available_nids =3D nm_i->max_nid - sbi->total_valid_node_count - @@ -3436,7 +3439,7 @@ static int init_free_nid_cache(struct f2fs_sb_info *s= bi) =20 for (i =3D 0; i < nm_i->nat_blocks; i++) { nm_i->free_nid_bitmap[i] =3D f2fs_kvzalloc(sbi, - f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK), GFP_KERNEL); + f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)), GFP_KERNEL); if (!nm_i->free_nid_bitmap[i]) return -ENOMEM; } diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 5e114f352099..d4a20d48432c 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -6,14 +6,21 @@ * http://www.samsung.com/ */ /* start node id of a node block dedicated to the given node id */ -#define START_NID(nid) (((nid) / NAT_ENTRY_PER_BLOCK) * NAT_ENTRY_PER_BLOC= K) +static inline nid_t f2fs_start_nid(struct f2fs_sb_info *sbi, nid_t nid) +{ + unsigned int entries =3D NAT_ENTRY_PER_BLOCK(sbi); + + return (nid / entries) * entries; +} =20 /* node block offset on the NAT area dedicated to the given start node id = */ -#define NAT_BLOCK_OFFSET(start_nid) ((start_nid) / NAT_ENTRY_PER_BLOCK) +#define NAT_BLOCK_OFFSET(sbi, start_nid) \ + ((start_nid) / NAT_ENTRY_PER_BLOCK(sbi)) =20 /* # of pages to perform synchronous readahead before building free nids */ #define FREE_NID_PAGES 8 -#define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) +#define MAX_FREE_NIDS(sbi) ((unsigned long)NAT_ENTRY_PER_BLOCK(sbi) * \ + FREE_NID_PAGES) =20 /* size of free nid batch when shrinking */ #define SHRINK_NID_BATCH_SIZE 8 @@ -208,7 +215,7 @@ static inline pgoff_t current_nat_addr(struct f2fs_sb_i= nfo *sbi, nid_t start) * OLD =3D (segment_off * 512) * 2 + off_in_segment * NEW =3D 2 * (segment_off * 512 + off_in_segment) - off_in_segment */ - block_off =3D NAT_BLOCK_OFFSET(start); + block_off =3D NAT_BLOCK_OFFSET(sbi, start); =20 block_addr =3D (pgoff_t)(nm_i->nat_blkaddr + (block_off << 1) - @@ -230,9 +237,10 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_inf= o *sbi, return block_addr + nm_i->nat_blkaddr; } =20 -static inline void set_to_next_nat(struct f2fs_nm_info *nm_i, nid_t start_= nid) +static inline void set_to_next_nat(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, nid_t start_nid) { - unsigned int block_off =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int block_off =3D NAT_BLOCK_OFFSET(sbi, start_nid); =20 f2fs_change_bit(block_off, nm_i->nat_bitmap); #ifdef CONFIG_F2FS_CHECK_FS diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b3bf1b62cdad..b29df65ab5b7 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -512,10 +512,10 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, boo= l from_bg) =20 /* check the # of cached NAT entries */ if (!f2fs_available_free_memory(sbi, NAT_ENTRIES)) - f2fs_try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK); + f2fs_try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK(sbi)); =20 if (!f2fs_available_free_memory(sbi, FREE_NIDS)) - f2fs_try_to_free_nids(sbi, MAX_FREE_NIDS); + f2fs_try_to_free_nids(sbi, MAX_FREE_NIDS(sbi)); else f2fs_build_free_nids(sbi, false, false); =20 diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c index 4f6bf5926de4..e3e0a7e89406 100644 --- a/fs/f2fs/shrinker.c +++ b/fs/f2fs/shrinker.c @@ -23,7 +23,7 @@ static unsigned long __count_nat_entries(struct f2fs_sb_i= nfo *sbi) =20 static unsigned long __count_free_nids(struct f2fs_sb_info *sbi) { - long count =3D NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS; + long count =3D NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS(sbi); =20 return count > 0 ? count : 0; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ad88ce8d40a7..32c050257d7d 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->nat_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); @@ -4391,7 +4393,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->total_sections =3D le32_to_cpu(raw_super->section_count); sbi->total_node_count =3D SEGS_TO_BLKS(sbi, ((le32_to_cpu(raw_super->segment_count_nat) / 2) * - NAT_ENTRY_PER_BLOCK)); + NAT_ENTRY_PER_BLOCK(sbi))); sbi->allocate_section_hint =3D le32_to_cpu(raw_super->section_count); sbi->allocate_section_policy =3D ALLOCATE_FORWARD_NOHINT; F2FS_ROOT_INO(sbi) =3D le32_to_cpu(raw_super->root_ino); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index ecd6694af572..061f906a7b94 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -375,8 +375,6 @@ struct f2fs_node { /* * For NAT entries */ -#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_nat_entry)) - struct f2fs_nat_entry { __u8 version; /* latest version of cached nat entry */ __le32 ino; /* inode number */ @@ -384,7 +382,8 @@ struct f2fs_nat_entry { } __packed; =20 struct f2fs_nat_block { - struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; + /* The entry count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(struct f2fs_nat_entry, entries); } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 07EBE390226 for ; Thu, 3 Sep 2026 23:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477105; cv=none; b=U53QfISqsF5594ct/UJH9DFU2g4DwPwgamqcg2FZKCtqB7FP5lpR+wAGCeNtdYsEtAFe8GEne6biLhkERoQL0pPjoIJBoZDnApvs6WSy0ORmzophoCiA04PZJRdnbvpQd4o46Bjqx1LiJtL71YVdeSHayUy3cd5tLHSL3XRREFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477105; c=relaxed/simple; bh=dT2LBKaYrCihF2oYM87tvdo7Z90lV23ofefFX/ejS6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DRuby6vq3xPjhyK5yn+a1fEcCWWp9/8RaVhYGJOXSJcXvbv7tElVW8KeMAlJ8fl2tkDoJgNWaE9kHU+N/G+JmZhfzOaiTyd89RxOUsYQE/rETdqumDh34fAkW8irX3CfmfWyak8FvvX8xxbdvUVFlvrAojgQlVkf7dupjDXIuAk= 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=L+xYukHs; arc=none smtp.client-ip=209.85.216.49 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="L+xYukHs" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-38e42560ebcso319230a91.1 for ; Thu, 03 Sep 2026 16:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477103; x=1789081903; 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=LiO/HZyQ66ZVLjgkl46SE6ZbrPgYtx0eLhZ31mShgv0=; b=L+xYukHsY4Qa3Q9tW3ZV3VvJuW+sBXWwPrtdviOsLpF3CTFcoFhpNTW64qU4URakiP HaakscfHA+00ySp5CZUarzVivbFoAT7RcMLI2OW2+T/SnVsEKywYRH6mscqR6WbkKvT7 ij/TAbQWJsTGcASVoAksgsFdWSUcQ47yXJmgmUA1uqCzj8fQoHzRjBxV7XlW1PO++8BC bVfBmGgZKH0PYk+N0tRPT58M3NTxJO/1qlh4KU0qmWJBqywFfw9K/kHqse6Z1KqEpFMw mX9PgoXCHEZgujo9GZ5sJgI6hkLyOmpYUV1oKqNrIRVFxiLFdvokoPAs4o9zwNI0EBEB zyfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477103; x=1789081903; 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=LiO/HZyQ66ZVLjgkl46SE6ZbrPgYtx0eLhZ31mShgv0=; b=NaEh4r1d18Ww+/DDyeCIxHR32txTWMsRgGTHHxW5OcJIx7zNV1HC965rU6bo2uAjMn HylZCYi7YxTCCx77rsvV8oRixSPyt6O8NmkxkIuMoazlb4i3G+ti5YfKG8IWLjBJDMuQ ue6fAyl8+cjAdJKkVFIdjIX3UGmDkdeWweUHJTVs+G7HZ1BJNlmAWx7mTjbEJQChEWUG PVLcF2mAlgRWJGlnr0M3Tj8T8dJ39O4yXpuvTTQQIE2oR2ZWjTLvzVpYLvgpJAfiZ1FW NUhx0/TJE2KYKvdRjfbqvxuUTG1ltgyutkwAnItmbTwHOUtTeVwCM6Txhv4K/KkpS2qn tg8g== X-Forwarded-Encrypted: i=1; AKwUvBxvaeR6+6n6yLWe5lLKUorcFe+hJzofhYGbCyx1uGmEK0g+xgC4diW8fye82rSZM7f+EwSq0c5t99bWCmE=@vger.kernel.org X-Gm-Message-State: AFuF++kMB8jAN9zG0xo5YjFTzH3U1PNyGJd8D8EFhSEDjM0hbZ3YI5U+ emWXGheS4uWM/n9oKfdb8xlW78Ee46p/Tkchk5Hwx7UoCLjqtUg7wbWo X-Gm-Gg: AYBFou1ZG70Ump55KGo/ZlA9jLUGUAfsn15B9wIfa2yzZ7JSlD1UF9f5VQZqMf6NKWE f08qjeBsfF3bfHpVmdpieKyEzd1avSKSoDw/n/trZK2V+jilxJds3BBqy9gC1wwQJPg8MUljnd7 1fp5A3eQMap3G1M+q+fhIg0VLC9gnw979zxlOFvqATLqspJtzewbSANZRMzBXYl0QMCUvFaRnnK BgWO5jdNGs9ljI013BD2jWtHZpNYvNI/RWY2WVKdNNQiayXgYIiTxVRP2ogNJLzfbRMQcqHGh03 RYzPbP09HoJKdJpzSZSNnBmXAbE7B1uS9zd2jBAu2kRQJ6moUYwlVbbpMx7OKXUoK+GbGO+D9si ZyaBGbFYBxmwYynmx00ofbcMiavLvu9FSnJdPIBpLqi3kot+ZMRKVG4tPPbJxoEki0YI7zt3DcA d3CaN9i2W5mX7m/PjKEsL4bAu1iSgG20cbVXdB4C1WwNsMKbkexZCPQl7eNWOCnJxL/A== X-Received: by 2002:a17:90b:2884:b0:398:e86b:ce14 with SMTP id 98e67ed59e1d1-39b262ab44emr2824941a91.20.1788477103244; Thu, 03 Sep 2026 16:11:43 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b260fdc1dsm1095550a91.7.2026.09.03.16.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:42 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 04/11] f2fs: describe orphan block layout dynamically Date: Thu, 3 Sep 2026 16:11:31 -0700 Message-ID: <14ec93f97f034507d19317f793c4bb4c1dc0f9ba.1788476500.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.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" An on-disk orphan block contains a variable-length array of 32-bit inode numbers followed by a fixed footer at the end of the block. A compile-time whole-block structure cannot represent the footer position when the block size varies at runtime. Remove struct f2fs_orphan_block, introduce struct f2fs_orphan_block_footer, and compute sbi->orphans_per_block dynamically in init_sb_info(). Add helpers to access the inode entry array and footer from a block buffer. Update orphan inode recovery, checkpointing, and mount paths to use the parameterized helpers. This preserves the on-disk format while decoupling orphan handling from compile-time constants. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 32 ++++++++++++++++++-------------- fs/f2fs/f2fs.h | 12 ++++++++++++ fs/f2fs/super.c | 2 ++ include/linux/f2fs_fs.h | 20 ++++++++++++++------ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 3ecced9b4d57..e615477307f9 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1042,6 +1042,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) for (i =3D 0; i < orphan_blocks; i++) { struct folio *folio; struct f2fs_orphan_block *orphan_blk; + struct f2fs_orphan_footer *footer; unsigned int entry_count; =20 folio =3D f2fs_get_meta_folio(sbi, start_blk + i); @@ -1051,8 +1052,9 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) } =20 orphan_blk =3D folio_address(folio); - entry_count =3D le32_to_cpu(orphan_blk->entry_count); - if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + footer =3D f2fs_orphan_footer(orphan_blk, sbi); + entry_count =3D le32_to_cpu(footer->entry_count); + if (entry_count > F2FS_ORPHANS_PER_BLOCK(sbi)) { f2fs_err(sbi, "invalid orphan inode entry count %u", entry_count); set_sbi_flag(sbi, SBI_NEED_FSCK); @@ -1085,6 +1087,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *= sbi, block_t start_blk) { struct list_head *head; struct f2fs_orphan_block *orphan_blk =3D NULL; + struct f2fs_orphan_footer *footer =3D NULL; unsigned int nentries =3D 0; unsigned short index =3D 1; unsigned short orphan_blocks; @@ -1092,7 +1095,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *= sbi, block_t start_blk) struct ino_entry *orphan =3D NULL; struct inode_management *im =3D &sbi->im[ORPHAN_INO]; =20 - orphan_blocks =3D GET_ORPHAN_BLOCKS(im->ino_num); + orphan_blocks =3D GET_ORPHAN_BLOCKS(sbi, im->ino_num); =20 /* * we don't need to do spin_lock(&im->ino_lock) here, since all the @@ -1106,20 +1109,21 @@ static void write_orphan_inodes(struct f2fs_sb_info= *sbi, block_t start_blk) if (!folio) { folio =3D f2fs_grab_meta_folio(sbi, start_blk++); orphan_blk =3D folio_address(folio); - memset(orphan_blk, 0, sizeof(*orphan_blk)); + footer =3D f2fs_orphan_footer(orphan_blk, sbi); + memset(orphan_blk, 0, sbi->blocksize); } =20 orphan_blk->ino[nentries++] =3D cpu_to_le32(orphan->ino); =20 - if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK) { + if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK(sbi)) { /* - * an orphan block is full of 1020 entries, + * an orphan block is full, * then we need to flush current orphan blocks * and bring another one in memory */ - orphan_blk->blk_addr =3D cpu_to_le16(index); - orphan_blk->blk_count =3D cpu_to_le16(orphan_blocks); - orphan_blk->entry_count =3D cpu_to_le32(nentries); + footer->blk_addr =3D cpu_to_le16(index); + footer->blk_count =3D cpu_to_le16(orphan_blocks); + footer->entry_count =3D cpu_to_le32(nentries); folio_mark_dirty(folio); f2fs_folio_put(folio, true); index++; @@ -1129,9 +1133,9 @@ static void write_orphan_inodes(struct f2fs_sb_info *= sbi, block_t start_blk) } =20 if (folio) { - orphan_blk->blk_addr =3D cpu_to_le16(index); - orphan_blk->blk_count =3D cpu_to_le16(orphan_blocks); - orphan_blk->entry_count =3D cpu_to_le32(nentries); + footer->blk_addr =3D cpu_to_le16(index); + footer->blk_count =3D cpu_to_le16(orphan_blocks); + footer->entry_count =3D cpu_to_le32(nentries); folio_mark_dirty(folio); f2fs_folio_put(folio, true); } @@ -1824,7 +1828,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, st= ruct cp_control *cpc) __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); spin_unlock_irqrestore(&sbi->cp_lock, flags); =20 - orphan_blocks =3D GET_ORPHAN_BLOCKS(orphan_num); + orphan_blocks =3D GET_ORPHAN_BLOCKS(sbi, orphan_num); ckpt->cp_pack_start_sum =3D cpu_to_le32(1 + cp_payload_blks + orphan_blocks); =20 @@ -2080,7 +2084,7 @@ void f2fs_init_ino_entry_info(struct f2fs_sb_info *sb= i) =20 sbi->max_orphans =3D (BLKS_PER_SEG(sbi) - F2FS_CP_PACKS - NR_CURSEG_PERSIST_TYPE - __cp_payload(sbi)) * - F2FS_ORPHANS_PER_BLOCK; + F2FS_ORPHANS_PER_BLOCK(sbi); } =20 int __init f2fs_create_checkpoint_caches(void) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8e6000e7d766..2a4ba7d4ec0e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1865,6 +1865,7 @@ struct f2fs_sb_info { unsigned int blocksize; /* block size */ unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ + unsigned int orphans_per_block; /* orphan inodes in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2255,6 +2256,17 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const s= truct folio *folio) =20 #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) +#define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) +#define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ + F2FS_ORPHANS_PER_BLOCK(sbi)) + +static inline struct f2fs_orphan_footer * +f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) +{ + return (struct f2fs_orphan_footer *) + ((char *)orphan_block + sbi->blocksize - + sizeof(struct f2fs_orphan_footer)); +} =20 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 32c050257d7d..5891dba76bce 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4386,6 +4386,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); + sbi->orphans_per_block =3D (sbi->blocksize - + sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 061f906a7b94..bdb8c63ac0c6 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -220,14 +220,22 @@ struct f2fs_checkpoint { =20 /* * For orphan inode management + * + * The number of inode entries in an orphan block depends on the filesystem + * block size. Its exact on-disk layout is: + * + * 0 blocksize - 16 blocksize + * +--------------------------+--------------------------+ + * | ino[0] ... ino[n - 1] | struct f2fs_orphan_footer | + * +--------------------------+--------------------------+ + * + * n =3D (blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32) */ -#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / size= of(__le32)) - -#define GET_ORPHAN_BLOCKS(n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \ - F2FS_ORPHANS_PER_BLOCK) - struct f2fs_orphan_block { - __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ + DECLARE_FLEX_ARRAY(__le32, ino); +} __packed; + +struct f2fs_orphan_footer { __le32 reserved; /* reserved */ __le16 blk_addr; /* block index in current CP */ __le16 blk_count; /* Number of orphan inode blocks in CP */ --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 7F18E38398D for ; Thu, 3 Sep 2026 23:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477107; cv=none; b=eLO8TCoAqNAHDQ/vNoLKHC2ifvhHrqhJCR43wZ/pJBy/WtbKu2q72QpkWQHH/TI5zzkhfZ9iSdw1HZd3DCMjdUKhf2Q2ZHfP08PJyhSd13QylNp6atS2Jt21c0aFd6ibq8cb1vpy33ey708XvLvhYgUKEzL6zB33TAvXrlVdIe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477107; c=relaxed/simple; bh=q7DE46S0VL2Y5rqmOfW0crdlhsnFc9DoLpSY7wBk6ho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aIDCYLXECYv1oMvv7gdQme/z/mYjMEiB8DzWMtSL4BpfWOai8UiFEF+jpcYZKkW+O2jF3FuG4Spto2pDN9/aW97y6d2y71chREy95zx8U8XknvsAHg7Tc5xH53km3Et6JWPIe9G0j7WNeCfpKsiqTlh1JCqVNwjZTgHHDdDswcc= 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=f+c2Z00W; arc=none smtp.client-ip=209.85.214.174 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="f+c2Z00W" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2d91518a63fso3565995ad.0 for ; Thu, 03 Sep 2026 16:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477105; x=1789081905; 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=CLwAES2u1MQkbbFWItpUQu4cQcCnvsnD60S+KPQRK2U=; b=f+c2Z00WvilwP63Kg5ZfSHG5mkzs7qHzTgbHMHe8BUceXjZwyJALwbhoN5KVW9zB3m AmiuXQdDR27/YCOjgRlK4RKxkw5M6F92fGKg3E+MguvGPTZcJiKqwJoMSS0z0ZfCBj2G XRyUf5MtjWpAk+9GRvT1xPvqqDCMpWLEZdU10TQn5QAI8lFuaSaNLqsagr4mkIw8Bbrb ED3x5HxpqaiQGwE67ztZxcD+bdfVAalDiBydiWkArylDqp4Am6X46dDTl+2mNGER5bv8 5nrEV5AUi7+6K322rOj3fzIdN0FvPUGpG8UGQXA1zi4az45uulf3RCj/31mGb7gebOY0 YR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477105; x=1789081905; 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=CLwAES2u1MQkbbFWItpUQu4cQcCnvsnD60S+KPQRK2U=; b=o/1FZqimxVTYCZFuMAuXLbbDBaC+g4Ci73X/brhXdlJ9t4v24Xnz0KmHCCuo6oCiK+ QsZYLqx9laMgTW34yFoMoWUoftoAG4LsJarM5sSShggE8A7er89jPQgEXsx0nYDjw/65 AtFDcNnJKyqWgWJu6L58Pf0MELfz2qa15+xLUI6/NxYSPjczo/9LLqyohA8hbfziVwUE rYsp95Ze4Rr9zK5lWMm7RoOpdRlG3Sf6NEo77k5dToWHu/lhr+KUe12K3zIjfhINmTeq xyFhlgy7oFHyVrCQ9XbF8hplAA5d/sULw7GbnKsehSLVZahfsNIEg/4rNGNMvOd3mShI gVIg== X-Forwarded-Encrypted: i=1; AKwUvBzy3h14hvFHjHxewWVhfnueRsV5MfN8dDDlmenC/dC9BYClUzBHD5OqVFcjbNKTttNBeF0Ev9nlMMAQioo=@vger.kernel.org X-Gm-Message-State: AFuF++mNx5LEMFzMb38jTFsGCAfJlpY1OBRPLAaaFWZu60To4sNFMtbn mbQom5HdvVR1mA2n6fV0gcxcTzh61rPEKARkDkttG55On724yLxsWXdgU50miieAbjw= X-Gm-Gg: AYBFou37jFJCSNlrLiCW2fDeRDx5AITzaskZ7SYM58Fuvu59aHzhaWosPjzeKLzpbPa sDvocup7Qzt9PkeCP/zc6LCIph/JfRohlfWubk+90GlHTIicMwWxmdi3DXD9bhnnrwiTQedk5mt etxQmMMf4OsnoG/RJLQNh6hXo6FynJTzR/Wk3iHQkVssh57hKgTHorDzZxaSMlfu/xxN8ikf3xs aBxX3bhF9cudkv92bKWJvVEoZ+1P1hbXarpRqyunuMAJyY9X8HdZYVUMVGUT5OWjtDBxvAFzzp1 SKveZNt8cz0oHI6rxkfj8CD3vwx3FLsk07hSbkyWvCqfpMXqoFy9uW/TI+5c79SfrhFHNeaUE82 aZLo6HIt6aLARoNXvKSPxUGSeFSi2J28B37HbYB78jPntjvdi+AHdT/Drwzpf8wmOWvqRUjpn3u +NpNfwpPvHJ6N8s7Rth5/ko3GFUg8hqXdT8Q5JgKykXFiPVKV3quof6VItGeU5mg/WjQ== X-Received: by 2002:a17:902:f092:b0:2d8:df44:a5c2 with SMTP id d9443c01a7336-2db126afe54mr23783235ad.20.1788477104649; Thu, 03 Sep 2026 16:11:44 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1495acf7sm1835205ad.25.2026.09.03.16.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:44 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 05/11] f2fs: describe dentry block layout dynamically Date: Thu, 3 Sep 2026 16:11:32 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" An on-disk directory block contains a bitmap, reserved padding, an array of directory entries (struct f2fs_dir_entry), and matching filename slots. A fixed compile-time structure couples their offsets to 4KB blocks and relies on static reserved-space definitions. Remove struct f2fs_dentry_block and compute region offsets (bitmap bytes, directory-entry count, and filename slots) dynamically from the filesystem block size. Access directory blocks through struct f2fs_dentry_ptr views initialized with the runtime geometry. Update directory operations, inline dentry handling, and recovery paths to use the dynamic block layout. No functional change is introduced for 4KB blocks. Signed-off-by: Kelvin Zhang --- fs/f2fs/dir.c | 51 +++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 31 ++++++++++++++++--------- fs/f2fs/inline.c | 2 +- fs/f2fs/super.c | 6 +++++ include/linux/f2fs_fs.h | 31 ++++++++++++------------- 5 files changed, 68 insertions(+), 53 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index fd0e2cd31a81..75ff36a13f60 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -195,7 +195,7 @@ static struct f2fs_dir_entry *find_in_block(struct inod= e *dir, int *max_slots, bool use_hash) { - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr d; =20 dentry_blk =3D folio_address(dentry_folio); @@ -518,7 +518,7 @@ static int make_empty_dir(struct inode *inode, struct inode *parent, struct folio *folio) { struct folio *dentry_folio; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr d; =20 if (f2fs_has_inline_dentry(inode)) @@ -530,7 +530,7 @@ static int make_empty_dir(struct inode *inode, =20 dentry_blk =3D folio_address(dentry_folio); =20 - make_dentry_ptr_block(NULL, &d, dentry_blk); + make_dentry_ptr_block(inode, &d, dentry_blk); f2fs_do_make_empty_dir(inode, parent, &d); =20 folio_mark_dirty(dentry_folio); @@ -690,7 +690,7 @@ int f2fs_add_regular_entry(struct inode *dir, const str= uct f2fs_filename *fname, unsigned long bidx, block; unsigned int nbucket, nblock; struct folio *dentry_folio =3D NULL; - struct f2fs_dentry_block *dentry_blk =3D NULL; + void *dentry_blk =3D NULL; struct f2fs_dentry_ptr d; struct folio *folio =3D NULL; int slots, err =3D 0; @@ -727,9 +727,9 @@ int f2fs_add_regular_entry(struct inode *dir, const str= uct f2fs_filename *fname, return PTR_ERR(dentry_folio); =20 dentry_blk =3D folio_address(dentry_folio); - bit_pos =3D f2fs_room_for_filename(&dentry_blk->dentry_bitmap, - slots, NR_DENTRY_IN_BLOCK); - if (bit_pos < NR_DENTRY_IN_BLOCK) + make_dentry_ptr_block(dir, &d, dentry_blk); + bit_pos =3D f2fs_room_for_filename(d.bitmap, slots, d.max); + if (bit_pos < d.max) goto add_dentry; =20 f2fs_folio_put(dentry_folio, true); @@ -750,7 +750,6 @@ int f2fs_add_regular_entry(struct inode *dir, const str= uct f2fs_filename *fname, } } =20 - make_dentry_ptr_block(NULL, &d, dentry_blk); f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, bit_pos); =20 @@ -887,7 +886,8 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *i= node) void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio, struct inode *dir, struct inode *inode) { - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; + struct f2fs_dentry_ptr d; unsigned int bit_pos; int slots =3D GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); pgoff_t index =3D folio->index; @@ -905,18 +905,17 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry,= struct folio *folio, f2fs_folio_wait_writeback(folio, DATA, true, true); =20 dentry_blk =3D folio_address(folio); - bit_pos =3D dentry - dentry_blk->dentry; + make_dentry_ptr_block(dir, &d, dentry_blk); + bit_pos =3D dentry - d.dentry; for (i =3D 0; i < slots; i++) - __clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap); + __clear_bit_le(bit_pos + i, d.bitmap); =20 /* Let's check and deallocate this dentry page */ - bit_pos =3D find_next_bit_le(&dentry_blk->dentry_bitmap, - NR_DENTRY_IN_BLOCK, - 0); + bit_pos =3D find_next_bit_le(d.bitmap, d.max, 0); folio_mark_dirty(folio); =20 - if (bit_pos =3D=3D NR_DENTRY_IN_BLOCK && - !f2fs_truncate_hole(dir, index, index + 1)) { + if (bit_pos =3D=3D d.max && + !f2fs_truncate_hole(dir, index, index + 1)) { f2fs_clear_page_cache_dirty_tag(folio); folio_clear_dirty_for_io(folio); folio_clear_uptodate(folio); @@ -938,7 +937,8 @@ bool f2fs_empty_dir(struct inode *dir) { unsigned long bidx =3D 0; unsigned int bit_pos; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; + struct f2fs_dentry_ptr d; unsigned long nblock =3D dir_blocks(dir); =20 if (f2fs_has_inline_dentry(dir)) @@ -959,17 +959,16 @@ bool f2fs_empty_dir(struct inode *dir) } =20 dentry_blk =3D folio_address(dentry_folio); + make_dentry_ptr_block(dir, &d, dentry_blk); if (bidx =3D=3D 0) bit_pos =3D 2; else bit_pos =3D 0; - bit_pos =3D find_next_bit_le(&dentry_blk->dentry_bitmap, - NR_DENTRY_IN_BLOCK, - bit_pos); + bit_pos =3D find_next_bit_le(d.bitmap, d.max, bit_pos); =20 f2fs_folio_put(dentry_folio, false); =20 - if (bit_pos < NR_DENTRY_IN_BLOCK) + if (bit_pos < d.max) return false; =20 bidx++; @@ -1066,10 +1065,12 @@ static int f2fs_readdir(struct file *file, struct d= ir_context *ctx) { struct inode *inode =3D file_inode(file); unsigned long npages =3D dir_blocks(inode); - struct f2fs_dentry_block *dentry_blk =3D NULL; + void *dentry_blk =3D NULL; struct file_ra_state *ra =3D &file->f_ra; loff_t start_pos =3D ctx->pos; - unsigned int n =3D ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int entries =3D sbi->dentries_per_block; + unsigned int n =3D (unsigned long)ctx->pos / entries; struct f2fs_dentry_ptr d; struct fscrypt_str fstr =3D FSTR_INIT(NULL, 0); int err =3D 0; @@ -1089,7 +1090,7 @@ static int f2fs_readdir(struct file *file, struct dir= _context *ctx) goto out_free; } =20 - for (; n < npages; ctx->pos =3D n * NR_DENTRY_IN_BLOCK) { + for (; n < npages; ctx->pos =3D n * entries) { struct folio *dentry_folio; pgoff_t next_pgofs; =20 @@ -1122,7 +1123,7 @@ static int f2fs_readdir(struct file *file, struct dir= _context *ctx) make_dentry_ptr_block(inode, &d, dentry_blk); =20 err =3D f2fs_fill_dentries(ctx, &d, - n * NR_DENTRY_IN_BLOCK, &fstr); + n * entries, &fstr); f2fs_folio_put(dentry_folio, false); if (err) break; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2a4ba7d4ec0e..d2e54573ed34 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -669,17 +669,6 @@ struct f2fs_dentry_ptr { int nr_bitmap; }; =20 -static inline void make_dentry_ptr_block(struct inode *inode, - struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) -{ - d->inode =3D inode; - d->max =3D NR_DENTRY_IN_BLOCK; - d->nr_bitmap =3D SIZE_OF_DENTRY_BITMAP; - d->bitmap =3D t->dentry_bitmap; - d->dentry =3D t->dentry; - d->filename =3D t->filename; -} - static inline void make_dentry_ptr_inline(struct inode *inode, struct f2fs_dentry_ptr *d, void *t) { @@ -1866,6 +1855,9 @@ struct f2fs_sb_info { unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int orphans_per_block; /* orphan inodes in a block */ + unsigned int dentries_per_block; /* dentries in a block */ + unsigned int dentry_bitmap_size; /* dentry bitmap size in bytes */ + unsigned int dentry_reserved_size; /* dentry reserved bytes */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2268,6 +2260,23 @@ f2fs_orphan_footer(void *orphan_block, struct f2fs_s= b_info *sbi) sizeof(struct f2fs_orphan_footer)); } =20 +static inline void make_dentry_ptr_block(struct inode *inode, + struct f2fs_dentry_ptr *d, void *t) +{ + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int entries =3D sbi->dentries_per_block; + unsigned int bitmap_size =3D sbi->dentry_bitmap_size; + unsigned int reserved_size =3D sbi->dentry_reserved_size; + + d->inode =3D inode; + d->max =3D entries; + d->nr_bitmap =3D bitmap_size; + d->bitmap =3D t; + d->dentry =3D t + bitmap_size + reserved_size; + d->filename =3D t + bitmap_size + reserved_size + + SIZE_OF_DIR_ENTRY * entries; +} + static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { return (struct f2fs_super_block *)(sbi->raw_super); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index aec06fb4fd76..718dd785865a 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -415,7 +415,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, = struct folio *ifolio, { struct folio *folio; struct dnode_of_data dn; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr src, dst; int err; =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 5891dba76bce..5ca4f54e794c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4388,6 +4388,12 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); + sbi->dentries_per_block =3D (BITS_PER_BYTE * sbi->blocksize) / + ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1); + sbi->dentry_bitmap_size =3D DIV_ROUND_UP(sbi->dentries_per_block, + BITS_PER_BYTE); + sbi->dentry_reserved_size =3D sbi->blocksize - sbi->dentry_bitmap_size - + (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * sbi->dentries_per_block; sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bdb8c63ac0c6..2370af742c8f 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -605,15 +605,7 @@ typedef __le32 f2fs_hash_t; * dentry, when converting inline dentry we should handle this carefully. */ =20 -/* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1)) #define SIZE_OF_DIR_ENTRY 11 /* by byte */ -#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define SIZE_OF_RESERVED (F2FS_BLKSIZE - ((SIZE_OF_DIR_ENTRY + \ - F2FS_SLOT_LEN) * \ - NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) #define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */ =20 /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ @@ -624,14 +616,21 @@ struct f2fs_dir_entry { __u8 file_type; /* file type */ } __packed; =20 -/* Block-sized directory entry block */ -struct f2fs_dentry_block { - /* validity bitmap for directory entries in each block */ - __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; - __u8 reserved[SIZE_OF_RESERVED]; - struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; - __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; -} __packed; +/* + * A dentry block is laid out as follows, where the number of entries and = all + * offsets are determined by the filesystem block size at runtime: + * + * 0 blocksize + * +--------+----------+-------------------+-----------------------+ + * | bitmap | reserved | dir_entry[entries]| filename[entries][8] | + * +--------+----------+-------------------+-----------------------+ + * + * entries =3D (BITS_PER_BYTE * blocksize) / + * ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1) + * bitmap_size =3D DIV_ROUND_UP(entries, BITS_PER_BYTE) + * reserved_size =3D blocksize - bitmap_size - + * (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * entries + */ =20 #define F2FS_DEF_PROJID 0 /* default project ID */ =20 --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 1CA23391851 for ; Thu, 3 Sep 2026 23:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477109; cv=none; b=ktIkrccgLd4wDrCUbTXSqiCq6YK2xpDXnc6UVD0l0KGI9+llXpw/KDjI+JZ0Hr2FxwUWksC9uIIKGZepfsSbXNP/dZVeTNB35aRX97Vc8tyeuOg6sGo70qDmyjzBQcJxloNDwGOkJzGTZtG9m+f9Np+W/j5SAdHr4H9TwgpS7t0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477109; c=relaxed/simple; bh=D7/NB1OzGiwGaGwPTBw/kMOE48E3kA++wwBufFlRjjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E7TEzPDKmUmCS0dbu0KPh+7Uh2qkZdsqJR7XrMo/IVb2jYCjdQ8jvVF7hKP8n+Dpg9zH1hCE451x4NYlL7jg35fZMXDbMA/eLTKFFJ6pUMpVMqDoTlhb5OYJmlNXLeyglST+xw5q7HbgqtcMxkVJ8kppdz8uTPnNZf4qKumoci0= 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=ViakyZnh; arc=none smtp.client-ip=209.85.210.182 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="ViakyZnh" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-855d2bfae95so1885741b3a.1 for ; Thu, 03 Sep 2026 16:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477106; x=1789081906; 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=uqZO6Brwcf00/mVxYFXz26sDFJ0VWrxYomoCtks7rio=; b=ViakyZnhIdlvESjK7+7sg26vDJqu34djvlADoy/TV6qkkTmC1YB5RbEWFDwXlxgH39 XAsogVE7UJnx5P/GgbqBtCx1O3S/MaFJuAbD3tG3ZinXlpoEQM2DVcyj470CaUk0drWf 5fTQn1oFzEIhSESXln1pEiNMb5jLCm+fLEja40ZNuJdS55QM9YL3hDpxGwruLYGJK7Vz JKDdozul9X43+HtY/6aLfzNQzhvoYadrap32KMvN4i6jyFGi/N5UKhm8B9HK1w083fJS NQFPWtd3PuLWt1LkRMv+l4bePD3IIFKoWSaDUlZ1C57yAWbGNDxn2BxjCp1auJo6TLe8 cToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477106; x=1789081906; 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=uqZO6Brwcf00/mVxYFXz26sDFJ0VWrxYomoCtks7rio=; b=ckd/CdJAZ/AeGBqMCwRlXIxU6teSBvvDXvSXu5ZxTD4t7vS0ZWI79jZqyNnI5d2Hcd OGveaCbMruXyvAu22JT928n3t1wlDaXDo9dRTZOSYRC9b+e3uobOomFlnwAjZHiaaFob +9w1uIfzyxfAinDcXA9KTtJbj+CcTXpRxV4zPT2KoEf9TGMESiL7bKZHqo9PIEg0eavm wYVUwaNup3A3jmImn28084PQtu/pzVy96kKOuHG+3CC3WlkJ6ZlVjH+qMLfUyA6mp5Nq hzKSuPcgo/H6Bi78z6SLIuYi2opWBGdMcPCAJ0hZMx052EUdAXeQGWPuDHjNrULTyn4h Rq3g== X-Forwarded-Encrypted: i=1; AKwUvBz/E5ou3FNHzJvMg+ktuEUfk8Mtb/pRGdIIrrBTldTjJqjWvSMP8UxlP0Pke9weXNW0t4crWaGEVqD/wr0=@vger.kernel.org X-Gm-Message-State: AFuF++k2Fs/5AmeWUb1zjQv176DehmhcA6X+q22E8CagtPmcx1pF40PO IElzTbvYPUc/17EKzns3lmahBEl5Vvc6suO95REQK+noc3BRrpVWyJis X-Gm-Gg: AYBFou1QJckxVc3uYucvh9NoLVvfs/d8XkVDI82ApiindVGFjGn4NFskK9dpMVAGjJC Va5tdczhOyT0ASDydQ5ArLbecbPT/fGviXp2pOv09OuN4Fy3FrIKohI+UQpjhFOvX12Gjzrt9mn +jMSXYEdwKY2bvM9xhMYQb4COh8+E666eq6fzqgcin2Y3wjnPhnWZ3d9On9KLb8TETvnWB4KyOL 7OlB++wsSL0jJFP6+iswzaTv1mC9vu+iqKp9xWpEzsE5JpxGC82wJnYz/64YD1G2eLgO1rqlauM DyrJUwdJrPs7Zn6ik01Wn/egb3y2IuTmxlVTA+I/PpxAs0Qyh+YXTdzwyNnd7VRE2g7fTaFRG/A rnc+n8kCLEAPteKGzO+BFn0o3af8HRwcgnsa5Jubq5SRovdb01vb3dWo7Pe7oNVzVZO0iwynJBN /zrApvWJDdeCSEpmb4BN29hPFCIIrhovjz6LxLPoKaCBrHUMkdFX+nuz5imYJGAFF9Qw== X-Received: by 2002:a05:6a00:138f:b0:851:80de:db56 with SMTP id d2e1a72fcca58-85ffe10a09amr7507305b3a.13.1788477106117; Thu, 03 Sep 2026 16:11:46 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-86152e39a38sm432289b3a.39.2026.09.03.16.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:45 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 06/11] f2fs: describe {i,d,id}node block layout dynamically Date: Thu, 3 Sep 2026 16:11:33 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" An inode block ends with five i_nid entries followed by a node footer. Data block address pointers (i_addr[]) precede them. Similarly, direct and indirect node blocks contain data addresses or node IDs followed by a node footer at the end of the block. Describe struct f2fs_inode, struct direct_node, and struct indirect_node using flexible array members. Compute the locations of i_nid and node footers dynamically from the filesystem block size. Introduce F2FS_INODE_NIDS() and F2FS_NODE_FOOTER() helpers to access these tail fields. Compute sbi->addrs_per_inode, sbi->addrs_per_block, and sbi->nids_per_block in init_sb_info(), and update node management, file mapping, and recovery paths accordingly. Signed-off-by: Kelvin Zhang --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 42 ++++++++++++++++++++++++-------- fs/f2fs/gc.c | 2 +- fs/f2fs/inline.c | 3 +-- fs/f2fs/inode.c | 5 ++-- fs/f2fs/node.c | 4 +--- fs/f2fs/node.h | 53 +++++++++++++++++++---------------------- fs/f2fs/super.c | 4 ++++ fs/f2fs/xattr.h | 2 +- include/linux/f2fs_fs.h | 44 +++++++++++++++++++++------------- 10 files changed, 95 insertions(+), 66 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6ae0eb37d20f..632513b5453c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2027,7 +2027,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, =20 phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + - sizeof(__le32) * (DEF_ADDRS_PER_INODE - + sizeof(__le32) * (DEF_ADDRS_PER_INODE(sbi) - get_inline_xattr_addrs(inode)); =20 phys +=3D offset; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d2e54573ed34..84f2d0cabda4 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -602,8 +602,9 @@ static inline int update_sits_in_cursum(struct f2fs_jou= rnal *journal, int i) #define DEF_INLINE_RESERVED_SIZE 1 static inline int get_extra_isize(struct inode *inode); static inline int get_inline_xattr_addrs(struct inode *inode); +static inline unsigned int cur_addrs_per_inode(struct inode *inode); #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ - (CUR_ADDRS_PER_INODE(inode) - \ + (cur_addrs_per_inode(inode) - \ get_inline_xattr_addrs(inode) - \ DEF_INLINE_RESERVED_SIZE)) =20 @@ -1853,6 +1854,9 @@ struct f2fs_sb_info { unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ unsigned int nat_entries_per_block; /* NAT entries in a block */ + unsigned int addrs_per_inode; /* addresses in an inode block */ + unsigned int addrs_per_block; /* addresses in a direct node block */ + unsigned int nids_per_block; /* node IDs in an indirect node block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int orphans_per_block; /* orphan inodes in a block */ unsigned int dentries_per_block; /* dentries in a block */ @@ -2248,6 +2252,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) =20 #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) +#define DEF_ADDRS_PER_INODE(sbi) ((sbi)->addrs_per_inode) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) @@ -2297,6 +2302,12 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(stru= ct f2fs_sb_info *sbi) return (struct f2fs_checkpoint *)(sbi->ckpt); } =20 +static inline struct node_footer *F2FS_NODE_FOOTER(const struct folio *fol= io) +{ + return folio_address(folio) + F2FS_BLKSIZE - + sizeof(struct node_footer); +} + static inline struct f2fs_node *F2FS_NODE(const struct folio *folio) { return (struct f2fs_node *)folio_address(folio); @@ -2307,6 +2318,12 @@ static inline struct f2fs_inode *F2FS_INODE(const st= ruct folio *folio) return &((struct f2fs_node *)folio_address(folio))->i; } =20 +static inline __le32 *F2FS_INODE_NIDS(const struct folio *folio) +{ + return folio_address(folio) + F2FS_BLKSIZE - sizeof(struct node_footer) - + SIZE_OF_I_NID; +} + static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) { return (struct f2fs_nm_info *)(sbi->nm_info); @@ -3277,13 +3294,11 @@ static inline void f2fs_radix_tree_insert(struct ra= dix_tree_root *root, cond_resched(); } =20 -#define RAW_IS_INODE(p) ((p)->footer.nid =3D=3D (p)->footer.ino) - static inline bool IS_INODE(const struct folio *folio) { - struct f2fs_node *p =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); =20 - return RAW_IS_INODE(p); + return footer->nid =3D=3D footer->ino; } =20 static inline int offset_in_addr(struct f2fs_inode *i) @@ -3292,9 +3307,11 @@ static inline int offset_in_addr(struct f2fs_inode *= i) (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; } =20 -static inline __le32 *blkaddr_in_node(struct f2fs_node *node) +static inline __le32 *blkaddr_in_node(const struct folio *folio) { - return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; + struct f2fs_node *node =3D F2FS_NODE(folio); + + return IS_INODE(folio) ? node->i.i_addr : node->dn.addr; } =20 static inline int f2fs_has_extra_attr(struct inode *inode); @@ -3311,7 +3328,7 @@ static inline unsigned int get_dnode_base(struct inod= e *inode, static inline __le32 *get_dnode_addr(struct inode *inode, struct folio *node_folio) { - return blkaddr_in_node(F2FS_NODE(node_folio)) + + return blkaddr_in_node(node_folio) + get_dnode_base(inode, node_folio); } =20 @@ -3626,7 +3643,7 @@ static inline bool f2fs_need_compress_data(struct ino= de *inode) static inline unsigned int addrs_per_page(struct inode *inode, bool is_inode) { - unsigned int addrs =3D is_inode ? (CUR_ADDRS_PER_INODE(inode) - + unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; =20 if (f2fs_compressed_file(inode)) @@ -3634,12 +3651,17 @@ static inline unsigned int addrs_per_page(struct in= ode *inode, return addrs; } =20 +static inline unsigned int cur_addrs_per_inode(struct inode *inode) +{ + return DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_extra_isize(inode); +} + static inline void *inline_xattr_addr(struct inode *inode, const struct folio *folio) { struct f2fs_inode *ri =3D F2FS_INODE(folio); =20 - return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - + return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_inline_xattr_addrs(inode)]); } =20 diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index c15c6ba91597..164612dbe2c6 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1176,7 +1176,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct= f2fs_summary *sum, =20 if (IS_INODE(node_folio)) { base =3D offset_in_addr(F2FS_INODE(node_folio)); - max_addrs =3D DEF_ADDRS_PER_INODE; + max_addrs =3D DEF_ADDRS_PER_INODE(sbi); } else { base =3D 0; max_addrs =3D DEF_ADDRS_PER_BLOCK; diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 718dd785865a..73cd9b6ddcc5 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -36,14 +36,13 @@ bool f2fs_may_inline_data(struct inode *inode) =20 static bool inode_has_blocks(struct inode *inode, struct folio *ifolio) { - struct f2fs_inode *ri =3D F2FS_INODE(ifolio); int i; =20 if (F2FS_HAS_BLOCKS(inode)) return true; =20 for (i =3D 0; i < DEF_NIDS_PER_INODE; i++) { - if (ri->i_nid[i]) + if (F2FS_INODE_NIDS(ifolio)[i]) return true; } return false; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 96cc0e777567..fda9ee3bfc61 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -150,9 +150,8 @@ bool f2fs_enable_inode_chksum(struct f2fs_sb_info *sbi,= struct folio *folio) =20 static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi, struct folio *fol= io) { - struct f2fs_node *node =3D F2FS_NODE(folio); - struct f2fs_inode *ri =3D &node->i; - __le32 ino =3D node->footer.ino; + struct f2fs_inode *ri =3D F2FS_INODE(folio); + __le32 ino =3D F2FS_NODE_FOOTER(folio)->ino; __le32 gen =3D ri->i_generation; __u32 chksum, chksum_seed; __u32 dummy_cs =3D 0; diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 960c6657d0d6..e3f594f7bcce 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -3001,7 +3001,6 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi,= struct folio *folio) int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, unsigned int segno, struct f2fs_summary_block *sum) { - struct f2fs_node *rn; struct f2fs_summary *sum_entry; block_t addr; int i, idx, last_offset, nrpages; @@ -3023,8 +3022,7 @@ int f2fs_restore_node_summary(struct f2fs_sb_info *sb= i, if (IS_ERR(folio)) return PTR_ERR(folio); =20 - rn =3D F2FS_NODE(folio); - sum_entry->nid =3D rn->footer.nid; + sum_entry->nid =3D F2FS_NODE_FOOTER(folio)->nid; sum_entry->version =3D 0; sum_entry->ofs_in_node =3D 0; sum_entry++; diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index d4a20d48432c..911c3d336533 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -250,73 +250,68 @@ static inline void set_to_next_nat(struct f2fs_sb_inf= o *sbi, =20 static inline nid_t ino_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.ino); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->ino); } =20 static inline nid_t nid_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.nid); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->nid); } =20 static inline unsigned int ofs_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - unsigned flag =3D le32_to_cpu(rn->footer.flag); + unsigned int flag =3D le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->flag); return flag >> OFFSET_BIT_SHIFT; } =20 static inline __u64 cpver_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le64_to_cpu(rn->footer.cp_ver); + return le64_to_cpu(F2FS_NODE_FOOTER(node_folio)->cp_ver); } =20 static inline block_t next_blkaddr_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.next_blkaddr); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->next_blkaddr); } =20 static inline void fill_node_footer(const struct folio *folio, nid_t nid, nid_t ino, unsigned int ofs, bool reset) { struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); unsigned int old_flag =3D 0; =20 if (reset) - memset(rn, 0, sizeof(*rn)); + memset(rn, 0, F2FS_BLKSIZE); else - old_flag =3D le32_to_cpu(rn->footer.flag); + old_flag =3D le32_to_cpu(footer->flag); =20 - rn->footer.nid =3D cpu_to_le32(nid); - rn->footer.ino =3D cpu_to_le32(ino); + footer->nid =3D cpu_to_le32(nid); + footer->ino =3D cpu_to_le32(ino); =20 /* should remain old flag bits such as COLD_BIT_SHIFT */ - rn->footer.flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | + footer->flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | (old_flag & OFFSET_BIT_MASK)); } =20 static inline void copy_node_footer(const struct folio *dst, const struct folio *src) { - struct f2fs_node *src_rn =3D F2FS_NODE(src); - struct f2fs_node *dst_rn =3D F2FS_NODE(dst); - memcpy(&dst_rn->footer, &src_rn->footer, sizeof(struct node_footer)); + memcpy(F2FS_NODE_FOOTER(dst), F2FS_NODE_FOOTER(src), + sizeof(struct node_footer)); } =20 static inline void fill_node_footer_blkaddr(struct folio *folio, block_t b= lkaddr) { struct f2fs_checkpoint *ckpt =3D F2FS_CKPT(F2FS_F_SB(folio)); - struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); __u64 cp_ver =3D cur_cp_version(ckpt); =20 if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) cp_ver |=3D (cur_cp_crc(ckpt) << 32); =20 - rn->footer.cp_ver =3D cpu_to_le64(cp_ver); - rn->footer.next_blkaddr =3D cpu_to_le32(blkaddr); + footer->cp_ver =3D cpu_to_le64(cp_ver); + footer->next_blkaddr =3D cpu_to_le32(blkaddr); } =20 static inline bool is_recoverable_dnode(const struct folio *folio) @@ -376,11 +371,12 @@ static inline bool IS_DNODE(const struct folio *node_= folio) static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 f2fs_folio_wait_writeback(folio, NODE, true, true); =20 if (i) - rn->i.i_nid[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -389,9 +385,10 @@ static inline int set_nid(struct folio *folio, int off= , nid_t nid, bool i) static inline nid_t get_nid(const struct folio *folio, int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 if (i) - return le32_to_cpu(rn->i.i_nid[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); return le32_to_cpu(rn->in.nid[off]); } =20 @@ -404,8 +401,7 @@ static inline nid_t get_nid(const struct folio *folio, = int off, bool i) =20 static inline int is_node(const struct folio *folio, int type) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - return le32_to_cpu(rn->footer.flag) & BIT(type); + return le32_to_cpu(F2FS_NODE_FOOTER(folio)->flag) & BIT(type); } =20 #define is_cold_node(folio) is_node(folio, COLD_BIT_SHIFT) @@ -414,14 +410,13 @@ static inline int is_node(const struct folio *folio, = int type) =20 static inline void __set_mark(const struct folio *folio, bool mark, int ty= pe) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - unsigned int flag =3D le32_to_cpu(rn->footer.flag); - + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); + unsigned int flag =3D le32_to_cpu(footer->flag); if (mark) flag |=3D BIT(type); else flag &=3D ~BIT(type); - rn->footer.flag =3D cpu_to_le32(flag); + footer->flag =3D cpu_to_le32(flag); } =20 static inline void set_cold_node(const struct folio *folio, bool is_dir) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 5ca4f54e794c..87fc0a8ec246 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4384,6 +4384,10 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->blocksize =3D BIT(sbi->log_blocksize); sbi->nat_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_nat_entry); + sbi->addrs_per_inode =3D F2FS_DEF_ADDRS_PER_INODE(sbi->blocksize); + sbi->addrs_per_block =3D (sbi->blocksize - + sizeof(struct node_footer)) / sizeof(__le32); + sbi->nids_per_block =3D sbi->addrs_per_block; sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index bce3d93e4755..7cd7ce58334b 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -85,7 +85,7 @@ struct f2fs_xattr_entry { =20 #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(_= _le32)) #define MAX_INLINE_XATTR_SIZE \ - (DEF_ADDRS_PER_INODE - \ + (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 2370af742c8f..bec31591b398 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -268,11 +268,9 @@ struct node_footer { } __packed; =20 /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ - - SIZE_OF_I_NID \ - - sizeof(struct node_footer)) / sizeof(__le32)) -#define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ - get_extra_isize(inode)) +#define F2FS_DEF_ADDRS_PER_INODE(blocksize) \ + (((blocksize) - OFFSET_OF_END_OF_I_EXT - SIZE_OF_I_NID - \ + sizeof(struct node_footer)) / sizeof(__le32)) #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ @@ -283,11 +281,11 @@ struct node_footer { =20 #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) =20 -#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) -#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) -#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3) -#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4) -#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5) +#define NODE_DIR1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 1) +#define NODE_DIR2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 2) +#define NODE_IND1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 3) +#define NODE_IND2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 4) +#define NODE_DIND_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 5) =20 #define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02 /* file inline data flag */ @@ -347,18 +345,26 @@ struct f2fs_inode { */ __le32 i_extra_end[0]; /* for attribute size calculation */ } __packed; - __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ + DECLARE_FLEX_ARRAY(__le32, i_addr); /* data block pointers */ }; - __le32 i_nid[DEF_NIDS_PER_INODE]; /* direct(2), indirect(2), - double_indirect(1) node id */ + /* + * __le32 i_nid[DEF_NIDS_PER_INODE]; + * direct(2), indirect(2), double_indirect(1) node IDs + * + * It is stored immediately before the node footer at the end of the + * filesystem block. Its offset depends on the filesystem block size, so + * locate it dynamically with F2FS_INODE_NIDS(). + */ } __packed; =20 struct direct_node { - __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */ + /* The address count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, addr); /* array of data block address */ } __packed; =20 struct indirect_node { - __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ + /* The node ID count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, nid); /* array of data block address */ } __packed; =20 enum { @@ -377,7 +383,13 @@ struct f2fs_node { struct direct_node dn; struct indirect_node in; }; - struct node_footer footer; + /* + * struct node_footer footer; + * + * It is stored at the end of the filesystem block, after the inode or + * direct/indirect node data. Its offset depends on the filesystem block + * size, so locate it dynamically with F2FS_NODE_FOOTER(). + */ } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 A1D1B397347 for ; Thu, 3 Sep 2026 23:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477110; cv=none; b=MFGjhJWIoCd3OQyJ05GRuRV4RgfadXntaacw30sjrRHgeewRyGNmqfCXWIbPkLMRmbMRB40j7cljffZnHFhNMtH3dTtb2ROHRzpQ6fwvYNprOXwVaUWDlS71pv9SK1j8yhLNBMDKefpEJeWI/G2uPSXoV2dno6AZAjNZO0QPLI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477110; c=relaxed/simple; bh=Sz1G0zlz4u5afeRzBLtAp00tEeH67JMRrxu/MardOTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ifPYLpwEqWuTG5+VLGhJSBerTFbEp5MigmElbYLNDyOCZ0fyNraCS7mBbOiVh/5EQ+oYF4sUtsfeMRFnMkPLv3nIwmXJMVi5LeH8rhRAykE3PGrYEnqv29yNPNlbhoPU4vgTg6cexD9Cms3rqOt3jMhMZ5nKlhYcreKoxByiYuA= 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=dfngvV11; arc=none smtp.client-ip=209.85.215.178 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="dfngvV11" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-cc1cc1b42b5so509898a12.2 for ; Thu, 03 Sep 2026 16:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477108; x=1789081908; 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=oI0SdKfcZHgfXMNdZMI4amVSwVJWRyNSiFrZzvdLQQc=; b=dfngvV11bLAtlx46kv6rfr4/Pubf2UJcZFd4wnrPki0K8p1FrWxQnrpw7f5cl/ecCV SbgWpnFPc4j6QEuhmt4zPhNKU6cfdzbB7vReJ2q4mhuPJQn05WrDVSt9GBQoglKnpp8f RQ2R7S3p/GBMlk9ZWli1D2Smklpl4Ybh4XuSIVJraAQg3FOnOeQi45e/zH2IRDf9AuHk Y791pDbE+e7CAjEI1UK94QIo3HVRZsMUBJQQBFgRUCR+CRQdq6X+Mn4fnZKfs1qrsxSG Pw1qUpoNIqA56i/1QFf0vZ1nKRMFbD4UJhJKNvy49h1pRKVa/lvrfvEoPW8uSJ9NnL7T mIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477108; x=1789081908; 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=oI0SdKfcZHgfXMNdZMI4amVSwVJWRyNSiFrZzvdLQQc=; b=iEV0vublZ7w255jTHOOHdsWM8hFLTlI9/oARatfh3YoL5f2CV1sN7Y1ptyjoLwrdgm te/YWRJ1s7HtQbMNOzyGzQaQuGdZh9BU7pEKpi+Lo4cjh8B8baqWrhdyChCMCZk4FDH4 M3jaty92soSxbZ4Uwv6nw7ljfynsy1dURmrvhaGa4kAmeLbIN5xyJiR6TqWl52i313dt PYNUM6Or0MpJBgmHGs+A22PcLCn8b4JNTnpdKgF1VwUCwklnwc3MtoBsBfpmxtmgIRGI BIXzEjsIiGrrtCOvFGhwguG7sN5oDDPRYcdgzYw67bR9nqkCnqasOgiWA1NoAqXvTXls vQIQ== X-Forwarded-Encrypted: i=1; AKwUvByMCrhAwFvEH3HQTZiEDnQhkwn+/9RkwH903h3nsrwJeOLmC6iHsHwIQuYGGVZ9xxJ3zt3yl264CQqXdes=@vger.kernel.org X-Gm-Message-State: AFuF++lOVm0jERXu252hbJjuCe7nIdFxUswxC9IkAHWqQ29KTrZPIZZW HyPuo8dpPu/H3PSc3s9yHbfltbM44c0VlIFbL/aAQ0D5KcUqiWHSZdWT X-Gm-Gg: AYBFou2P76iZhggBkPECko5n42nomqwy76/x6gfuOOL3sXAoO/rTDle1iHGkE0ejKUD QSy5anXZQbAdBe7+OWCbYnsC/jqTy2zx/PYpLoI3i1mRNKQK1d5Osj2lUDE2rBQJ/jXKfx251MJ P1k+DzDJSdFbBmUSR9i26o/P/yVDmYVPu9hWUy2oCZEzWwBnfdDORo7/+CGqXf8Xf+zYvYu2Eux LS5+v2HQhpkOBI6ftOOBZsfZIh0h76hIEKhW68EriM2uM/KrcE3HQIdWjnP5GpTQfPnn7745U2c MmorJEmI8bIdzfgHZ3FfXLO8gVQrxfmBp4vfyPnyA9Y9tWRuyDPzZjeO/plshkG8IGH1rG2Ikbw zaW7gLWTx8yHZBhLwmQ4GP+gHnO0Wd4pgzIlQeMfiawhHRlKerlepLMYGe86HRZlyN0hotcjHvs OQ1vNxE0Gk2PE5L3ICsTzAyIqewzoGzyW3lGamJJ2iunlN+y0hYgljRguyG0Rl1kK8Tw== X-Received: by 2002:a17:90b:1343:b0:38e:9eb2:9d43 with SMTP id 98e67ed59e1d1-39b261b1bcfmr3039830a91.16.1788477107926; Thu, 03 Sep 2026 16:11:47 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b260cd2aasm1135006a91.3.2026.09.03.16.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:47 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 07/11] f2fs: describe xattr block layout dynamically Date: Thu, 3 Sep 2026 16:11:34 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" The usable capacity of dedicated on-disk extended attribute blocks and inline xattr regions scales with the filesystem block size. Parameterize VALID_XATTR_BLOCK_SIZE and MAX_INLINE_XATTR_SIZE to calculate usable xattr limits dynamically from sbi->blocksize rather than hardcoding PAGE_SIZE or DEF_ADDRS_PER_INODE. Update mount option consistency validation for inline_xattr_size to evaluate allowed boundaries dynamically against the runtime block size. Signed-off-by: Kelvin Zhang --- fs/f2fs/inode.c | 7 ++++--- fs/f2fs/node.c | 2 +- fs/f2fs/super.c | 17 +++++++++++++++-- fs/f2fs/xattr.c | 8 +++++--- fs/f2fs/xattr.h | 11 ++++++----- include/linux/f2fs_fs.h | 3 +++ 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index fda9ee3bfc61..79c0a1301996 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -337,12 +337,13 @@ static bool sanity_check_inode(struct inode *inode, s= truct folio *node_folio) } =20 if (f2fs_sb_has_flexible_inline_xattr(sbi) && - (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE || + (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE(i_blocksize(inode)) || (f2fs_has_inline_xattr(inode) && fi->i_inline_xattr_size < MIN_INLINE_XATTR_SIZE))) { - f2fs_warn(sbi, "%s: inode (ino=3D%llx) has corrupted i_inline_xattr_size= : %d, min: %zu, max: %lu", + f2fs_warn(sbi, "%s: inode (ino=3D%llx) has corrupted i_inline_xattr_size= : %d, min: %zu, max: %zu", __func__, inode->i_ino, fi->i_inline_xattr_size, - MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE); + MIN_INLINE_XATTR_SIZE, + (size_t)MAX_INLINE_XATTR_SIZE(i_blocksize(inode))); return false; } =20 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e3f594f7bcce..7dabfada1b54 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2919,7 +2919,7 @@ int f2fs_recover_xattr_data(struct inode *inode, stru= ct folio *folio) /* 3: update and set xattr node page dirty */ if (folio) { memcpy(F2FS_NODE(xfolio), F2FS_NODE(folio), - VALID_XATTR_BLOCK_SIZE); + VALID_XATTR_BLOCK_SIZE(inode)); folio_mark_dirty(xfolio); } f2fs_folio_put(xfolio, true); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 87fc0a8ec246..df5572084af0 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -855,9 +855,11 @@ static int f2fs_parse_param(struct fs_context *fc, str= uct fs_parameter *param) break; case Opt_inline_xattr_size: if (result.int_32 < MIN_INLINE_XATTR_SIZE || - result.int_32 > MAX_INLINE_XATTR_SIZE) { + result.int_32 > + MAX_INLINE_XATTR_SIZE(F2FS_MAX_BLKSIZE)) { f2fs_err(NULL, "inline xattr size is out of range: %u ~ %u", - (u32)MIN_INLINE_XATTR_SIZE, (u32)MAX_INLINE_XATTR_SIZE); + (u32)MIN_INLINE_XATTR_SIZE, + (u32)MAX_INLINE_XATTR_SIZE(F2FS_MAX_BLKSIZE)); return -EINVAL; } ctx_set_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE); @@ -1596,6 +1598,8 @@ static int f2fs_check_opt_consistency(struct fs_conte= xt *fc, } =20 if (ctx_test_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE)) { + int min_size, max_size; + if (!f2fs_sb_has_extra_attr(sbi) || !f2fs_sb_has_flexible_inline_xattr(sbi)) { f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); @@ -1605,6 +1609,15 @@ static int f2fs_check_opt_consistency(struct fs_cont= ext *fc, f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr= option"); return -EINVAL; } + min_size =3D MIN_INLINE_XATTR_SIZE; + max_size =3D MAX_INLINE_XATTR_SIZE(sbi->blocksize); + + if (F2FS_OPTION(sbi).inline_xattr_size < min_size || + F2FS_OPTION(sbi).inline_xattr_size > max_size) { + f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", + min_size, max_size); + return -EINVAL; + } } =20 if (ctx_test_opt(ctx, F2FS_MOUNT_ATGC) && diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 6728d1488cad..99c863513725 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -310,7 +310,8 @@ static int read_xattr_block(struct inode *inode, void *= txattr_addr) return PTR_ERR(xfolio); =20 xattr_addr =3D folio_address(xfolio); - memcpy(txattr_addr + inline_size, xattr_addr, VALID_XATTR_BLOCK_SIZE); + memcpy(txattr_addr + inline_size, xattr_addr, + VALID_XATTR_BLOCK_SIZE(inode)); f2fs_folio_put(xfolio, true); =20 return 0; @@ -393,7 +394,7 @@ static int read_all_xattrs(struct inode *inode, struct = folio *ifolio, { struct f2fs_xattr_header *header; nid_t xnid =3D F2FS_I(inode)->i_xattr_nid; - unsigned int size =3D VALID_XATTR_BLOCK_SIZE; + unsigned int size =3D VALID_XATTR_BLOCK_SIZE(inode); unsigned int inline_size =3D inline_xattr_size(inode); void *txattr_addr; int err; @@ -502,7 +503,8 @@ static inline int write_all_xattrs(struct inode *inode,= __u32 hsize, =20 if (inline_size) memcpy(inline_addr, txattr_addr, inline_size); - memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE); + memcpy(xattr_addr, txattr_addr + inline_size, + VALID_XATTR_BLOCK_SIZE(inode)); =20 if (inline_size) folio_mark_dirty(ifolio ? ifolio : in_folio); diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index 7cd7ce58334b..75beab2d1ee3 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -71,21 +71,22 @@ struct f2fs_xattr_entry { for (entry =3D XATTR_FIRST_ENTRY(addr);\ !IS_XATTR_LAST_ENTRY(entry);\ entry =3D XATTR_NEXT_ENTRY(entry)) -#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) +#define VALID_XATTR_BLOCK_SIZE(i) (i_blocksize(i) - \ + sizeof(struct node_footer)) #define XATTR_PADDING_SIZE (sizeof(__u32)) #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \ - VALID_XATTR_BLOCK_SIZE : 0) + \ + VALID_XATTR_BLOCK_SIZE(i) : 0) + \ (inline_xattr_size(i))) #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ - VALID_XATTR_BLOCK_SIZE) + VALID_XATTR_BLOCK_SIZE(i)) =20 #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ sizeof(struct f2fs_xattr_header) - \ sizeof(struct f2fs_xattr_entry)) =20 #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(_= _le32)) -#define MAX_INLINE_XATTR_SIZE \ - (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ +#define MAX_INLINE_XATTR_SIZE(blocksize) \ + (F2FS_DEF_ADDRS_PER_INODE(blocksize) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bec31591b398..e98bff846b23 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -15,7 +15,10 @@ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ #define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sect= or/blk */ +#define F2FS_MIN_LOG_BLOCKSIZE 12 +#define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ +#define F2FS_MAX_BLKSIZE PAGE_SIZE #define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 339BD38DC5B for ; Thu, 3 Sep 2026 23:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477113; cv=none; b=ma6IrMz0jyRxId9UD0SxTQ49pJSgGGWYnTwsCEEL2QF5Cn1SiLkh0d/D4YRoyv9LDR1VAZHMi8bf8BXLxwn7RbOcrPf2oc5Bj0TdZYnkBsvDfMDQeR6bIuCPzu7o4s1RQpqVU0viHZVqJukpCXnwY3whsbV3CQ/xFQODHajjlgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477113; c=relaxed/simple; bh=lHeDJ4nFM3eTx+K2HCQREbDxOLqPq11pE318P4JK74E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T94ns5FbYXr0L4xx4r878Jd9GCNm33+qiDLbRWL2tWeZ/gj/MUXBhNQexOJlmqLXWNsKKHqwOy+5ezCjbDgvwImfGc6C04du8EcKocyZ3Eeesk5tXSq8D3V5lajbz+Enoy2pxnpHKwMFndXNEZcuGL56dzLSL9tTgnvHkWDL4NY= 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=TRbI9P1M; arc=none smtp.client-ip=209.85.216.49 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="TRbI9P1M" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3856d6fbcb3so262234a91.2 for ; Thu, 03 Sep 2026 16:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477109; x=1789081909; 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=kw+qmFr37Q7/LtQ8UqbmCTsqXbxzNguI36NDb1SL/60=; b=TRbI9P1MsacGTyltrF9XUuN0l3xntLeACp8VVFm6Mffh39fRnb8LbBc/GKGYpwEjSA v0iKHL/uz8csJiffd4rgs7YCm1/bPI30D3YI3qSDuyX8qtAFlUtq68ZfQRJ1nO872v+T 7vci/KNqWgbjy7rUwlf44rLQhd3VmLtHHw1nWqesc4P7KvHK3fBW64swcecM4xQ3DD9O xxLwcFEG/rG8ElhR6UjisdcJUYkhvQ+SUIviqZ73EqDFqMA8zQDH+qvs0OZC1WQEHkAX UXMfqe5XjiV4L3wD/RlCgry3yZlRttC/V9qDV3y1lQIVVnRgFNG4tfpTZzfMG62OX+YR zbPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477109; x=1789081909; 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=kw+qmFr37Q7/LtQ8UqbmCTsqXbxzNguI36NDb1SL/60=; b=KHhP/BJjkTKVT2H+UcPqQovJWzuWmyGhlu+nkfBGNaEl0xPUaAu5fphgDFwmPjOW8E uzpr2Vp8H2CKPOMevmYvUj0FDK06ESsXq/M8ZMlLlp274KAm+/1v8HgOJgryjKeTGo0Z do3EpJ22bveIqF3jLDGORoO/v5FTETiel3y81M3YHSBDVk/jMG8k5v6MDdqC6RugcdvR IT6gsUoGHrirjN0qMjnMiGTMXFKEmMHTywtOU3d0Wxf5YruVIWbVo5Fx4CaBSmDJQq6M B+ab3WKYx1kSEeNlAMVwLoMPrGcDm8QbyrxLGVOuOLHxirDa++iQyzR7Sh+je2CapIw+ wMgA== X-Forwarded-Encrypted: i=1; AKwUvBxqxznFWA++mcNa2bkwih/N1rKHirTkADk3iK5ALCvkLnlT+yjcVOOTmbMBRAc/aNg4r9LN+AT3Gcv9kn4=@vger.kernel.org X-Gm-Message-State: AFuF++mXHT/2yCiNNv0wC31ClxjutgidJnvC6vTkVLeb0V9ng6HyX/o0 epQLwL+NiqjRWgpxEP7j3WUUaPvuph9+8hGlDPrklNOVT07xIpSW7ieF X-Gm-Gg: AYBFou1aCmXTXgjhs2DJZiuKds+G1lEx07Yxh6qOcO6Mp42tTdRO4U8029o+rU8/UYb 3ZhfuVAHuBfFIuyiVgbJUiVCEw3ztvDwhoSiQbtKy73lmowYf0MaDEa4ixGyXeQxbcrYbFTLBwx Z+CX+A1Zhqptre6VnH/aVEJZb5MHtfaBesJK0hICGUcb/LgiZDHzSabHg4SKwctD5Uk7/CNn0U7 AeoV5otzVBVd43d3XZ+43TjtYQF3INmCBM8QYGurz1F+/hvzGgHKckp6hPQ6lyktNg7qYC7Gjr3 RlKtkNgOkP1Fri7wgFcGLiNbXSU7fX3TgQCg2gTmSBmWKZiFphDrP1UK4tZMzHF9D2nRCadbRd4 GRfTpuGwiHXfDRUTljFfHgTngOr16F8v8/DNDwqYN36EyQf3uAYslsVMtJuKOfM8DQRznbmrNYq ZgMSWxQq0jsIfY0jWMf5Cq1Ryy21gKjPXcAZ5k8Moxmj9aYlk7ncbcuARyirdop67sBw== X-Received: by 2002:a17:90b:5826:b0:38e:7168:281 with SMTP id 98e67ed59e1d1-39b261b07b6mr2831887a91.10.1788477109342; Thu, 03 Sep 2026 16:11:49 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b26123c99sm1108512a91.11.2026.09.03.16.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:48 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 08/11] f2fs: parameterize sector conversion macros Date: Thu, 3 Sep 2026 16:11:35 -0700 Message-ID: <7ddc7d42143ecbd6637c9470ba325119b340675b.1788476500.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.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" Sector-to-block and block-to-sector conversion helpers previously assumed a fixed sector count per block derived from 4KB pages. Parameterize F2FS_LOG_SECTORS_PER_BLOCK, SECTOR_FROM_BLOCK, and SECTOR_TO_BLOCK with struct f2fs_sb_info *sbi, using sbi->log_sectors_per_block. Update all call sites across metadata I/O, data mapping, discard operations, and zoned block device reporting. Signed-off-by: Kelvin Zhang --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 5 +++-- fs/f2fs/file.c | 4 ++-- fs/f2fs/inode.c | 11 +++++++---- fs/f2fs/segment.c | 14 +++++++------- fs/f2fs/segment.h | 8 ++++---- fs/f2fs/super.c | 10 +++++----- include/linux/f2fs_fs.h | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 632513b5453c..6a74af3fb396 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -466,7 +466,7 @@ struct block_device *f2fs_target_device(struct f2fs_sb_= info *sbi, } =20 if (sector) - *sector =3D SECTOR_FROM_BLOCK(blk_addr); + *sector =3D SECTOR_FROM_BLOCK(sbi, blk_addr); return bdev; } =20 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 84f2d0cabda4..e1006931f1af 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2610,7 +2610,8 @@ static inline int F2FS_HAS_BLOCKS(struct inode *inode) { block_t xattr_block =3D F2FS_I(inode)->i_xattr_nid ? 1 : 0; =20 - return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; + return (inode->i_blocks >> + F2FS_LOG_SECTORS_PER_BLOCK(F2FS_I_SB(inode))) > xattr_block; } =20 static inline bool f2fs_has_xattr_block(unsigned int ofs) @@ -2816,7 +2817,7 @@ static inline void dec_valid_block_count(struct f2fs_= sb_info *sbi, struct inode *inode, block_t count) { - blkcnt_t sectors =3D count << F2FS_LOG_SECTORS_PER_BLOCK; + blkcnt_t sectors =3D count << F2FS_LOG_SECTORS_PER_BLOCK(sbi); =20 spin_lock(&sbi->stat_lock); if (unlikely(sbi->total_valid_block_count < count)) { diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d440231b8cb9..2c72e028cec2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4510,8 +4510,8 @@ static int f2fs_reserve_compress_blocks(struct file *= filp, unsigned long arg) static int f2fs_secure_erase(struct block_device *bdev, struct inode *inod= e, pgoff_t off, block_t block, block_t len, u32 flags) { - sector_t sector =3D SECTOR_FROM_BLOCK(block); - sector_t nr_sects =3D SECTOR_FROM_BLOCK(len); + sector_t sector =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), block); + sector_t nr_sects =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), len); int ret =3D 0; =20 if (flags & F2FS_TRIM_FILE_DISCARD) { diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 79c0a1301996..aa22e457d5b3 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -221,11 +221,11 @@ static bool sanity_check_compress_inode(struct inode = *inode, return false; } if (le64_to_cpu(ri->i_compr_blocks) > - SECTOR_TO_BLOCK(inode->i_blocks)) { + SECTOR_TO_BLOCK(sbi, inode->i_blocks)) { f2fs_warn(sbi, "%s: inode (ino=3D%llx) has inconsistent i_compr_blocks:%llu, i_blocks:= %llu, run fsck to fix", __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), - SECTOR_TO_BLOCK(inode->i_blocks)); + SECTOR_TO_BLOCK(sbi, inode->i_blocks)); return false; } if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || @@ -447,7 +447,8 @@ static int do_read_inode(struct inode *inode) i_gid_write(inode, le32_to_cpu(ri->i_gid)); set_nlink(inode, le32_to_cpu(ri->i_links)); inode->i_size =3D le64_to_cpu(ri->i_size); - inode->i_blocks =3D SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1); + inode->i_blocks =3D SECTOR_FROM_BLOCK(sbi, + le64_to_cpu(ri->i_blocks) - 1); =20 inode_set_atime(inode, le64_to_cpu(ri->i_atime), le32_to_cpu(ri->i_atime_nsec)); @@ -696,6 +697,7 @@ struct inode *f2fs_iget_retry(struct super_block *sb, u= nsigned long ino) =20 void f2fs_update_inode(struct inode *inode, struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_inode_info *fi =3D F2FS_I(inode); struct f2fs_inode *ri; struct extent_tree *et =3D fi->extent_tree[EX_READ]; @@ -712,7 +714,8 @@ void f2fs_update_inode(struct inode *inode, struct foli= o *node_folio) ri->i_uid =3D cpu_to_le32(i_uid_read(inode)); ri->i_gid =3D cpu_to_le32(i_gid_read(inode)); ri->i_links =3D cpu_to_le32(inode->i_nlink); - ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(READ_ONCE(inode->i_blocks)) = + 1); + ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(sbi, + READ_ONCE(inode->i_blocks)) + 1); =20 if (!f2fs_is_atomic_file(inode) || is_inode_flag_set(inode, FI_ATOMIC_COMMITTED)) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b29df65ab5b7..f565b6873832 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1310,7 +1310,7 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_in= fo *sbi, /* sanity check on discard range */ __check_sit_bitmap(sbi, dc->di.lstart, dc->di.lstart + dc->di.len); =20 - bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(dc->di.start); + bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(sbi, dc->di.start); bio->bi_private =3D dc; bio->bi_end_io =3D f2fs_submit_discard_endio; submit_bio(bio); @@ -1327,7 +1327,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, { struct block_device *bdev =3D dc->bdev; unsigned int max_discard_blocks =3D - SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev)); + SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev)); struct discard_cmd_control *dcc =3D SM_I(sbi)->dcc_info; struct list_head *wait_list =3D (dpolicy->type =3D=3D DPOLICY_FSTRIM) ? &(dcc->fstrim_list) : &(dcc->wait_list); @@ -1389,8 +1389,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, =20 dc->di.len +=3D len; =20 - __blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start), - SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio); + __blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(sbi, start), + SECTOR_FROM_BLOCK(sbi, len), GFP_NOFS, &bio); f2fs_bug_on(sbi, !bio); =20 /* @@ -1518,7 +1518,7 @@ static void __update_discard_tree_range(struct f2fs_s= b_info *sbi, struct discard_info di =3D {0}; struct rb_node **insert_p =3D NULL, *insert_parent =3D NULL; unsigned int max_discard_blocks =3D - SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev)); + SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev)); block_t end =3D lstart + len; =20 dc =3D __lookup_discard_cmd_ret(&dcc->root, lstart, @@ -2041,8 +2041,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_i= nfo *sbi, =20 /* For sequential zones, reset the zone write pointer */ if (f2fs_blkz_is_seq(sbi, devi, blkstart)) { - sector =3D SECTOR_FROM_BLOCK(blkstart); - nr_sects =3D SECTOR_FROM_BLOCK(blklen); + sector =3D SECTOR_FROM_BLOCK(sbi, blkstart); + nr_sects =3D SECTOR_FROM_BLOCK(sbi, blklen); div64_u64_rem(sector, bdev_zone_sectors(bdev), &remainder); =20 if (remainder || nr_sects !=3D bdev_zone_sectors(bdev)) { diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 534e376cbc92..2275404e769c 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -114,10 +114,10 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned i= nt segno) #define f2fs_bitmap_size(nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long)) =20 -#define SECTOR_FROM_BLOCK(blk_addr) \ - (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK) -#define SECTOR_TO_BLOCK(sectors) \ - ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK) +#define SECTOR_FROM_BLOCK(sbi, blk_addr) \ + (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi)) +#define SECTOR_TO_BLOCK(sbi, sectors) \ + ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi)) =20 /* * In the victim_sel_policy->alloc_mode, there are three block allocation = modes. diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index df5572084af0..5fd163e60296 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3944,7 +3944,7 @@ static int __f2fs_commit_super(struct f2fs_sb_info *s= bi, struct folio *folio, bio =3D bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS); =20 /* it doesn't need to set crypto context for superblock update */ - bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(folio->index); + bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(sbi, folio->index); =20 if (!bio_add_folio(bio, folio, folio_size(folio), 0)) f2fs_bug_on(sbi, 1); @@ -4519,7 +4519,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone,= unsigned int idx, { struct f2fs_report_zones_args *rz_args =3D data; block_t unusable_blocks =3D (zone->len - zone->capacity) >> - F2FS_LOG_SECTORS_PER_BLOCK; + F2FS_LOG_SECTORS_PER_BLOCK(rz_args->sbi); =20 if (zone->type =3D=3D BLK_ZONE_TYPE_CONVENTIONAL) return 0; @@ -4562,10 +4562,10 @@ static int init_blkz_info(struct f2fs_sb_info *sbi,= int devi) =20 zone_sectors =3D bdev_zone_sectors(bdev); if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=3D - SECTOR_TO_BLOCK(zone_sectors)) + SECTOR_TO_BLOCK(sbi, zone_sectors)) return -EINVAL; - sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(zone_sectors); - FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(nr_sectors), + sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(sbi, zone_sectors); + FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(sbi, nr_sectors), sbi->blocks_per_blkz); if (nr_sectors & (zone_sectors - 1)) FDEV(devi).nr_blkz++; diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index e98bff846b23..33995cd3dd6d 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,7 +14,7 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sect= or/blk */ +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log = number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 B85EB39934B for ; Thu, 3 Sep 2026 23:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477115; cv=none; b=PrAxcDAumJ97/s/Y88a9kPPb7LtjqGFOmTt4KK9TBM/Axag95HyG7AOHmylA96nf5LU70Mq03Wei0BAL7y59+aJ3uKuKtyB//3Mh0f4qb03hyjUq/5zNrLeC0C6PePDz0MaefZI9pQciZP9TaGdNmJH29TaxscEBjLqH59eHpSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477115; c=relaxed/simple; bh=Nn/4xO3KjXXBGL+Eupx5njUhwEaCJ9VzoatunVuZGJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KT/LViQCzMvGqed00DiO8h7vPRjBYJQs2SZEtmhA2ohwb2xBcgfuidMu9o15O1bhq5ktRtlR0Ccn+eGbORUUEBi25M10gCV60IlTrh601GSCLmg7ZwmvUDJJ23TjNhDrifJ7FmXk3hRdrBf3lDPb+ikENK1vhtSnaSx3O82vlVI= 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=ME17cVKW; arc=none smtp.client-ip=209.85.214.178 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="ME17cVKW" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2cc891373e0so3835095ad.2 for ; Thu, 03 Sep 2026 16:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477111; x=1789081911; 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=xHSOBAgNWDLnBxg1bVYblXXkiHXU97I78a7dWBX6r/o=; b=ME17cVKWxBR1x2nYNYo/9NmHunqYSCGDksND7qlwdhDLb9Sh2okVPtpWgDXocQaiKl gpRxGCB5TlkLLQwiZ4/Kt3fl2xwcsQf07Z2sCW8c1BjCajcC1MPXAVdLhlT2PaCRIZ+v OTK/ja10ozff1W8IdKW4k+QQhPb4QDGem+vQmJZg2kr2h3vH6I5OKUE/Ruk+Fx5Z0KJU OEdNwbUvhkLgCzOZfjVapGsTd21IzyxHSdgsHjLbqTjbSScTmtonPQq6/s3LNpFTQhbo i7W/lYSH2675CXAtKtgjA90Gq9Z0lYsEFs7GxwLJc7PTKfeUz7h5PgcmNyvkhGWCZ0gy CGWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477111; x=1789081911; 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=xHSOBAgNWDLnBxg1bVYblXXkiHXU97I78a7dWBX6r/o=; b=ciyRwaqUE+0UibYgbQDS3VWrPj7sAT6/4tTno20ZrytpWj0USF2USuqW6Um2Ze9OTm hdgYCBkJr5zt4LLXQ6iRiu6ckPcMDO5UURiu75pARu7ngY2MZyAsSK2mxpOApdpBjHIq 0FrTluhYehaN6glRA9zzQCffKfjglh7q5rn2TrKTZ91hAdLRgjsO2kW+kXOLwk7g3tDo szi2SSaZxeC6UVeYKXYfIrHfcy0yGyYd0eyAEyT5JUXJ0p9HgunztqhFRsRkS0rISH0/ tb2K0jB7Og6nT3U5wXiW6orK5NxR95EuA7v8NapMl8zBCK/Gx2lURRd6hSZuznsKgB6T Vzeg== X-Forwarded-Encrypted: i=1; AKwUvBzKKVM8Rp0wyF5QaLWXuWel0McP4YPSMM6XelrTKlxQXkbOhcA8PLY7wbO3E85ZL1qfmJzud4njwa7y3GA=@vger.kernel.org X-Gm-Message-State: AFuF++mc4sJVMZds6juMt3HVzAHWbaUFKyuam4/PnJwedLJQJw9GXkxr fBSPyA8K3F2Df/42QjIcVk6sX1BLHPWhFJ4OdUlDOO7sx0w8hcTCi9jz X-Gm-Gg: AYBFou0aTu4yqxPYAktKSS+DPOZ5xcfojykflmHd5CqV8jl9jj6Zhr5Vab/vHAaKDK/ 6Pze4ukq9RevipFoCqIf1F0J95GoZyXsybq1eJMfOLcXX79pVagb+lbWlX9uOhV9tFyULbCO5tB Zrvj+dZ7io3g1NVyNGl8XyUHYwWG/KK8Nqq+Kbjju3dFPEGB5202+Zg2V1xpYf8RaoIxq5ftmjm wLOlwimu8rMILUiszUle1/uCu0yjLED2ey91/KtnGj2xd9jizmE4vejL0Oh2zCkgGl3LXAWvndv GGQxRsiZFbhTC9KDO3UUNyNd9UK5Htg7V+cxvvHtQcIq+ts3sN9+Z+np+cHVprim/4uAIyw+g0j UXfeJxXrBut1ozIbtLgc+w9IE1oMNQ+Hn3/MDMK6S4jLABDazGTJgVstmxtPCz3i9ZKx0BX5a1T t5vx/gvzHLsLGvxkH+tIC6SCElgvFstoKwrUQrpKg0fRPhb7neZF2lI9gUlB+7mmDzZ6Lsp21y5 DwR X-Received: by 2002:a17:90b:1dc3:b0:398:d6f4:c61a with SMTP id 98e67ed59e1d1-39b26207ee4mr3051335a91.17.1788477110871; Thu, 03 Sep 2026 16:11:50 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b260fdf9asm1131472a91.9.2026.09.03.16.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:50 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 09/11] f2fs: parameterize byte and block conversion macros Date: Thu, 3 Sep 2026 16:11:36 -0700 Message-ID: <782055ac2a263ecccacf10d27c6bcb874693f8cc.1788476500.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.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" Byte-to-block and block-to-byte conversion helpers previously relied on global PAGE_SIZE, PAGE_SHIFT, or F2FS_BLKSIZE_BITS. Parameterize F2FS_BYTES_TO_BLK, F2FS_BLK_TO_BYTES, F2FS_BLK_END_BYTES, F2FS_BLK_ALIGN, and max_file_blocks with struct f2fs_sb_info *sbi using sbi->log_blocksize. Update all call sites across data mapping, file operations, fiemap queries, fsverity checks, NAT bitmap allocations, and truncate paths. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 58 +++++++++++++++++++++++------------------ fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 7 ++--- fs/f2fs/file.c | 54 +++++++++++++++++++++----------------- fs/f2fs/node.c | 7 ++--- fs/f2fs/recovery.c | 4 +-- fs/f2fs/segment.c | 9 ++++--- fs/f2fs/super.c | 9 ++++--- fs/f2fs/verity.c | 6 +++-- include/linux/f2fs_fs.h | 13 ++++++--- 11 files changed, 97 insertions(+), 74 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index e615477307f9..a3490be98c51 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1866,7 +1866,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, st= ruct cp_control *cpc) blk =3D start_blk + BLKS_PER_SEG(sbi) - nm_i->nat_bits_blocks; for (i =3D 0; i < nm_i->nat_bits_blocks; i++) f2fs_update_meta_page(sbi, nm_i->nat_bits + - F2FS_BLK_TO_BYTES(i), blk + i); + F2FS_BLK_TO_BYTES(sbi, i), blk + i); } =20 /* write out checkpoint buffer at block 0 */ diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6a74af3fb396..d058617b50f4 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1977,12 +1977,12 @@ static bool __f2fs_overwrite_io(struct inode *inode= , loff_t pos, size_t len, if (pos + len > i_size_read(inode)) return false; =20 - map.m_lblk =3D F2FS_BYTES_TO_BLK(pos); + map.m_lblk =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), pos); map.m_next_pgofs =3D NULL; map.m_next_extent =3D NULL; map.m_seg_type =3D NO_CHECK_TYPE; map.m_may_create =3D false; - last_lblk =3D F2FS_BLK_ALIGN(pos + len); + last_lblk =3D F2FS_BLK_ALIGN(F2FS_I_SB(inode), pos + len); =20 while (map.m_lblk < last_lblk) { map.m_len =3D last_lblk - map.m_lblk; @@ -2025,7 +2025,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } =20 - phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(sbi, ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + sizeof(__le32) * (DEF_ADDRS_PER_INODE(sbi) - get_inline_xattr_addrs(inode)); @@ -2059,7 +2059,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } =20 - phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(sbi, ni.blk_addr); len =3D inode->i_sb->s_blocksize; =20 f2fs_folio_put(folio, true); @@ -2078,6 +2078,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_map_blocks map; sector_t start_blk, last_blk, blk_len, max_len; pgoff_t next_pgofs; @@ -2101,7 +2102,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, =20 inode_lock_shared(inode); =20 - maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + maxbytes =3D F2FS_BLK_TO_BYTES(sbi, max_file_blocks(sbi, inode)); if (start > maxbytes) { ret =3D -EFBIG; goto out; @@ -2121,10 +2122,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_= extent_info *fieinfo, goto out; } =20 - start_blk =3D F2FS_BYTES_TO_BLK(start); - last_blk =3D F2FS_BYTES_TO_BLK(start + len - 1); + start_blk =3D F2FS_BYTES_TO_BLK(sbi, start); + last_blk =3D F2FS_BYTES_TO_BLK(sbi, start + len - 1); blk_len =3D last_blk - start_blk + 1; - max_len =3D F2FS_BYTES_TO_BLK(maxbytes) - start_blk; + max_len =3D F2FS_BYTES_TO_BLK(sbi, maxbytes) - start_blk; =20 next: memset(&map, 0, sizeof(map)); @@ -2146,7 +2147,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) { start_blk =3D next_pgofs; =20 - if (F2FS_BLK_TO_BYTES(start_blk) < maxbytes) + if (F2FS_BLK_TO_BYTES(sbi, start_blk) < maxbytes) goto prep_next; =20 flags |=3D FIEMAP_EXTENT_LAST; @@ -2194,14 +2195,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_= extent_info *fieinfo, } else if (compr_appended) { unsigned int appended_blks =3D cluster_size - count_in_cluster + 1; - size +=3D F2FS_BLK_TO_BYTES(appended_blks); + size +=3D F2FS_BLK_TO_BYTES(sbi, appended_blks); start_blk +=3D appended_blks; compr_cluster =3D false; } else { - logical =3D F2FS_BLK_TO_BYTES(start_blk); + logical =3D F2FS_BLK_TO_BYTES(sbi, start_blk); phys =3D __is_valid_data_blkaddr(map.m_pblk) ? - F2FS_BLK_TO_BYTES(map.m_pblk) : 0; - size =3D F2FS_BLK_TO_BYTES(map.m_len); + F2FS_BLK_TO_BYTES(sbi, map.m_pblk) : 0; + size =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); flags =3D 0; =20 if (compr_cluster) { @@ -2215,7 +2216,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, flags =3D FIEMAP_EXTENT_UNWRITTEN; } =20 - start_blk +=3D F2FS_BYTES_TO_BLK(size); + start_blk +=3D F2FS_BYTES_TO_BLK(sbi, size); } =20 prep_next: @@ -2235,7 +2236,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, static inline loff_t f2fs_readpage_limit(struct inode *inode) { if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) - return F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + return F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); =20 return i_size_read(inode); } @@ -2263,7 +2265,8 @@ static int f2fs_read_single_page(struct inode *inode,= struct fsverity_info *vi, =20 block_in_file =3D (sector_t)index; last_block =3D block_in_file + nr_pages; - last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + last_block_in_file =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), + f2fs_readpage_limit(inode) + blocksize - 1); if (last_block > last_block_in_file) last_block =3D last_block_in_file; @@ -2374,7 +2377,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, st= ruct bio **bio_ret, =20 f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc)); =20 - last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + last_block_in_file =3D F2FS_BYTES_TO_BLK(sbi, + f2fs_readpage_limit(inode) + blocksize - 1); =20 /* get rid of pages beyond EOF */ @@ -4236,7 +4240,7 @@ static sector_t f2fs_bmap(struct address_space *mappi= ng, sector_t block) filemap_write_and_wait(mapping); =20 /* Block number less than F2FS MAX BLOCKS */ - if (unlikely(block >=3D max_file_blocks(inode))) + if (unlikely(block >=3D max_file_blocks(F2FS_I_SB(inode), inode))) goto out; =20 if (f2fs_compressed_file(inode)) { @@ -4352,7 +4356,7 @@ static int check_swap_activate(struct swap_info_struc= t *sis, * to be very smart. */ cur_lblock =3D 0; - last_lblock =3D F2FS_BYTES_TO_BLK(i_size_read(inode)); + last_lblock =3D F2FS_BYTES_TO_BLK(sbi, i_size_read(inode)); =20 while (cur_lblock < last_lblock && cur_lblock < sis->max) { struct f2fs_map_blocks map; @@ -4607,12 +4611,14 @@ static int f2fs_iomap_begin(struct inode *inode, lo= ff_t offset, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_map_blocks map =3D { NULL, }; pgoff_t next_pgofs =3D 0; int err; =20 - map.m_lblk =3D F2FS_BYTES_TO_BLK(offset); - map.m_len =3D F2FS_BYTES_TO_BLK(offset + length - 1) - map.m_lblk + 1; + map.m_lblk =3D F2FS_BYTES_TO_BLK(sbi, offset); + map.m_len =3D F2FS_BYTES_TO_BLK(sbi, offset + length - 1) - + map.m_lblk + 1; map.m_next_pgofs =3D &next_pgofs; map.m_seg_type =3D f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode), inode->i_write_hint); @@ -4633,7 +4639,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff= _t offset, loff_t length, if (err) return err; =20 - iomap->offset =3D F2FS_BLK_TO_BYTES(map.m_lblk); + iomap->offset =3D F2FS_BLK_TO_BYTES(sbi, map.m_lblk); =20 /* * When inline encryption is enabled, sometimes I/O to an encrypted file @@ -4653,11 +4659,11 @@ static int f2fs_iomap_begin(struct inode *inode, lo= ff_t offset, loff_t length, if (WARN_ON_ONCE(map.m_pblk =3D=3D NEW_ADDR)) return -EINVAL; =20 - iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); iomap->type =3D IOMAP_MAPPED; iomap->flags |=3D IOMAP_F_MERGED; iomap->bdev =3D map.m_bdev; - iomap->addr =3D F2FS_BLK_TO_BYTES(map.m_pblk); + iomap->addr =3D F2FS_BLK_TO_BYTES(sbi, map.m_pblk); =20 if (flags & IOMAP_WRITE && map.m_last_pblk) iomap->private =3D (void *)map.m_last_pblk; @@ -4666,11 +4672,11 @@ static int f2fs_iomap_begin(struct inode *inode, lo= ff_t offset, loff_t length, return -ENOTBLK; =20 if (map.m_pblk =3D=3D NULL_ADDR) { - iomap->length =3D F2FS_BLK_TO_BYTES(next_pgofs) - + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, next_pgofs) - iomap->offset; iomap->type =3D IOMAP_HOLE; } else if (map.m_pblk =3D=3D NEW_ADDR) { - iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); iomap->type =3D IOMAP_UNWRITTEN; } else { f2fs_bug_on(F2FS_I_SB(inode), 1); diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 5980b9d79afb..a6cfceafe2fe 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -343,7 +343,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) /* build nm */ si->base_mem +=3D sizeof(struct f2fs_nm_info); si->base_mem +=3D __bitmap_size(sbi, NAT_BITMAP); - si->base_mem +=3D F2FS_BLK_TO_BYTES(NM_I(sbi)->nat_bits_blocks); + si->base_mem +=3D F2FS_BLK_TO_BYTES(sbi, NM_I(sbi)->nat_bits_blocks); si->base_mem +=3D NM_I(sbi)->nat_blocks * f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)); si->base_mem +=3D NM_I(sbi)->nat_blocks / 8; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e1006931f1af..2b8bb42e235a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4022,7 +4022,7 @@ void f2fs_inode_synced(struct inode *inode); int f2fs_dquot_initialize(struct inode *inode); int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); int f2fs_do_quota_sync(struct super_block *sb, int type); -loff_t max_file_blocks(struct inode *inode); +loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode); void f2fs_quota_off_umount(struct super_block *sb); void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag); void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error); @@ -5269,8 +5269,9 @@ static inline void f2fs_truncate_meta_inode_pages(str= uct f2fs_sb_info *sbi, NULL, 0, DATA); =20 truncate_inode_pages_range(META_MAPPING(sbi), - F2FS_BLK_TO_BYTES((loff_t)blkaddr), - F2FS_BLK_END_BYTES((loff_t)(blkaddr + cnt - 1))); + F2FS_BLK_TO_BYTES(sbi, (loff_t)blkaddr), + F2FS_BLK_END_BYTES(sbi, + (loff_t)(blkaddr + cnt - 1))); } =20 static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 2c72e028cec2..6fafb32bc5f2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -513,7 +513,8 @@ static bool __found_offset(struct address_space *mappin= g, static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) { struct inode *inode =3D file->f_mapping->host; - loff_t maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + loff_t maxbytes =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); struct dnode_of_data dn; pgoff_t pgofs, end_offset; loff_t data_ofs =3D offset; @@ -537,9 +538,10 @@ static loff_t f2fs_seek_block(struct file *file, loff_= t offset, int whence) } } =20 - pgofs =3D (pgoff_t)(offset >> PAGE_SHIFT); + pgofs =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), offset); =20 - for (; data_ofs < isize; data_ofs =3D (loff_t)pgofs << PAGE_SHIFT) { + for (; data_ofs < isize; + data_ofs =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), pgofs)) { set_new_dnode(&dn, inode, NULL, NULL, 0); err =3D f2fs_get_dnode_of_data(&dn, pgofs, LOOKUP_NODE); if (err && err !=3D -ENOENT) { @@ -559,7 +561,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t= offset, int whence) /* find data/hole in dnode block */ for (; dn.ofs_in_node < end_offset; dn.ofs_in_node++, pgofs++, - data_ofs =3D (loff_t)pgofs << PAGE_SHIFT) { + data_ofs =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), pgofs)) { block_t blkaddr; =20 blkaddr =3D f2fs_data_blkaddr(&dn); @@ -595,7 +597,8 @@ static loff_t f2fs_seek_block(struct file *file, loff_t= offset, int whence) static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode =3D file->f_mapping->host; - loff_t maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + loff_t maxbytes =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); =20 switch (whence) { case SEEK_SET: @@ -846,9 +849,9 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 fr= om, bool lock) goto out_err; } =20 - free_from =3D (pgoff_t)F2FS_BLK_ALIGN(from); + free_from =3D (pgoff_t)F2FS_BLK_ALIGN(sbi, from); =20 - if (free_from >=3D max_file_blocks(inode)) + if (free_from >=3D max_file_blocks(sbi, inode)) goto free_partial; =20 if (lock) @@ -959,9 +962,10 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from= , bool lock) =20 int f2fs_truncate(struct inode *inode) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); int err; =20 - if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) + if (unlikely(f2fs_cp_error(sbi))) return -EIO; =20 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || @@ -970,7 +974,7 @@ int f2fs_truncate(struct inode *inode) =20 trace_f2fs_truncate(inode); =20 - if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) + if (time_to_inject(sbi, FAULT_TRUNCATE)) return -EIO; =20 err =3D f2fs_dquot_initialize(inode); @@ -986,8 +990,8 @@ int f2fs_truncate(struct inode *inode) * leak in evict() path. */ truncate_inode_pages_range(inode->i_mapping, - F2FS_BLK_TO_BYTES(0), - F2FS_BLK_END_BYTES(0)); + F2FS_BLK_TO_BYTES(sbi, 0), + F2FS_BLK_END_BYTES(sbi, 0)); return err; } } @@ -1161,7 +1165,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, return -EOPNOTSUPP; if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) && !IS_ALIGNED(attr->ia_size, - F2FS_BLK_TO_BYTES(fi->i_cluster_size))) + F2FS_BLK_TO_BYTES(sbi, fi->i_cluster_size))) return -EINVAL; =20 if (f2fs_is_pinned_file(inode)) { @@ -1177,7 +1181,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, * pinned file. */ else if (!IS_ALIGNED(attr->ia_size, - F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi)))) + F2FS_BLK_TO_BYTES(sbi, CAP_BLKS_PER_SEC(sbi)))) return -EINVAL; } } @@ -2648,7 +2652,8 @@ static int f2fs_keep_noreuse_range(struct inode *inod= e, loff_t offset, loff_t len) { struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); - u64 max_bytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + u64 max_bytes =3D F2FS_BLK_TO_BYTES(sbi, + max_file_blocks(sbi, inode)); u64 start, end; int ret =3D 0; =20 @@ -3191,8 +3196,8 @@ static int f2fs_ioc_defragment(struct file *filp, uns= igned long arg) if (range.start & (F2FS_BLKSIZE - 1) || range.len & (F2FS_BLKSIZE - 1)) return -EINVAL; =20 - if (unlikely((range.start + range.len) >> PAGE_SHIFT > - max_file_blocks(inode))) + if (unlikely(F2FS_BYTES_TO_BLK(sbi, range.start + range.len) > + max_file_blocks(sbi, inode))) return -EINVAL; =20 err =3D mnt_want_write_file(filp); @@ -3326,9 +3331,9 @@ static int f2fs_move_file_range(struct file *file_in,= loff_t pos_in, } =20 f2fs_lock_op(sbi, &lc); - ret =3D __exchange_data_block(src, dst, F2FS_BYTES_TO_BLK(pos_in), - F2FS_BYTES_TO_BLK(pos_out), - F2FS_BYTES_TO_BLK(len), false); + ret =3D __exchange_data_block(src, dst, F2FS_BYTES_TO_BLK(sbi, pos_in), + F2FS_BYTES_TO_BLK(sbi, pos_out), + F2FS_BYTES_TO_BLK(sbi, len), false); =20 if (!ret) { if (dst_max_i_size) @@ -3994,7 +3999,7 @@ int f2fs_precache_extents(struct inode *inode) map.m_next_extent =3D &m_next_extent; map.m_seg_type =3D NO_CHECK_TYPE; map.m_may_create =3D false; - end =3D F2FS_BLK_ALIGN(i_size_read(inode)); + end =3D F2FS_BLK_ALIGN(F2FS_I_SB(inode), i_size_read(inode)); =20 while (map.m_lblk < end) { map.m_len =3D end - map.m_lblk; @@ -4594,7 +4599,7 @@ static int f2fs_sec_trim_file(struct file *filp, unsi= gned long arg) goto err; } =20 - index =3D F2FS_BYTES_TO_BLK(range.start); + index =3D F2FS_BYTES_TO_BLK(sbi, range.start); pg_end =3D DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); =20 ret =3D f2fs_convert_inline_inode(inode); @@ -5385,7 +5390,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb= , struct iov_iter *iter, * buffered IO, if DIO meets any holes. */ if (dio && i_size_read(inode) && - (F2FS_BYTES_TO_BLK(pos) < F2FS_BLK_ALIGN(i_size_read(inode)))) + (F2FS_BYTES_TO_BLK(sbi, pos) < + F2FS_BLK_ALIGN(sbi, i_size_read(inode)))) return 0; =20 /* No-wait I/O can't allocate blocks. */ @@ -5406,8 +5412,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb= , struct iov_iter *iter, } =20 /* Do not preallocate blocks that will be written partially in 4KB. */ - map.m_lblk =3D F2FS_BLK_ALIGN(pos); - map.m_len =3D F2FS_BYTES_TO_BLK(pos + count); + map.m_lblk =3D F2FS_BLK_ALIGN(sbi, pos); + map.m_len =3D F2FS_BYTES_TO_BLK(sbi, pos + count); if (map.m_len > map.m_lblk) map.m_len -=3D map.m_lblk; else diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 7dabfada1b54..e7aa3b790214 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -3294,9 +3294,10 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sb= i) if (!enabled_nat_bits(sbi, NULL)) return 0; =20 - nm_i->nat_bits_blocks =3D F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + nm_i->nat_bits_blocks =3D F2FS_BLK_ALIGN(sbi, + (nat_bits_bytes << 1) + 8); nm_i->nat_bits =3D f2fs_kvzalloc(sbi, - F2FS_BLK_TO_BYTES(nm_i->nat_bits_blocks), GFP_KERNEL); + F2FS_BLK_TO_BYTES(sbi, nm_i->nat_bits_blocks), GFP_KERNEL); if (!nm_i->nat_bits) return -ENOMEM; =20 @@ -3309,7 +3310,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) if (IS_ERR(folio)) return PTR_ERR(folio); =20 - memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(i), + memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(sbi, i), folio_address(folio), F2FS_BLKSIZE); f2fs_folio_put(folio, true); } diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index aaa5227739c8..b52718741ddc 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -734,9 +734,9 @@ static int do_recover_data(struct f2fs_sb_info *sbi, st= ruct inode *inode, } =20 if (!file_keep_isize(inode) && - (i_size_read(inode) <=3D ((loff_t)index << PAGE_SHIFT))) + (i_size_read(inode) <=3D F2FS_BLK_TO_BYTES(sbi, index))) f2fs_i_size_write(inode, - (loff_t)(index + 1) << PAGE_SHIFT); + F2FS_BLK_TO_BYTES(sbi, index + 1)); =20 /* * dest is reserved block, invalidate src block diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f565b6873832..f58b26c84b3a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3592,8 +3592,8 @@ static unsigned int __issue_discard_cmd_range(struct = f2fs_sb_info *sbi, =20 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) { - __u64 start =3D F2FS_BYTES_TO_BLK(range->start); - __u64 end =3D start + F2FS_BYTES_TO_BLK(range->len) - 1; + __u64 start =3D F2FS_BYTES_TO_BLK(sbi, range->start); + __u64 end =3D start + F2FS_BYTES_TO_BLK(sbi, range->len) - 1; unsigned int start_segno, end_segno; block_t start_block, end_block; struct cp_control cpc; @@ -3624,7 +3624,8 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fst= rim_range *range) } =20 cpc.reason =3D CP_DISCARD; - cpc.trim_minlen =3D max_t(__u64, 1, F2FS_BYTES_TO_BLK(range->minlen)); + cpc.trim_minlen =3D max_t(__u64, 1, + F2FS_BYTES_TO_BLK(sbi, range->minlen)); cpc.trim_start =3D start_segno; cpc.trim_end =3D end_segno; =20 @@ -3658,7 +3659,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fst= rim_range *range) start_block, end_block); out: if (!err) - range->len =3D F2FS_BLK_TO_BYTES(trimmed); + range->len =3D F2FS_BLK_TO_BYTES(sbi, trimmed); return err; } =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 5fd163e60296..3aa8a2198471 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3884,7 +3884,7 @@ static const struct export_operations f2fs_export_ops= =3D { .get_parent =3D f2fs_get_parent, }; =20 -loff_t max_file_blocks(struct inode *inode) +loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode) { loff_t result =3D 0; loff_t leaf_count; @@ -3918,7 +3918,8 @@ loff_t max_file_blocks(struct inode *inode) * fit within U32_MAX + 1 data units. */ =20 - result =3D umin(result, F2FS_BYTES_TO_BLK(((loff_t)U32_MAX + 1) * 4096)); + result =3D umin(result, F2FS_BYTES_TO_BLK(sbi, + ((loff_t)U32_MAX + 1) * 4096)); =20 return result; } @@ -4370,7 +4371,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) =20 nat_blocks =3D nat_segs << log_blocks_per_seg; nat_bits_bytes =3D nat_blocks / BITS_PER_BYTE; - nat_bits_blocks =3D F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + nat_bits_blocks =3D F2FS_BLK_ALIGN(sbi, (nat_bits_bytes << 1) + 8); if (__is_set_ckpt_flags(ckpt, CP_NAT_BITS_FLAG) && (cp_payload + F2FS_CP_PACKS + NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >=3D blocks_per_seg)) { @@ -5192,7 +5193,7 @@ static int f2fs_fill_super(struct super_block *sb, st= ruct fs_context *fc) if (err) goto free_options; =20 - sb->s_maxbytes =3D max_file_blocks(NULL) << + sb->s_maxbytes =3D max_file_blocks(sbi, NULL) << le32_to_cpu(raw_super->log_blocksize); sb->s_max_links =3D F2FS_LINK_MAX; =20 diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c index 39f482515445..ee838f880c4a 100644 --- a/fs/f2fs/verity.c +++ b/fs/f2fs/verity.c @@ -75,7 +75,8 @@ static int pagecache_write(struct inode *inode, const voi= d *buf, size_t count, struct address_space *mapping =3D inode->i_mapping; const struct address_space_operations *aops =3D mapping->a_ops; =20 - if (pos + count > F2FS_BLK_TO_BYTES(max_file_blocks(inode))) + if (pos + count > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode))) return -EFBIG; =20 while (count) { @@ -239,7 +240,8 @@ static int f2fs_get_verity_descriptor(struct inode *ino= de, void *buf, =20 /* Get the descriptor */ if (pos + size < pos || - pos + size > F2FS_BLK_TO_BYTES(max_file_blocks(inode)) || + pos + size > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)) || pos < f2fs_verity_metadata_pos(inode) || size > INT_MAX) { f2fs_warn(F2FS_I_SB(inode), "invalid verity xattr"); f2fs_handle_error(F2FS_I_SB(inode), diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 33995cd3dd6d..4c9540981db4 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -28,10 +28,15 @@ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ =20 #define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) -#define F2FS_BYTES_TO_BLK(bytes) ((unsigned long long)(bytes) >> F2FS_BLKS= IZE_BITS) -#define F2FS_BLK_TO_BYTES(blk) ((unsigned long long)(blk) << F2FS_BLKSIZE= _BITS) -#define F2FS_BLK_END_BYTES(blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1) -#define F2FS_BLK_ALIGN(x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1)) +#define F2FS_BYTES_TO_BLK(sbi, bytes) \ + ((unsigned long long)(bytes) >> (sbi)->log_blocksize) +#define F2FS_BLK_TO_BYTES(sbi, blk) \ + ((unsigned long long)(blk) << (sbi)->log_blocksize) +#define F2FS_BLK_END_BYTES(sbi, blk) \ + (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) +#define F2FS_BLK_ALIGN(sbi, bytes) \ + F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ + (sbi)->blocksize - 1) =20 /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 4E356386C13 for ; Thu, 3 Sep 2026 23:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477115; cv=none; b=tZO0Pt96YVns5VX7vzMzVC1MlGjoDmZ4Gi8G4+uojkBlfic0GnDKk08xM8KbGzTHeDabQob6Vm9rlHfgM/hFdNNyaEoksKU0tfU7jNXObuvAikh86F0iMNf2Ik3PRHIp98unjvjl0uccWUbl52N5x4AK9nmy6RyH5rWV7jbqwLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477115; c=relaxed/simple; bh=mqtfP0i8XGy/hBN15B4uWSSaMudv0JPOfNB78SntzjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=agdHugkXFmXcrYqBCrz37o0Zu1CghCMCUMbMbosXPCjnWKBwioQrXR1raV4CkurVQf22ejh7SZDZv2xJ4E5kdsw2irpoScy3Pag5sL7zTk6nayhMAcUf4adsLUpIgIIqc3Oa0vA/BIarpNQjpqju4mCSTr9a7ojeU8SAxq3Xol4= 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=iNbIYC4K; arc=none smtp.client-ip=209.85.214.172 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="iNbIYC4K" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2caced6038eso4253195ad.0 for ; Thu, 03 Sep 2026 16:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477112; x=1789081912; 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=BtydBFXs7CRcOTOCX1YpFxCvg86LjXn5nkZhhKF1CLw=; b=iNbIYC4KwKHS1C5r/V9TegzZHtYtTguf53M9CsOZcKbISuE03d0f1wap+8SpRiadh7 PIpS2L/LYbtCrMnb9Xg8obJF+foPsWciexpOioQ6IJyR1EYwxCBwa9Eipxkgfut7XdIa GD6+w4711s0exHDz8T1HmrfsLbbNnVOtusBUOqsXpXgq5R+jyTz7oNRtmlXOyLSz/phW nGjIuayCHPqpfgHTpHBFAm4FqX7ppkXE8FWdP1/PGCd/wgHJmuUIEJ3OdOCA2tkYDx+r lywegrvMbQueZLVYk+GvxsEh30Ywmt8hN44FjsI1usstKWD6gQlCO1eN/TnqB83odDzi 70rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477112; x=1789081912; 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=BtydBFXs7CRcOTOCX1YpFxCvg86LjXn5nkZhhKF1CLw=; b=Lu8M12jh5dUN8g9ghUN8ceF9J5JxpYMWS6S5DC2ugyM2E3dwoUAM+DUDsH0R5tpLPx CWKokZN3Zqac2C/vgLqh/FFSwjFRKrZym6HgHzEMuDJfE+9JB0kvBsz3D2eQskLqt7tN 8EFdGI3h3RkK+0aqJFx4E9EZiwWR2IXh6nejFErgkED2SAuwfCbyzz8oJjjUY8r13hJe Pk0Mko2qoDH9QGH+wuUW3UFiWZXeIjt/9UDxK32SxilTG52WwbMUWS/j06bPKumiR5Ib R1QvWtT3iF28+VoFSdzalO8A9muankm3a7k/1FrFdB/XmKBwSSXVATPh0ifkcRw1WVZw EdaQ== X-Forwarded-Encrypted: i=1; AKwUvBw5zzmtc7C7YtKyaYaS8Azj85TFrfooI1Ls32FIvVh+/trsyA/EEiMW4TlmEcp5PW031gRccRHudAGBZFg=@vger.kernel.org X-Gm-Message-State: AFuF++nc1SoNPXIEMSSpia4lu5vlFA2WgrKFUmoUcnH71M1yBvwX5jH3 x7gjhwKTmIMXFqbUBPtb+WV3vRKgy8eDrOAGLwOABMIDZPaQHUuMpPPK+U7G9DisRDs= X-Gm-Gg: AYBFou2r2M498HBitxnKayK4mc4KtdM9hMbAscO5gqHy3dEliH2mUlXuXm8MKQOxBjq 63DhW/AKrNM7o9R2RftJ9sfMN8MtryTRRsXPYLirIJNJGcH+k3hrnN78e/udksvMn/C6nkjHalL AERDxnUDTBAbsapvKIgDU9DPNXnXK/8BVKUYde0cnTdtjJz+4P8XZVp57X/efxL801S+oa6Qztf d8letNwcGc5Qx1W9ondLup1SJCVWyXJvPP/Dz4BxtZvWoOTAJyuv7IyYZjMinddZ5BTQM6pDbug Fwq6hZRCccxL77kKC8E54N72ZopDJ/9bLGXAiokS2Rl76TNavMjTPOLokrZwm+RJsx8lefd9aY8 A/00vX5RuLYBkJSRmgQLG31sTh4WjlZ1LAKIxKJY8Ins4Qmc7VzKAs3It/zxdp3VBboyr0KxHGb 7XJ4d972XvXy02BIuYjjltQPRReYdebwQyzT6Hr+k29GvgbfspE+Sg4JezNCepAT+ifw== X-Received: by 2002:a17:902:d48b:b0:2d8:d4d2:d139 with SMTP id d9443c01a7336-2dafb1820bcmr82014165ad.21.1788477112433; Thu, 03 Sep 2026 16:11:52 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db148404b8sm1942205ad.2.2026.09.03.16.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:51 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 10/11] f2fs: describe node tree geometry dynamically Date: Thu, 3 Sep 2026 16:11:37 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" The file indexing tree boundaries separating direct, indirect, and double-indirect node blocks depend on the number of data block addresses and node IDs contained in each node block. Parameterize index boundary macros (NODE_DIR1_BLOCK, NODE_DIR2_BLOCK, NODE_IND1_BLOCK, NODE_IND2_BLOCK, and NODE_DIND_BLOCK) and address capacity helpers (DEF_ADDRS_PER_BLOCK, NIDS_PER_BLOCK, cur_addrs_per_inode, addrs_per_page, and addrs_per_folio) with struct f2fs_sb_info *sbi. Update file mapping, block allocation, truncate, garbage collection, and recovery paths to compute indexing tree offsets from the runtime geometry. Signed-off-by: Kelvin Zhang --- fs/f2fs/f2fs.h | 11 +++++- fs/f2fs/gc.c | 10 +++--- fs/f2fs/node.c | 74 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 18 ++++++---- fs/f2fs/super.c | 8 ++--- include/linux/f2fs_fs.h | 10 ------ 6 files changed, 69 insertions(+), 62 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2b8bb42e235a..f293bdd2baca 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2253,10 +2253,18 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const = struct folio *folio) #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) #define DEF_ADDRS_PER_INODE(sbi) ((sbi)->addrs_per_inode) +#define DEF_ADDRS_PER_BLOCK(sbi) ((sbi)->addrs_per_block) +#define NIDS_PER_BLOCK(sbi) ((sbi)->nids_per_block) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) =20 +#define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 1) +#define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 2) +#define NODE_IND1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 3) +#define NODE_IND2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 4) +#define NODE_DIND_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 5) + static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) { @@ -3645,7 +3653,8 @@ static inline unsigned int addrs_per_page(struct inod= e *inode, bool is_inode) { unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; + get_inline_xattr_addrs(inode)) : + DEF_ADDRS_PER_BLOCK(F2FS_I_SB(inode)); =20 if (f2fs_compressed_file(inode)) return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 164612dbe2c6..39fa4776404e 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1123,7 +1123,8 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, */ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode) { - unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK + 4; + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK(sbi) + 4; unsigned int bidx; =20 if (node_ofs =3D=3D 0) @@ -1132,11 +1133,12 @@ block_t f2fs_start_bidx_of_node(unsigned int node_o= fs, struct inode *inode) if (node_ofs <=3D 2) { bidx =3D node_ofs - 1; } else if (node_ofs <=3D indirect_blks) { - int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK(sbi) + 1); =20 bidx =3D node_ofs - 2 - dec; } else { - int dec =3D (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - indirect_blks - 3) / + (NIDS_PER_BLOCK(sbi) + 1); =20 bidx =3D node_ofs - 5 - dec; } @@ -1179,7 +1181,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct= f2fs_summary *sum, max_addrs =3D DEF_ADDRS_PER_INODE(sbi); } else { base =3D 0; - max_addrs =3D DEF_ADDRS_PER_BLOCK; + max_addrs =3D DEF_ADDRS_PER_BLOCK(sbi); } =20 if (base + ofs_in_node >=3D max_addrs) { diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e7aa3b790214..7bb99988833a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -691,7 +691,7 @@ static void f2fs_ra_node_pages(struct folio *parent, in= t start, int n) =20 /* Then, try readahead for siblings of the desired node */ end =3D start + n; - end =3D min(end, (int)NIDS_PER_BLOCK); + end =3D min_t(int, end, NIDS_PER_BLOCK(sbi)); for (i =3D start; i < end; i++) { nid =3D get_nid(parent, i, false); f2fs_ra_node_page(sbi, nid); @@ -702,9 +702,11 @@ static void f2fs_ra_node_pages(struct folio *parent, i= nt start, int n) =20 pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); const long direct_index =3D ADDRS_PER_INODE(dn->inode); const long direct_blks =3D ADDRS_PER_BLOCK(dn->inode); - const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * NIDS_PER_BLOCK; + const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * + NIDS_PER_BLOCK(sbi); unsigned int skipped_unit =3D ADDRS_PER_BLOCK(dn->inode); int cur_level =3D dn->cur_level; int max_level =3D dn->max_level; @@ -714,7 +716,7 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data = *dn, pgoff_t pgofs) return pgofs + 1; =20 while (max_level-- > cur_level) - skipped_unit *=3D NIDS_PER_BLOCK; + skipped_unit *=3D NIDS_PER_BLOCK(sbi); =20 switch (dn->max_level) { case 3: @@ -740,11 +742,13 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_dat= a *dn, pgoff_t pgofs) static int get_node_path(struct inode *inode, long block, int offset[4], unsigned int noffset[4]) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); const long direct_index =3D ADDRS_PER_INODE(inode); const long direct_blks =3D ADDRS_PER_BLOCK(inode); - const long dptrs_per_blk =3D NIDS_PER_BLOCK; - const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * NIDS_PER_BLOCK; - const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK; + const long dptrs_per_blk =3D NIDS_PER_BLOCK(sbi); + const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * + NIDS_PER_BLOCK(sbi); + const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK(sbi); int n =3D 0; int level =3D 0; =20 @@ -756,7 +760,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_index; if (block < direct_blks) { - offset[n++] =3D NODE_DIR1_BLOCK; + offset[n++] =3D NODE_DIR1_BLOCK(sbi); noffset[n] =3D 1; offset[n] =3D block; level =3D 1; @@ -764,7 +768,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < direct_blks) { - offset[n++] =3D NODE_DIR2_BLOCK; + offset[n++] =3D NODE_DIR2_BLOCK(sbi); noffset[n] =3D 2; offset[n] =3D block; level =3D 1; @@ -772,7 +776,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND1_BLOCK; + offset[n++] =3D NODE_IND1_BLOCK(sbi); noffset[n] =3D 3; offset[n++] =3D block / direct_blks; noffset[n] =3D 4 + offset[n - 1]; @@ -782,7 +786,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND2_BLOCK; + offset[n++] =3D NODE_IND2_BLOCK(sbi); noffset[n] =3D 4 + dptrs_per_blk; offset[n++] =3D block / direct_blks; noffset[n] =3D 5 + dptrs_per_blk + offset[n - 1]; @@ -792,7 +796,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < dindirect_blks) { - offset[n++] =3D NODE_DIND_BLOCK; + offset[n++] =3D NODE_DIND_BLOCK(sbi); noffset[n] =3D 5 + (dptrs_per_blk * 2); offset[n++] =3D block / indirect_blks; noffset[n] =3D 6 + (dptrs_per_blk * 2) + @@ -1054,6 +1058,7 @@ static int truncate_dnode(struct dnode_of_data *dn) static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int ofs, int depth) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); struct dnode_of_data rdn =3D *dn; struct folio *folio; struct f2fs_node *rn; @@ -1063,7 +1068,7 @@ static int truncate_nodes(struct dnode_of_data *dn, u= nsigned int nofs, int i, ret; =20 if (dn->nid =3D=3D 0) - return NIDS_PER_BLOCK + 1; + return NIDS_PER_BLOCK(sbi) + 1; =20 trace_f2fs_truncate_nodes_enter(dn->inode, dn->nid, dn->data_blkaddr); =20 @@ -1074,11 +1079,11 @@ static int truncate_nodes(struct dnode_of_data *dn,= unsigned int nofs, return PTR_ERR(folio); } =20 - f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK); + f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK(sbi)); =20 rn =3D F2FS_NODE(folio); if (depth < 3) { - for (i =3D ofs; i < NIDS_PER_BLOCK; i++, freed++) { + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++, freed++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) continue; @@ -1090,16 +1095,16 @@ static int truncate_nodes(struct dnode_of_data *dn,= unsigned int nofs, dn->node_changed =3D true; } } else { - child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK + 1) + 1; - for (i =3D ofs; i < NIDS_PER_BLOCK; i++) { + child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK(sbi) + 1) + 1; + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) { - child_nofs +=3D NIDS_PER_BLOCK + 1; + child_nofs +=3D NIDS_PER_BLOCK(sbi) + 1; continue; } rdn.nid =3D child_nid; ret =3D truncate_nodes(&rdn, child_nofs, 0, depth - 1); - if (ret =3D=3D (NIDS_PER_BLOCK + 1)) { + if (ret =3D=3D (NIDS_PER_BLOCK(sbi) + 1)) { if (set_nid(folio, i, 0, false)) dn->node_changed =3D true; child_nofs +=3D ret; @@ -1156,10 +1161,12 @@ static int truncate_partial_nodes(struct dnode_of_d= ata *dn, nid[i + 1] =3D get_nid(folios[i], offset[i + 1], false); } =20 - f2fs_ra_node_pages(folios[idx], offset[idx + 1], NIDS_PER_BLOCK); + f2fs_ra_node_pages(folios[idx], offset[idx + 1], + NIDS_PER_BLOCK(F2FS_I_SB(dn->inode))); =20 /* free direct nodes linked to a partial indirect node */ - for (i =3D offset[idx + 1]; i < NIDS_PER_BLOCK; i++) { + for (i =3D offset[idx + 1]; + i < NIDS_PER_BLOCK(F2FS_I_SB(dn->inode)); i++) { child_nid =3D get_nid(folios[idx], i, false); if (!child_nid) continue; @@ -1193,7 +1200,9 @@ static int truncate_partial_nodes(struct dnode_of_dat= a *dn, } =20 /* - * All the block addresses of data and nodes should be nullified. + * All the node blocks actually belong to the inode will be released. + * If the level is 0, we will simply truncate the dnode, + * or else we should do dynamic truncate for the node pointers with the de= pth. */ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) { @@ -1240,10 +1249,10 @@ int f2fs_truncate_inode_blocks(struct inode *inode,= pgoff_t from) err =3D truncate_partial_nodes(&dn, offset, level); if (err < 0 && err !=3D -ENOENT) goto fail; - nofs +=3D 1 + NIDS_PER_BLOCK; + nofs +=3D 1 + NIDS_PER_BLOCK(sbi); break; case 3: - nofs =3D 5 + 2 * NIDS_PER_BLOCK; + nofs =3D 5 + 2 * NIDS_PER_BLOCK(sbi); if (!offset[level - 1]) goto skip_partial; err =3D truncate_partial_nodes(&dn, offset, level); @@ -1257,23 +1266,16 @@ int f2fs_truncate_inode_blocks(struct inode *inode,= pgoff_t from) skip_partial: while (cont) { dn.nid =3D get_nid(folio, offset[0], true); - switch (offset[0]) { - case NODE_DIR1_BLOCK: - case NODE_DIR2_BLOCK: + if (offset[0] =3D=3D NODE_DIR1_BLOCK(sbi) || + offset[0] =3D=3D NODE_DIR2_BLOCK(sbi)) { err =3D truncate_dnode(&dn); - break; - - case NODE_IND1_BLOCK: - case NODE_IND2_BLOCK: + } else if (offset[0] =3D=3D NODE_IND1_BLOCK(sbi) || + offset[0] =3D=3D NODE_IND2_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 2); - break; - - case NODE_DIND_BLOCK: + } else if (offset[0] =3D=3D NODE_DIND_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 3); cont =3D 0; - break; - - default: + } else { BUG(); } if (err =3D=3D -ENOENT) { diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 911c3d336533..2766ced7bef7 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -352,17 +352,18 @@ static inline bool is_recoverable_dnode(const struct = folio *folio) */ static inline bool IS_DNODE(const struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(node_folio); unsigned int ofs =3D ofs_of_node(node_folio); =20 if (f2fs_has_xattr_block(ofs)) return true; =20 - if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK || - ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK) + if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK(sbi) || + ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK(sbi)) return false; - if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK) { - ofs -=3D 6 + 2 * NIDS_PER_BLOCK; - if (!((long int)ofs % (NIDS_PER_BLOCK + 1))) + if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK(sbi)) { + ofs -=3D 6 + 2 * NIDS_PER_BLOCK(sbi); + if (!((long)ofs % (NIDS_PER_BLOCK(sbi) + 1))) return false; } return true; @@ -370,13 +371,15 @@ static inline bool IS_DNODE(const struct folio *node_= folio) =20 static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(folio); struct f2fs_node *rn =3D F2FS_NODE(folio); __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 f2fs_folio_wait_writeback(folio, NODE, true, true); =20 if (i) - inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK(sbi)] =3D + cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -386,9 +389,10 @@ static inline nid_t get_nid(const struct folio *folio,= int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); + int nid_index =3D off - NODE_DIR1_BLOCK(F2FS_F_SB(folio)); =20 if (i) - return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[nid_index]); return le32_to_cpu(rn->in.nid[off]); } =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 3aa8a2198471..0bb8b8048d78 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3890,7 +3890,7 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, stru= ct inode *inode) loff_t leaf_count; =20 /* - * note: previously, result is equal to (DEF_ADDRS_PER_INODE - + * note: previously, result is equal to (DEF_ADDRS_PER_INODE(sbi) - * DEFAULT_INLINE_XATTR_ADDRS), but now f2fs try to reserve more * space in inode.i_addr, it will be more safe to reassign * result as zero. @@ -3899,17 +3899,17 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, st= ruct inode *inode) if (inode && f2fs_compressed_file(inode)) leaf_count =3D ADDRS_PER_BLOCK(inode); else - leaf_count =3D DEF_ADDRS_PER_BLOCK; + leaf_count =3D DEF_ADDRS_PER_BLOCK(sbi); =20 /* two direct node blocks */ result +=3D (leaf_count * 2); =20 /* two indirect node blocks */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D (leaf_count * 2); =20 /* one double indirect node block */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D leaf_count; =20 /* diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 4c9540981db4..9036cc6c2a2c 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -282,19 +282,9 @@ struct node_footer { #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ -#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) /= sizeof(__le32)) #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) -/* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / siz= eof(__le32)) - #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) =20 -#define NODE_DIR1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 1) -#define NODE_DIR2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 2) -#define NODE_IND1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 3) -#define NODE_IND2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 4) -#define NODE_DIND_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 5) - #define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02 /* file inline data flag */ #define F2FS_INLINE_DENTRY 0x04 /* file inline dentry flag */ --=20 2.53.0 From nobody Sat Sep 26 06:20:28 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 2D05835AC37 for ; Thu, 3 Sep 2026 23:11:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477119; cv=none; b=qdf2VPXi2ushoV3hQpDkzo0oqKVb3keFHaa5A25B2wH+bY65Xi0Wwqy2NXxMU1nY0xDcYCsTlWTryRin1XflHghMm8MmC0WeLRoFBJT2XZAX3QJWMUyILGmIx0ZKi8Mg61MKlet63pl3CSG2NndYrXOQdv+dQtXGBP1wyqTvhfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788477119; c=relaxed/simple; bh=S/Nc6Ra6L8tssWL4pFfDJ4Skbud8831rHGXyJZqxOyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g49RwIXAI3V5KYV+8pLwKhHgc6rE5EqNlH2zTaGiudoUhyvtwj3Dtm4Rfocfv9UUN7YJxsxH7d0BGa8L4oJb4Dw+y6Q486laA2+hhq2pLjwz0i+L4+iBIOZnrDWqQPepnPjOnqGE7GEirgM5sWlhrmZBHyFJBwv1fkiga5tzoN0= 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=XH3Xco0X; arc=none smtp.client-ip=209.85.214.171 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="XH3Xco0X" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2d01663d816so3029935ad.1 for ; Thu, 03 Sep 2026 16:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788477114; x=1789081914; 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=UStGGDUYNH+jGUu3MdmkQZBNNFo8Y3Nyr4EO5zHwYT8=; b=XH3Xco0XskQ6aY9QwO5Z6Hyy2pwmX2+uzMn0CKb4HNOcznJ5kNvwcOtyZUkHpw2CRj PxfOIpl77bZJuvsYjlRM7eP9yblsWePHbNM71145dknpEHkngiNsgcezXGmeRvgqOenZ zia44VePOwpV49eGO6fs4SobvGzTD0byIhtaskm0sqggCaVwhF8bqwg0RgbegAV958to NnucNVj+Zvrdt+BOGvNWgG0FWVqdGoOxaaT7wSODn4hhp4ldhTW6//Rs1V44PDa4OO+m iItGC26Mf6ZYzqZbkoTWthPuIhYx8+Ikx1pZ7Aul98TJbAK346tAElIAfKhKOY4i+eH0 ZJyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788477114; x=1789081914; 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=UStGGDUYNH+jGUu3MdmkQZBNNFo8Y3Nyr4EO5zHwYT8=; b=GgU1D0qBF/SYdEtRFWn75Ww8avbZnpOBX5SIjebGX9sYZgtCh9ww/r756py0Xi0P6I 1RBe6h3dEQzI/AgfBgVrU6kmN3TtNL0wDCc9pAfZsi8akdoqNGGcsYZ5p672J0/Bzmx+ vFecjP+ao49k5nAJR+oC5oL5pHQrCRtKmo3VEx9yUKJW8VJaajdAoLpb9v7Vpr1VSga1 X6ap6g7DBQdqmwv7pDjjkmXDOHH4+T/gBKIMrXfRV6g2rVhpTsarAbJSAp5pPG6SwcxR ee5mwP5XwK76ivLP052gHxG2XO3EW91/wF//BcSofpCWtUvXZ1iNfSrH/cNwcMl8ovTu jWnw== X-Forwarded-Encrypted: i=1; AKwUvBya/1N1hpFWS3KPHZzjK2I+KtG74JXHmE5jO+Mj782vPvzg8zoB8VDKuJuc6LR4shvmPyYcKEx9/VeMYMA=@vger.kernel.org X-Gm-Message-State: AFuF++n7FXlLDxUaOKQDTKkvgBZZqzSbNPYdzKq10vwkORJ277F3Qs9O 59Xo9zsiqG27csDX3jgEm06PYNt4kw11I8Vn3bNoomR8X/BOMI6Oedxj X-Gm-Gg: AYBFou13sjcfqFXDCm/4aZUgAKBBOxoYWD63nsDSgpCjoxM6yLbZYtfleeHUN6p5GZv 3jS2l0quSJK5SFSeKqf3813rzSMg4xRlQqk71pZhkgmr1c2C9VHgoSaxPrwtCHlh2BjEZhSOlOn xQgVYjQFcGZMwNgcsKbRf0ti3gmWSIaSKt8xAgFwgjY7IoIuG73mRunNxMJsVRrrKQEYYUNMEyh ZioK2Z4vTSzNcqtpiowbRy9w37/QHk6N39hpR6U6Sw2NsA321Z33ac1XYxdbM0EvlJkQ1iiqDm4 EHozC1BRTcxUDNhdZn83pRh4HYYkHC4wrjFvhYjX0KMSu2objnCtDPkdBZjobSwOft62CUq+wrz kcfgfYhcwUDag53RFSOFWUnSLp4sMcOlY9qPIgkHubIQX0sc2OK09nmZsnq1rrAl3WXhzTOFwmF lUtFlj5d/v2eTeE27kVb0E8h8V5IQDCTqUO5/LPciSzi4BsHmGTEJO9APuURXltGZI8Q== X-Received: by 2002:a17:90b:54c3:b0:398:d6e8:f84e with SMTP id 98e67ed59e1d1-39b2612ecebmr3152515a91.9.1788477114155; Thu, 03 Sep 2026 16:11:54 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b08bcc081sm7395097a91.6.2026.09.03.16.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:11:53 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v8 11/11] f2fs: parameterize block size and mask macros Date: Thu, 3 Sep 2026 16:11:38 -0700 Message-ID: X-Mailer: git-send-email 2.53.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" Block size constants, shift counts, masks, and page-to-block ratios were globally defined assuming a fixed 4KB block size. Parameterize F2FS_BLKSIZE, F2FS_BLKSIZE_BITS, F2FS_BLKSIZE_MASK, F2FS_BLKS_PER_PAGE, and CP_CHKSUM_OFFSET with struct f2fs_sb_info *sbi to reference sbi->blocksize, sbi->log_blocksize, and runtime masks. Update call sites across metadata operations, data I/O, file operations, garbage collection, inline data, and sysfs information. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 23 ++++++++++++----------- fs/f2fs/data.c | 25 ++++++++++++++----------- fs/f2fs/extent_cache.c | 9 +++++---- fs/f2fs/f2fs.h | 8 +++++--- fs/f2fs/file.c | 30 +++++++++++++++++------------- fs/f2fs/gc.c | 11 ++++++----- fs/f2fs/inline.c | 6 +++--- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 7 ++++--- fs/f2fs/node.h | 2 +- fs/f2fs/segment.c | 18 +++++++++++------- fs/f2fs/segment.h | 2 +- fs/f2fs/super.c | 6 +++--- fs/f2fs/sysfs.c | 10 +++++----- fs/f2fs/xattr.c | 2 +- include/linux/f2fs_fs.h | 16 ++++++++-------- 16 files changed, 97 insertions(+), 80 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index a3490be98c51..ff61dd18a285 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -288,7 +288,7 @@ static struct folio *__get_meta_folio(struct f2fs_sb_in= fo *sbi, pgoff_t index, return ERR_PTR(err); } =20 - f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, F2FS_BLKSIZE(sbi)); =20 folio_lock(folio); if (unlikely(!is_meta_folio(folio))) { @@ -513,7 +513,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_= t start, int nrpages, =20 if (!err) f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(sbi)); } out: blk_finish_plug(&plug); @@ -1141,16 +1141,17 @@ static void write_orphan_inodes(struct f2fs_sb_info= *sbi, block_t start_blk) } } =20 -static __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *ckpt) +static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi, + struct f2fs_checkpoint *ckpt) { unsigned int chksum_ofs =3D le32_to_cpu(ckpt->checksum_offset); __u32 chksum; =20 chksum =3D f2fs_crc32(ckpt, chksum_ofs); - if (chksum_ofs < CP_CHKSUM_OFFSET) { + if (chksum_ofs < CP_CHKSUM_OFFSET(sbi)) { chksum_ofs +=3D sizeof(chksum); chksum =3D f2fs_chksum(chksum, (__u8 *)ckpt + chksum_ofs, - F2FS_BLKSIZE - chksum_ofs); + F2FS_BLKSIZE(sbi) - chksum_ofs); } return chksum; } @@ -1170,13 +1171,13 @@ static int get_checkpoint_version(struct f2fs_sb_in= fo *sbi, block_t cp_addr, =20 crc_offset =3D le32_to_cpu((*cp_block)->checksum_offset); if (crc_offset < CP_MIN_CHKSUM_OFFSET || - crc_offset > CP_CHKSUM_OFFSET) { + crc_offset > CP_CHKSUM_OFFSET(sbi)) { f2fs_folio_put(*cp_folio, true); f2fs_warn(sbi, "invalid crc_offset: %zu", crc_offset); return -EINVAL; } =20 - crc =3D f2fs_checkpoint_chksum(*cp_block); + crc =3D f2fs_checkpoint_chksum(sbi, *cp_block); if (crc !=3D cur_cp_crc(*cp_block)) { f2fs_folio_put(*cp_folio, true); f2fs_warn(sbi, "invalid crc value"); @@ -1713,7 +1714,7 @@ static void commit_checkpoint(struct f2fs_sb_info *sb= i, */ struct folio *folio =3D f2fs_grab_meta_folio(sbi, blk_addr); =20 - memcpy(folio_address(folio), src, PAGE_SIZE); + memcpy(folio_address(folio), src, F2FS_BLKSIZE(sbi)); =20 folio_mark_dirty(folio); if (unlikely(!folio_clear_dirty_for_io(folio))) @@ -1848,7 +1849,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, st= ruct cp_control *cpc) get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP)); get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP)); =20 - crc32 =3D f2fs_checkpoint_chksum(ckpt); + crc32 =3D f2fs_checkpoint_chksum(sbi, ckpt); *((__le32 *)((unsigned char *)ckpt + le32_to_cpu(ckpt->checksum_offset))) =3D cpu_to_le32(crc32); @@ -1873,8 +1874,8 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, st= ruct cp_control *cpc) f2fs_update_meta_page(sbi, ckpt, start_blk++); =20 for (i =3D 1; i < 1 + cp_payload_blks; i++) - f2fs_update_meta_page(sbi, (char *)ckpt + i * F2FS_BLKSIZE, - start_blk++); + f2fs_update_meta_page(sbi, (char *)ckpt + + i * F2FS_BLKSIZE(sbi), start_blk++); =20 if (orphan_num) { write_orphan_inodes(sbi, start_blk); diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d058617b50f4..b40d85a21edc 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1227,7 +1227,7 @@ static void f2fs_submit_page_read(struct inode *inode= , struct fsverity_info *vi, f2fs_bug_on(sbi, 1); =20 inc_page_count(sbi, F2FS_RD_DATA); - f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE(sbi)); f2fs_submit_read_bio(sbi, bio, DATA); } =20 @@ -2210,7 +2210,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, count_in_cluster +=3D map.m_len; if (count_in_cluster =3D=3D cluster_size) { compr_cluster =3D false; - size +=3D F2FS_BLKSIZE; + size +=3D F2FS_BLKSIZE(sbi); } } else if (map.m_flags & F2FS_MAP_DELALLOC) { flags =3D FIEMAP_EXTENT_UNWRITTEN; @@ -2255,7 +2255,7 @@ static int f2fs_read_single_page(struct inode *inode,= struct fsverity_info *vi, struct readahead_control *rac) { struct bio *bio =3D *bio_ret; - const unsigned int blocksize =3D F2FS_BLKSIZE; + const unsigned int blocksize =3D F2FS_BLKSIZE(F2FS_I_SB(inode)); sector_t block_in_file; sector_t last_block; sector_t last_block_in_file; @@ -2344,7 +2344,7 @@ static int f2fs_read_single_page(struct inode *inode,= struct fsverity_info *vi, =20 inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(F2FS_I_SB(inode))); *last_block_in_bio =3D block_nr; out: *bio_ret =3D bio; @@ -2362,7 +2362,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, st= ruct bio **bio_ret, struct bio *bio =3D *bio_ret; unsigned int start_idx =3D cc->cluster_idx << cc->log_cluster_size; sector_t last_block_in_file; - const unsigned int blocksize =3D F2FS_BLKSIZE; + const unsigned int blocksize =3D F2FS_BLKSIZE(sbi); struct decompress_io_ctx *dic =3D NULL; struct extent_info ei =3D {}; bool from_dnode =3D true; @@ -2495,7 +2495,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, st= ruct bio **bio_ret, refcount_inc(&dic->refcnt); =20 inc_page_count(sbi, F2FS_RD_DATA); - f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, + F2FS_BLKSIZE(sbi)); *last_block_in_bio =3D blkaddr; } =20 @@ -2669,14 +2670,14 @@ static int f2fs_read_data_large_folio(struct inode = *inode, */ f2fs_wait_on_block_writeback(inode, block_nr); =20 - if (!bio_add_folio(bio, folio, F2FS_BLKSIZE, - offset << PAGE_SHIFT)) + if (!bio_add_folio(bio, folio, F2FS_BLKSIZE(F2FS_I_SB(inode)), + offset << PAGE_SHIFT)) goto submit_and_realloc; =20 folio_in_bio =3D true; inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(F2FS_I_SB(inode))); last_block_in_bio =3D block_nr; } trace_f2fs_read_folio(folio, DATA); @@ -4230,6 +4231,7 @@ static sector_t f2fs_bmap_compress(struct inode *inod= e, sector_t block) static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode =3D mapping->host; + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); sector_t blknr =3D 0; =20 if (f2fs_has_inline_data(inode)) @@ -4240,7 +4242,7 @@ static sector_t f2fs_bmap(struct address_space *mappi= ng, sector_t block) filemap_write_and_wait(mapping); =20 /* Block number less than F2FS MAX BLOCKS */ - if (unlikely(block >=3D max_file_blocks(F2FS_I_SB(inode), inode))) + if (unlikely(block >=3D max_file_blocks(sbi, inode))) goto out; =20 if (f2fs_compressed_file(inode)) { @@ -4442,7 +4444,8 @@ static int check_swap_activate(struct swap_info_struc= t *sis, out: if (not_aligned) f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) io= ctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)", - not_aligned, blks_per_sec * F2FS_BLKSIZE); + not_aligned, + (unsigned long)blks_per_sec * F2FS_BLKSIZE(sbi)); return ret; } =20 diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 37cf9fa8d537..57217dc5b310 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -904,11 +904,12 @@ static int __get_new_block_age(struct inode *inode, s= truct extent_info *ei, struct extent_info tei =3D *ei; /* only fofs and len are valid */ =20 /* - * When I/O is not aligned to a PAGE_SIZE, update will happen to the last - * file block even in seq write. So don't record age for newly last file - * block here. + * When I/O is not aligned to the filesystem block size, update will + * happen to the last file block even in seq write. Do not record the age + * of the new last file block here. */ - if ((f_size >> PAGE_SHIFT) =3D=3D ei->fofs && f_size & (PAGE_SIZE - 1) && + if ((f_size >> sbi->log_blocksize) =3D=3D ei->fofs && + f_size & F2FS_BLKSIZE_MASK(sbi) && blkaddr =3D=3D NEW_ADDR) return -EINVAL; =20 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f293bdd2baca..b7584e289bc4 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2258,6 +2258,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) +#define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) =20 #define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 1) #define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 2) @@ -2312,7 +2313,7 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struc= t f2fs_sb_info *sbi) =20 static inline struct node_footer *F2FS_NODE_FOOTER(const struct folio *fol= io) { - return folio_address(folio) + F2FS_BLKSIZE - + return folio_address(folio) + F2FS_BLKSIZE(F2FS_F_SB(folio)) - sizeof(struct node_footer); } =20 @@ -2328,7 +2329,8 @@ static inline struct f2fs_inode *F2FS_INODE(const str= uct folio *folio) =20 static inline __le32 *F2FS_INODE_NIDS(const struct folio *folio) { - return folio_address(folio) + F2FS_BLKSIZE - sizeof(struct node_footer) - + return folio_address(folio) + F2FS_BLKSIZE(F2FS_F_SB(folio)) - + sizeof(struct node_footer) - SIZE_OF_I_NID; } =20 @@ -2977,7 +2979,7 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info = *sbi, int flag) if (flag =3D=3D NAT_BITMAP) return tmp_ptr; else - return (unsigned char *)ckpt + F2FS_BLKSIZE; + return (unsigned char *)ckpt + F2FS_BLKSIZE(sbi); } else { offset =3D (flag =3D=3D NAT_BITMAP) ? le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 6fafb32bc5f2..7001c18da506 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -110,7 +110,8 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *v= mf) ret =3D filemap_fault(vmf); if (ret & VM_FAULT_LOCKED) f2fs_update_iostat(F2FS_I_SB(inode), inode, - APP_MAPPED_READ_IO, F2FS_BLKSIZE); + APP_MAPPED_READ_IO, + F2FS_BLKSIZE(F2FS_I_SB(inode))); =20 trace_f2fs_filemap_fault(inode, vmf->pgoff, flags, ret); =20 @@ -233,7 +234,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault = *vmf) } folio_mark_dirty(folio); =20 - f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE(sbi)); f2fs_update_time(sbi, REQ_TIME); =20 out_sem: @@ -974,7 +975,7 @@ int f2fs_truncate(struct inode *inode) =20 trace_f2fs_truncate(inode); =20 - if (time_to_inject(sbi, FAULT_TRUNCATE)) + if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) return -EIO; =20 err =3D f2fs_dquot_initialize(inode); @@ -1675,7 +1676,8 @@ static int f2fs_collapse_range(struct inode *inode, l= off_t offset, loff_t len) return -EINVAL; =20 /* collapse range should be aligned to block size of f2fs. */ - if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) + if (offset & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode)) || + len & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode))) return -EINVAL; =20 ret =3D f2fs_convert_inline_inode(inode); @@ -1890,7 +1892,8 @@ static int f2fs_insert_range(struct inode *inode, lof= f_t offset, loff_t len) return -EINVAL; =20 /* insert range should be aligned to block size of f2fs. */ - if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) + if (offset & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode)) || + len & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode))) return -EINVAL; =20 ret =3D f2fs_convert_inline_inode(inode); @@ -3193,7 +3196,8 @@ static int f2fs_ioc_defragment(struct file *filp, uns= igned long arg) return -EFAULT; =20 /* verify alignment of offset & size */ - if (range.start & (F2FS_BLKSIZE - 1) || range.len & (F2FS_BLKSIZE - 1)) + if (range.start & F2FS_BLKSIZE_MASK(sbi) || + range.len & F2FS_BLKSIZE_MASK(sbi)) return -EINVAL; =20 if (unlikely(F2FS_BYTES_TO_BLK(sbi, range.start + range.len) > @@ -3279,7 +3283,7 @@ static int f2fs_move_file_range(struct file *file_in,= loff_t pos_in, if (src =3D=3D dst && pos_out > pos_in && pos_out < pos_in + len) goto out_unlock; if (pos_in + len =3D=3D src->i_size) - len =3D ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in; + len =3D ALIGN(src->i_size, F2FS_BLKSIZE(sbi)) - pos_in; if (len =3D=3D 0) { ret =3D 0; goto out_unlock; @@ -3297,9 +3301,9 @@ static int f2fs_move_file_range(struct file *file_in,= loff_t pos_in, } =20 /* verify the end result is block aligned */ - if (!IS_ALIGNED(pos_in, F2FS_BLKSIZE) || - !IS_ALIGNED(pos_in + len, F2FS_BLKSIZE) || - !IS_ALIGNED(pos_out, F2FS_BLKSIZE)) + if (!IS_ALIGNED(pos_in, F2FS_BLKSIZE(sbi)) || + !IS_ALIGNED(pos_in + len, F2FS_BLKSIZE(sbi)) || + !IS_ALIGNED(pos_out, F2FS_BLKSIZE(sbi))) goto out_unlock; =20 ret =3D f2fs_convert_inline_inode(src); @@ -4593,14 +4597,14 @@ static int f2fs_sec_trim_file(struct file *filp, un= signed long arg) to_end =3D true; } =20 - if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || - (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE))) { + if (!IS_ALIGNED(range.start, F2FS_BLKSIZE(sbi)) || + (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE(sbi)))) { ret =3D -EINVAL; goto err; } =20 index =3D F2FS_BYTES_TO_BLK(sbi, range.start); - pg_end =3D DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); + pg_end =3D F2FS_BLK_ALIGN(sbi, end_addr); =20 ret =3D f2fs_convert_inline_inode(inode); if (ret) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 39fa4776404e..bc22dde1cb30 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1305,8 +1305,8 @@ static int ra_data_block(struct inode *inode, pgoff_t= index) f2fs_put_page(fio.encrypted_page, false); f2fs_folio_put(folio, true); =20 - f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); - f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE(sbi)); + f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE(sbi)); =20 if (atomic_inode) iput(atomic_inode); @@ -1426,9 +1426,9 @@ static int move_data_block(struct inode *inode, block= _t bidx, } =20 f2fs_update_iostat(fio.sbi, inode, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); f2fs_update_iostat(fio.sbi, NULL, FS_GDATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); =20 folio_lock(mfolio); if (unlikely(!is_meta_folio(mfolio) || @@ -1479,7 +1479,8 @@ static int move_data_block(struct inode *inode, block= _t bidx, fio.new_blkaddr =3D newaddr; f2fs_submit_page_write(&fio); =20 - f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, F2FS_BLKSIZE); + f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, + F2FS_BLKSIZE(fio.sbi)); =20 f2fs_update_data_blkaddr(&dn, newaddr); set_inode_flag(inode, FI_APPEND_WRITE); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 73cd9b6ddcc5..3e0b9449ffba 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -448,7 +448,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, = struct folio *ifolio, * Start by zeroing the full block, to ensure that all unused space is * zeroed and no uninitialized memory is leaked to disk. */ - memset(dentry_blk, 0, F2FS_BLKSIZE); + memset(dentry_blk, 0, F2FS_BLKSIZE(F2FS_I_SB(dir))); =20 make_dentry_ptr_inline(dir, &src, inline_dentry); make_dentry_ptr_block(dir, &dst, dentry_blk); @@ -477,8 +477,8 @@ static int f2fs_move_inline_dirents(struct inode *dir, = struct folio *ifolio, F2FS_I(dir)->i_inline_xattr_size =3D 0; =20 f2fs_i_depth_write(dir, 1); - if (i_size_read(dir) < PAGE_SIZE) - f2fs_i_size_write(dir, PAGE_SIZE); + if (i_size_read(dir) < F2FS_BLKSIZE(F2FS_I_SB(dir))) + f2fs_i_size_write(dir, F2FS_BLKSIZE(F2FS_I_SB(dir))); out: f2fs_folio_put(folio, true); return err; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index aa22e457d5b3..82ebcb338b0c 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -165,7 +165,7 @@ static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi= , struct folio *folio) chksum =3D f2fs_chksum(chksum, (__u8 *)&dummy_cs, cs_size); offset +=3D cs_size; chksum =3D f2fs_chksum(chksum, (__u8 *)ri + offset, - F2FS_BLKSIZE - offset); + F2FS_BLKSIZE(sbi) - offset); return chksum; } =20 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 7bb99988833a..68a95d703c4a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -165,7 +165,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_= info *sbi, nid_t nid) =20 src_addr =3D folio_address(src_folio); dst_addr =3D folio_address(dst_folio); - memcpy(dst_addr, src_addr, PAGE_SIZE); + memcpy(dst_addr, src_addr, F2FS_BLKSIZE(sbi)); folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); =20 @@ -1500,7 +1500,8 @@ static int read_node_folio(struct folio *folio, blk_o= pf_t op_flags) err =3D f2fs_submit_page_bio(&fio); =20 if (!err) - f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, + F2FS_BLKSIZE(sbi)); =20 return err; } @@ -3313,7 +3314,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) return PTR_ERR(folio); =20 memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(sbi, i), - folio_address(folio), F2FS_BLKSIZE); + folio_address(folio), F2FS_BLKSIZE(sbi)); f2fs_folio_put(folio, true); } =20 diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 2766ced7bef7..c265739f2105 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -282,7 +282,7 @@ static inline void fill_node_footer(const struct folio = *folio, nid_t nid, unsigned int old_flag =3D 0; =20 if (reset) - memset(rn, 0, F2FS_BLKSIZE); + memset(rn, 0, F2FS_BLKSIZE(F2FS_F_SB(folio))); else old_flag =3D le32_to_cpu(footer->flag); =20 diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f58b26c84b3a..f2641a6080ae 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1316,7 +1316,8 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_in= fo *sbi, submit_bio(bio); =20 atomic_inc(&dcc->issued_discard); - f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, dc->di.len * F2FS_BLKSIZE= ); + f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, + dc->di.len * F2FS_BLKSIZE(sbi)); } #endif =20 @@ -1419,7 +1420,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, =20 atomic_inc(&dcc->issued_discard); =20 - f2fs_update_iostat(sbi, NULL, FS_DISCARD_IO, len * F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_DISCARD_IO, + len * F2FS_BLKSIZE(sbi)); =20 lstart +=3D len; start +=3D len; @@ -2797,7 +2799,7 @@ void f2fs_update_meta_page(struct f2fs_sb_info *sbi, if (IS_ERR(folio)) return; =20 - memcpy(folio_address(folio), src, PAGE_SIZE); + memcpy(folio_address(folio), src, F2FS_BLKSIZE(sbi)); folio_mark_dirty(folio); f2fs_folio_put(folio, true); } @@ -4152,7 +4154,7 @@ void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi= , struct folio *folio, f2fs_submit_page_write(&fio); =20 stat_inc_meta_count(sbi, folio->index); - f2fs_update_iostat(sbi, NULL, io_type, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, io_type, F2FS_BLKSIZE(sbi)); } =20 void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio) @@ -4162,7 +4164,8 @@ void f2fs_do_write_node_page(unsigned int nid, struct= f2fs_io_info *fio) set_summary(&sum, nid, 0, 0); do_write_page(&sum, fio); =20 - f2fs_update_iostat(fio->sbi, NULL, fio->io_type, F2FS_BLKSIZE); + f2fs_update_iostat(fio->sbi, NULL, fio->io_type, + F2FS_BLKSIZE(fio->sbi)); } =20 void f2fs_outplace_write_data(struct dnode_of_data *dn, @@ -4178,7 +4181,8 @@ void f2fs_outplace_write_data(struct dnode_of_data *d= n, do_write_page(&sum, fio); f2fs_update_data_blkaddr(dn, fio->new_blkaddr); =20 - f2fs_update_iostat(sbi, dn->inode, fio->io_type, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, dn->inode, fio->io_type, + F2FS_BLKSIZE(sbi)); } =20 int f2fs_inplace_write_data(struct f2fs_io_info *fio) @@ -4220,7 +4224,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) f2fs_update_device_state(fio->sbi, fio->ino, fio->new_blkaddr, 1); f2fs_update_iostat(fio->sbi, fio_inode(fio), - fio->io_type, F2FS_BLKSIZE); + fio->io_type, F2FS_BLKSIZE(fio->sbi)); } =20 return err; diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 2275404e769c..cc0428b614da 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -432,7 +432,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb= _info *sbi, int i; =20 raw_sit =3D folio_address(folio); - memset(raw_sit, 0, PAGE_SIZE); + memset(raw_sit, 0, F2FS_BLKSIZE(sbi)); for (i =3D 0; i < end - start; i++) { rs =3D &raw_sit->entries[i]; se =3D get_seg_entry(sbi, start + i); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 0bb8b8048d78..6ff79832fc03 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1610,7 +1610,7 @@ static int f2fs_check_opt_consistency(struct fs_conte= xt *fc, return -EINVAL; } min_size =3D MIN_INLINE_XATTR_SIZE; - max_size =3D MAX_INLINE_XATTR_SIZE(sbi->blocksize); + max_size =3D MAX_INLINE_XATTR_SIZE(F2FS_BLKSIZE(sbi)); =20 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || F2FS_OPTION(sbi).inline_xattr_size > max_size) { @@ -4079,10 +4079,10 @@ static int sanity_check_raw_super(struct f2fs_sb_in= fo *sbi, } =20 /* only support block_size equals to PAGE_SIZE */ - if (le32_to_cpu(raw_super->log_blocksize) !=3D F2FS_BLKSIZE_BITS) { + if (le32_to_cpu(raw_super->log_blocksize) !=3D PAGE_SHIFT) { f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", le32_to_cpu(raw_super->log_blocksize), - F2FS_BLKSIZE_BITS); + PAGE_SHIFT); return -EFSCORRUPTED; } =20 diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 811e350a1430..aaca9ed9b169 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1871,8 +1871,8 @@ static int __maybe_unused disk_map_seq_show(struct se= q_file *seq, struct f2fs_sb_info *sbi =3D F2FS_SB(sb); int i; =20 - seq_printf(seq, "Address Layout : %5luB Block address (# of Segments)\n= ", - F2FS_BLKSIZE); + seq_printf(seq, "Address Layout : %5uB Block address (# of Segments)\n", + F2FS_BLKSIZE(sbi)); seq_printf(seq, " SB : %12s\n", "0/1024B"); seq_printf(seq, " seg0_blkaddr : 0x%010x\n", SEG0_BLKADDR(sbi)); seq_printf(seq, " Checkpoint : 0x%010x (%10d)\n", @@ -1889,13 +1889,13 @@ static int __maybe_unused disk_map_seq_show(struct = seq_file *seq, seq_printf(seq, " Main : 0x%010x (%10d)\n", SM_I(sbi)->main_blkaddr, le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main)); - seq_printf(seq, " Block size : %12lu KB\n", F2FS_BLKSIZE >> 10); + seq_printf(seq, " Block size : %12u KB\n", F2FS_BLKSIZE(sbi) >> 10); seq_printf(seq, " Segment size : %12d MB\n", - (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " Segs/Sections : %12d\n", SEGS_PER_SEC(sbi)); seq_printf(seq, " Section size : %12d MB\n", - (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " # of Sections : %12d\n", le32_to_cpu(F2FS_RAW_SUPER(sbi)->section_count)); =20 diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 99c863513725..98059e583b09 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -850,4 +850,4 @@ int __init f2fs_init_xattr_cache(void) void f2fs_destroy_xattr_cache(void) { kmem_cache_destroy(inline_xattr_slab); -} \ No newline at end of file +} diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 9036cc6c2a2c..92a11e984d7a 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,12 +14,9 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log = number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL -#define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ #define F2FS_MAX_BLKSIZE PAGE_SIZE -#define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ =20 @@ -27,16 +24,20 @@ #define NEW_ADDR ((block_t)-1) /* used as block_t addresses */ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ =20 -#define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) +#define F2FS_BLKSIZE(sbi) ((sbi)->blocksize) +#define F2FS_BLKSIZE_BITS(sbi) ((sbi)->log_blocksize) +#define F2FS_BLKSIZE_MASK(sbi) (F2FS_BLKSIZE(sbi) - 1) +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) (F2FS_BLKSIZE_BITS(sbi) - 9) +#define F2FS_BLKS_PER_PAGE(sbi) (PAGE_SIZE / F2FS_BLKSIZE(sbi)) #define F2FS_BYTES_TO_BLK(sbi, bytes) \ - ((unsigned long long)(bytes) >> (sbi)->log_blocksize) + ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_TO_BYTES(sbi, blk) \ - ((unsigned long long)(blk) << (sbi)->log_blocksize) + ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_END_BYTES(sbi, blk) \ (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) #define F2FS_BLK_ALIGN(sbi, bytes) \ F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ - (sbi)->blocksize - 1) + F2FS_BLKSIZE(sbi) - 1) =20 /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 @@ -222,7 +223,6 @@ struct f2fs_checkpoint { unsigned char sit_nat_version_bitmap[]; } __packed; =20 -#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32)) /* default chksum= offset in checkpoint */ #define CP_MIN_CHKSUM_OFFSET \ (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap)) =20 --=20 2.53.0