From nobody Sat Sep 26 13:46:39 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 94C4E3A8758 for ; Mon, 31 Aug 2026 22:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788213942; cv=none; b=GIjuhR9ty3I/PO3OU6r2eUQ1KwsVZY6dJ0y+aaLHE6lIM/Bsu9N0R8vpsm21JI1X46jf9yM/FBBUxJEm8JxwCL92i8of772Hpl+Xhz4YRjFQcFd53o/Yg5xJ3mlPkzJKOou7wkmGBtKjCN5thJM71SQ1hDY3mYDOBTzIfbpuyFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788213942; c=relaxed/simple; bh=XP6yj8rw6hG7bTSPi7oGkgkS+EJ6C8E4iteUrKh0Fh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ozaxnupd78sEeO/O0IKehcMaCwOdx8OXcKkEqyRNgFqfdq7ucxitHBMyshswRtg2nh6I86wdjW1sYYmbpswDoaj6sC8NOLWPvnAfBqd2gmHWxyvQOIfXB1f2fWjdE3hM1qlvSc6J09UQMCvoxNifsfViK/CqVp/MrKkfU11WrKg= 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=NLKSM6fD; arc=none smtp.client-ip=209.85.216.47 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="NLKSM6fD" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-39675172593so3570925a91.2 for ; Mon, 31 Aug 2026 15:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788213940; x=1788818740; 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=1SU3rdh97lkeZJr+7CduyypOUNik8G+JmicPTmnCyvI=; b=NLKSM6fDz8uBX4Mru4o9lXfZPYdf0jh8MKOO0aK7prfQFl5LKP8Oev4ynLP0yJqgYH /8CyPAXji2RIIgnJAGdGn7f6qeofaiu/Fw4gVka2T2Uylprdieoio/eiik2pJU5XLPVm qDHEWIDmpWyRpLyCSfDkUzaocoE0s2Hdl9e8C04vo+j94eHS3BGg+ZxJwt1jxu9nfyRM R3/f9HYTcNtjLTwYaw/H4rVdUhmrUMs/w23ReaXTkQKXjP1/NAMeRJm6FXj6dMRghw3b 1azeZQkXn6aedkEDuOt4fohH5W8HN3bUw78/9IrrW5W3X8Wopk3ltGuN7YTyx+b049FH eNIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788213940; x=1788818740; 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=1SU3rdh97lkeZJr+7CduyypOUNik8G+JmicPTmnCyvI=; b=pMJf1w2MDxWYb+NiPx6g3ffFPwLJIDx5ruVOOiP4xbnV21cs8QOVfTTOzSY5gfsJlg KMuzIfmkipZb0bvPxwgZJXOda28kfbv6rKqEM916wPzH4vvh8q8mSqn2D0XY9Uioasav RPkbVdIQVKlchwJuw3e7VoPROFUlQV/+80YHMV4BFBKcZW9mARZ0+Mky4b6oARsj8/Sl +HrSHaS1kCjrVZ2Bk+SKLibx/rB2n2h0e77YfIOVUHV2buEokPghwCaBTN+duAnJ69Eo d7ask4IxS/O+os0LglCLy5NwPWmEaXVHexim8rg/dF9PVRnXldP4+3rSSSENC1cyopTU A/9g== X-Forwarded-Encrypted: i=1; AKwUvBwwl9mKSCAQR/D58u6EXHmQwnQ5a4IdfcRTVKRgdlB0Jo4HLrbTbJW9rAR/l4uPwUVIknRJfuuqYt8FL/U=@vger.kernel.org X-Gm-Message-State: AFuF++kGul53pmrEGpDqUbLd0ihxxAUc9+XCcj5prQXYE1s1w/mGIk05 cSuT1LjN6DtCb1xhkmGHaBBZvFpmkAs0JENlU9NBRmagnRwZJhRgCtzQfWultC+u X-Gm-Gg: AYBFou33Tbvsv45tGrew4WKUArsW93L3E6790jVGM7cGXN3u95BELG3Ju8Xbec6ZZHo SbYBzq4oG7wo4JhEE+L0AsdOZv3tVl1zaZYJEH5GNF0oCGhh/Qdxp7iymzyrWt8OALsru7yXyCg G0jqLOPHp7xsVzGns2m3JutCGoal6CS6YjBuf4fcclqnvBomLviTkHQX0Ld3pH8kg0RMtSPCP8c 9/LRcIHahXId4gk40YkRN1FoL45RyIWxb7+r+nlRiblv9BUxqiBT+oUrygew4fNIDavCo1OaP7S 9TXzPq4VfRidu6afJLYLwbQJ2DugWokgJIvCgeC94mP3s8EJ6d70KZ0NRhmnsRsO1UwSSzAUsZU TPhvvuVrQ95uY6awLE6V3BBxU8RD+dAYqOkgPOyiH7UwUFB0UmK0WNaX2DdHVsZh53Mb19alQdY 6u0wucAjcpvTPf8Co9zy5V2SHJnfe63ANaW1p63sEm/7jOK665okMY77IgFZNH+Gng2MI= X-Received: by 2002:a17:90b:538c:b0:398:d6e6:4671 with SMTP id 98e67ed59e1d1-398d6e68870mr18634235a91.25.1788213939680; Mon, 31 Aug 2026 15:05:39 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990d499811sm1952863a91.10.2026.08.31.15.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:05:39 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 01/11] f2fs: initialize sb_info early in f2fs_fill_super Date: Mon, 31 Aug 2026 15:05: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" 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..2d9f5b77f815 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 (!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 13:46:39 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 351D83B42C6 for ; Mon, 31 Aug 2026 22:08:13 +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=1788214095; cv=none; b=aua9s1Zeo94PrJinQrA1MV73ihKh+lkayv/Ec9XW/P4nNs87JGwSPkS5Rzze6soy5q37m2GhiLL4I1v+Z33DporqgmzfGbGzXL5/ywQKUmYUGPBfPnPGlBh7oItrdpoMLoCWvTp4KbpaCXmRzZxm6dHYVuCtRWDsoCE7qmLUlis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214095; c=relaxed/simple; bh=eBC2eBPumwJIDm4WhwpcjIg7HmgeIFouYQQQ9D6zISc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YTqthsk4ghDrESL3/6tIiVLKt1kW2PuYwWryrs4zCVo16U5JoZN/DsG/z6RbDTSdtLosWbuEB6AoNWZiPvmSwpqztoXQznkK1kq84ZOexJbDSBwgo4QcBjZVROBfp2FkesJ3eLbwJjLJJOIr9M5q9AgWbWTuyFj4uxbYVOPFA6E= 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=R8qbCm96; 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="R8qbCm96" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2d71a50caa9so2173805ad.0 for ; Mon, 31 Aug 2026 15:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214093; x=1788818893; 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=73Dvng3mI/lVEk+nvH7YpbUeDY808BAoyKaozDCNYWI=; b=R8qbCm96soGdMhVJ6cPDfw2IKrrm+dtUh+C0H1WobqwmVT7T6zi3ViWFuIiM/4yz5y 2TjKtSCTEtw8b8pfBWw533iB7y7ENfkSFVZ2O7EmIz6UCuFhCXjVEeZHuiqMrelr2ZlQ czW4YBtoSl076LYhAtXsI9/gexNWf3zk/8dAI6V4MpY6UiuyP/zsspRbnbWIKSoog4v5 AkYsCR6WYac0TaqQuXwKTmOnHPrcpJVeD4mYU1+SML3b4oOuhvewlKKo6O9NI/M5yXbW /FJ0d+OeRF2ZrZ2zRxpZa6OpSTEBv0wu0qrYHtysDatsYUH1aDIjueoGArzksdqtsQlF DdLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214093; x=1788818893; 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=73Dvng3mI/lVEk+nvH7YpbUeDY808BAoyKaozDCNYWI=; b=HC2ax+FaZy1Pk1LKzbusuWlpRa5NMDvTy5DV8LtACTofN6wHZuLVLFmtDoEQjCqP1S E80gTaAx+BKvVr/CsOTst8SGkHpPlZX6wt5NCq/KVVv1C8flgMPstp08usT8LdTMZfzz hXpZe32lf0+vy8a0eATX6OWSFLlbbqwUt/NAeoAehr9TP/xsgu0tbdzUhzpLnNd0NIMU t/97UPfSujoCTiF9H1+UN5X3o/hrJiiBHJHhcZkD0iGbiKLjHZBBpaUadIUbntDP+5m3 WZwj8txRv1DUnmZ4UqDIs/+DOOOsp4cVDq5o/rdVElOL7TEZYxa/t7d5Jys2828M0UPT do6w== X-Forwarded-Encrypted: i=1; AKwUvBysh7/RsjJ4oLoqaWuh9Waz8XCrshwUMseysq6D0HmxQ2/vQkIwPOdkJnG+TRbmx32OLrmn5qraE3/ftFg=@vger.kernel.org X-Gm-Message-State: AFuF++mUCxL3Pv6rVwFM4TpmjJLVxLNkabQ2TDW8GOCYC2+Hh5PAtrCn kSUfdE+bboYyBcOmE0LZGFbqDXVkzU90WSVd/g3PNEzkfSaxtabF75op X-Gm-Gg: AYBFou1hlXNb7joxKQJGJM9gtIPqKlLbQMzoPPwk7WaoNfwfS/eiwW4qstsxI8uTKlE lVX9R2XdvxVW5NaeeZfodB9x7HHwZvdAbhvUkop1Uzdc/5r6WKv2qXPaOmcrJgLVs1gtBYBmovz XYOAz8W05uMIacH47jUB9JGzJ0mxYRMvzsSYy96ZwE5dvD7eQxviDRjiR0PzqoZXX2wAm8c772s 6hDFN4+ztYPeH4v2GKgMUnEUi/6w0i/smDfh6SBZ32ZNkRpWx6togbPIcPPX/nRf0ZAo/RXEF3L aUPk3vlr/PNX6Zb/xbsRQKbl7wmOA7KihTOPWISRJngHOC5mcsafxH8CBd1KfbQxF91xkN1TfGv wxKiuLojOvNsu8kSlcRv7NbLW5EUgIyCOx5OJ0cZ68O53WekE6I95ozHXw4CUfH1h1gd+x+23Gq TPea9T/eWVoznLbdFihCL3Zbt/xHkpwB1KmqQVAL3stPL+a55YK+ixFbcMZdatkP3CiggrEC7Ao 6DG X-Received: by 2002:a17:902:ef52:b0:2d9:383a:30f1 with SMTP id d9443c01a7336-2d9383a326bmr96736725ad.4.1788214093376; Mon, 31 Aug 2026 15:08:13 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d759869afasm41626105ad.42.2026.08.31.15.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:12 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 02/11] f2fs: describe SIT block layout dynamically Date: Mon, 31 Aug 2026 15:08:03 -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 2d9f5b77f815..4bd1c9fb1f7f 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 13:46:39 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 957493B4E8F for ; Mon, 31 Aug 2026 22:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214097; cv=none; b=ETbRu1P2JKplAn4AM09aDh9FBOGBb2yIYq3aFj/pxb5g+EbYJeJD5gkx6LnSMZMW/Y3dUuMFQ6CwVD7B3LoojUQx7m4wZL2dbf5HJLszoHlH7sE+ZWiBQUYUAZNe4HQaKMFRXv7ftl1IC9W5eA18pzMhERoKvr9uvapG7D6lupQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214097; c=relaxed/simple; bh=E0/oj/KOuR187CbjScbJfTxAvITEmhB/Yj8H1imqSns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g3jzBxMZ+cGCGlxKcXGtif/1z33dI7ih0CaXQh06Mds8nYXBB6Kh0/NJ0ayY2U6aP1eKu0xrrnsd5P+rtt5lBVrZTuvwqnQTKD81AlhbLEJPaMb0wIUXvI3jUjpQHxbBgP7JsHX1mmOTlJ+9v5yGeAidPj79TrGwP21u4B5Jnfw= 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=AywkCyiG; arc=none smtp.client-ip=209.85.215.169 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="AywkCyiG" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-cc2276e6daeso627966a12.0 for ; Mon, 31 Aug 2026 15:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214095; x=1788818895; 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=MxBPSiGREhAhPA4w8Ogt4vVXD6aoADqBeEuVZcqzI3Q=; b=AywkCyiGmQcgeIfPJUyvJsvfSZsctZoI1vrhegcK6U3nCxpK8STfbaElpcRlkgaRur evI3P5VQBqeBUQorNc18lDXJjMkiPIawyUqcHBOaX726MztUW8GKFGalXtzaJb3Z1B54 2Faj6hS6iqBKednIh0RhJx7BKU2u/dOJNhd35yDEDbz0AB8Jg5R6PeohAI+3hzRXm5tL 2boNgrm8uTIHm0/cPlHvvkE4s42t41Zn8XVHps/jI1MTHKHBAAAtBRgD5YqlpG2CIJnK vFElfRGGYuH8P5R6f0xB57K91LRbDAUNg/MIzUbIlr5D17x9dl6hZEAx/q/yTPn2dc29 2deQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214095; x=1788818895; 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=MxBPSiGREhAhPA4w8Ogt4vVXD6aoADqBeEuVZcqzI3Q=; b=mCXn7AySsVFYlJ8i0Dz48nVl3O9sw1LoYq58h90Bqk2eT6MiC0BFM55X7Ku6HPyPLM Dva8hp/NbySr6EP5U1Qb7T+P2A7r2nh3fB9y+ij8SnwbnBZdq8q0NtFAqgTS1X03wYnF CC6D/+ekuXz1GP1qOxZkbKadqd1aZlw8/4FBm7+n1IWvZ7of9D1Us6kgl8EKZCt0NXyL 4NJzAjUe0yAjjCVhbxARvt1rPk7DYnz3Y/Tkf4FjD6HH+54Z5sDP+8/zwyZpG/qnszRZ wg+vDLNCrH8Bb3XkxpY4xpq2SklOt4IoFRzXWMJMR+xqGP3O2Yx7oRqoCgd6ArA9n1i5 zJAA== X-Forwarded-Encrypted: i=1; AKwUvByjYE29+tNuD/WMKka2jdLHCyFQNqP6RWm3LTvteJfT0wZv6Bm6cfhMQKzkIJorrMSz/Y8NNWRuQ0ZvSyA=@vger.kernel.org X-Gm-Message-State: AFuF++mwRIttivTaX4d2JM9J8VrdRD6XauZxOUdfHe4lSgT43QPGsems Mb3JtMin1Cf+RPJ4r3KYwNDUaNWG+fsR318e/DwMmXTyXSIP7XiAwmDc X-Gm-Gg: AYBFou3pSAExCaOsloxkCUS4E4S8O5Gj4ANxxWhiG9rbzhfrJYBz+H08aGk15u4hb0x dZIGKb+LAuG1zRP02QWwHA320zfBCAChZRbgMjWBytKplGSaEwbRWO/WTePAmm0pX8N7YPcF5oS xxyz5YrgDAZxV7OiHP2Uw/s4u3ayKiwstWsxhw68lgs4/8i8PUX1+KTJa+50Thc61Lc3YcltQxL iVQOX0n1asaCQHVPYk6oRlJYL3S+Rh6siKpzrkTHZLunghwRAuU+Ci+Ta0k4QF22OGgS863hvpg /JcFCa3NMozHosHdOQEOGE2umvneu8/ZjFlUDLTSNmidkH6BoOaRI8AgGhl1ljIZoS+qjSGcOzS TRG8iViwE83mHbyOAU21GG1TZNbiiW+GzFX41zbDe/aH+NfSAwEsYaUQMNZxwc5puToVMNC0Vd2 5FzT7ydBgUZOIkAIo77CYpiPGCa5JO+w6EdKzFX7hph4apflgfCf5ckm9geEIsZO6/qQ== X-Received: by 2002:a17:90b:48d1:b0:393:194d:5366 with SMTP id 98e67ed59e1d1-39907b5fefamr5117407a91.10.1788214094753; Mon, 31 Aug 2026 15:08:14 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990d76463csm1658592a91.9.2026.08.31.15.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:14 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 03/11] f2fs: describe NAT block layout dynamically Date: Mon, 31 Aug 2026 15:08:04 -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" 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 | 22 ++++++++---- fs/f2fs/segment.c | 4 +-- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 4 ++- include/linux/f2fs_fs.h | 5 ++- 10 files changed, 71 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..0dce97aac5fc 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -6,14 +6,23 @@ * 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; +} + +#define START_NID(sbi, nid) f2fs_start_nid(sbi, nid) =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 +217,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 +239,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 4bd1c9fb1f7f..fdc2b0c51c06 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 13:46:39 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 F3A4C3B6370 for ; Mon, 31 Aug 2026 22:08:16 +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=1788214098; cv=none; b=A7hyUaIEFtjyaxyLqzfcYwsZcKtyGL3rMf/+OoTCG6RT7SJYp0nPW9qq7rg25OwYHyqAnHbWleDyna7d8vRYeOEQ86F8Sb+yffSAQSs/3C5yTYnizcbOC/K7N+Q7lVrOvon3+O4iuVRn1ss7+S/fVGMKZKrUot7CrIYTT31Gt5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214098; c=relaxed/simple; bh=hPN3nXcUHnWcSipjfnKgYJRavDMvUtuFljq2XKWqBt4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JIij7Jdbcks1UJ1//QJEDEdBZx0HU417wukzfiF4gRgDnVzMR4QtuFK1Kg/Kaisi158rr8MyskHcjpUvky7MOc13mPtv15XljtW3MUDr3dGm2k9+Ux4bTT2uRWesBWBz0HHHXzE3tVQiumDgvBpyiN2Z37swgFkdgdeUO+Q+P7g= 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=bf5eM8v5; 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="bf5eM8v5" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-cc1bc88a20eso386094a12.3 for ; Mon, 31 Aug 2026 15:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214096; x=1788818896; 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=dW4wycsn7ZP7cjkV107YVoHC6HCM3f5tAGyKmMmlafw=; b=bf5eM8v5ZUrKXOZ7dmo06pCdF6DBh663q/cCVbCK9viFK8+XJzPdIRk8c20VVQotGo okfOANSKAT425161bU6hMv4AyuunP+4/s+grh1AaVmFYR9JTAe2MfnGXUnRxB2jdTvr7 4k0U/c3hDZYmmG4jM5Pcs5PzMeBO6byMHBLpAw8ULE52V/bXlM6uvK4SJTw59hj2Nl6p WI+1d/eNDf+ZBY9LbvtIqtBNAhzD+S3dELWvsugauGsPSZTyCLBe4efqTrhM8XNxR3jj o3em0GJvatn2sFMwddD4Qz2dCoHlITs+L+U1b+GhH/0FMpAT+iYEV/blZYBEpXA1bVv0 VaWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214096; x=1788818896; 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=dW4wycsn7ZP7cjkV107YVoHC6HCM3f5tAGyKmMmlafw=; b=oiKQQKLHhi77sE4rPSk5SNP5RRMC3UvHQMlp3yTqlQ+ov6pX0iQAnXHVGGLnZwRSvd 0bygMCpa6pfmzDJk31oDGzyUyL5m1cIub31edUYo6GZu9lsFRwSfuNdeQRNTn6LcqWvw c/w/tpY9iSyViuyDu3f+eyVveJhmmQubPyp1j+q73CP+qZmpKhZDb4066iTpjVnIr8YU 4OXgY36JX+D3SPiQDiSnfK+Q2rUbc+tSNN328gYwYtPZ3vMuOaHjj3GTDDb8BD3aqcaC qsM36BSTCldgW75kmx7MoPf8pLZ/qDOlsOQFQq15kHkhpSAj8xq7G4I5oeuSwcD9WfJ4 3gfw== X-Forwarded-Encrypted: i=1; AKwUvBy+e9TZcft8YwSYFzdvf7z9w+VPHhJQNOT77GEHKsqYjjU3ynmeBYPxuJ+PNPYsOqgE6dfH8cQk1hdxqcA=@vger.kernel.org X-Gm-Message-State: AFuF++kasXbbHJRwmqfaxwoehbjSv7XFX06CA0+nHyLLjPUuj63zyCgP 1+WS8vZLu8gp/PD5sJ3D1otVE6XdCN4l6JOzr/fX3Rj7uxhAwDqpOUxkXpz7mfbv X-Gm-Gg: AYBFou1e0Kvk+j8W06kzElwCcjP8Heds5nKZXVtbzm9fsbnn6LVRmr9gRBaPTWQA7dg JZiriDaTSME1lU28GpocaeGx4YoVVNrHCE29oaLKCLToV+rIRpHqrNk4Ou9FcwWFzynlSzH/51L Ibhwo4WtXTEe0xKqAh83Dn4hNx0EnzdiazfYrvO+Lm+C2P5PW936hh8QMO9659gOmEIdoAnwppF oWCO3Ipd78zzG+OB4TBai7xuAFt/kH/ygEHcncX/z8wj103nkIJit67AkcsUY0oCzu483nNyS6m WoKbR7+82zkW3p3vpn7jgte3XKQH/kSRsxdgBQbMUT6YVdi/UamIKPwwHSkv8ycBiYHijULBtKD nzXX/evUlsx7JTHTIIAhxuh3g08xKDjxpMqb5661h5GupPoIovpdDrtHqSRaoMMiPhC8JbCcJCk ldAhBqeRM3X+uRpWYjvBGwWC/Pl6So/ZLNGBvWedZINwoq7pQcpzajfuUBN3/RR+uQPQ== X-Received: by 2002:a17:90b:5102:b0:38e:70d5:b12d with SMTP id 98e67ed59e1d1-396d0ea862fmr47687127a91.6.1788214096149; Mon, 31 Aug 2026 15:08:16 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990bcf7ca7sm1906193a91.4.2026.08.31.15.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:15 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 04/11] f2fs: describe orphan block layout dynamically Date: Mon, 31 Aug 2026 15:08: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" 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 | 44 ++++++++++++++++++++++------------------- fs/f2fs/f2fs.h | 12 +++++++++++ fs/f2fs/super.c | 2 ++ include/linux/f2fs_fs.h | 18 ++++++++++------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 3ecced9b4d57..37a72b693545 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1041,7 +1041,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) =20 for (i =3D 0; i < orphan_blocks; i++) { struct folio *folio; - struct f2fs_orphan_block *orphan_blk; + __le32 *orphan_inos; + struct f2fs_orphan_footer *footer; unsigned int entry_count; =20 folio =3D f2fs_get_meta_folio(sbi, start_blk + i); @@ -1050,9 +1051,10 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *= sbi) goto out; } =20 - orphan_blk =3D folio_address(folio); - entry_count =3D le32_to_cpu(orphan_blk->entry_count); - if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + orphan_inos =3D folio_address(folio); + footer =3D f2fs_orphan_footer(orphan_inos, 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); @@ -1063,7 +1065,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) } =20 for (j =3D 0; j < entry_count; j++) { - nid_t ino =3D le32_to_cpu(orphan_blk->ino[j]); + nid_t ino =3D le32_to_cpu(orphan_inos[j]); =20 err =3D recover_orphan_inode(sbi, ino); if (err) { @@ -1084,7 +1086,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_bl= k) { struct list_head *head; - struct f2fs_orphan_block *orphan_blk =3D NULL; + __le32 *orphan_inos =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 @@ -1105,21 +1108,22 @@ static void write_orphan_inodes(struct f2fs_sb_info= *sbi, block_t start_blk) list_for_each_entry(orphan, head, list) { if (!folio) { folio =3D f2fs_grab_meta_folio(sbi, start_blk++); - orphan_blk =3D folio_address(folio); - memset(orphan_blk, 0, sizeof(*orphan_blk)); + orphan_inos =3D folio_address(folio); + footer =3D f2fs_orphan_footer(orphan_inos, sbi); + memset(orphan_inos, 0, sbi->blocksize); } =20 - orphan_blk->ino[nentries++] =3D cpu_to_le32(orphan->ino); + orphan_inos[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 fdc2b0c51c06..f9811d571ae5 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..7d2cbceb42d5 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -220,14 +220,18 @@ struct f2fs_checkpoint { =20 /* * For orphan inode management + * + * An orphan block has no fixed-size C structure because the number of ino= de + * entries 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 */ +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 13:46:39 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 750083B14C0 for ; Mon, 31 Aug 2026 22:08:18 +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=1788214100; cv=none; b=Zs/BNolrhoFRvtwM82BKpLDxdWGO1tAqFjAwZFkhbj34ufOHLRiKZhKeqZMHcD6A8NwKSEeobTEnTpqfDH6QeC4TK/tPikLgSdAfytCiCu/kjw6/5Df874kgT/slxIZ3affaJg0nAsObGCzDKbAdJEFxqSTHKAyQMfJui4e97Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214100; c=relaxed/simple; bh=mgoMyXlC/lUnw14AUcWcJs+axOEXVsmV0cqIdXOP69Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kMJJpca8SNgc+nh/37THzn1iV+yiMEs/Mqu5CE4h3Z9EjLql+cYP6Rh4FDGnbzEWjocciJChtDbrGIni2ycuyzotBiqSL2Qdp71BHVJu4kA6H1/oGAXun0JWpWlqUehFZHhpa/MZHbue2R9s1VzHTW8EcLXdBut4BiUdDtUsP/w= 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=Qlrv131w; 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="Qlrv131w" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2cf452def93so3519445ad.1 for ; Mon, 31 Aug 2026 15:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214098; x=1788818898; 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=D0PaHFXOwSud6UZFH2TxjY6/bCXYw/h8j6SRlXWiD8U=; b=Qlrv131wImiGGmxFk9135PkkOJezZ1yJSXMwRhSgXud8rVYT6hpcSnThLiw+NtTeEe NLGzrQ48afFDZrZXFkHsAxjZxl2Lq4MJaIfLUPT6CGRKgXjjZDai+BPch52huOe9GG+4 Vj65DbPfo2kryw9HK2Fq42U8UzHX34zLPz3Y7iei6BpuBLFVYSWlXdFMysAfCySykiv1 XUiPi0EwaQqgUNwH8fs9fl+ETw4WGG/uoSDDvKrjWfTKdPReLoS7ekmTY1Xg0ownlhtF wl0xognsOggdzx24pXUgvsmjBeKIOgDmPx1FzV+c1jxvlHrK3F3xvn8uZZexdvwkO6Ua qLtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214098; x=1788818898; 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=D0PaHFXOwSud6UZFH2TxjY6/bCXYw/h8j6SRlXWiD8U=; b=OdTv9WQR3P5HbE2JIMz0eDPmgvvpve/PSNKc1HxYIyqrrLptD0fhU3HNhxQEFlTqPZ uZ507EgLccTmVFZ3OMa/EiGaKV3oRkzKPluZXwjAmKQdMbmeH9CA2v4EfTcejSZlvanO l2Zx/psAxgYY79cry3UYgLJIUbhuoqt14B2gaiep+SFlSQSATraMsUyfk7lqS2a8K1fI by1GpoP6MmCbr+DYRNFZK2faEReEU5IVZypqR2CUTkO4yDH5xYBnWvNL9mJjrlysecKR QxUu5Iws0qZDzmjlABr6hEb2Vv1jd+BqcbZ3TZKifJNe11+WGruJA0IBjlCON3xPZnvu 2lng== X-Forwarded-Encrypted: i=1; AKwUvBxqbG8mqXHR9lRo2hnbvyRXU7sAGmYfYF+iPxsrUOvbcf5QCNza3WF2+q/z+38QMKOe+BzQCYtoIaz5Qjg=@vger.kernel.org X-Gm-Message-State: AFuF++l+4AHRdExjiVnxGohAO+zRxL/2ZRrSDRmLc4qwrlD39l0QdTo4 ONkTRzQNnwg8V1O/6IO9ZtjTLChLhVWobhe5ZD2o80XT4wRi9rgpPcOAPFk4tZwLwFU= X-Gm-Gg: AYBFou0snMCiNg4AFu9fObMxsx6mChrCNyROL33DaqKyS4pLdsMVgC9nqtv6+Z7b5X5 6m+2jfU0TIIU0uhx3D7fkLt9fFYrIXJrdowdvqQFt0TrUInbup09/wqK8Hd6UBS9oTcJvj4JjZR rzC6oWtNJQHcpx2qL/dLct9DUA4V4MMdKjupjfP3U6GiZDiq4YAu4QpbXFDh+HsmX91bYG6V/LQ 9EzhPNC/wrOJKFVtRMFcBnUiNPcMV+fbFxFcgcz5lCJQazTwvaMDn3rcnXxSVBsmulDxh2NOIEt GOwSJOpOEjotIXM4riudw8Ij7uu3XE5f3GHEpQMmQ9Avc9UwDdj9Hj9as+pXn+iaS2zRwgdPwHL 1i2U98/fua316Nmn4Ox2RNWfKW1JzRLWxKhUBl27sLt7SM7uf7m3sZ+A231xNDhrwhXEVbN1Hjf 8BE76voXccSkgWFdHBXzPmcmu/rWzjEhvd3pBu7EaLXBy+SnAcyd3U9h0C3Gy80XPe5w== X-Received: by 2002:a17:90b:3808:b0:398:ba46:1d9f with SMTP id 98e67ed59e1d1-3990f88aabdmr759903a91.13.1788214097479; Mon, 31 Aug 2026 15:08:17 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990baaeec3sm1827712a91.0.2026.08.31.15.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:17 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 05/11] f2fs: describe dentry block layout dynamically Date: Mon, 31 Aug 2026 15:08:06 -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 f9811d571ae5..8d2224e585d3 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 7d2cbceb42d5..d1059a27e1b9 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -601,15 +601,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 */ @@ -620,14 +612,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 13:46:39 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 901593B47DF for ; Mon, 31 Aug 2026 22:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214101; cv=none; b=BK9v33GNRQ7bhdezyfXySA6WchwXErjghnYf6gbOKzjwBkVU43fbV53pZ3KpV2cCeKhVHklqU+iUokco4UBcFnFyLiq/Ed1pH8WYgHKvZxRoVz0hRbpC5OkQIPvtF313kpPIgrj19FxFYfqdDpIrFcZTApb74+4EOQv+eA+SEOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214101; c=relaxed/simple; bh=hLyo3XhEEbx6lsBnzV8H18Vz5t7RetvaUVKPxINBpwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uNZTIdh7tlMJnsUM/KQY40H7uPS5kORgu6Q/XUolczPEAC6eoK3gXKVNfk/Z3B+ZIR/yqSDmK+Pqmu0AJ9zqktR+s+4gkarMozNsgNOTh3rfz9Hs6Pm9n4CQBaTl6mLcSY9nC5lJtIBAcq+NBwe5QGtBHY0TJ6kXi4FGjeQ0bJ4= 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=BDJy59n5; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BDJy59n5" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38dfe7eb825so302015a91.0 for ; Mon, 31 Aug 2026 15:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214099; x=1788818899; 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=kFKK56sn+t6AJ7zgQy1TxPHePL4McZGnR+JHTvl23pU=; b=BDJy59n5TlFUYDd/l0Bhpmvj+FnSbdCxq7mGdXtyfd23qRqy5/pE4VREvnPLT0jL8V kRiskneiUqjdiIVriyRFR+A1wgfOx7Mg/QMfu0TTAW45xz+UhygBMzrxFpxppxvAPF3C mhTrcyzht04xPCRgEZr172f6bvZhDRIEpyASAODx53gybQAJ0+AfgIALaU3lt2PrjOr7 LD9lf30uCcwIQdN4xo5n509friSYozY5AB1AqPlKoN0RuVE4ggOqlct8eHWyLnGj7PxO ZYLBQ7XwSp0BnU1nOc315f1ugkb6agRLPxikIxORzuLpWt0w7PUOH0OiRrjBF7W3EsJT VhzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214099; x=1788818899; 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=kFKK56sn+t6AJ7zgQy1TxPHePL4McZGnR+JHTvl23pU=; b=IH27y9LyfArFo9FYL+15rdT0FYB3aKAbz30OZf//AJay03S3Rr6nuoLdwP9Y4Cvn7z +ZDJKT7jRQq0hy8KfIRfCM0DdkENuqNO8V/p5pC2aovaZf0DXiW+gI0wirUMA7lplDev Ptt37iDOqK3JCbEe8OOahhNfAICXqU7jRUxmLDdIRqls42Qj6yQYEgeiupbShkVKfojg 4O6maWnaUthx3tD9Njt8+VghUY7HE1yILqZPZTp/HMxgXlJBkVChDgrXapGso6uLmquR p9aR2jOzuy9yqSlTafpGE+BTsAKiXpT4wjHouZwFahlkYoHtqBqs2iNzzj+YDr7YrC75 8Phg== X-Forwarded-Encrypted: i=1; AKwUvBwp4dqEywNftH8keJ8gUuQRud+ObOs7ffb5GGgwJuA6aiCwF5MLMygWYUCqk+TadAyY2MqlJCfnWtKLmzo=@vger.kernel.org X-Gm-Message-State: AFuF++n83RfvhZKHVFqmPc13+xgX9JSzRfKBS3GoR4FJFvldjpyUmbKp KXVi+g5ybwGY1twas5DdiTmFitWYL7juR8j/bjABmYdg3qLYU8nUH0l9 X-Gm-Gg: AYBFou0w+pUjkZyNq+jdMXSNYhW0X2/fv1wLhsSr1cHhlgQesJNbaZrnT8tJ8D0CC+7 VnAgN4zVx4Wo7RWt+3etGJ7Fad6nK9flRB606dJSK567QQ8tACFRJBB8a1csUJfTJmkSAF2lmR/ LFkrzVCymxuSwETnijX/7BOfZXcA/JSwb/cNyngQjL9rXw2JHvPFrIrIpdJ+WCdGnWPKzIn1XAQ UzIsV/ekPEZM21usdmBDiZwBv9gUC/WyzqW3GkQCOKCx5Oe9PKw6oEXNfZj/Mj6BDOI/7r0jAX2 5+o3x7mhnWt3TXTg6F35cIYUN8W4+M1VSAoCPH7c1psuKIzFo8WplAd1Rproyiyt6gDZY7c4DYq v5kucRusaYvjnqs88hCenM+Yqfc/EBH9kiWkoLWyYaoywxvLMOx79ZOcsx1m0H2LE+0rdFAg9g/ mUnMv0o5Y4ADkF/wUxOgGUGUIoJ0lljvNBKVoPBLKjcxI/Pj3QuIrr15rpVSc9vtI4HA== X-Received: by 2002:a17:90b:48c5:b0:398:9be9:ab8c with SMTP id 98e67ed59e1d1-3989be9ac97mr31388074a91.17.1788214098842; Mon, 31 Aug 2026 15:08:18 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990d7bb9d7sm1776642a91.15.2026.08.31.15.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:18 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 06/11] f2fs: describe {i,d,id}node block layout dynamically Date: Mon, 31 Aug 2026 15:08:07 -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 | 32 ++++++++++++++++++------- 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 | 5 ++++ include/linux/f2fs_fs.h | 26 +++++++++++++++----- 9 files changed, 79 insertions(+), 53 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6ae0eb37d20f..751b7a457d9a 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(sbi) - get_inline_xattr_addrs(inode)); =20 phys +=3D offset; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d2e54573ed34..247e56522441 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1853,6 +1853,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 +2251,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) ((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 +2301,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 +2317,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 +3293,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 +3306,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 +3327,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 @@ -3639,7 +3655,7 @@ void *inline_xattr_addr(struct inode *inode, const st= ruct 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_SBI(F2FS_I_SB(inode)) - get_inline_xattr_addrs(inode)]); } =20 diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index c15c6ba91597..f15ab07a7347 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(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 0dce97aac5fc..6a2b7c63f4a3 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -252,73 +252,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) @@ -378,11 +373,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); @@ -391,9 +387,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 @@ -406,8 +403,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) @@ -416,14 +412,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 8d2224e585d3..fcaeaacaab33 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4384,6 +4384,11 @@ 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 (sbi->blocksize - OFFSET_OF_END_OF_I_EXT - + SIZE_OF_I_NID - sizeof(struct node_footer)) / sizeof(__le32); + 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/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index d1059a27e1b9..3d0fe2c78e12 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -16,6 +16,7 @@ #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_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 */ @@ -343,18 +344,25 @@ 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]; + * + * 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 { @@ -373,7 +381,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 13:46:39 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 061833B7772 for ; Mon, 31 Aug 2026 22:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214103; cv=none; b=UYrv3o5BHeZo01eEfVYm7fE3mSsKD5D5lWf58RQoK2Bb/xySuyFqSIjb1wcDzLfHF+PvxyXifPQz7arOB5bpPvqcOm69RUvGgjFk+HzjbSP2cA4tJTsh//ffO/U7Jy7++O/C8Poy797G2Ndw2sMz3Bq+GnwqYXb/ZMJMUogpmCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214103; c=relaxed/simple; bh=jTmvmjXg1/0UaREBco3p+0viQC0YYu7/puGz2WO4k8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uv9m+CZTTbR36/SDIK1WRS4I+IiILAGTBgfgGrpRCkYnYdZFm8+nFOq7GC+dNjoUO1Z5zCRo4VvA2m6U6t+hpRjaiKMcA7vMur1nhUMhdd3KemZdmNG6fvLA+wzoeRv1DNw/nA7MQmC61ufSO+QBD55xNYjvO99a9v9Y5R6mjzs= 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=kqMmRah5; arc=none smtp.client-ip=209.85.214.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="kqMmRah5" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2d8fd3b729dso20311615ad.1 for ; Mon, 31 Aug 2026 15:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214100; x=1788818900; 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=NCI0OV/FT2Wv0ZVg/++5r9fvRHaFYSFdep74WCObUkQ=; b=kqMmRah5pujNofle6BEounIQOaV136PG3+Lk+bLtMvJ64AWAN65UjCYZenJYdQm6vL GZRfUQpBnUA4k7rK33zZETlBMnVD+Hxjcq6PPhphGlGm3SAVtSJD74Cx+gkzYwIjpRqs W5XUFTfk/w0AzbAr1J/qLL2HXBPtiH1/0dnVGOcblO84+XnDZfBKJOP4R6uLN+cL7RtX sGkRiGqSVGEI6tgipnDuFSzzHEYbhDS1DHKd9idBJoD+ESlb/bi1g1I92g5CMdM4tGbZ WtSB6bIAo2VB+NtWtZls5gt6/JSLIJbU7Kq7Xio5m44GEWb55q2wLvmcLQdnvswRhWeY I9eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214100; x=1788818900; 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=NCI0OV/FT2Wv0ZVg/++5r9fvRHaFYSFdep74WCObUkQ=; b=q1/+hmddfOiZ4F+iw9T87ThlDfv+Zq1dtNGvtRo6wK3X2pWB60AHkZaufZAH+c7h5x b2fDS9OzBCcjFRNaNgy76Ip9BoWrSihrLQt18kWib3cVTE/67251mmJfztYAo2W1Z+k7 u7XFnjFp9cjiYWzs++vSWTtBJ5TmuhsJHaqBLx5+Erj2JIL/3x932behllggwy5XtI64 pDfLOj5NfdSRI6vE8RySlmk9Xl3+qWeGlVoOKTusQROqUKnyPd5My+pnVNum1oqCQEDe Cd1Fen0tr8Y62Tl+/R9Z5RYJ2IEkn4bVzCOKfNmh2oRkH9PxHBupDHXj51ZJ+/ae4hsB 0wag== X-Forwarded-Encrypted: i=1; AKwUvByC7BtxdrEZ/QixLjbUytj83MOcmTRq7yDQ7ri8OLHgl6dQG8qW6RZwv+cwlCl5lv5XR8cx65il2ihQFHs=@vger.kernel.org X-Gm-Message-State: AFuF++nq8u7x65TTSZv7LVhqeJ2WLQWkGZSM/HCGO8Ib6o6cOCzG9+OK ZOe3Ub6aHmNmBYjGeC2QTBIxqZEpjd6LkqlOFPV5kijjwp3FemkoqK3c X-Gm-Gg: AYBFou1wobQGkJ3A/kB3POb1XrFFj3FE57m9fBexEJCipddxZ+lrtht8OSQEU1gyXcO NFrsepVctqZMNqO2Bj6wQu59LMdX0gmO4Hcrt5dbLWC+x0x5+f/uxM8pzwRkXsCEgxIiMtW7qoK JIBXG+c+RdzGDWNgdkYhdN6p4/bPds653jnHh25Aj7FPSjQH5xuVmuuJ8YvshQv0n8f8HSc0Dbo M3/BG9/kX99YPO+rhQ7dmSfkoMYQaRcRGZRUUHFpelNzBNC4KNAlFmqT3EOdzk4hJ3Q/SC2mVBM pvVQLiZn3PsSO55q0/B20umBt7giKYEuUr3Is8/K3drCu+/Wa5/bWZvYn83HjxLZROH+wDuId3x 1SK7TgovzOmyF2rNEOIbHb46t3fiJc0wqoaNWCsCwNIqvSM1k2HrYuCZ5Oi0WmxKO4jLIoMESHo 4FEGic07yIaF8HbLFGoja2T2B0xH/sVLfSef0F03koCOL6vjaM77Zm7Chl9HkjMXXfCg== X-Received: by 2002:a17:902:d48b:b0:2d6:e401:9676 with SMTP id d9443c01a7336-2d94a713d37mr44957745ad.1.1788214100179; Mon, 31 Aug 2026 15:08:20 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d75952f3d9sm41516375ad.25.2026.08.31.15.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:19 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 07/11] f2fs: describe xattr block layout dynamically Date: Mon, 31 Aug 2026 15:08:08 -0700 Message-ID: <65b4a84c4504019ea6b208f424917f9df4eed2dd.1788213716.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" 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 | 4 ++-- fs/f2fs/node.c | 2 +- fs/f2fs/super.c | 17 +++++++++++++++-- fs/f2fs/xattr.c | 8 +++++--- fs/f2fs/xattr.h | 15 ++++++++++----- include/linux/f2fs_fs.h | 2 ++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index fda9ee3bfc61..20b0561fe35d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -337,12 +337,12 @@ 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(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", __func__, inode->i_ino, fi->i_inline_xattr_size, - MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE); + MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE(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 fcaeaacaab33..3ba4df757213 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_FOR_BLOCKSIZE(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_FOR_BLOCKSIZE(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_FOR_BLOCKSIZE(F2FS_BLKSIZE); + + 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 bce3d93e4755..d9e2c65a1fc7 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -71,24 +71,29 @@ 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 \ - (DEF_ADDRS_PER_INODE - \ +#define MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(blocksize) \ + (((blocksize) - OFFSET_OF_END_OF_I_EXT - \ + SIZE_OF_I_NID - sizeof(struct node_footer)) / \ + sizeof(__le32) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) +#define MAX_INLINE_XATTR_SIZE(inode) \ + MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(i_blocksize(inode)) #define DEFAULT_XATTR_SLAB_SIZE (DEFAULT_INLINE_XATTR_ADDRS * \ sizeof(__le32) + XATTR_PADDING_SIZE) =20 diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 3d0fe2c78e12..d4151970ae86 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -15,6 +15,8 @@ #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 */ --=20 2.53.0 From nobody Sat Sep 26 13:46:39 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 835BB3B5311 for ; Mon, 31 Aug 2026 22:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214104; cv=none; b=sVFutdTVJ4iOJzhGFRJikl76TUnghGJURDyBPAncDRff9j6zh9DgsQ9IZz09BrdvWAVQ7GyaTFs+hsuPO5DIjmvSeyJxxDKDKqFZL873w8sDGiM28ZRV4Nh7bFhO7EtU3Mgky1rpNmTYXvqHc7ioydtop9lhkbTw09qZEDT6kCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214104; c=relaxed/simple; bh=SCdUmFZa54url3za5OonSDGiKjxVc+gHlagNL3BRmxQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YrD4n98QbWBxRgR/dQw6BKNFjg1bxcicoCpykHijM6rqncRanWb5qRymQhMP3mN3qpADDPFfq3uP+tlsR+TpJLnRHF6m0ANxzkSMzqDEdBzoAV1bjK3RyFlaSod/U7TCV04LTijwV/BvAck/Ew6FcCJyoa3AuQ9lvh+0C3+quBM= 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=Xy9sJaI9; arc=none smtp.client-ip=209.85.216.47 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="Xy9sJaI9" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-38e58034d05so3407158a91.2 for ; Mon, 31 Aug 2026 15:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214102; x=1788818902; 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=5OG7+sQTIvAIIbYnYVYVp53dHRLfqDE4yCuONUAxpKs=; b=Xy9sJaI9+do1ypS5Wr/TDw9EtC630LbmjaWLAY/bdf8ztkLFmaNQAfXuwcvQRkX0x1 +tcpCoHp+Mtl0angrOTygq7JtLDjG8QbRakWNl/U8x62Rso7r1sJk4p9no+vu0dIK8Fl nserKfx4z+XViQmPgmXZeNtHCDUwWrmubKK2NNKv1d5YD6v2Bro8C4NkU5xK9Pt5sGtr Q+mqfYzTX6t4NwPOD1pd8FHA0ifnATPIe0Rp9TTc/PgPobslY1yMfQykw+fSUCrl0Lw3 L55L4o0x8Iju9V+Mv9TPPKrEqW0w398HYsa+R+HCwyqiFdHneJ1DEENbQTfjb32YKCb8 pUZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214102; x=1788818902; 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=5OG7+sQTIvAIIbYnYVYVp53dHRLfqDE4yCuONUAxpKs=; b=X+WXwsr128mim47W9GBQB5peE4e4TNDwu9C1FUtyRWB2d5XXNu8jmZvuRrkzMShMOY q2+UvDlFviVsgzEX0WaACriX/pU/aVU/OglJWuwNvzWkLrNTAedthRSwQQ6AY2mXij+e t4+uM8p9uXr0wTiCCbLhlfApQXYtyuJ/Mq4D9gNhgUdHZCNeCEZ0wKdttxxF0/QFlSp1 s94Xb+wvpGLrxK1rdkhXB6BaUEzvNcFkq6IDFjH2Zrrp5lo+9GgaUxoMqY/Nengl4wQO tCfhrgEMfg/1wsys1oA77AXsZ/MIGT5beAzs6xGvGJWFgI7S5akMtJnmk3GVS38d9gRf qmkg== X-Forwarded-Encrypted: i=1; AKwUvBx9GMbJuXO2pp54kPSyzb20G5hH0HFRPl7xit7m1MFFoHzcXeFfzUnbZnS/EG+PJlyAx+FhZ/OvcZCj/3k=@vger.kernel.org X-Gm-Message-State: AFuF++nhNJ0TLsr/DZBbZ2EpUO4Lm/tGeoIMt7LTg6fCx1a6V9Azi1PY /rdZtpF6/vXnQ0iugsMHAPSQ/xuCPhuVlsjGr66JiH3D7Cd4K6huBLzZ X-Gm-Gg: AYBFou1iYtlGh41bkValJIY22zlcbAj3/oj2OwBCWQccw/e2i+R7El7Rc2ltiX1RKmT qpH4TslwFS3V42yS19UHLoZq10nbNj24uBFcM3GTUx3abcmDNCqsMNzQIFXORSaBmPIIqqnANbs 5PuQU2FUl0wm6fF2vzJC/Gu/vAnrSUeimFnhRMjqVIBwj6xhbABp/INwDxHCJAZROtJUJsBtY43 mSLKnDKPndpG3CTwF2bBfS9ouCyzaG9iJbm098OLK+gsHX9lDGc9+3dXSn4TEuTynHSrNtaWuzC m1VE8Z1SnEU3CDur3srCtdFiitDm4SXhWxe2D3FWV2bVxlfyYyqfaxXWDO1CrutdbtRjhJwffQm ZBK3eiCaFJa2SWmi2YLuUu1CqGkR9bTcZwt1DWxZaoJ9UwACaB8+qg7RNXLAN3uB+ma0tL+ibYo 087j7ZhG8R01HBsf9A6sxB4m+uK7qkP4UWv+9EX3dTlyXf44es/RHJUJgsYGqKvjPuOQ== X-Received: by 2002:a17:90b:4a4b:b0:398:9be6:f999 with SMTP id 98e67ed59e1d1-39907e17dcdmr4198197a91.24.1788214101479; Mon, 31 Aug 2026 15:08:21 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990bd1dcfbsm1764503a91.2.2026.08.31.15.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:21 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 08/11] f2fs: parameterize sector conversion macros Date: Mon, 31 Aug 2026 15:08:09 -0700 Message-ID: <1ee43d8f316153304f71674f3b3c565923699ce1.1788213716.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 751b7a457d9a..44e1ae43565e 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 247e56522441..b90c5a42703f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2609,7 +2609,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) @@ -2815,7 +2816,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 20b0561fe35d..b628fdc4198f 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 || @@ -446,7 +446,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)); @@ -695,6 +696,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]; @@ -711,7 +713,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 3ba4df757213..46973207cd7b 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); @@ -4520,7 +4520,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; @@ -4563,10 +4563,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 d4151970ae86..f89609356be8 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 13:46:39 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 D41C93B42CB for ; Mon, 31 Aug 2026 22:08:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214106; cv=none; b=qAGhqMkVf2T6apKtWrvqn2EwugVwPhkjm34iDOh8bDuusgCdt4aZWV2rc8hTwe/TmMSrjw6JwC0x4KwB8sPuGt6XbAHyQMZKr1iX+7uLSdMdf5qnhqknRNUp0OyDy3CkAT13Q0XUq1w4O6j5tNSAuU2pX4nPbIkBDm6GO0+vdcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214106; c=relaxed/simple; bh=NlnZVQBKOf9KC30jcZUdhwwTPhv8O023I4p0tszqr9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O1Y4PVwgDWB2DHWY5Qv+G1LvTgo6zJsuYL4I9GQovrt6nhN2v971/hdTrsAnN1Mdau0iEMZ1s2jBg8vQ1GORd94JEQrVwUbKqq0ytNVwoKIdlpJ7ux4muchnB5pfLqTI+QWpsDAdLVE38mp82ABOy4imxoSI7fVgBXaifFin9Aw= 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=Jh+0HK2h; arc=none smtp.client-ip=209.85.210.169 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="Jh+0HK2h" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-84830c774a0so225137b3a.1 for ; Mon, 31 Aug 2026 15:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214103; x=1788818903; 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=H9DO0wscALDP0CiUo/XwHzEdwCyyV2LVPgR3YPOFqy0=; b=Jh+0HK2hiBzS+SpOMxyZnb+rzLxXmBOuPvYgqXZvJTkxiTNM/BxkkASery78HIR+vG dRaD96TlPAqtTpTYr2gcgiLUDx/v0v7sRojwRa4GuWCuP1ZnC3rADdH4REwXkNlcoxd4 OAOpB65XVDwSWGWYmpJEONos8tdsCV0ttjlJbbI+OQAG5z4XfV6X74GdJEG/7vGo8EHF awzXSMPyTutgvxVN6kjyX+ODrn+brab+g5sFlQR1Y16KjTyKIpraRMVuaEA4BMEvnJHC YCFz/Hji6B3gKtQGVAOqG6wK4l0JJff+KdlOGnHQuNoGsGjC6dOXLgw4QMw+ltevZHkh YanQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214103; x=1788818903; 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=H9DO0wscALDP0CiUo/XwHzEdwCyyV2LVPgR3YPOFqy0=; b=PCzFiWCgRafsSZo8d7GVrUHu3dMFkHmoXDuR6KTuuc+FnI9wDLuY2D/YYGLhAlUuhj VPB/H9FfnIAG29lTbSboyTHpzK+mgWKMon5kbFAo9sqXM0PljVYMDq6Y7SkIBnYJOHGz yrU3hNQtI0vPVMdoO4NFy0iNFjbT9RazO0M3YcLfIbGOq+nQ8CFOYlnG1ThRNSKj5U0u LjfxAY5j3OCjmGCBPcj+z7u2uhWHe0WuRDdhNSG3/z5yDBbPe8eC1aWAAA1EB1XPvbV5 9bETWU/+wa+HVOAIqQtknU37jf4GLMtCIKj9M9Kl35f6sMBBHfhNoEH5snSVmoI5M49B zhhQ== X-Forwarded-Encrypted: i=1; AHgh+Rp9M+CfdxkeTqzd0D0OHpP/Db6WlUaZuG/ukqzc+DHigSdP8pvQQeq9FX5snAe+BpQlC9MSkwB8sXa6Dx0=@vger.kernel.org X-Gm-Message-State: AFuF++kKcD33T1uPwdSmREriTs0KsTAxuvxiNtocVQ39G9g80sgLbDCT tTrg8Hc3sBwfdBGiis+I3G8niy3mP9AnnkUdgm9ffqPMKthZvFw1Psht X-Gm-Gg: AR+sD127o1wzg/FBWdV53XYIL6Xu6pPijoLA4elfEpg3KecAhJ/we9q0O/yH72CwEa/ /nQqSJE+PAZ1aQMsRWaJvZU24lepc9OKplYh3p9jPKDe1WPL88wUlnQ0jQKifxyrOSy6iFZPKDd qwEIslbeFRwDXT0zJLsBrwlxaBmzDcqG7nvSgClo7PdjPeiWH3oSfnMINeA+sQNFxQp7cKkHX6f 7OJASPRQ5LfKSJZguioEIlu1huyM6YM7j0U5qgSS6VJE2WtOjFjO4D4/lMKsBVgOpEvsraegPrp R7Ns3Rq3xp0NeQGj9f/NtY1tXhq0FQpZO/L9BBgPh+iCOHQSFgOea37JHJZgA1o+/171n+qcujs uwvgs2yGeSYGDiBLADgXxkymmFZmipUsj6GvZfxjvAcW+6AQ1D96C2nl/X3k0LWIEaAvPkLr3ol fDFvq1BNuxgg7dns4tnj0EPR2lNUzj2Xud2ENE6XbqXgsBxkNKbZ7oLpepPt1bH2hNug== X-Received: by 2002:a05:6a00:9512:b0:857:727c:a1f5 with SMTP id d2e1a72fcca58-857727ca45fmr26273939b3a.23.1788214102932; Mon, 31 Aug 2026 15:08:22 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85be5ca4abesm108506b3a.10.2026.08.31.15.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:22 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 09/11] f2fs: parameterize byte and block conversion macros Date: Mon, 31 Aug 2026 15:08:10 -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" 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 | 12 ++++++--- 11 files changed, 96 insertions(+), 74 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 37a72b693545..d0dcc918422e 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 44e1ae43565e..6ee4440c17dd 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(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 b90c5a42703f..c625a2572841 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4016,7 +4016,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); @@ -5263,8 +5263,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 46973207cd7b..b962c14cbcc1 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)) { @@ -5193,7 +5194,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 f89609356be8..f622d26f37a7 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -28,10 +28,14 @@ #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, x) \ + DIV_ROUND_UP_ULL((x), (sbi)->blocksize) =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 13:46:39 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 5E8A93C1986 for ; Mon, 31 Aug 2026 22:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214108; cv=none; b=EOtskr5j7F0fdJvSf48+TWdXYQ/NHN3d311aYen4yIQJldSYvDp+u7HWk9k8l3N2a8I5XEt2vLKxkqvcTowqU9ZV15cshxW3iavg5hmbk25HGWs1E1ucl9vaGAn4jn6qZifINre7YmKN5xPuHmnumyo6B+TYqCL1bykhppFRc04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214108; c=relaxed/simple; bh=wS5EOvQTpKNBGE62SR8cCPxFF15GYC9/ZmGB4ltiQw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHSFWRptpsvcrC6bOGM1H6dzDZrZrcyUezjn9HBaev6H857Q+3jF3w0DoH/CPI2AWrkCP5G3kSDNzuSOKOfrJWvlNpmDO+urW9Zs5IJdNoAuFj2bkn3RDZRVmQKoSXr96ZqYaZ+iBby1eRCohI9P9AJ1WQwDhcbiuIPC2EHt4Aw= 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=NOeZZh0k; arc=none smtp.client-ip=209.85.210.181 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="NOeZZh0k" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-84f3ab8750cso3135724b3a.0 for ; Mon, 31 Aug 2026 15:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214105; x=1788818905; 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=bGEBYtiy0saQqUn2f5UxlhfzLZ+y5Gfzq+Sc96GsWMw=; b=NOeZZh0kJYIaadxzIGqcHhKPTn/kAUWLA3q/L5+4wLVJBnvfuV0iCbaDBM27u+EjNk Qo1EG8+YtW4Vt5Cx4pZJBnp0nMU4plxO9OlwIHHh5o7k46r3ojnheEo0WHXJMB+hhtuU nK7VWT8tOL6MssCRp6y4in928nH8MOt4orMXY2+BJyxB7Mo3TxvBW7omteuxUOWEqvfC vSx/a1pLjRiM7hb1E2WTbZZlEmNeCVKw56HNw9WjzhUqRFsu9Qh1hIjwQmwCYwy34a8M ipCSPojxafA63DQkRWkCCuGNpyTo2MUkXM9EWtE/FYtYnzM8h8yt0f8TsH45DfyGcOMu waOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214105; x=1788818905; 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=bGEBYtiy0saQqUn2f5UxlhfzLZ+y5Gfzq+Sc96GsWMw=; b=oWr7cil7TjYgAeQfbOv9B7YhvMt5pvwLe5hp6KtY/hHZnOHn2UV1Gdieq4gU+v9ZFa 9uXwufMtm/paHso+nM9XGkHRaDwI/5TNrJzodDoUcqGkvMqMrQrQx8qqceFqZAvWfYxm 7Wa4P2wM+AW0MmdptKfjoJDR3L1cLgrjerdiN8sJfIQSGkMvFkgx4MzLY51facz5jwGd HwOt9Ar2DUpkSGWphPA48oD8V/v5yAqPZhEesTrco8SOsCOVj7Ks3UtzhZwo/+c/rwiL NLwr/yRMGAgf6LoszZTVUMEhpiQIcpFDzC7dIu9dnZqOyYPhw9u7HLziUhUbNSEgpWEu C6pg== X-Forwarded-Encrypted: i=1; AHgh+RrBqZlkRipjkIfSlxO7+MjlMK+PkLLUfP0ermTnwvdKPX9CfT2/oR5AWeedSbZOt2QQl0yLQftg8SKK3J4=@vger.kernel.org X-Gm-Message-State: AFuF++nbHDMTzO54IaUUs1bMHT1ADeOEuBeNf4ee0GpoAsyLud/Rg24D yuuFwcFGr/zCG+SAarw7+5ly9onKAyzSTdI+k9drLzp7a9WIZ/bdvAKr/a7+1FWBT+U= X-Gm-Gg: AR+sD13xj+PHrgZ2FNOdB5aiPMVlYWcAQ4zkJ8SrmAZqm897SkyUA8voTn5spASyug4 Lz7harOE0KY0ZsS1qJZLf/eMh95L+xYoiQnh0YhzB9XymM4i/xMRpTYXEEjhI9d9excqW5FyI/t XVNsLv08ixBz3V/2/bjFUm4TcBVm0e/j3XygbY85A0Kl4sAo8hvOUoHyATvmpQhyDViuwJWAu8W tRjm+A8g9qSSw7Gq+XvwkAXchSCqgu9Z1pQ4ocFc1bmY6FjacABDCd9lTIOFaPJQroj6LirpFnV ynAR5u9tp6xlmfS0eyuQwvM+jGK+mIemGOmfyiRR7U+wstMDGuP1IA2NdH+pxieI867KbbjYZjE E0q94w8yfRs6DIfvDz9+acLgGSwhCYGiRGt8/zsFytbX1OHyRysVegZ0LwqoHZ5UESrvgwC81A5 yKD4bEHV5lDtTTGYi0E/GoIBCTD5xbXiiAx2he9yhKmJAv4sk0ju0wJBlxvGRF2FSiKoB71G5Yf /9F X-Received: by 2002:a05:6a00:181c:b0:84e:e741:174f with SMTP id d2e1a72fcca58-85b59c69513mr4794654b3a.7.1788214104404; Mon, 31 Aug 2026 15:08:24 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85be9349383sm93839b3a.44.2026.08.31.15.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:23 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 10/11] f2fs: parameterize block size and mask macros Date: Mon, 31 Aug 2026 15:08:11 -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 | 6 ++++-- fs/f2fs/f2fs.h | 15 +++++++++++---- fs/f2fs/file.c | 30 +++++++++++++++++------------- fs/f2fs/gc.c | 11 ++++++----- fs/f2fs/inline.c | 6 +++--- fs/f2fs/inode.c | 4 ++-- fs/f2fs/node.c | 7 ++++--- fs/f2fs/node.h | 2 +- fs/f2fs/segment.c | 18 +++++++++++------- fs/f2fs/segment.h | 4 ++-- fs/f2fs/super.c | 6 +++--- fs/f2fs/sysfs.c | 10 +++++----- fs/f2fs/xattr.c | 2 +- include/linux/f2fs_fs.h | 22 +++++++++++----------- 16 files changed, 107 insertions(+), 84 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index d0dcc918422e..015c7449e45a 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 6ee4440c17dd..d7b22eaa746e 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..2d3fdd82b13d 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -904,11 +904,13 @@ 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 + * When I/O is not aligned to the filesystem block size, update will + * happen to the last * file block even in seq write. So don't record age for newly 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 c625a2572841..f83cdab66f54 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2234,7 +2234,7 @@ static inline struct f2fs_sb_info *F2FS_SB(struct sup= er_block *sb) return sb->s_fs_info; } =20 -static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) +static inline struct f2fs_sb_info *F2FS_I_SB(const struct inode *inode) { return F2FS_SB(inode->i_sb); } @@ -2249,12 +2249,18 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const = struct folio *folio) return F2FS_M_SB(folio->mapping); } =20 +static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) +{ + return F2FS_F_SB(page_folio(page)); +} + #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) ((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)) +#define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) =20 static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) @@ -2303,7 +2309,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 @@ -2319,7 +2325,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 @@ -2968,7 +2975,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 f15ab07a7347..299d5310e597 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1303,8 +1303,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); @@ -1424,9 +1424,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) || @@ -1477,7 +1477,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 b628fdc4198f..b947b724b3bc 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 @@ -447,7 +447,7 @@ static int do_read_inode(struct inode *inode) 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(sbi, - le64_to_cpu(ri->i_blocks) - 1); + 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)); diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e7aa3b790214..8d16715a3aae 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 @@ -1498,7 +1498,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; } @@ -3311,7 +3312,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 6a2b7c63f4a3..32125f8fc753 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -284,7 +284,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..2c85c085961b 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -116,7 +116,7 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int= segno) =20 #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi)) -#define SECTOR_TO_BLOCK(sbi, sectors) \ +#define SECTOR_TO_BLOCK(sbi, sectors) \ ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi)) =20 /* @@ -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 b962c14cbcc1..ca6403a0ed88 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_FOR_BLOCKSIZE(F2FS_BLKSIZE); + max_size =3D MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(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 f622d26f37a7..957bb713ff24 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,15 +24,19 @@ #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, x) \ - DIV_ROUND_UP_ULL((x), (sbi)->blocksize) + DIV_ROUND_UP_ULL((x), F2FS_BLKSIZE(sbi)) =20 /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 @@ -221,7 +222,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 @@ -271,7 +271,7 @@ struct node_footer { } __packed; =20 /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ +#define DEF_ADDRS_PER_INODE ((PAGE_SIZE - 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 - \ @@ -279,10 +279,10 @@ 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 DEF_ADDRS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / si= zeof(__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 NIDS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof= (__le32)) =20 #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) =20 --=20 2.53.0 From nobody Sat Sep 26 13:46:39 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 A431F3C2798 for ; Mon, 31 Aug 2026 22:08:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214109; cv=none; b=jVA7v2h0RAOhUQoknJvJxJVe43ZHuh4faAOWPn7EEVfgC3ySgUz4e+r4kQ9e3FkyhVgZgUdJDuOp7xXPAK5srZoXSqOAxWsDhVIVagN9I5KR6MO2MClNGGAwrBhPCnhaz075PQjLJM8ik0tCrDrE4VG2+6hNirwJqHDcla5xJsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788214109; c=relaxed/simple; bh=MOoD3EidD6YR3ERZ42TYxe/W6fWahswwQZ6tImAc2BM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcVLPDw+lWDlw7ucEz9lKbVukn4yj3/fEvDPjCPwOQ4Co67+MZ7OApZtL2R2Yqf6Fez8Ng1J5uOcLe7I4GDxNiqDviWqbjKrCek7HYKt2yCB2F72Oy6OGEgLVGsOg+IK/dvkM029EGxPjiwion2O8c+9mSsdt/MlD8BeNJTtBD8= 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=RaD5KbFL; arc=none smtp.client-ip=209.85.216.44 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="RaD5KbFL" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-38d489b6b71so4614387a91.0 for ; Mon, 31 Aug 2026 15:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788214106; x=1788818906; 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=pzD6Qgco6utzkju+m2uoC36z1vRssf5I1H5k3p9Aq34=; b=RaD5KbFLncykwDYb88/ixl24qmEAEKo8TO/EdfjYQBInvVqaArSvmrEeHX60c6rFZb uSeObQa+d99x2r6MckiEwkjGgkUeg8uosZ6+fChhCKfuDgBQxr+s84tdAx2pOsQfrYBk oyghbvprUUfNsC+Ql8OnmN36SfgCXYdhKEUzTzK+EeIqKNb/SUCJoi8EWYiJEhe6jwmu gTbGyoNe/yIs6d7Fmwa7c1294Xlt+d/mRdA5UyeSrH2o55zPLqz79mZS304PNDGf7SXn 7f3HYOCXkbOCQfj7Y0OE3QmNVxK0A979vZHqHtcxsawu5VjPJTeNptJuT85o3vqEMssH u3Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788214106; x=1788818906; 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=pzD6Qgco6utzkju+m2uoC36z1vRssf5I1H5k3p9Aq34=; b=aAtcy0+gdyWmRYUQpwFMINwMRepz12Sdw8a3hLhEr8wsSDZK330PKxQF48KQuCn1BC 6CMxFlic7NH5fWwlC0XdOQhdf6KnywMp45sVjGYgiAMBySn5JdOHIeExQjWCdERlwWI6 7XH0gkKEatUjzl1ipjTMkse7geyhtkgCiimHb443kILllwXWkfjfV7ZCu+7RPIgC+7/h PVQvp6JT7mWL711H3MUm9d1G4jkyaL1IYt45HPyHHkcitNVt3NDxcyzyWIasXA7aqzD9 WNAz0/RhnElO14iGnzQ/8vQAeRD6T0BEjBKUwwOPIeYWh2Y0PTql1ATnVwGJxBDVurbC BC2Q== X-Forwarded-Encrypted: i=1; AKwUvBwwuYtKPSGP+/G4GPX3esd8NnK9yGc1wG1nvYluRDAFK8K7l/adPzMOhRyDumRjhj4HBJnSVmZ9kUPGs2U=@vger.kernel.org X-Gm-Message-State: AFuF++nOw4RL8MYZaLej8jTR87aE2hCA+KqDqxnC3tYsVVLrGDLRaggr uPl4NTWzPb4FRJzVSZTb95afP2RzrY9cV0w4pmMIkGKkp+CPbAKDUwH+ X-Gm-Gg: AYBFou2ckmIrinC4WqEe5jbrikneYOuxIRPSPoHqQ4j4y7IPV3OIWheSu8yDYOG/mmL Mwjnszmncjb68pIsTBQsvxM7AJQAbkm7cZH8nfJ2UGecnt3+pbqVSv9mm5m8h56k/p9tnW9X9+B 01JpyKspd+J4vJQmNak5Pykc+31eejFMmjrX33F5O9lwpFMEvd139ernRsB+I9xNi7hdL0z+3L4 tXuVrctI3nCyBMvgXf9UPyEjn4eT8r66wXnQIJsXyBAsJ/uPu/yTzrWumk5jays0vxme8E8ZUQr jdV7x00fDF6NGxWatL+Q3CrGJ4+QvNUtKKHcX2y0iAZcFVntbAd9hSRuyeILXHdqXce3aC06hRS ivTjDd8DWdpaUP0X0tSPaSFu1Ip3X7woV2ogZ4Zt2fRMU/gVUVHVyw5x6XW+nAuyhj1Xlp8fSfq WPW344S1RVmuSXPc5ouRM51P89/iE6cg9rQk+pzbSaytrxvdYY3oRJJhHzpKYLS920YA== X-Received: by 2002:a17:90b:384f:b0:396:40e6:f631 with SMTP id 98e67ed59e1d1-39907b6759bmr4619796a91.3.1788214105846; Mon, 31 Aug 2026 15:08:25 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:91a4:c2d8:1d54:21ad]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3990d75b540sm1704841a91.10.2026.08.31.15.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 15:08:25 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 11/11] f2fs: describe node tree geometry dynamically Date: Mon, 31 Aug 2026 15:08:12 -0700 Message-ID: <48104cd0c1fb5198a8f48e473ce13c4b89d0b5de.1788213716.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" 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 | 19 +++++++++-- fs/f2fs/gc.c | 10 +++--- fs/f2fs/node.c | 74 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 18 ++++++---- fs/f2fs/super.c | 6 ++-- include/linux/f2fs_fs.h | 18 ++-------- 6 files changed, 77 insertions(+), 68 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f83cdab66f54..e1f33ac24c6e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -602,8 +602,12 @@ static inline int update_sits_in_cursum(struct f2fs_jo= urnal *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) +{ + return DEF_ADDRS_PER_INODE(inode) - get_extra_isize(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 @@ -2257,11 +2261,19 @@ static inline struct f2fs_sb_info *F2FS_P_SB(struct= page *page) #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) ((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)) #define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) =20 +#define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 1) +#define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 2) +#define NODE_IND1_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 3) +#define NODE_IND2_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 4) +#define NODE_DIND_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 5) + static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) { @@ -3650,8 +3662,9 @@ 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) - - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; + unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - + 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 299d5310e597..b17e7ce58f2c 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(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 8d16715a3aae..68a95d703c4a 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 32125f8fc753..66898288b961 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -354,17 +354,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; @@ -372,13 +373,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); @@ -388,9 +391,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 ca6403a0ed88..f6c492f76f0c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -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 957bb713ff24..e43ac6509550 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -271,27 +271,15 @@ struct node_footer { } __packed; =20 /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((PAGE_SIZE - 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 DEF_ADDRS_PER_INODE(inode) \ + ((i_blocksize(inode) - 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 */ -#define DEF_ADDRS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / si= zeof(__le32)) #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) -/* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof= (__le32)) - #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 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