From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33E8436896D for ; Thu, 3 Sep 2026 23:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479662; cv=none; b=G9JPE+BRcgom+JTjY0E7F82jMeutDxKsdtMxKoZjU0DZFMg72wX+1qg3BhQixWgnv3DPMuHTSdM1aEQHrvEIcnpsVq1oYFhZESiEj3kw1NbvQjgJEel+MvxPZqwCoBioTJ4BEP8O9hAnMa+OyXyYVMIzol+2jDSAluYuiUY8wSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479662; c=relaxed/simple; bh=ZADxnoT0j0p10TKrdx9DXbb6iuHuK7Yn9OIArtJq6RE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WfcbFVfL+qHbSGFJpFnoTg6SOVDjDM18VAOjgkh50AggMEPccya8WtM+4eSA24Lg0I9/QFRGtIoyzhS4bxnm8VV7Fd8CVmdp+iSiSIivGlMPdsPAsFeSVl19W0zvVNeqBnjp1mmayWHYGnKyp2E6c6vdT5RccElCHJmWYorng3U= 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=c1pR1F6g; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c1pR1F6g" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-cc1a4c62804so476928a12.3 for ; Thu, 03 Sep 2026 16:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479660; x=1789084460; 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=AEnmAlX/LH/SeLgbqUjIwUEnaiBZCUaJcuwBR8UE3MI=; b=c1pR1F6geQeTzVBBbDWhrY31n7MXZX1nCcmfOsGeZzlPHrRLFzWzuh54KND1Y5WnED kCB1H3l2qinrf1ZM/Jm2ys1SQyAbezjJSw8ZnGGS5yTM53hGAl7hiKIsAqL0olm2hxPC KReXZsrLjJz4uXowxmDMKyRvU6eRgQ5tCxCo0oavk78Ggs9/jql2I14ZwlsDs9p6dAI/ k5Hc8S6zK4jHDC2nmEA+KoUC9VmTu9U0FD6UEPcUKPwnqH7t2/HlPISWuiYySQUJrbai IFyEc4Yf6Loc0/qzR2UEiN3YW1f8sDMMGcxtUx+wgu8UgtI32rCie2pIcZPFfzm087h8 54RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479660; x=1789084460; 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=AEnmAlX/LH/SeLgbqUjIwUEnaiBZCUaJcuwBR8UE3MI=; b=mWOxDSwWJC5lLUWrmLJ8iz4Tuk6CA9RzaMcXVVm27NYfO0meY/TXLZFM40T/9KyLNb IdY1+mU8r6Rh0bXJsxwtgE2UBEGWVs3hK1qpA3lhfYPglWU/pTomcdtyiDAi5ORuTZpw hjBx12F6IgOdbjTDGxi9Dw6egscH8SjlR0tJba0yDtQfbqWtnVoCBfRfBNEs0eASbGvF 8scoazAtP7vGEtZABIUfuSI/iRIzoajq15rLVD0kHLa11bXnKSNfCBYPvu8Z8E+O3N+j ffpPiJhw9pQTCTWbCQJAtDOs2IY5iEo1uQBBYYCWuZzXroc2LhN2GqEHRD/bAGCLHPAB 69kA== X-Forwarded-Encrypted: i=1; AKwUvBytxNnV0Ar57l042yRufQRUkDuUxsamqQkLvq3kph/X/6gkGHLJk111XZ9l4UHoA4G6Ub2tMX717H4PJ/c=@vger.kernel.org X-Gm-Message-State: AFuF++l//+z9byi4OlviGEoh5zqP2QB7HGVLQ2NW+gmZ2pfMGzp0/Ri6 m0GKi0pWPSbLjSzyZrUjalKHWqLMaPEQaIjDdNY3khxDmmPNFEBX+krU X-Gm-Gg: AYBFou0CvcEO2Z243JHNvzmt4AfkJ0ZXxklb25q7Ot4+cLS84LyQ+AIWy2UAS9uow5P Kw9Pc54sNhX98my98j4q+43o72FC3oSGa+b5MDBbpDeY9QC+vDH4KJkD4ehWH6OiJ5ULwlV4zMG QzYi2wbbnzk6WFD2p8POs5/bTgfp+Nc6dmcScZK9FFmbOFaH2CjTddQDDg2zE+fw+zutJUCKqMU 3rV5QjffXv7Zn5nAO6l36oqxQDS+tIoH6SPCyd2b0moE/gMj/PMNVCCbJpuj46YPX8Qq8NytgUV o+kVJPDm9mNlzdPMITftv+3ESEFaUo6O1OHKLh/EuJWJMeQ7Am/sHfUwnI+90V4GS0wYCpTooR3 JsDSDIs1qcdSv0idkFo606HT/oiXlZrmIUoWdtYykC4h06OtRMCYDpFEXxDz2XmqpjzKMqiJdT5 UL7XngYMkIlTAn0pufcoaPesmwBfkDeyjUf4GcilMn2GwSODFQnZv2/QW8tEZNYydmCXqac7+KF K3q X-Received: by 2002:a17:90b:1c0a:b0:398:d132:ba76 with SMTP id 98e67ed59e1d1-39b2623abfemr2881705a91.21.1788479660384; Thu, 03 Sep 2026 16:54:20 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1432424d27asm3699926c88.2.2026.09.03.16.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:54:20 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 01/11] f2fs: initialize sb_info early in f2fs_fill_super Date: Thu, 3 Sep 2026 16:54:17 -0700 Message-ID: <41898b6a3cc76d464d6d1d8774daae6c185e88b3.1788479509.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" 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 Reviewed-by: Chao Yu --- 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 1314b6ccced9..eda8dd8f4eb0 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5125,12 +5125,6 @@ static int f2fs_fill_super(struct super_block *sb, s= truct fs_context *fc) } mutex_init(&sbi->flush_lock); =20 - /* set a block size */ - if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { - f2fs_err(sbi, "unable to set blocksize"); - goto free_sbi; - } - err =3D read_raw_super_block(sbi, &raw_super, &valid_super_block, &recovery); if (err) @@ -5138,6 +5132,14 @@ static int f2fs_fill_super(struct super_block *sb, s= truct fs_context *fc) =20 sb->s_fs_info =3D sbi; sbi->raw_super =3D raw_super; + init_sb_info(sbi); + + /* set a block size */ + if (unlikely(!sb_set_blocksize(sb, sbi->blocksize))) { + f2fs_err(sbi, "unable to set blocksize %u", sbi->blocksize); + err =3D -EINVAL; + goto free_sb_buf; + } sbi->max_atc_write_bio_size =3D UINT_MAX; =20 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); @@ -5217,8 +5219,6 @@ static int f2fs_fill_super(struct super_block *sb, st= ruct fs_context *fc) if (err) goto free_bio_info; =20 - init_sb_info(sbi); - err =3D f2fs_init_iostat(sbi); if (err) goto free_bio_info; --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 EBA2F2C11E6 for ; Thu, 3 Sep 2026 23:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479787; cv=none; b=S58nCmQorwdWAjZTkD1SSI/5Li763SpjwX9OM/n6lcpOjExGT3Yvf0oQnYE17VeHwAnIjUgjtl+GI1i0qRNhEQYSdWu33qyl6YUDVh5dYIZ9BV/IK4Zhqb+cPoIB0tXKiVYSAaSlmeRQwLp2BfN9YJ2S2gR9LAZ8XI5QITA2IBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479787; c=relaxed/simple; bh=6TpaOv8NZYz3qN+vhzp+Pln0coZildUhq0C4eCSoU1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R+ugNL0zTcflKFbY8JGmKGu6w0u4fPS+U4nzp1TfamDFuFmxS2ueoeIcmIzfnqUJ2h9dvR7Cm1Qda+aUIga5yV84yovNV8pNK+slb/VUiQxvUn34e/aKVxZAqrjvfDX8JRA4ySd490rhtTyQ/u/SU4BBG74MRMPxiMpz1pnTuJg= 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=YlrUfqb2; arc=none smtp.client-ip=209.85.216.53 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="YlrUfqb2" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-38dfe910e9dso447924a91.3 for ; Thu, 03 Sep 2026 16:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479785; x=1789084585; 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=QzZggu0453tGRKVkTcHNa67VAVh0WqG17qQs+4BQESY=; b=YlrUfqb2iK0CGKMcJ9BCPg4Jk7RGe0Q1dzpzDI0POlb//1eJfkH9tUSlzK2l/f+Hub gl30QuZN9s+3kNnuD/8FZkMkoCgyyuHgiprUaau6C3gQhJp6IkQyHwLqzKoM//Xouevt ts8Zb7vT/16hWccR0E4QPvSvC18O77CslF7T/97nTiF/qgRLHm7KhuD3VANnRr2LfT2o l192PmtP/61R6RYTEX5ZIydM2f+p157olBWZy6PlWQjXFP6xOb3ewtQ4UWI10+uPWwv5 p+2ANVRIHQQyW27CT4KztFvywIeJn18G0nuNLApsIqxgGUMAJs0glfvd5MovmXRbpypQ 5nzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479785; x=1789084585; 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=QzZggu0453tGRKVkTcHNa67VAVh0WqG17qQs+4BQESY=; b=GyJrwYkMSOJBmuZgeSTS+uVp8IKTZ1KCihizQFZYJwIf/27xOfhCz6WqVW2hAFulFv y6xYp0jZ80two4JEd0XwIprUSmO/1NhvtUnZ4LCzQsfUEf/huAPIGM8Vkzj67676fXKz 7PP4afMLPhthkQTIFUF5gtiTZ1so2/tkMj31VdW5S8xFI+oLthsalHoft6wUYHBPoLM9 gkHAxgkoDzpCsKOWkFoJoyW2gzv8sDYqlOeiVKvl+RibkWMwpOSwJiO5oUm0EnNl7PZr h/CQzTIapL9XwKCYdx0tv22uHpDHFZoMyXYZ7ejDIOv+OjYDFqYKUMrqdnW7FrpV/SBn MLsw== X-Forwarded-Encrypted: i=1; AKwUvBymsR4N/sEFrTL4Y3gfhlxEN7mWpwMFDMDVDQvQG8+Tw7GdPK3VAmumXFwzi//ia0F1lTsW721/j/Wcm1w=@vger.kernel.org X-Gm-Message-State: AFuF++msIju7ssXmsMMfFOcFZd3Rz0zq3vWTiEMwMHqmGzzPfJ1GmpTh 45wUmtoTA2PH4G+fpk3zwu+rgaHeV/LkyWsncJTnj7Ue07qZY5eUZvHw X-Gm-Gg: AYBFou2Lx4D4dqnc+CFIr8Y35bQAsjK8B4Vl1lZicM65WQbaDKnUJV3+sffeXSDeu/m hd8jI+K2qslAOwIZVWbC5yUhWY0urjtj5SHka/9ykoaXLZo3CXb+T2iIDQS9IJizo4bG7yrxapo M6NnbDtCCArWIQxkfX709Q5kAm9wCM/k5+tbig6FaluoQg8XLZ3uDJzkcZVF12Fi0cEXfT2w8Ph Ac+IJKbFbc+mJQcYsiYC1nHj2kuAeiEupP0nVs1UDNWm4s6YJXizr0VIjNI7KWn7VAjtxSuiio3 Lfjc81W+HwajVRp6NhsQG0cwWG6u54p71F+ZTvpD2+AkuxrdZqAt1er4/VkHANpyQ3a7M0DA16E QLL6roC7XHW+IuK2HmiVKqjKZu1l0LXwDSXszfCahw61C2nK5YFSwFDWzksCPgyrIAKukc6eeLX pabTVN85ABjEeXMf30O53K7gSLhTgj7L3ffV8BDB4kwBEpQ2Gqv4PsEB1HImX4bSZA4foX+XDIo q8TBQ== X-Received: by 2002:a17:90b:2ccd:b0:398:b88c:2b7b with SMTP id 98e67ed59e1d1-39b260d7297mr3541846a91.8.1788479785112; Thu, 03 Sep 2026 16:56:25 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-143243a9388sm2373680c88.10.2026.09.03.16.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:24 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 02/11] f2fs: describe SIT block layout dynamically Date: Thu, 3 Sep 2026 16:56:14 -0700 Message-ID: <10843e36038ce78374ef20fe8c19f6ec392bc078.1788479509.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An 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 Reviewed-by: Chao Yu --- 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 cf88b463fde5..7fcda18e9cda 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 2f7ab5888b07..cd49b03befa3 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1862,6 +1862,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*/ @@ -2250,6 +2251,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 63b712d3d599..2427649402f6 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4706,7 +4706,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; } @@ -4745,10 +4745,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) { @@ -4773,7 +4774,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) @@ -4791,7 +4792,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); @@ -4841,7 +4842,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 @@ -5006,7 +5007,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 eda8dd8f4eb0..4e10a84b4142 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4329,7 +4329,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) return 1; } =20 - sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK); + sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK(sbi)); if (sit_bitmap_size * 8 < sit_blk_cnt) { f2fs_err(sbi, "Wrong bitmap size: sit: %u, sit_blk_cnt:%u", sit_bitmap_size, sit_blk_cnt); @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->sit_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bb2b6cd5d507..ecd6694af572 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -396,8 +396,6 @@ struct f2fs_nat_block { * Not allow to change this. */ #define SIT_VBLOCK_MAP_SIZE 64 -#define SIT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_sit_entry)) - /* * F2FS uses 4 bytes to represent block address. As a result, supported si= ze of * disk is 16 TB for a 4K page size and 64 TB for a 16K page size and it e= quals @@ -424,8 +422,13 @@ struct f2fs_sit_entry { __le64 mtime; /* segment age for cleaning */ } __packed; =20 +/* + * The on-disk SIT block is a filesystem-block-sized array of SIT entries. + * Its entry count depends on the filesystem block size, so it must be + * calculated by the caller rather than implied by this C structure. + */ struct f2fs_sit_block { - struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; + DECLARE_FLEX_ARRAY(struct f2fs_sit_entry, entries); } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD8DC36896D for ; Thu, 3 Sep 2026 23:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479789; cv=none; b=OvQVR56Mkx0MKyZvKXEulZPCkzUB9MaihffQydL54IyE68kdq6F4SvlmYI59a6j7Kkpem482SAjHlRtTRPPylWI/jcOGzDhWXnpky2cBO3rO+O357OdFjh06KV5An+aSoa6XG6gbW7fe0JuEEsIK5WPuKQ/CQVs2q5YnYuBFTiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479789; c=relaxed/simple; bh=vC1CUYkzK+qnMUAtGHX5q034cQp/lYccnZj530d9KEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Olrf+sOwN2Gn09PHxHKsJ4lAMEfyfDvgFLt+urHL/sUQoRPZSFlMycVM7debjOYFa95flD/OwoHq01Mu4U9n7oRjLejhF9HH7l0vtiWmfPEGifZtcnS20SSTiBB7E1unbT4hLEN4EQa/gHkpfEkUEBliRGJq9+PZpuZIhemV7gE= 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=rlWAqwea; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rlWAqwea" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c9e7391839cso550163a12.0 for ; Thu, 03 Sep 2026 16:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479787; x=1789084587; 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=6oFvp6pDW30ShI4O1VgYqyh4zbNIYVo/Za5v51Hl8OY=; b=rlWAqweapvN2qofreHN+YglVDEGA2PfwfXs+W6xN3FnGNbLmSN4w6ELBsO0ZSxK6mU q7v17bcCBDe80/4UP7l10GIX6Tq1D1552CE5Zav53MZC8Q7RSH4P+ObmaegVwEcrCgEm SqZ2Ddo67up9NpxmSoXPc/EwrTxVcVqENt8Gn5EiDFDj4SB96in37eCoC6gQHjYu91+N Z5Ia4jvpO5toHTq7jiRLdmbYYnRpgkv2nEMJoph8fR3q+xFvyv6Te3M6uqRfjCuXNAqm /EshHrAL4foOTRvCJmzXTQ4LGWAYkcp/LHm5PwOAt8HAaXjCig2pvdArrC4h05BOggW9 DOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479787; x=1789084587; 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=6oFvp6pDW30ShI4O1VgYqyh4zbNIYVo/Za5v51Hl8OY=; b=f1oLGMS+QIddb2mhxMn220J8FSMgCZ7Z+ioftLX1fxLYGIOZMQc0KAtpLdGubKgBeM oToCqUEoWqVdbZUB4uaAG5pVzEn9lBEMp607jEFzFLi4183501pCs2JroyV9J4JaqNM+ tellpaZKIPRcjYjI0WfYbjWmYAkyf58OoKOQ/6ICr3Lf7QvoZHfiUkFWMUB82SxLYvp+ 9XehtxXzLuJIp3eXzbf+/uUP8xy79t2v7CY/D4rMRYg1nNGz9A8UzvYqpkY9VYaRSJFW P0IvCW/wgfyj5zD4maLyC8uBOf15c+7nI6YhR8qZV1Dyb0mqBL9agIFJbQ3/SnSIf4vu ppGA== X-Forwarded-Encrypted: i=1; AKwUvBxUpvVKZKJOxK2Fkz1VjLCD8zcU0cgT25rkzqTOCxnHmV0oAwjD4NGOG/SNZuwVw7yekR54TaTyP8sAL5s=@vger.kernel.org X-Gm-Message-State: AFuF++lrK4oKgeOIwS8VHEAGGuaVMeHEEi48q6tl3wTePtyPGr0WUBSX Rb08WcKwD9RwKdaDGzT1HIp6NJyBkIwGuYRrYz0Hfp68d2azyGBLYGby X-Gm-Gg: AYBFou1/T1qFoUgdQn66CeUS9ltWfm8oc1dqHQ4LtGgAVkmwp8K7LyQJe4TKliLmYGm umKxvO2krLYRRY+4DF6gzjiAnctKTHdRz11emfqOt1yFYaTUsuqd0Y25cHE/8zc7rSjc/GhkTjk Uz1S1WJ3cUusuqGd3Sf3fkH1xfIgs9xWgoEHGtROano2RQvvQPb9lmtQ5FpeMuzxAKN+U6f4sgl ZtthDoGeSZjxMS+XdSWi9a6GMjtNqp521Fdc1i8QBFpzaSmtwN2pmkBh1YXAh6KKi792jWiL4pg x32WvS2RANGCbfQ+lCFACP3sYA1l1YFhPQIlYKlWx5SBSYj75bShcUSgwXD7bRMp/Ro05X8bDdy 4qsmHX3GJWu70DWw+RO9s4hAvILB0cVYs6A9Xk9EZC6b+D4E7dhoGkWt/s61mddE30RTyMKyxtD PDxRVET8gmX5Xzyx+3E3172drLRHCXV6O8lNKir7RjasQryepozBcr8x+LbNyBWk3lIPPkFbM1m 9/WMw== X-Received: by 2002:a17:90a:dfd0:b0:396:61f1:da5c with SMTP id 98e67ed59e1d1-39b260de667mr3212737a91.4.1788479787003; Thu, 03 Sep 2026 16:56:27 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339b8f44d7sm2078084eec.22.2026.09.03.16.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:26 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 03/11] f2fs: describe NAT block layout dynamically Date: Thu, 3 Sep 2026 16:56:15 -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 Reviewed-by: Chao Yu --- fs/f2fs/checkpoint.c | 4 +-- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/gc.c | 4 +-- fs/f2fs/node.c | 77 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 20 +++++++---- fs/f2fs/segment.c | 4 +-- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 4 ++- include/linux/f2fs_fs.h | 5 ++- 10 files changed, 69 insertions(+), 55 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 7fcda18e9cda..05366ba2675d 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 cd49b03befa3..6d3ca0bc2a76 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1862,6 +1862,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*/ @@ -2252,6 +2253,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) } =20 #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) +#define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) =20 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 0a00180c21dc..c15c6ba91597 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1066,7 +1066,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, continue; =20 if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } @@ -1614,7 +1614,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, = struct f2fs_summary *sum, continue; =20 if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 86c2e67e43b6..960c6657d0d6 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -169,7 +169,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_= info *sbi, nid_t nid) folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); =20 - set_to_next_nat(nm_i, nid); + set_to_next_nat(sbi, nm_i, nid); =20 return dst_folio; } @@ -254,10 +254,11 @@ static void __del_from_nat_cache(struct f2fs_nm_info = *nm_i, struct nat_entry *e) __free_nat_entry(e); } =20 -static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_= i, +static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne) { - nid_t set =3D NAT_BLOCK_OFFSET(ne->ni.nid); + nid_t set =3D NAT_BLOCK_OFFSET(sbi, ne->ni.nid); struct nat_entry_set *head; =20 head =3D radix_tree_lookup(&nm_i->nat_set_root, set); @@ -274,14 +275,15 @@ static struct nat_entry_set *__grab_nat_entry_set(str= uct f2fs_nm_info *nm_i, return head; } =20 -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne, bool init_dirty) { struct nat_entry_set *head; bool new_ne =3D nat_get_blkaddr(ne) =3D=3D NEW_ADDR; =20 if (!new_ne) - head =3D __grab_nat_entry_set(nm_i, ne); + head =3D __grab_nat_entry_set(sbi, nm_i, ne); =20 /* * update entry_cnt in below condition: @@ -527,7 +529,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, str= uct node_info *ni, nat_set_blkaddr(e, new_blkaddr); if (!__is_valid_data_blkaddr(new_blkaddr)) set_nat_flag(e, IS_CHECKPOINTED, false); - __set_nat_cache_dirty(nm_i, e, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, e, init_dirty); =20 /* update fsync_mark if its inode nat entry is still alive */ if (ni->nid !=3D ni->ino) @@ -578,7 +580,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t = nid, struct f2fs_nm_info *nm_i =3D NM_I(sbi); struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D START_NID(nid); + nid_t start_nid =3D f2fs_start_nid(sbi, nid); struct f2fs_nat_block *nat_blk; struct folio *folio =3D NULL; struct f2fs_nat_entry ne; @@ -2403,8 +2405,8 @@ static void update_free_nid_bitmap(struct f2fs_sb_inf= o *sbi, nid_t nid, bool set, bool build) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(nid); - unsigned int nid_ofs =3D nid - START_NID(nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, nid); + unsigned int nid_ofs =3D nid - f2fs_start_nid(sbi, nid); =20 if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) return; @@ -2524,14 +2526,14 @@ static int scan_nat_page(struct f2fs_sb_info *sbi, { struct f2fs_nm_info *nm_i =3D NM_I(sbi); block_t blk_addr; - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, start_nid); int i; =20 __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); =20 - i =3D start_nid % NAT_ENTRY_PER_BLOCK; + i =3D start_nid % NAT_ENTRY_PER_BLOCK(sbi); =20 - for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++, start_nid++) { if (unlikely(start_nid >=3D nm_i->max_nid)) break; =20 @@ -2587,16 +2589,16 @@ static void scan_free_nid_bits(struct f2fs_sb_info = *sbi) continue; if (!nm_i->free_nid_count[i]) continue; - for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { + for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK(sbi); idx++) { idx =3D find_next_bit_le(nm_i->free_nid_bitmap[i], - NAT_ENTRY_PER_BLOCK, idx); - if (idx >=3D NAT_ENTRY_PER_BLOCK) + NAT_ENTRY_PER_BLOCK(sbi), idx); + if (idx >=3D NAT_ENTRY_PER_BLOCK(sbi)) break; =20 - nid =3D i * NAT_ENTRY_PER_BLOCK + idx; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi) + idx; add_free_nid(sbi, nid, true, false); =20 - if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS(sbi)) goto out; } } @@ -2617,11 +2619,11 @@ static int __f2fs_build_free_nids(struct f2fs_sb_in= fo *sbi, if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; =20 - if (unlikely(nid % NAT_ENTRY_PER_BLOCK)) - nid =3D NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK; + if (unlikely(nid % NAT_ENTRY_PER_BLOCK(sbi))) + nid =3D NAT_BLOCK_OFFSET(sbi, nid) * NAT_ENTRY_PER_BLOCK(sbi); =20 /* Enough entries */ - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; =20 if (!sync && !f2fs_available_free_memory(sbi, FREE_NIDS)) @@ -2631,18 +2633,18 @@ static int __f2fs_build_free_nids(struct f2fs_sb_in= fo *sbi, /* try to find free nids in free_nid_bitmap */ scan_free_nid_bits(sbi); =20 - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; } =20 /* readahead nat pages to be scanned */ - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), FREE_NID_PAGES, META_NAT, true); =20 f2fs_down_read_trace(&nm_i->nat_tree_lock, &lc); =20 while (1) { - if (!test_bit_le(NAT_BLOCK_OFFSET(nid), + if (!test_bit_le(NAT_BLOCK_OFFSET(sbi, nid), nm_i->nat_block_bitmap)) { struct folio *folio =3D get_current_nat_folio(sbi, nid); =20 @@ -2668,7 +2670,8 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info= *sbi, } } =20 - nid +=3D (NAT_ENTRY_PER_BLOCK - (nid % NAT_ENTRY_PER_BLOCK)); + nid +=3D NAT_ENTRY_PER_BLOCK(sbi) - + (nid % NAT_ENTRY_PER_BLOCK(sbi)); if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; =20 @@ -2684,7 +2687,7 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info= *sbi, =20 f2fs_up_read_trace(&nm_i->nat_tree_lock, &lc); =20 - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nm_i->next_scan_nid), nm_i->ra_nid_pages, META_NAT, false); =20 return 0; @@ -2811,20 +2814,20 @@ int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi,= int nr_shrink) struct f2fs_nm_info *nm_i =3D NM_I(sbi); int nr =3D nr_shrink; =20 - if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) return 0; =20 if (!mutex_trylock(&nm_i->build_lock)) return 0; =20 - while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS) { + while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS(sbi)) { struct free_nid *i, *next; unsigned int batch =3D SHRINK_NID_BATCH_SIZE; =20 spin_lock(&nm_i->nid_list_lock); list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) { if (!nr_shrink || !batch || - nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) break; __remove_free_nid(sbi, i, FREE_NID); kmem_cache_free(free_nid_slab, i); @@ -3074,7 +3077,7 @@ static void remove_nats_in_journal(struct f2fs_sb_inf= o *sbi) spin_unlock(&nm_i->nid_list_lock); } =20 - __set_nat_cache_dirty(nm_i, ne, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, ne, init_dirty); } update_nats_in_cursum(journal, -i); up_write(&curseg->journal_rwsem); @@ -3102,7 +3105,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, const struct f2fs_nat_block *nat_blk) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK; + unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK(sbi); int valid =3D 0; int i =3D 0; =20 @@ -3113,7 +3116,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, valid =3D 1; i =3D 1; } - for (; i < NAT_ENTRY_PER_BLOCK; i++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++) { if (le32_to_cpu(nat_blk->entries[i].block_addr) !=3D NULL_ADDR) valid++; } @@ -3124,7 +3127,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sb= i, nid_t start_nid, } =20 __clear_bit_le(nat_index, nm_i->empty_nat_bits); - if (valid =3D=3D NAT_ENTRY_PER_BLOCK) + if (valid =3D=3D NAT_ENTRY_PER_BLOCK(sbi)) __set_bit_le(nat_index, nm_i->full_nat_bits); else __clear_bit_le(nat_index, nm_i->full_nat_bits); @@ -3135,7 +3138,7 @@ static int __flush_nat_entry_set(struct f2fs_sb_info = *sbi, { struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK; + nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK(sbi); bool to_journal =3D true; struct f2fs_nat_block *nat_blk; struct nat_entry *ne, *cur; @@ -3342,8 +3345,8 @@ static inline void load_free_nid_bitmap(struct f2fs_s= b_info *sbi) =20 __set_bit_le(i, nm_i->nat_block_bitmap); =20 - nid =3D i * NAT_ENTRY_PER_BLOCK; - last_nid =3D nid + NAT_ENTRY_PER_BLOCK; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi); + last_nid =3D nid + NAT_ENTRY_PER_BLOCK(sbi); =20 spin_lock(&NM_I(sbi)->nid_list_lock); for (; nid < last_nid; nid++) @@ -3373,7 +3376,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) /* segment_count_nat includes pair segment so divide to 2. */ nat_segs =3D le32_to_cpu(sb_raw->segment_count_nat) >> 1; nm_i->nat_blocks =3D nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); - nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks; + nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK(sbi) * nm_i->nat_blocks; =20 /* not used nids: 0, node, meta, (and root counted as valid node) */ nm_i->available_nids =3D nm_i->max_nid - sbi->total_valid_node_count - @@ -3436,7 +3439,7 @@ static int init_free_nid_cache(struct f2fs_sb_info *s= bi) =20 for (i =3D 0; i < nm_i->nat_blocks; i++) { nm_i->free_nid_bitmap[i] =3D f2fs_kvzalloc(sbi, - f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK), GFP_KERNEL); + f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)), GFP_KERNEL); if (!nm_i->free_nid_bitmap[i]) return -ENOMEM; } diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 5e114f352099..d4a20d48432c 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -6,14 +6,21 @@ * http://www.samsung.com/ */ /* start node id of a node block dedicated to the given node id */ -#define START_NID(nid) (((nid) / NAT_ENTRY_PER_BLOCK) * NAT_ENTRY_PER_BLOC= K) +static inline nid_t f2fs_start_nid(struct f2fs_sb_info *sbi, nid_t nid) +{ + unsigned int entries =3D NAT_ENTRY_PER_BLOCK(sbi); + + return (nid / entries) * entries; +} =20 /* node block offset on the NAT area dedicated to the given start node id = */ -#define NAT_BLOCK_OFFSET(start_nid) ((start_nid) / NAT_ENTRY_PER_BLOCK) +#define NAT_BLOCK_OFFSET(sbi, start_nid) \ + ((start_nid) / NAT_ENTRY_PER_BLOCK(sbi)) =20 /* # of pages to perform synchronous readahead before building free nids */ #define FREE_NID_PAGES 8 -#define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) +#define MAX_FREE_NIDS(sbi) ((unsigned long)NAT_ENTRY_PER_BLOCK(sbi) * \ + FREE_NID_PAGES) =20 /* size of free nid batch when shrinking */ #define SHRINK_NID_BATCH_SIZE 8 @@ -208,7 +215,7 @@ static inline pgoff_t current_nat_addr(struct f2fs_sb_i= nfo *sbi, nid_t start) * OLD =3D (segment_off * 512) * 2 + off_in_segment * NEW =3D 2 * (segment_off * 512 + off_in_segment) - off_in_segment */ - block_off =3D NAT_BLOCK_OFFSET(start); + block_off =3D NAT_BLOCK_OFFSET(sbi, start); =20 block_addr =3D (pgoff_t)(nm_i->nat_blkaddr + (block_off << 1) - @@ -230,9 +237,10 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_inf= o *sbi, return block_addr + nm_i->nat_blkaddr; } =20 -static inline void set_to_next_nat(struct f2fs_nm_info *nm_i, nid_t start_= nid) +static inline void set_to_next_nat(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, nid_t start_nid) { - unsigned int block_off =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int block_off =3D NAT_BLOCK_OFFSET(sbi, start_nid); =20 f2fs_change_bit(block_off, nm_i->nat_bitmap); #ifdef CONFIG_F2FS_CHECK_FS diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 2427649402f6..7bf8fa992600 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 4e10a84b4142..534f6678e4ae 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->nat_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); @@ -4391,7 +4393,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->total_sections =3D le32_to_cpu(raw_super->section_count); sbi->total_node_count =3D SEGS_TO_BLKS(sbi, ((le32_to_cpu(raw_super->segment_count_nat) / 2) * - NAT_ENTRY_PER_BLOCK)); + NAT_ENTRY_PER_BLOCK(sbi))); sbi->allocate_section_hint =3D le32_to_cpu(raw_super->section_count); sbi->allocate_section_policy =3D ALLOCATE_FORWARD_NOHINT; F2FS_ROOT_INO(sbi) =3D le32_to_cpu(raw_super->root_ino); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index ecd6694af572..061f906a7b94 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -375,8 +375,6 @@ struct f2fs_node { /* * For NAT entries */ -#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_nat_entry)) - struct f2fs_nat_entry { __u8 version; /* latest version of cached nat entry */ __le32 ino; /* inode number */ @@ -384,7 +382,8 @@ struct f2fs_nat_entry { } __packed; =20 struct f2fs_nat_block { - struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; + /* The entry count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(struct f2fs_nat_entry, entries); } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51F9A378813 for ; Thu, 3 Sep 2026 23:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479790; cv=none; b=Z9yaSyGTqTCNP+iI8INco59o8jk4WDqu8bute62fVRDNZKgZokeLct4wb66D22LYuwIpQTmSzXm1UyuQnYYgvEZDKxYx6kx6xqcwfyNEDd10nQJfT+uMtTWAdQoV5DxaKfMQc4LiFGUuVCccVHSc4PO/YAdOHOZtyPVnEgfetS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479790; c=relaxed/simple; bh=rj7PE6AhaGCK4c3T/hHLrWRCngTeg8BZgdR+llra94g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qweLl3smhvq1bL70rBsx3mDX4XGwg0nh2t46B/PC+lhGuD40XPp9IA7/rJadBL1ePi4HVGp4S0DE65lIMc9N6lJztV8t5J6A0CZQKBWpod085HxlDZRV9IpZrltOsEr+frVL+36UudT0rWxROIgWBbsFMrCaVY+uNh1QggPhwac= 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=imVAN5qb; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="imVAN5qb" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-cc1c7364550so633189a12.1 for ; Thu, 03 Sep 2026 16:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479788; x=1789084588; 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=m9wKI0Z0DpMpYM/1mHsDF/pZnszi7sqs9bFOkpAyOMY=; b=imVAN5qb3TTIZk9EZyssPnOTxwNrvUsjSINzMlYI06ncvOjfVJjhpVnEqb8wFKuhyq 3DGj7zXwSrHINDGQH5UawfSwpnatMs9r6mwB7uDcJE1a6sFW7cOEx0fI+lphvty/oa0z vG3ScaxuwW6fnzUFo7+KFE0GPTBmxSwqgUpo+eTTi4J9/axyHK+YmcKt1Vi36RX2w+nF 69DSOHx/LiNjKAyqLv/4LUdi/f/J4A21wZKjHagRFyVDhczruXkzSrOxuc3WTyAYzhXD 7iSdGsZhXFXOnNx4Xnccm6HZalbSuoxfNdPbJbcudSM5GlAc+eDrx8gOuIO5YOEFR9fU Yi6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479788; x=1789084588; 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=m9wKI0Z0DpMpYM/1mHsDF/pZnszi7sqs9bFOkpAyOMY=; b=a4nakN84ebs4tM3ovNL2fqI1x1tf6oNS+uNxw0Pj1HSKM40Brrc59hXXhzWqJbqk/S C+macftns6K3Ujyj7ffZIkhIJtaYJM3s8aWgXZkcMLrmaZIVKPZ4IQKnbX7bcn0bUJ8I JS1hHzDKE6gcKShkWfmtIp4ptxDy5e2KJwHsvKRMOPANBwTfEyzm8ji/0RYMpi8frcBN d0CG1hF6GdfLNiRILxN0QD/egeiwh6iek7dfG/frXPQQzHhU8ly6cOALbkQimlQtzZhW uIUzn7IuzyLkXFt04XYwAOe2iRhOTGei/fA8xvDIclymr7bDhh/unaaTl4kp79MIPU2K SqLg== X-Forwarded-Encrypted: i=1; AKwUvBxWlH29LW+vXlKkW25rOxd2AZcAHQG6a3NwTLX77BUH+M/s82FoFhQ5wHFuohznAfdf/+e2xQ2WJVPubMM=@vger.kernel.org X-Gm-Message-State: AFuF++lnX5CBkeA2/nQslnHbOeHJItoJf9gPRcfaC2pYbjWGVNKinsny tHiqp54DTdj0Iq9sGxKXrDZA+Qy7/vL2ZKP3qba0IDoz83A5wYU7KYvI X-Gm-Gg: AYBFou3WlliTJmzonebH7r8FkzPYb3RNYZQ+DkuVBsTwn/d3NBuL1UFvCEIUYsYYFJd Eym59hkSDGdyDd/enycXKk7VyzwMqo9vRH+fCuoWFOtWp3xPpIH1YKSusafrm3fnZYpn4KgY6+p uSfQl7Euo7yR1+uwPNWOjaRUnySB7mlGvgUQy/vGhf1jhlGU4X0N+N+ts6KpR1U9qK+k0ePaxMu wQbFftkyGQcQuBqfRrzAxP5bEJZ+49oDA55Vc7z1o7Ik6+GRALi2tHoODygZP60UKACvEHsmnqU m7cH2Mnc6g8AmxD8HQQ7Gql2NbQ5huMR5s6+vSeF2U8srZ+IJ8hdMT8tAoX3hWyUfUdxKPKWtoK 8skrCy8nY6hbPzsrN7R7uUBqgR/om9bbV15b18/e2SggDc0W+LDWlYissy/vthNxNBo7pZWRJYZ uVIBLd8m4+cMIQJCJG1GcO7Zg6rkVFNVhsgk8fsYWv7JturDezFliFJ/hNIcQnux3IXw== X-Received: by 2002:a17:90b:5845:b0:383:5a16:bd70 with SMTP id 98e67ed59e1d1-39b2620547amr3221584a91.16.1788479788557; Thu, 03 Sep 2026 16:56:28 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339b6036fcsm2268682eec.20.2026.09.03.16.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:28 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 04/11] f2fs: describe orphan block layout dynamically Date: Thu, 3 Sep 2026 16:56:16 -0700 Message-ID: <99c37e861d74328fa6203c58284dc33505d326ad.1788479509.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An on-disk orphan block contains a variable-length array of 32-bit inode numbers followed by a fixed footer at the end of the block. A compile-time whole-block structure cannot represent the footer position when the block size varies at runtime. Remove struct f2fs_orphan_block, introduce struct f2fs_orphan_block_footer, and compute sbi->orphans_per_block dynamically in init_sb_info(). Add helpers to access the inode entry array and footer from a block buffer. Update orphan inode recovery, checkpointing, and mount paths to use the parameterized helpers. This preserves the on-disk format while decoupling orphan handling from compile-time constants. Signed-off-by: Kelvin Zhang Reviewed-by: Chao Yu --- fs/f2fs/checkpoint.c | 32 ++++++++++++++++++-------------- fs/f2fs/f2fs.h | 12 ++++++++++++ fs/f2fs/super.c | 2 ++ include/linux/f2fs_fs.h | 20 ++++++++++++++------ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 05366ba2675d..c7183d4b6765 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1034,6 +1034,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) for (i =3D 0; i < orphan_blocks; i++) { struct folio *folio; struct f2fs_orphan_block *orphan_blk; + struct f2fs_orphan_footer *footer; unsigned int entry_count; =20 folio =3D f2fs_get_meta_folio(sbi, start_blk + i); @@ -1043,8 +1044,9 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) } =20 orphan_blk =3D folio_address(folio); - entry_count =3D le32_to_cpu(orphan_blk->entry_count); - if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + footer =3D f2fs_orphan_footer(orphan_blk, sbi); + entry_count =3D le32_to_cpu(footer->entry_count); + if (entry_count > F2FS_ORPHANS_PER_BLOCK(sbi)) { f2fs_err(sbi, "invalid orphan inode entry count %u", entry_count); set_sbi_flag(sbi, SBI_NEED_FSCK); @@ -1077,6 +1079,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *= sbi, block_t start_blk) { struct list_head *head; struct f2fs_orphan_block *orphan_blk =3D NULL; + struct f2fs_orphan_footer *footer =3D NULL; unsigned int nentries =3D 0; unsigned short index =3D 1; unsigned short orphan_blocks; @@ -1084,7 +1087,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 @@ -1098,20 +1101,21 @@ static void write_orphan_inodes(struct f2fs_sb_info= *sbi, block_t start_blk) if (!folio) { folio =3D f2fs_grab_meta_folio(sbi, start_blk++); orphan_blk =3D folio_address(folio); - memset(orphan_blk, 0, sizeof(*orphan_blk)); + footer =3D f2fs_orphan_footer(orphan_blk, sbi); + memset(orphan_blk, 0, sbi->blocksize); } =20 orphan_blk->ino[nentries++] =3D cpu_to_le32(orphan->ino); =20 - if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK) { + if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK(sbi)) { /* - * an orphan block is full of 1020 entries, + * an orphan block is full, * then we need to flush current orphan blocks * and bring another one in memory */ - orphan_blk->blk_addr =3D cpu_to_le16(index); - orphan_blk->blk_count =3D cpu_to_le16(orphan_blocks); - orphan_blk->entry_count =3D cpu_to_le32(nentries); + footer->blk_addr =3D cpu_to_le16(index); + footer->blk_count =3D cpu_to_le16(orphan_blocks); + footer->entry_count =3D cpu_to_le32(nentries); folio_mark_dirty(folio); f2fs_folio_put(folio, true); index++; @@ -1121,9 +1125,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); } @@ -1816,7 +1820,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 @@ -2072,7 +2076,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 6d3ca0bc2a76..69a558fe46c7 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1864,6 +1864,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*/ @@ -2254,6 +2255,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 534f6678e4ae..5f630ee748d0 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4386,6 +4386,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); + sbi->orphans_per_block =3D (sbi->blocksize - + sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 061f906a7b94..bdb8c63ac0c6 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -220,14 +220,22 @@ struct f2fs_checkpoint { =20 /* * For orphan inode management + * + * The number of inode entries in an orphan block depends on the filesystem + * block size. Its exact on-disk layout is: + * + * 0 blocksize - 16 blocksize + * +--------------------------+--------------------------+ + * | ino[0] ... ino[n - 1] | struct f2fs_orphan_footer | + * +--------------------------+--------------------------+ + * + * n =3D (blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32) */ -#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / size= of(__le32)) - -#define GET_ORPHAN_BLOCKS(n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \ - F2FS_ORPHANS_PER_BLOCK) - struct f2fs_orphan_block { - __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ + DECLARE_FLEX_ARRAY(__le32, ino); +} __packed; + +struct f2fs_orphan_footer { __le32 reserved; /* reserved */ __le16 blk_addr; /* block index in current CP */ __le16 blk_count; /* Number of orphan inode blocks in CP */ --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 08A803382F4 for ; Thu, 3 Sep 2026 23:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479792; cv=none; b=JJ2vCrOhQDDru9eyDRW2lwYi/MEDbWNHvfptpD21Ih48H12khg61f9TSr5l7TVngE6o7xAyKtgysXRzkf5n5N7aCt4C2gxA2hPTaiU08XWlxqoel4d4oU5FiUn5JeZHLpbTkIuE97W1vcwRvkpwDiY1xRsar0xT5RMC2mxNLAoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479792; c=relaxed/simple; bh=Muz8SXHLpDxs2fMeaBLo8wKBbeGofu9N8mmm7fEcAqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hA3FMGEsrxjKMExH9BxoWVEAClfTBPjsK4OMYSW9myEBkNLOkzwvDarUM3iHx7OOLD7c5vGRXnHU1p8n7r57/VGMeCNUhh8jnjNFy92nsnpnXo6LmssFuZhKCFhEAdbNi7dOywJhRw2yjuVVQJdaCl474AWBnCH3SHS8/8+nWn0= 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=JD5816w8; arc=none smtp.client-ip=209.85.215.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="JD5816w8" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-ca766c1c9ccso372759a12.0 for ; Thu, 03 Sep 2026 16:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479790; x=1789084590; 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=uMS/dGNzwzqE+5nr/1Ra6IaWVc1EaPMc+7Aj/vbd03E=; b=JD5816w8CqDZP8Jl7MiV5ui61TgqayQBwptZIHumRfEx6Rxn2holwyBga8RUUilweu YKBXnUN4BNyyvsgv3YaDVzmnD0sYAdMm60mc121mjOl862zwtmeEqP+PFP5F2euoG4UM C2rV18fytVhn3BdbePV9SyQBWVtfmcwccD2P7r/efdtLVnW+u5xWYbawIJHqqZlb76SM XFKr2qVS2kXdPZzsHoMfp1oUFKJujXSu3K4z8+l7JQoduxWVSn2IkkXpzhPkZLMeoWiX dHJLx/3/+KtpEKv+gyo4sHfhchB6b6YzaVBD/R3USnQVq/VM2C/5LPjNWElbg7lMCtsa Pzzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479790; x=1789084590; 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=uMS/dGNzwzqE+5nr/1Ra6IaWVc1EaPMc+7Aj/vbd03E=; b=B6a2WHfrCgqJBwebb/sv3GH2iEIBtOfSAEt0jpiAUiqfKFffJEYOc257H18KhGDZKd NkGq4k2+qGCt0VktXBMqMswPGl1EOruw302EiDCMBk4Dkqewf7y8W5FryakggHAm9KTr Zp46XexEv9CdoVNmESgWIKsCh9rtbBELf9ZKcYJ1kuQcUMtgpFFt2sbUb/id3JCfsiJ1 U0OtIPcVspGBpoPC21O8fHsvPqG7+KVKw5n77MtDlykiR9ZEpUe05CUE8egTA0PgsRZQ +7RmAp8AMsg9qqsNK/fvQcnYf7gkJjOkQ/2O3943auimTlTHS/PJMXASP//Ux02ZCSPJ L/uQ== X-Forwarded-Encrypted: i=1; AKwUvBx3x6dnPcOMmsyV2i51NlZDMcAmalr0wZtA3tkbAlxntX4IByu1P+2rih0E6Bb+t4PRefWEsqbaMvu/8hY=@vger.kernel.org X-Gm-Message-State: AFuF++mNaFLafQieLi2Rm82FMU5xfjIdOLbLuesjuXK9DkDE6vt8+mZY ie/KhDVw+c3xD3Apyk0e1nfHyExo0UxA62WSXblpAJeZC4UueoN8X+sN X-Gm-Gg: AYBFou2M5Jq5iLII6Swlb+CLGGL/7XrwI5LL2LIBjbR5tqzxAHFVbfJDtzXHihUmnt4 xYngG0AK7XdmK8AIjRI7gmW4q8cJIZ4Z/I2ZPdfooDFDC2eYazrmLckjzErtM8Kb2P8rkqRX18B 1fQvjKUuRNVX6Bp2loF+JMaTwYv44iVjpNogv6IG4mRX7Ysr9gqT8HsM+/lqger0lArkbbovTj7 E34oJ82R5lLyU/bticWZaksq9s/4tCD6vKS+DsCEq673ACqndG2vtUkEOAN7SD/a157rGOavVpv TaT8Mcy8Dr3yIhtROgnIWb1B7SdYoWS9sYqowTo6pwIvtL7SRi4/Pcifs2qL+S2fembTJmanhnB CMRuIHFeXC4kKrYz/jmPAFAxDCDbk7nAgmdfE5F4win6ovxqMCTPx2UMW5mZFDh3eIf2npL6/KD AQPYm4q2l6kIZ6Hdql8jQlAMwGkrg1S4Zqo2sAdwdSYM/HHXTgVtr8069CkseTY0Q7qg== X-Received: by 2002:a17:90b:2687:b0:398:9c0c:7c71 with SMTP id 98e67ed59e1d1-39b26277b88mr3153534a91.24.1788479790126; Thu, 03 Sep 2026 16:56:30 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339b9f68e4sm2052462eec.24.2026.09.03.16.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:29 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 05/11] f2fs: describe dentry block layout dynamically Date: Thu, 3 Sep 2026 16:56:17 -0700 Message-ID: <3a430f1eaa7b07583d83828477adff5a90ede9e8.1788479509.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An on-disk 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 Reviewed-by: Chao Yu --- 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 69a558fe46c7..5c351d499e59 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) { @@ -1865,6 +1854,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*/ @@ -2267,6 +2259,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 5f630ee748d0..b0747c0b2c10 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4388,6 +4388,12 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); + sbi->dentries_per_block =3D (BITS_PER_BYTE * sbi->blocksize) / + ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1); + sbi->dentry_bitmap_size =3D DIV_ROUND_UP(sbi->dentries_per_block, + BITS_PER_BYTE); + sbi->dentry_reserved_size =3D sbi->blocksize - sbi->dentry_bitmap_size - + (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * sbi->dentries_per_block; sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bdb8c63ac0c6..2370af742c8f 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -605,15 +605,7 @@ typedef __le32 f2fs_hash_t; * dentry, when converting inline dentry we should handle this carefully. */ =20 -/* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1)) #define SIZE_OF_DIR_ENTRY 11 /* by byte */ -#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define SIZE_OF_RESERVED (F2FS_BLKSIZE - ((SIZE_OF_DIR_ENTRY + \ - F2FS_SLOT_LEN) * \ - NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) #define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */ =20 /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ @@ -624,14 +616,21 @@ struct f2fs_dir_entry { __u8 file_type; /* file type */ } __packed; =20 -/* Block-sized directory entry block */ -struct f2fs_dentry_block { - /* validity bitmap for directory entries in each block */ - __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; - __u8 reserved[SIZE_OF_RESERVED]; - struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; - __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; -} __packed; +/* + * A dentry block is laid out as follows, where the number of entries and = all + * offsets are determined by the filesystem block size at runtime: + * + * 0 blocksize + * +--------+----------+-------------------+-----------------------+ + * | bitmap | reserved | dir_entry[entries]| filename[entries][8] | + * +--------+----------+-------------------+-----------------------+ + * + * entries =3D (BITS_PER_BYTE * blocksize) / + * ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1) + * bitmap_size =3D DIV_ROUND_UP(entries, BITS_PER_BYTE) + * reserved_size =3D blocksize - bitmap_size - + * (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * entries + */ =20 #define F2FS_DEF_PROJID 0 /* default project ID */ =20 --=20 2.53.0 From nobody Sat Sep 26 06:20:27 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 A30D02C11E6 for ; Thu, 3 Sep 2026 23:56:32 +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=1788479794; cv=none; b=hFMl37ZDSTtt3+KXI1c2VkFdZvpJzFevYF4Zj2oWc3k9zgPhDPbhpPHNqh0foqDXB4q3CVOQKiy/RLtiKCFQNUeUHQsDLJD44hQd8f/fk+eAbKGk4iCbEqRtddfsv59ILXMjhP6jHL2Fgl1nexZYWQRUCP8jZgJUT6GZowv8VLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479794; c=relaxed/simple; bh=S+DC3QM4baoSahFc7j54khzpoIqWmoLpJlF8/y76aEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UFMFDINLeS/6icoIwfxNjOed/UsPs0gkIP7lbN8SWbDNRNCqhrl+IAB7kDrwnGr4xV3r++jjS7NuoEXWTR7OzAUdCyV82KgTGPN6Sil1JtqA1kLZ1mW3mqyA9h1eMcYuq/8+hLpE4lbP9DHWJ9xzqfJTnWN3QXGNkg8EHGZUKQQ= 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=D47JLXUO; 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="D47JLXUO" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-cc1cf287ef8so475690a12.3 for ; Thu, 03 Sep 2026 16:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479792; x=1789084592; 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=/NrAQ06CoaW/6jV1k8T9/cQlm05hebEL4QZ63QXWHQM=; b=D47JLXUOIsaZKDLQ9o6vWAY9GuV1uSoBdzM6b9O4rIVAiI6xOpGX8lDalRHQAfFR60 XJvyUqKF+offva4Y32rlFWDWKakN22Cs2GicPfCx/7KFfhZvEc1ASfsauW71eZ5K27qo 3UR/Aj0bFZilATEQY1ZqPcozJvShDWcHml1nHcHet3a974Ys9TNOLm6HaqqrN8XTU50N wFMPLtn/t4XXYYhEwsoEQYmm4T4BWliHMKYa1BRvmzN8HiJ28JnsPyCVJWltk6rjQ2j1 NAPwXXO5loEt7rTb4rgavF9cM7Om4V5Z4c23ReLzff/Ub7H991zY8S8dxXU5Lg4roLe1 s1eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479792; x=1789084592; 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=/NrAQ06CoaW/6jV1k8T9/cQlm05hebEL4QZ63QXWHQM=; b=qDpkJGHhplQ0PQwz97zzc9q8EDYPuZZGwr8tPsvW95iXexFxaV73SjClFetuWfAEOF y4dePcg3GX10Ewu4erWJfPj4OgJ2gSo8xkt2JS1aXCtDU8FQ7iS4g2Z3l3DEFNnj2I01 JriZamoIrtsFDm6asAD3Cnz1OReBSsYjU9dC6Jgv2CjIpvJi+Gc/Qe1KVWaC67vbfxm4 JEFpZu+yFr31YnO45T9NQrdyWknnzEHFy+u9+XWrEHklHfIBKLBBFAMU+mr2DVuBZTtm Z1KifA5zFrgEublY6vuGNWY1QGyU+Y5PzO/UPJySDdWxv5OB68lVfcEfupEDTSRhW8Gq qg6A== X-Forwarded-Encrypted: i=1; AKwUvBzfsuLGmT9tZQEiMti9kTa24FvSryN4Wwlj1gar4BjprLBrDf8LQuvVbAcH6gETdHUaeU1jnXjMXvBxARw=@vger.kernel.org X-Gm-Message-State: AFuF++kZVLre1Y3X7twL0GMrR4k3ZTetppklf+fo36QSQmHRat3joPoD VcYTvGFb8aWHt/+U68q+YCQXoGxG/XMd1juSQcZuchjDoCznbdRPzAjWgrIzgPsvcTE= X-Gm-Gg: AYBFou1XD9FrYfWZELuO7/RnSypFCuHGGScEh5RL95Z0X/JVTM6uadWEaBrCaphJ9Pg YAcGl9LxLDX6TkS5/t5f4cUR+YCxVtb0OWF+GrdvbUwfXYIupCBbVNDweUIWeK0BeJgGXVcoS9n I/ryiVPiHwf0lCXdkz9WncsYA2oVeYGW2U7JgeyBmAVG+oMDyABEKEnRMgNheXYiVHJttHMJUSv Q2r/4GI5loF1SHJW70kDxYe+iJbplFBG7ftS/TkwlGHdbTeKaR8xuNOxph65rAxRQNiUDItushI vYUg7sFVD/RqiQDTdrG/QyGOEurYR+RPpL/MMB0Eqprz/vY9nwmRFmE94h/ZMNmN42FC8i4e6nC ZAFIeHFFwLRg/fnD6smU6FgI/4W8O0UGi01o4S0YGIjsV8/XzIhFcPBU2OTvKJgApEDYMeJsbR7 COuKaCDw7kAtC8H54AzSM5I6a3rXsKYfkpHIiD6fQEr8cUpfTmdiZkT1vuGRNQ6kSicw== X-Received: by 2002:a17:90b:50cc:b0:396:65dd:4093 with SMTP id 98e67ed59e1d1-39b26202ebamr3465440a91.14.1788479791838; Thu, 03 Sep 2026 16:56:31 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339bbf1feesm2041649eec.26.2026.09.03.16.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:31 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 06/11] f2fs: describe {i,d,id}node block layout dynamically Date: Thu, 3 Sep 2026 16:56:18 -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 Reviewed-by: Chao Yu --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 42 ++++++++++++++++++++++++-------- fs/f2fs/gc.c | 2 +- fs/f2fs/inline.c | 3 +-- fs/f2fs/inode.c | 5 ++-- fs/f2fs/node.c | 4 +--- fs/f2fs/node.h | 53 +++++++++++++++++++---------------------- fs/f2fs/super.c | 4 ++++ fs/f2fs/xattr.h | 2 +- include/linux/f2fs_fs.h | 44 +++++++++++++++++++++------------- 10 files changed, 95 insertions(+), 66 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 21f396ebe22c..460d95c9414c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1992,7 +1992,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, =20 phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + - sizeof(__le32) * (DEF_ADDRS_PER_INODE - + sizeof(__le32) * (DEF_ADDRS_PER_INODE(sbi) - get_inline_xattr_addrs(inode)); =20 phys +=3D offset; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 5c351d499e59..06ac655a16e9 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -602,8 +602,9 @@ static inline int update_sits_in_cursum(struct f2fs_jou= rnal *journal, int i) #define DEF_INLINE_RESERVED_SIZE 1 static inline int get_extra_isize(struct inode *inode); static inline int get_inline_xattr_addrs(struct inode *inode); +static inline unsigned int cur_addrs_per_inode(struct inode *inode); #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ - (CUR_ADDRS_PER_INODE(inode) - \ + (cur_addrs_per_inode(inode) - \ get_inline_xattr_addrs(inode) - \ DEF_INLINE_RESERVED_SIZE)) =20 @@ -1852,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 */ @@ -2247,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)->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)) @@ -2296,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); @@ -2306,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); @@ -3276,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) @@ -3291,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); @@ -3310,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 @@ -3625,7 +3642,7 @@ static inline bool f2fs_need_compress_data(struct ino= de *inode) static inline unsigned int addrs_per_page(struct inode *inode, bool is_inode) { - unsigned int addrs =3D is_inode ? (CUR_ADDRS_PER_INODE(inode) - + unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; =20 if (f2fs_compressed_file(inode)) @@ -3633,12 +3650,17 @@ static inline unsigned int addrs_per_page(struct in= ode *inode, return addrs; } =20 +static inline unsigned int cur_addrs_per_inode(struct inode *inode) +{ + return DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_extra_isize(inode); +} + static inline void *inline_xattr_addr(struct inode *inode, const struct folio *folio) { struct f2fs_inode *ri =3D F2FS_INODE(folio); =20 - return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - + return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_inline_xattr_addrs(inode)]); } =20 diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index c15c6ba91597..164612dbe2c6 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1176,7 +1176,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct= f2fs_summary *sum, =20 if (IS_INODE(node_folio)) { base =3D offset_in_addr(F2FS_INODE(node_folio)); - max_addrs =3D DEF_ADDRS_PER_INODE; + max_addrs =3D DEF_ADDRS_PER_INODE(sbi); } else { base =3D 0; max_addrs =3D DEF_ADDRS_PER_BLOCK; diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 718dd785865a..73cd9b6ddcc5 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -36,14 +36,13 @@ bool f2fs_may_inline_data(struct inode *inode) =20 static bool inode_has_blocks(struct inode *inode, struct folio *ifolio) { - struct f2fs_inode *ri =3D F2FS_INODE(ifolio); int i; =20 if (F2FS_HAS_BLOCKS(inode)) return true; =20 for (i =3D 0; i < DEF_NIDS_PER_INODE; i++) { - if (ri->i_nid[i]) + if (F2FS_INODE_NIDS(ifolio)[i]) return true; } return false; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 96cc0e777567..fda9ee3bfc61 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -150,9 +150,8 @@ bool f2fs_enable_inode_chksum(struct f2fs_sb_info *sbi,= struct folio *folio) =20 static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi, struct folio *fol= io) { - struct f2fs_node *node =3D F2FS_NODE(folio); - struct f2fs_inode *ri =3D &node->i; - __le32 ino =3D node->footer.ino; + struct f2fs_inode *ri =3D F2FS_INODE(folio); + __le32 ino =3D F2FS_NODE_FOOTER(folio)->ino; __le32 gen =3D ri->i_generation; __u32 chksum, chksum_seed; __u32 dummy_cs =3D 0; diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 960c6657d0d6..e3f594f7bcce 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -3001,7 +3001,6 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi,= struct folio *folio) int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, unsigned int segno, struct f2fs_summary_block *sum) { - struct f2fs_node *rn; struct f2fs_summary *sum_entry; block_t addr; int i, idx, last_offset, nrpages; @@ -3023,8 +3022,7 @@ int f2fs_restore_node_summary(struct f2fs_sb_info *sb= i, if (IS_ERR(folio)) return PTR_ERR(folio); =20 - rn =3D F2FS_NODE(folio); - sum_entry->nid =3D rn->footer.nid; + sum_entry->nid =3D F2FS_NODE_FOOTER(folio)->nid; sum_entry->version =3D 0; sum_entry->ofs_in_node =3D 0; sum_entry++; diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index d4a20d48432c..911c3d336533 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -250,73 +250,68 @@ static inline void set_to_next_nat(struct f2fs_sb_inf= o *sbi, =20 static inline nid_t ino_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.ino); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->ino); } =20 static inline nid_t nid_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.nid); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->nid); } =20 static inline unsigned int ofs_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - unsigned flag =3D le32_to_cpu(rn->footer.flag); + unsigned int flag =3D le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->flag); return flag >> OFFSET_BIT_SHIFT; } =20 static inline __u64 cpver_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le64_to_cpu(rn->footer.cp_ver); + return le64_to_cpu(F2FS_NODE_FOOTER(node_folio)->cp_ver); } =20 static inline block_t next_blkaddr_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.next_blkaddr); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->next_blkaddr); } =20 static inline void fill_node_footer(const struct folio *folio, nid_t nid, nid_t ino, unsigned int ofs, bool reset) { struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); unsigned int old_flag =3D 0; =20 if (reset) - memset(rn, 0, sizeof(*rn)); + memset(rn, 0, F2FS_BLKSIZE); else - old_flag =3D le32_to_cpu(rn->footer.flag); + old_flag =3D le32_to_cpu(footer->flag); =20 - rn->footer.nid =3D cpu_to_le32(nid); - rn->footer.ino =3D cpu_to_le32(ino); + footer->nid =3D cpu_to_le32(nid); + footer->ino =3D cpu_to_le32(ino); =20 /* should remain old flag bits such as COLD_BIT_SHIFT */ - rn->footer.flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | + footer->flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | (old_flag & OFFSET_BIT_MASK)); } =20 static inline void copy_node_footer(const struct folio *dst, const struct folio *src) { - struct f2fs_node *src_rn =3D F2FS_NODE(src); - struct f2fs_node *dst_rn =3D F2FS_NODE(dst); - memcpy(&dst_rn->footer, &src_rn->footer, sizeof(struct node_footer)); + memcpy(F2FS_NODE_FOOTER(dst), F2FS_NODE_FOOTER(src), + sizeof(struct node_footer)); } =20 static inline void fill_node_footer_blkaddr(struct folio *folio, block_t b= lkaddr) { struct f2fs_checkpoint *ckpt =3D F2FS_CKPT(F2FS_F_SB(folio)); - struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); __u64 cp_ver =3D cur_cp_version(ckpt); =20 if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) cp_ver |=3D (cur_cp_crc(ckpt) << 32); =20 - rn->footer.cp_ver =3D cpu_to_le64(cp_ver); - rn->footer.next_blkaddr =3D cpu_to_le32(blkaddr); + footer->cp_ver =3D cpu_to_le64(cp_ver); + footer->next_blkaddr =3D cpu_to_le32(blkaddr); } =20 static inline bool is_recoverable_dnode(const struct folio *folio) @@ -376,11 +371,12 @@ static inline bool IS_DNODE(const struct folio *node_= folio) static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 f2fs_folio_wait_writeback(folio, NODE, true, true); =20 if (i) - rn->i.i_nid[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -389,9 +385,10 @@ static inline int set_nid(struct folio *folio, int off= , nid_t nid, bool i) static inline nid_t get_nid(const struct folio *folio, int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 if (i) - return le32_to_cpu(rn->i.i_nid[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); return le32_to_cpu(rn->in.nid[off]); } =20 @@ -404,8 +401,7 @@ static inline nid_t get_nid(const struct folio *folio, = int off, bool i) =20 static inline int is_node(const struct folio *folio, int type) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - return le32_to_cpu(rn->footer.flag) & BIT(type); + return le32_to_cpu(F2FS_NODE_FOOTER(folio)->flag) & BIT(type); } =20 #define is_cold_node(folio) is_node(folio, COLD_BIT_SHIFT) @@ -414,14 +410,13 @@ static inline int is_node(const struct folio *folio, = int type) =20 static inline void __set_mark(const struct folio *folio, bool mark, int ty= pe) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - unsigned int flag =3D le32_to_cpu(rn->footer.flag); - + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); + unsigned int flag =3D le32_to_cpu(footer->flag); if (mark) flag |=3D BIT(type); else flag &=3D ~BIT(type); - rn->footer.flag =3D cpu_to_le32(flag); + footer->flag =3D cpu_to_le32(flag); } =20 static inline void set_cold_node(const struct folio *folio, bool is_dir) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index b0747c0b2c10..c1d76674ab7c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4384,6 +4384,10 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->blocksize =3D BIT(sbi->log_blocksize); sbi->nat_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_nat_entry); + sbi->addrs_per_inode =3D F2FS_DEF_ADDRS_PER_INODE(sbi->blocksize); + sbi->addrs_per_block =3D (sbi->blocksize - + sizeof(struct node_footer)) / sizeof(__le32); + sbi->nids_per_block =3D sbi->addrs_per_block; sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index bce3d93e4755..7cd7ce58334b 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -85,7 +85,7 @@ struct f2fs_xattr_entry { =20 #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(_= _le32)) #define MAX_INLINE_XATTR_SIZE \ - (DEF_ADDRS_PER_INODE - \ + (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 2370af742c8f..bec31591b398 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -268,11 +268,9 @@ struct node_footer { } __packed; =20 /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ - - SIZE_OF_I_NID \ - - sizeof(struct node_footer)) / sizeof(__le32)) -#define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ - get_extra_isize(inode)) +#define F2FS_DEF_ADDRS_PER_INODE(blocksize) \ + (((blocksize) - OFFSET_OF_END_OF_I_EXT - SIZE_OF_I_NID - \ + sizeof(struct node_footer)) / sizeof(__le32)) #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ @@ -283,11 +281,11 @@ struct node_footer { =20 #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) =20 -#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) -#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) -#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3) -#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4) -#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5) +#define NODE_DIR1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 1) +#define NODE_DIR2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 2) +#define NODE_IND1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 3) +#define NODE_IND2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 4) +#define NODE_DIND_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 5) =20 #define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02 /* file inline data flag */ @@ -347,18 +345,26 @@ struct f2fs_inode { */ __le32 i_extra_end[0]; /* for attribute size calculation */ } __packed; - __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ + DECLARE_FLEX_ARRAY(__le32, i_addr); /* data block pointers */ }; - __le32 i_nid[DEF_NIDS_PER_INODE]; /* direct(2), indirect(2), - double_indirect(1) node id */ + /* + * __le32 i_nid[DEF_NIDS_PER_INODE]; + * direct(2), indirect(2), double_indirect(1) node IDs + * + * It is stored immediately before the node footer at the end of the + * filesystem block. Its offset depends on the filesystem block size, so + * locate it dynamically with F2FS_INODE_NIDS(). + */ } __packed; =20 struct direct_node { - __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */ + /* The address count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, addr); /* array of data block address */ } __packed; =20 struct indirect_node { - __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ + /* The node ID count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, nid); /* array of data block address */ } __packed; =20 enum { @@ -377,7 +383,13 @@ struct f2fs_node { struct direct_node dn; struct indirect_node in; }; - struct node_footer footer; + /* + * struct node_footer footer; + * + * It is stored at the end of the filesystem block, after the inode or + * direct/indirect node data. Its offset depends on the filesystem block + * size, so locate it dynamically with F2FS_NODE_FOOTER(). + */ } __packed; =20 /* --=20 2.53.0 From nobody Sat Sep 26 06:20:27 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 326E037F723 for ; Thu, 3 Sep 2026 23:56:34 +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=1788479795; cv=none; b=QlSiuh28p2OBFKqOh6jun6pRF+L+YhFQjnXpdCwz+pZcuXir6oeH/LB5abDZfe9gXx70wO4jxctRf98/AeNhcWDuDKR12r3yzLerdWb84bUw/l+diES/AVrFnI3F32zMdwyDA+crUl9mz96uGYg6zP7Dabyp5xCFj7POKlbdBjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479795; c=relaxed/simple; bh=t241G7/ZKHBSwA70NCpYAVhPiF8oDmtty8rYOMdBTQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iF+9MbrCVPpwGDH8Q258ceumSbrpifyToGQnITSfQdeIjm8sMJtrxe0rL6k3z9XXg0BDGYk95HNMbLJR9Jf9Od1DyqTr76gsP3mpcNTTgB3t6fg5r2EL4/n6pqBTX0HEy6JTi3yIEJJzbC6u7wYdQbfDjhIbXPseWFj7c8ALQ3A= 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=K62H4Meh; 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="K62H4Meh" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2caced6038eso4531465ad.0 for ; Thu, 03 Sep 2026 16:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479793; x=1789084593; 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=j1HQbrF7PkJ6PeWLX/CZqb0BIOhOO4tfnaywHDSdkZ0=; b=K62H4Mehyyu3XJj7Ssn23wCOcVtr2jexjDQl4z9lcErdPyBdpOHYf5KrBysng1N/x8 Vzzlfe+DF5e7qHAS9NDHwwsCHJHoPkayCWkyfrKkvPSPPhKKOVCzACEYkUZeaxYv6jh9 qdgTnDxcVpDlLoVZWkq56y3X63f66apluncmJskpYL9a85EXoStTHBF+/ogzlGtxnVdW 8DnklinrTXNWoGF7Dzxcz71cKTVXwklnhVs8VnzJuRsqJ2oVKrQT8M2aHSJxnKbwE2vZ FtL/q+Q9gEHQMeY33VZurGn4ID5InwUhVsVozI4S7e0nr/bY00/Yo47+5oZFePNx8Od/ bFmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479793; x=1789084593; 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=j1HQbrF7PkJ6PeWLX/CZqb0BIOhOO4tfnaywHDSdkZ0=; b=DlkLoUhURMetpbT/6qNOkfMD8PvIKrRKtIzqiYOC2jap8dcU5PwMFlU1/R0IY1f/e4 ay7164RvWjpHmLWpJC5WfFLQpt6wFySfpTVc9OjFE3Lf6YocCVElM1v9Fp9M0t4N5/2f 2BNmjoTJwewp1Ur5wtiBTpFMvw17wKLCCKejZ7CQuJH8/gmFnSCLdFqBmQSlanuAvzpZ S/H4aTx1SYnyhkRvZ3oBJc1MuOw9Rnf2Pt1O3rL11uZiNRx8UhHo1n7z6oPGH6Fde7V+ bnDgImq+uro9mXOSDNJphvpDwF7TiyrYtEA52UOlm0Medw+p7Pg2IfpZgzbvkyCmDH8M cNYg== X-Forwarded-Encrypted: i=1; AKwUvBytPoHCUaNfWgDaUs9h9lAjqcmphtqFBCj/Fs0HNMCK/eIo0tg37yZYh4tbKvx0nIvY0qDtc8zLvO5Snio=@vger.kernel.org X-Gm-Message-State: AFuF++nm0qkbbghsTFHK212LAJW3kWb49I7ugnFs02TF2U/T4BxySPsJ 6SW3tMYriWdLrf/zXNy8bu1MbuqHt58rIBzMypl3+X0rJKpN1QtGk5jD X-Gm-Gg: AYBFou1LmIDDxyHaeRKNd7K8j+EA/2LA7+6xpi7Hm48PDPM7PS8Pb3++f2l4cXxsOLG ryvNsnAwft6CZwVyDldsl/BLdd6Ph1S5wa0q5N2WG1SCx6XQiwK1wRlzvuf4jG9sPeK80HpAc2j vNc/nCOIhX9neGJGb3K3E47vQ9FdsTi/8CbRrKH0Z1V8Umi3bnMYd/JXsDtV7bRfEE8rUcAxDzd QjlnefkK0RMEJdINB6AOMFmEDjytsRzLbIToZ2N0TfkBLTfz672B8JUt8xphHQiCUQxbaEg5klU ErxYx9l+J95LFY0i9YWdPbXcyrOsXX2OICQ9S4WsLVGXXMAG+Yl+XW4OKnMzhkjKC+3PJftdOaW HIfS5p05PVVS65j2PYWkKenfVz5wSEM8RyJb/+KbdDcGFfJUp69HXLRMvw0tuI5zUb0Q42c1mNC CoJRE6Iogvm/pBNhhHMUEZTDf8ztw2Q0ciZGoKXVDiwY/lOGvBkQZmK6DFFTSzAQSbog== X-Received: by 2002:a17:90a:e183:b0:37f:e5b1:ec4b with SMTP id 98e67ed59e1d1-39b07f305admr9839298a91.5.1788479793441; Thu, 03 Sep 2026 16:56:33 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339ac24d7esm3077063eec.15.2026.09.03.16.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:33 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 07/11] f2fs: describe xattr block layout dynamically Date: Thu, 3 Sep 2026 16:56:19 -0700 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The usable capacity of dedicated on-disk extended attribute blocks and inline xattr regions scales with the filesystem block size. Parameterize VALID_XATTR_BLOCK_SIZE and MAX_INLINE_XATTR_SIZE to calculate usable xattr limits dynamically from sbi->blocksize rather than hardcoding PAGE_SIZE or DEF_ADDRS_PER_INODE. Update mount option consistency validation for inline_xattr_size to evaluate allowed boundaries dynamically against the runtime block size. Signed-off-by: Kelvin Zhang Reviewed-by: Chao Yu --- fs/f2fs/inode.c | 7 ++++--- fs/f2fs/node.c | 2 +- fs/f2fs/super.c | 17 +++++++++++++++-- fs/f2fs/xattr.c | 8 +++++--- fs/f2fs/xattr.h | 11 ++++++----- include/linux/f2fs_fs.h | 3 +++ 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index fda9ee3bfc61..79c0a1301996 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -337,12 +337,13 @@ static bool sanity_check_inode(struct inode *inode, s= truct folio *node_folio) } =20 if (f2fs_sb_has_flexible_inline_xattr(sbi) && - (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE || + (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE(i_blocksize(inode)) || (f2fs_has_inline_xattr(inode) && fi->i_inline_xattr_size < MIN_INLINE_XATTR_SIZE))) { - f2fs_warn(sbi, "%s: inode (ino=3D%llx) has corrupted i_inline_xattr_size= : %d, min: %zu, max: %lu", + f2fs_warn(sbi, "%s: inode (ino=3D%llx) has corrupted i_inline_xattr_size= : %d, min: %zu, max: %zu", __func__, inode->i_ino, fi->i_inline_xattr_size, - MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE); + MIN_INLINE_XATTR_SIZE, + (size_t)MAX_INLINE_XATTR_SIZE(i_blocksize(inode))); return false; } =20 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e3f594f7bcce..7dabfada1b54 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2919,7 +2919,7 @@ int f2fs_recover_xattr_data(struct inode *inode, stru= ct folio *folio) /* 3: update and set xattr node page dirty */ if (folio) { memcpy(F2FS_NODE(xfolio), F2FS_NODE(folio), - VALID_XATTR_BLOCK_SIZE); + VALID_XATTR_BLOCK_SIZE(inode)); folio_mark_dirty(xfolio); } f2fs_folio_put(xfolio, true); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c1d76674ab7c..4c95229ac3f1 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -855,9 +855,11 @@ static int f2fs_parse_param(struct fs_context *fc, str= uct fs_parameter *param) break; case Opt_inline_xattr_size: if (result.int_32 < MIN_INLINE_XATTR_SIZE || - result.int_32 > MAX_INLINE_XATTR_SIZE) { + result.int_32 > + MAX_INLINE_XATTR_SIZE(F2FS_MAX_BLKSIZE)) { f2fs_err(NULL, "inline xattr size is out of range: %u ~ %u", - (u32)MIN_INLINE_XATTR_SIZE, (u32)MAX_INLINE_XATTR_SIZE); + (u32)MIN_INLINE_XATTR_SIZE, + (u32)MAX_INLINE_XATTR_SIZE(F2FS_MAX_BLKSIZE)); return -EINVAL; } ctx_set_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE); @@ -1596,6 +1598,8 @@ static int f2fs_check_opt_consistency(struct fs_conte= xt *fc, } =20 if (ctx_test_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE)) { + int min_size, max_size; + if (!f2fs_sb_has_extra_attr(sbi) || !f2fs_sb_has_flexible_inline_xattr(sbi)) { f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); @@ -1605,6 +1609,15 @@ static int f2fs_check_opt_consistency(struct fs_cont= ext *fc, f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr= option"); return -EINVAL; } + min_size =3D MIN_INLINE_XATTR_SIZE; + max_size =3D MAX_INLINE_XATTR_SIZE(sbi->blocksize); + + if (F2FS_OPTION(sbi).inline_xattr_size < min_size || + F2FS_OPTION(sbi).inline_xattr_size > max_size) { + f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", + min_size, max_size); + return -EINVAL; + } } =20 if (ctx_test_opt(ctx, F2FS_MOUNT_ATGC) && diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 6728d1488cad..99c863513725 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -310,7 +310,8 @@ static int read_xattr_block(struct inode *inode, void *= txattr_addr) return PTR_ERR(xfolio); =20 xattr_addr =3D folio_address(xfolio); - memcpy(txattr_addr + inline_size, xattr_addr, VALID_XATTR_BLOCK_SIZE); + memcpy(txattr_addr + inline_size, xattr_addr, + VALID_XATTR_BLOCK_SIZE(inode)); f2fs_folio_put(xfolio, true); =20 return 0; @@ -393,7 +394,7 @@ static int read_all_xattrs(struct inode *inode, struct = folio *ifolio, { struct f2fs_xattr_header *header; nid_t xnid =3D F2FS_I(inode)->i_xattr_nid; - unsigned int size =3D VALID_XATTR_BLOCK_SIZE; + unsigned int size =3D VALID_XATTR_BLOCK_SIZE(inode); unsigned int inline_size =3D inline_xattr_size(inode); void *txattr_addr; int err; @@ -502,7 +503,8 @@ static inline int write_all_xattrs(struct inode *inode,= __u32 hsize, =20 if (inline_size) memcpy(inline_addr, txattr_addr, inline_size); - memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE); + memcpy(xattr_addr, txattr_addr + inline_size, + VALID_XATTR_BLOCK_SIZE(inode)); =20 if (inline_size) folio_mark_dirty(ifolio ? ifolio : in_folio); diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index 7cd7ce58334b..75beab2d1ee3 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -71,21 +71,22 @@ struct f2fs_xattr_entry { for (entry =3D XATTR_FIRST_ENTRY(addr);\ !IS_XATTR_LAST_ENTRY(entry);\ entry =3D XATTR_NEXT_ENTRY(entry)) -#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) +#define VALID_XATTR_BLOCK_SIZE(i) (i_blocksize(i) - \ + sizeof(struct node_footer)) #define XATTR_PADDING_SIZE (sizeof(__u32)) #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \ - VALID_XATTR_BLOCK_SIZE : 0) + \ + VALID_XATTR_BLOCK_SIZE(i) : 0) + \ (inline_xattr_size(i))) #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ - VALID_XATTR_BLOCK_SIZE) + VALID_XATTR_BLOCK_SIZE(i)) =20 #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ sizeof(struct f2fs_xattr_header) - \ sizeof(struct f2fs_xattr_entry)) =20 #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(_= _le32)) -#define MAX_INLINE_XATTR_SIZE \ - (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ +#define MAX_INLINE_XATTR_SIZE(blocksize) \ + (F2FS_DEF_ADDRS_PER_INODE(blocksize) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bec31591b398..e98bff846b23 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -15,7 +15,10 @@ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ #define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sect= or/blk */ +#define F2FS_MIN_LOG_BLOCKSIZE 12 +#define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ +#define F2FS_MAX_BLKSIZE PAGE_SIZE #define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 CC18E37E2E6 for ; Thu, 3 Sep 2026 23:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479798; cv=none; b=NMcfl51/WsSdq7VeTmgkC4ntmOVCazhq7m2uE7bk5m8zbkMdmWlXVx2t69sjim9xH4ltLXxFyXSd/mcQrr3Df/kTpcnCSZlzm2z3u75dTJIqR6veUaaGgCcLQtCnxfIuDbzeC1K0MJKy2+gZ3wRadx3oAvCWI/8TkZhbJjCYMoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479798; c=relaxed/simple; bh=8iK9i/NqLUeuHV2sAqvUJRpqeFg1lmTTuf15Lkxscmk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P7miWiVH1WRq/7evCbz78Zho102kfNWkOBvx+Mk8HHZ3yOCdhoZpaC0GS/fwrpFLYA6cBZLwdpTxIP/A4UrM3WmZ0tfsbxJVM7UlTkXGrBWCkWmeruMD8Ho5hh+AIQBk8KvoZgCjKE/+cqrMBuL+xjXcuY2SNb6HFbD7nzkUTP4= 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=Q3LBvENQ; arc=none smtp.client-ip=209.85.215.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="Q3LBvENQ" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cb5b8572b70so588548a12.2 for ; Thu, 03 Sep 2026 16:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479795; x=1789084595; 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=MFGytssX5xYfgUs57Q55SXrdDTErkoIleyvcFFl1lvo=; b=Q3LBvENQviL/zKfvRJEXtZskpCTqN3/6nUf8/t/kBgVFm+5E66/JN+G5WjHvAz8r4O gCtJ0qjba8iE7p1Q9+ZwdhcNdbuKjPEWr0/pL4pNj0/wzAJhwQKkGrh+/Cju7uCFTjcf ztXamgKmNoP3wmc65UeidanTmRea/MAwj+Pq9MLyFZvEnCtiLaHIzfohB50XT/Hdw0QD E9Ny9U4vtF8bRWfO9zpHzvOmWfJ2hGl7iKnZ9PBW4FGRdwMTSdY1Jwdqvn1v6Di+8iD5 T3sS8fLIjPFqQHwSGRwKRs7/Rzo5jO8pVGRubu20MdjrLd+0iMosX4jIvcF3nzVoXAcf hdIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479795; x=1789084595; 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=MFGytssX5xYfgUs57Q55SXrdDTErkoIleyvcFFl1lvo=; b=XqINxt6Qwrzy1csibLULJ00cYCWPfOddlky0LoPvaVGbnYBH8wgu8AtnF0WvJ+OoQy uw5LnQaOxK5hib7mHCDGD4kGT/RhCZlc59s628fU9ii+tjS+/FqOoOyH/Q5PQcBpCoc6 qSz8HX+RG6h99HefGNVDiCh8kNK1eUi+fRCdKtK15Yeea4RjpDUqJuFrFkaU/Uvq9WGX b6T4go9f5noJmcewl0W3PbPFCQRLama9oiGjFmNQsH7yKiiOSLbJEhaHplTFXGs5/59Z b2sBXjGCTmtVe4FkUN64082dgmnEZ//i344vWRrtuEthtWLhvSxg+dHchxBBljjtIsKr xFXw== X-Forwarded-Encrypted: i=1; AKwUvByvGsCyC1P+z/cygU2mZlcljXW/Rwj4WUVEZz0SA+Uic5KFrftaqtsOCa6lkNFBlp0dOretyGLt7RR+/gQ=@vger.kernel.org X-Gm-Message-State: AFuF++m5usMVY29dAoaoT22o3g8+c4L68uWtpRq/iufSVWLqxUZcNA6l +WlzLPjRcHfBF3nnTvUdescO8aswGK4fuMZ2qTBG1AwfSOKmip6A6vaw X-Gm-Gg: AYBFou0MbVIDaUUs4bO+wUwOSbAIImGs6P5WtLMDK30TW1pmDp194f62CQ2rv9Mm+6J ZAGi6csQBTtziNW1EJk8SQ1UsjcfdGd+gmOasSrz0UZUyvJotpJHuJlQP/P7B9usNx0rcOSCJbm vJ9AOxk2R2SQZB0WEoLp4CiWQ7yQsq3AoLstyU/i1KYzDqbqWN7GCy2tskIUItdeIW4OHNRuaSv Kr436uWzzKwj65YImwEhGpD9BdDMiycyMl7YGoUI0oYLVvYjopfcrzFVpzkLM5e4TP4btTixHuD em88UUzffob7pKD6OFQG3yeE8gkh5CgvViPpOlciMyPrgm5Xupyq6KF4p/KOrNfAXs5EJ+0Gko8 X02a9UdkVjepYE6nlynHWGjUfFGreswxdKpoHExoSQg1Sz47jcsBNQhOruGrxzThHahgZeVH6uH d1Qf8c4+N2hhZNFvjsUewPnqxvq+6iqVey4WwOBLoV2kiWRBCZy14PYs4/F8+P3Z9hfg== X-Received: by 2002:a17:90b:1d45:b0:398:9bd4:d1a with SMTP id 98e67ed59e1d1-39b262995b8mr3063563a91.25.1788479795047; Thu, 03 Sep 2026 16:56:35 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339bdf26c5sm1997386eec.27.2026.09.03.16.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:34 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 08/11] f2fs: parameterize sector conversion macros Date: Thu, 3 Sep 2026 16:56:20 -0700 Message-ID: <534c0147c80d739938e90cc9f1c349fc9ae3f6fd.1788479509.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 Reviewed-by: Chao Yu --- 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 460d95c9414c..c8716926aee1 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -439,7 +439,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 06ac655a16e9..0de36ae0795d 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 edc352569e87..6c29a18b9fbd 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4506,8 +4506,8 @@ static int f2fs_reserve_compress_blocks(struct file *= filp, unsigned long arg) static int f2fs_secure_erase(struct block_device *bdev, struct inode *inod= e, pgoff_t off, block_t block, block_t len, u32 flags) { - sector_t sector =3D SECTOR_FROM_BLOCK(block); - sector_t nr_sects =3D SECTOR_FROM_BLOCK(len); + sector_t sector =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), block); + sector_t nr_sects =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), len); int ret =3D 0; =20 if (flags & F2FS_TRIM_FILE_DISCARD) { diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 79c0a1301996..aa22e457d5b3 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -221,11 +221,11 @@ static bool sanity_check_compress_inode(struct inode = *inode, return false; } if (le64_to_cpu(ri->i_compr_blocks) > - SECTOR_TO_BLOCK(inode->i_blocks)) { + SECTOR_TO_BLOCK(sbi, inode->i_blocks)) { f2fs_warn(sbi, "%s: inode (ino=3D%llx) has inconsistent i_compr_blocks:%llu, i_blocks:= %llu, run fsck to fix", __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), - SECTOR_TO_BLOCK(inode->i_blocks)); + SECTOR_TO_BLOCK(sbi, inode->i_blocks)); return false; } if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || @@ -447,7 +447,8 @@ static int do_read_inode(struct inode *inode) i_gid_write(inode, le32_to_cpu(ri->i_gid)); set_nlink(inode, le32_to_cpu(ri->i_links)); inode->i_size =3D le64_to_cpu(ri->i_size); - inode->i_blocks =3D SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1); + inode->i_blocks =3D SECTOR_FROM_BLOCK(sbi, + le64_to_cpu(ri->i_blocks) - 1); =20 inode_set_atime(inode, le64_to_cpu(ri->i_atime), le32_to_cpu(ri->i_atime_nsec)); @@ -696,6 +697,7 @@ struct inode *f2fs_iget_retry(struct super_block *sb, u= nsigned long ino) =20 void f2fs_update_inode(struct inode *inode, struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_inode_info *fi =3D F2FS_I(inode); struct f2fs_inode *ri; struct extent_tree *et =3D fi->extent_tree[EX_READ]; @@ -712,7 +714,8 @@ void f2fs_update_inode(struct inode *inode, struct foli= o *node_folio) ri->i_uid =3D cpu_to_le32(i_uid_read(inode)); ri->i_gid =3D cpu_to_le32(i_gid_read(inode)); ri->i_links =3D cpu_to_le32(inode->i_nlink); - ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(READ_ONCE(inode->i_blocks)) = + 1); + ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(sbi, + READ_ONCE(inode->i_blocks)) + 1); =20 if (!f2fs_is_atomic_file(inode) || is_inode_flag_set(inode, FI_ATOMIC_COMMITTED)) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 7bf8fa992600..c6adeeae9194 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 4c95229ac3f1..0bd6df924a97 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3944,7 +3944,7 @@ static int __f2fs_commit_super(struct f2fs_sb_info *s= bi, struct folio *folio, bio =3D bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS); =20 /* it doesn't need to set crypto context for superblock update */ - bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(folio->index); + bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(sbi, folio->index); =20 if (!bio_add_folio(bio, folio, folio_size(folio), 0)) f2fs_bug_on(sbi, 1); @@ -4519,7 +4519,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone,= unsigned int idx, { struct f2fs_report_zones_args *rz_args =3D data; block_t unusable_blocks =3D (zone->len - zone->capacity) >> - F2FS_LOG_SECTORS_PER_BLOCK; + F2FS_LOG_SECTORS_PER_BLOCK(rz_args->sbi); =20 if (zone->type =3D=3D BLK_ZONE_TYPE_CONVENTIONAL) return 0; @@ -4562,10 +4562,10 @@ static int init_blkz_info(struct f2fs_sb_info *sbi,= int devi) =20 zone_sectors =3D bdev_zone_sectors(bdev); if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=3D - SECTOR_TO_BLOCK(zone_sectors)) + SECTOR_TO_BLOCK(sbi, zone_sectors)) return -EINVAL; - sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(zone_sectors); - FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(nr_sectors), + sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(sbi, zone_sectors); + FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(sbi, nr_sectors), sbi->blocks_per_blkz); if (nr_sectors & (zone_sectors - 1)) FDEV(devi).nr_blkz++; diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index e98bff846b23..33995cd3dd6d 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,7 +14,7 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sect= or/blk */ +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log = number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B14C027A92D for ; Thu, 3 Sep 2026 23:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479800; cv=none; b=NGgNcZpbt0TJ1CZakuVOhu6yT6bhOkQC6qXqGb6ghbKJKWYp2DFDW2iAvOOtfgqw35Wv2+IxQvqW+RXXfAQHeYmtFL3P5ex4e0DxeSY0Aja4z+6PYPK/i+SYzRoY0s2ivtTgyfR86BlVL9uNj6oaF+c1cUfHP5EsVTHfZ3KggtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479800; c=relaxed/simple; bh=gODfPG2HdHktrlVtg7ms+FRdmMTtRU215fGhul/y3V4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQeVXM7DCoc0cUvGZ9HHhLb/euh/0oIyFUwNRg5gRGAVcIAR4brptFfRn78jYs1D6cDPnyn9cbs66xjpTl3H59MAHtqyjwCwRhSyJT/182mfTUo3F7qR/1YWWaLgnFPWlEkgbGZkXIlcI3vusMhQ091yuU8lVHsaMcfev44TDcI= 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=bO172Ofz; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bO172Ofz" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2d71ae3455aso5846085ad.1 for ; Thu, 03 Sep 2026 16:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479797; x=1789084597; 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=R0WqqHY1bFKVz896PwW4TtV+Us1aSvJ/ISPE7i5Zph8=; b=bO172OfzjSEOt+gLe19jp/jhl+UFn/Ml9ZSK4HUbLaaV+m1XUv4FduoOjzmorVuueS xBFl2/ZdCA8ianB1V6PAju/U47ef09dv4ZIr4R5Vau4Lh9RPxntAD6Cz/dh9QVKb/8fq tj+fLgFSiqeEw/8vakTAbx2/6VJFoI0DIWZ0Nq3uDxdpqQjCWAWozLcsDk0ZbSa+ppG2 kSg+YouXcNKf5soCDAWd6K/LxwJ6sf7dsLDTV3eBhFSVnvNIGeL1vqOI/uVUrYMQPtQe iTODlDUEqwMilKQtQs9i/vlnMvFW6YR4H+jvFVSYci0VERKOtT0OHgLr0BCPscgVZbXT VWhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479797; x=1789084597; 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=R0WqqHY1bFKVz896PwW4TtV+Us1aSvJ/ISPE7i5Zph8=; b=bQGclUoG7whLbKXFm3hIiH4802fmkr3H6oOeoMp4TtZ0ebqTf8U7Z4hzxp7KLJuSDH +4U3f/jbOWiSDWs0/7xvPXHXQQsRdGFUtTAp3tFGzFIWHfNGVGlzrUC/fNcHx40hlooE DoVI4am9ZvwMFP+QMXBPJJIAPsCfxJUPxnDkMApCg/dePyymVAA96cT/n/LjtX9dTeOb qZR9saRcPNgEBY+WpN/7/ehBnewdQzY/MWNAkyKZZANx9O8hD1hrPWL4LIve/RpLf4RP Z2QJJH/y5Mn/DOCUHUXe3Bk57EP2R2ODAEqpv/3QtdHfMNiVMdDBl5U5bGpXl3zTcLEZ Nh5g== X-Forwarded-Encrypted: i=1; AKwUvBywAX6VE8dqyKYiEgKS9eni/KLb9eVsINowvCmUGgGUQ+F6HdbY53fapDQ0eQpox+o5//2iJioV29D9k88=@vger.kernel.org X-Gm-Message-State: AFuF++mUllaU/cQP+0CjXGa+sQ5aOl67MybkrQA5NaVwDbqpIlUPVgUG RFprN8MdiaewAbPpEhgBdQ5Lpgp1RbGYu9B4OETWflEmUTe4tZM5z4b2 X-Gm-Gg: AYBFou07RB4E9wsGmXCnxCJccRxnGn4dNOPFPdplcJdAkDLlr3wA4Jj+j1rKNGttFuY AEdisEbGqO0/9oJ9GMaIdYS5JJeMFbjs5r2ZDaaNSRXMIZgmnaW0QIIiuZUaT/ijJZVa/7t/erR jEmegkoLqSXYQk7WPg4FxUs+5+4wiPGqzNyLsnb4NK7qk7p5f+awOmmC2fMy27KUHex2Mju5+4h +L+l7d5W4SOaYnYIpE/t3lbQ6RmJiO8Rd7McQJ6VXKd5th9zIyxw3fVdA1CLcYYHfSn1IyWqeO2 fP0A4hIv2fC0sWCm3VV+U7vBSXJx1PbsIgTPtyvjnfFBSaheQf8d6ir7q+2XY2NKkQaud0i7yTD oiRaTrAQufFqxRYZZSFcV35+M2C3cM23ErYBPPQs+8eW2NR1sLNpc0kXfSe1IV8nNOqENUZWlw9 1z0U1nG4lQ7SZjsz67WIWMVGWcAEktxlqW2kRXV0rF9X7xUUmiReSt0ot6K95C9gkcfA== X-Received: by 2002:a17:903:468d:b0:2d9:56d8:75f with SMTP id d9443c01a7336-2db1266772dmr39257205ad.9.1788479796724; Thu, 03 Sep 2026 16:56:36 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339b608409sm2206021eec.21.2026.09.03.16.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:36 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 09/11] f2fs: parameterize byte and block conversion macros Date: Thu, 3 Sep 2026 16:56:21 -0700 Message-ID: <7b563b3096652abe81f77edc886ab98c416f189f.1788479509.git.zhangxp1998@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Byte-to-block and block-to-byte conversion helpers previously relied on global PAGE_SIZE, PAGE_SHIFT, or F2FS_BLKSIZE_BITS. Parameterize F2FS_BYTES_TO_BLK, F2FS_BLK_TO_BYTES, F2FS_BLK_END_BYTES, F2FS_BLK_ALIGN, and max_file_blocks with struct f2fs_sb_info *sbi using sbi->log_blocksize. Update all call sites across data mapping, file operations, fiemap queries, fsverity checks, NAT bitmap allocations, and truncate paths. Signed-off-by: Kelvin Zhang Reviewed-by: Chao Yu --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 58 +++++++++++++++++++++++------------------ fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 7 ++--- fs/f2fs/file.c | 54 +++++++++++++++++++++----------------- fs/f2fs/node.c | 7 ++--- fs/f2fs/recovery.c | 4 +-- fs/f2fs/segment.c | 9 ++++--- fs/f2fs/super.c | 9 ++++--- fs/f2fs/verity.c | 6 +++-- include/linux/f2fs_fs.h | 13 ++++++--- 11 files changed, 97 insertions(+), 74 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index c7183d4b6765..4d1a0544bbf0 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1858,7 +1858,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 c8716926aee1..a4006b92da55 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1942,12 +1942,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; @@ -1990,7 +1990,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } =20 - phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(sbi, ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + sizeof(__le32) * (DEF_ADDRS_PER_INODE(sbi) - get_inline_xattr_addrs(inode)); @@ -2024,7 +2024,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); @@ -2043,6 +2043,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; @@ -2066,7 +2067,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; @@ -2086,10 +2087,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)); @@ -2111,7 +2112,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; @@ -2159,14 +2160,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) { @@ -2180,7 +2181,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: @@ -2200,7 +2201,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); } @@ -2228,7 +2230,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; @@ -2339,7 +2342,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 */ @@ -4161,7 +4165,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)) { @@ -4277,7 +4281,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; @@ -4532,12 +4536,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); @@ -4558,7 +4564,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 /* * Sometimes I/O to an encrypted file has to be broken up to guarantee @@ -4578,11 +4584,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; @@ -4591,11 +4597,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 0de36ae0795d..c0bccc763e70 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4021,7 +4021,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); @@ -5267,8 +5267,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 6c29a18b9fbd..5892247b3622 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; } } @@ -1157,7 +1161,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)) { @@ -1173,7 +1177,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; } } @@ -2644,7 +2648,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 @@ -3187,8 +3192,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); @@ -3322,9 +3327,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) @@ -3990,7 +3995,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; @@ -4590,7 +4595,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); @@ -5381,7 +5386,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. */ @@ -5402,8 +5408,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 c6adeeae9194..eb27b92fbad8 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 0bd6df924a97..da97f0f38ea0 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3884,7 +3884,7 @@ static const struct export_operations f2fs_export_ops= =3D { .get_parent =3D f2fs_get_parent, }; =20 -loff_t max_file_blocks(struct inode *inode) +loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode) { loff_t result =3D 0; loff_t leaf_count; @@ -3918,7 +3918,8 @@ loff_t max_file_blocks(struct inode *inode) * fit within U32_MAX + 1 data units. */ =20 - result =3D umin(result, F2FS_BYTES_TO_BLK(((loff_t)U32_MAX + 1) * 4096)); + result =3D umin(result, F2FS_BYTES_TO_BLK(sbi, + ((loff_t)U32_MAX + 1) * 4096)); =20 return result; } @@ -4370,7 +4371,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) =20 nat_blocks =3D nat_segs << log_blocks_per_seg; nat_bits_bytes =3D nat_blocks / BITS_PER_BYTE; - nat_bits_blocks =3D F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + nat_bits_blocks =3D F2FS_BLK_ALIGN(sbi, (nat_bits_bytes << 1) + 8); if (__is_set_ckpt_flags(ckpt, CP_NAT_BITS_FLAG) && (cp_payload + F2FS_CP_PACKS + NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >=3D blocks_per_seg)) { @@ -5192,7 +5193,7 @@ static int f2fs_fill_super(struct super_block *sb, st= ruct fs_context *fc) if (err) goto free_options; =20 - sb->s_maxbytes =3D max_file_blocks(NULL) << + sb->s_maxbytes =3D max_file_blocks(sbi, NULL) << le32_to_cpu(raw_super->log_blocksize); sb->s_max_links =3D F2FS_LINK_MAX; =20 diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c index 39f482515445..ee838f880c4a 100644 --- a/fs/f2fs/verity.c +++ b/fs/f2fs/verity.c @@ -75,7 +75,8 @@ static int pagecache_write(struct inode *inode, const voi= d *buf, size_t count, struct address_space *mapping =3D inode->i_mapping; const struct address_space_operations *aops =3D mapping->a_ops; =20 - if (pos + count > F2FS_BLK_TO_BYTES(max_file_blocks(inode))) + if (pos + count > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode))) return -EFBIG; =20 while (count) { @@ -239,7 +240,8 @@ static int f2fs_get_verity_descriptor(struct inode *ino= de, void *buf, =20 /* Get the descriptor */ if (pos + size < pos || - pos + size > F2FS_BLK_TO_BYTES(max_file_blocks(inode)) || + pos + size > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)) || pos < f2fs_verity_metadata_pos(inode) || size > INT_MAX) { f2fs_warn(F2FS_I_SB(inode), "invalid verity xattr"); f2fs_handle_error(F2FS_I_SB(inode), diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 33995cd3dd6d..4c9540981db4 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -28,10 +28,15 @@ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ =20 #define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) -#define F2FS_BYTES_TO_BLK(bytes) ((unsigned long long)(bytes) >> F2FS_BLKS= IZE_BITS) -#define F2FS_BLK_TO_BYTES(blk) ((unsigned long long)(blk) << F2FS_BLKSIZE= _BITS) -#define F2FS_BLK_END_BYTES(blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1) -#define F2FS_BLK_ALIGN(x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1)) +#define F2FS_BYTES_TO_BLK(sbi, bytes) \ + ((unsigned long long)(bytes) >> (sbi)->log_blocksize) +#define F2FS_BLK_TO_BYTES(sbi, blk) \ + ((unsigned long long)(blk) << (sbi)->log_blocksize) +#define F2FS_BLK_END_BYTES(sbi, blk) \ + (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) +#define F2FS_BLK_ALIGN(sbi, bytes) \ + F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ + (sbi)->blocksize - 1) =20 /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 482EC37E5FB for ; Thu, 3 Sep 2026 23:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479801; cv=none; b=iC7eRNzObDedInGBpOnI8n48/JLMbDgvv8x3ScvQi/Wyd8OvwGHk1mRU8OavWrCKmO+dT4vPQdoDCsa6eHqDYwOXI72IVr41v0zbnM9eZJyfUMdvtFdEPUMhq2u/1ibcY0Ahu28lmRQg7JmWp5VNJeWRRnQr3nvW3v3aD2vWJ4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479801; c=relaxed/simple; bh=0mrUii/MaSLsi6bq8LVuYjaXkLlnNieJ4YYAgdAG4Ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p523iNwC1mg+R9IcXtJolbksprJD8vXuBGHh6eGXBdJsH+DO8l8l3N5O0ji+bEULe5j8z+d/eGuimJ4ko6Bnom9v9famcY4bKrV0MIVrIYpfS4vshbX8jrNdHfsMnVXSO1nSrKsZ6lH1sb7mWgtWh75FDSKa0e60A3WnAWn2zK0= 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=aQ2kU4Up; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aQ2kU4Up" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-38dfe910e9dso448083a91.3 for ; Thu, 03 Sep 2026 16:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479798; x=1789084598; 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=jhID0HeDATlzbNd87PMdvslGko3QPJeYrmg+eaXmErU=; b=aQ2kU4UpskDi3SfQqAtpem8VUSAeQaw8ZZkQdo6PdBilKoGlu0uNHS7Cz14oOwxrkY LsgcfutbGscOU58JrZC0Gov7UV1wXGVuT25NPmoBCuEiThvmop71AT5c4/QqUcr4niU4 s140GAf8BJFhnHzqPJ3ID9GLrIY7z57TaVh6XwWn0y5Ec4yLqXKM25/Ccrly3cBLJw6N mqOcrIR1XI+b5Gp5CcFX+Y9nGZyLl9F1AMWhM6jfPFpgK64MkJPcKMsyEtlH8rfYu8aK mntxUISkdCt9NbhIMJauGjOGwzBHDy1FTRN0ed3pXunDXex4E2tEIQYXnNeyWuM5o7oC 12pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479798; x=1789084598; 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=jhID0HeDATlzbNd87PMdvslGko3QPJeYrmg+eaXmErU=; b=Q7kbub9Fsm2l2iDPLtAsEZhY0h7Tk1LeSJR81fFzgZuvj4Mrzc5Rz0LNTxlqacFCht ZNeTMIbUwO9qnfpE3oEC45llzpfGRSegT/URO/tWebc7ERHPt0NdXiTqQTOSSTayV3+G io2lnkQaznEqcKy/RWsjE1f3xSj5jhAPmpwrMtSAd85hlHi3bZhHpRlUmdCZKLixqWg8 hZab8FMhbNZifTdHabL1IGgD5THO2RJvK523186bRaNFI0yN4PtFrokNgmt4jsL7yKuy Vd3bGZbWpOOhaitvkBMVI6pFSXbTCZsEZM7ZgygpFDyYevGCWkV3WWYTTf0AtMIKbyeD Z0TA== X-Forwarded-Encrypted: i=1; AKwUvBzKrdJ3uwVrGKq0nFGZ8VaSdwqZGO2deWUMXnHyLxuyykhtTk71ru1X7X6wso2/klkkxDynluiCQM9jNA8=@vger.kernel.org X-Gm-Message-State: AFuF++kSYxv1FRlIe+6tFV67dpo554ZurWT9Kyj5LVM45XTRJrhlEijt AglYFczj+M6yzgTkuulV8zUmeiM+ivjDYOwT193wK0PP34MqES4/j7em X-Gm-Gg: AYBFou3KFxdbIWAthtQtfxgXVtSg4zIfDz9auZp10rqikqDR+qHwx4yJM0BBqfOVK4N ThyMpBXJOAVR/CCZArekxOt1n8JiS2ExPQXe2HM5RoaFceZ4n5GezwoFFVsq1+YlhbAM340ZwzZ ryxm/fqk0fJGktt0namy1rriEZStASRe8yaCGCnUAcbmedm/s0lghJ1iVOz5pi26XcD5VgsjJVJ BQLiMxUgPDpMQ/YIRalRYcPyM/wT6JOVuPsNp+tYTmPbwo54v79vmLL5U4yijGaRKMg5EPuVlAL SwIoajDLmvNq/Pngz1Ppu5j+dHFjjYD/YVZhkPJnfIzJK1k84UDK0WMv/s7jLELxCbE37wx6hT1 jpCk7aruUOGcyEFuamL5dKHQaw0GMYzpufF9FmHUUaM7ak2NZS4P6JS2Tz+ifVYLRImvjvz18Rs j1Ai+Qke6n1B0UekGpYvL9fWPHAoOK4gPQdE3Rf6GuxUBwTtSfvPObWJ/Ra9qhP/I/Yg== X-Received: by 2002:a17:90b:3b88:b0:398:dcfe:968e with SMTP id 98e67ed59e1d1-39b261da746mr2521725a91.20.1788479798277; Thu, 03 Sep 2026 16:56:38 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3339b123731sm1861230eec.18.2026.09.03.16.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:37 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 10/11] f2fs: describe node tree geometry dynamically Date: Thu, 3 Sep 2026 16:56:22 -0700 Message-ID: <04bf8eb2c833d8fbb767558c49b53c715f6698b8.1788479509.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 Reviewed-by: Chao Yu --- fs/f2fs/f2fs.h | 11 +++++- fs/f2fs/gc.c | 10 +++--- fs/f2fs/node.c | 74 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 18 ++++++---- fs/f2fs/super.c | 8 ++--- include/linux/f2fs_fs.h | 10 ------ 6 files changed, 69 insertions(+), 62 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index c0bccc763e70..df8d1bfef34c 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2252,10 +2252,18 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const = struct folio *folio) #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) #define DEF_ADDRS_PER_INODE(sbi) ((sbi)->addrs_per_inode) +#define DEF_ADDRS_PER_BLOCK(sbi) ((sbi)->addrs_per_block) +#define NIDS_PER_BLOCK(sbi) ((sbi)->nids_per_block) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) =20 +#define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 1) +#define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 2) +#define NODE_IND1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 3) +#define NODE_IND2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 4) +#define NODE_DIND_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 5) + static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) { @@ -3644,7 +3652,8 @@ static inline unsigned int addrs_per_page(struct inod= e *inode, bool is_inode) { unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; + get_inline_xattr_addrs(inode)) : + DEF_ADDRS_PER_BLOCK(F2FS_I_SB(inode)); =20 if (f2fs_compressed_file(inode)) return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 164612dbe2c6..39fa4776404e 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1123,7 +1123,8 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, */ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode) { - unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK + 4; + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK(sbi) + 4; unsigned int bidx; =20 if (node_ofs =3D=3D 0) @@ -1132,11 +1133,12 @@ block_t f2fs_start_bidx_of_node(unsigned int node_o= fs, struct inode *inode) if (node_ofs <=3D 2) { bidx =3D node_ofs - 1; } else if (node_ofs <=3D indirect_blks) { - int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK(sbi) + 1); =20 bidx =3D node_ofs - 2 - dec; } else { - int dec =3D (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - indirect_blks - 3) / + (NIDS_PER_BLOCK(sbi) + 1); =20 bidx =3D node_ofs - 5 - dec; } @@ -1179,7 +1181,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct= f2fs_summary *sum, max_addrs =3D DEF_ADDRS_PER_INODE(sbi); } else { base =3D 0; - max_addrs =3D DEF_ADDRS_PER_BLOCK; + max_addrs =3D DEF_ADDRS_PER_BLOCK(sbi); } =20 if (base + ofs_in_node >=3D max_addrs) { diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e7aa3b790214..7bb99988833a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -691,7 +691,7 @@ static void f2fs_ra_node_pages(struct folio *parent, in= t start, int n) =20 /* Then, try readahead for siblings of the desired node */ end =3D start + n; - end =3D min(end, (int)NIDS_PER_BLOCK); + end =3D min_t(int, end, NIDS_PER_BLOCK(sbi)); for (i =3D start; i < end; i++) { nid =3D get_nid(parent, i, false); f2fs_ra_node_page(sbi, nid); @@ -702,9 +702,11 @@ static void f2fs_ra_node_pages(struct folio *parent, i= nt start, int n) =20 pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); const long direct_index =3D ADDRS_PER_INODE(dn->inode); const long direct_blks =3D ADDRS_PER_BLOCK(dn->inode); - const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * NIDS_PER_BLOCK; + const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * + NIDS_PER_BLOCK(sbi); unsigned int skipped_unit =3D ADDRS_PER_BLOCK(dn->inode); int cur_level =3D dn->cur_level; int max_level =3D dn->max_level; @@ -714,7 +716,7 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data = *dn, pgoff_t pgofs) return pgofs + 1; =20 while (max_level-- > cur_level) - skipped_unit *=3D NIDS_PER_BLOCK; + skipped_unit *=3D NIDS_PER_BLOCK(sbi); =20 switch (dn->max_level) { case 3: @@ -740,11 +742,13 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_dat= a *dn, pgoff_t pgofs) static int get_node_path(struct inode *inode, long block, int offset[4], unsigned int noffset[4]) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); const long direct_index =3D ADDRS_PER_INODE(inode); const long direct_blks =3D ADDRS_PER_BLOCK(inode); - const long dptrs_per_blk =3D NIDS_PER_BLOCK; - const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * NIDS_PER_BLOCK; - const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK; + const long dptrs_per_blk =3D NIDS_PER_BLOCK(sbi); + const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * + NIDS_PER_BLOCK(sbi); + const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK(sbi); int n =3D 0; int level =3D 0; =20 @@ -756,7 +760,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_index; if (block < direct_blks) { - offset[n++] =3D NODE_DIR1_BLOCK; + offset[n++] =3D NODE_DIR1_BLOCK(sbi); noffset[n] =3D 1; offset[n] =3D block; level =3D 1; @@ -764,7 +768,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < direct_blks) { - offset[n++] =3D NODE_DIR2_BLOCK; + offset[n++] =3D NODE_DIR2_BLOCK(sbi); noffset[n] =3D 2; offset[n] =3D block; level =3D 1; @@ -772,7 +776,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND1_BLOCK; + offset[n++] =3D NODE_IND1_BLOCK(sbi); noffset[n] =3D 3; offset[n++] =3D block / direct_blks; noffset[n] =3D 4 + offset[n - 1]; @@ -782,7 +786,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND2_BLOCK; + offset[n++] =3D NODE_IND2_BLOCK(sbi); noffset[n] =3D 4 + dptrs_per_blk; offset[n++] =3D block / direct_blks; noffset[n] =3D 5 + dptrs_per_blk + offset[n - 1]; @@ -792,7 +796,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < dindirect_blks) { - offset[n++] =3D NODE_DIND_BLOCK; + offset[n++] =3D NODE_DIND_BLOCK(sbi); noffset[n] =3D 5 + (dptrs_per_blk * 2); offset[n++] =3D block / indirect_blks; noffset[n] =3D 6 + (dptrs_per_blk * 2) + @@ -1054,6 +1058,7 @@ static int truncate_dnode(struct dnode_of_data *dn) static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int ofs, int depth) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); struct dnode_of_data rdn =3D *dn; struct folio *folio; struct f2fs_node *rn; @@ -1063,7 +1068,7 @@ static int truncate_nodes(struct dnode_of_data *dn, u= nsigned int nofs, int i, ret; =20 if (dn->nid =3D=3D 0) - return NIDS_PER_BLOCK + 1; + return NIDS_PER_BLOCK(sbi) + 1; =20 trace_f2fs_truncate_nodes_enter(dn->inode, dn->nid, dn->data_blkaddr); =20 @@ -1074,11 +1079,11 @@ static int truncate_nodes(struct dnode_of_data *dn,= unsigned int nofs, return PTR_ERR(folio); } =20 - f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK); + f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK(sbi)); =20 rn =3D F2FS_NODE(folio); if (depth < 3) { - for (i =3D ofs; i < NIDS_PER_BLOCK; i++, freed++) { + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++, freed++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) continue; @@ -1090,16 +1095,16 @@ static int truncate_nodes(struct dnode_of_data *dn,= unsigned int nofs, dn->node_changed =3D true; } } else { - child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK + 1) + 1; - for (i =3D ofs; i < NIDS_PER_BLOCK; i++) { + child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK(sbi) + 1) + 1; + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) { - child_nofs +=3D NIDS_PER_BLOCK + 1; + child_nofs +=3D NIDS_PER_BLOCK(sbi) + 1; continue; } rdn.nid =3D child_nid; ret =3D truncate_nodes(&rdn, child_nofs, 0, depth - 1); - if (ret =3D=3D (NIDS_PER_BLOCK + 1)) { + if (ret =3D=3D (NIDS_PER_BLOCK(sbi) + 1)) { if (set_nid(folio, i, 0, false)) dn->node_changed =3D true; child_nofs +=3D ret; @@ -1156,10 +1161,12 @@ static int truncate_partial_nodes(struct dnode_of_d= ata *dn, nid[i + 1] =3D get_nid(folios[i], offset[i + 1], false); } =20 - f2fs_ra_node_pages(folios[idx], offset[idx + 1], NIDS_PER_BLOCK); + f2fs_ra_node_pages(folios[idx], offset[idx + 1], + NIDS_PER_BLOCK(F2FS_I_SB(dn->inode))); =20 /* free direct nodes linked to a partial indirect node */ - for (i =3D offset[idx + 1]; i < NIDS_PER_BLOCK; i++) { + for (i =3D offset[idx + 1]; + i < NIDS_PER_BLOCK(F2FS_I_SB(dn->inode)); i++) { child_nid =3D get_nid(folios[idx], i, false); if (!child_nid) continue; @@ -1193,7 +1200,9 @@ static int truncate_partial_nodes(struct dnode_of_dat= a *dn, } =20 /* - * All the block addresses of data and nodes should be nullified. + * All the node blocks actually belong to the inode will be released. + * If the level is 0, we will simply truncate the dnode, + * or else we should do dynamic truncate for the node pointers with the de= pth. */ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) { @@ -1240,10 +1249,10 @@ int f2fs_truncate_inode_blocks(struct inode *inode,= pgoff_t from) err =3D truncate_partial_nodes(&dn, offset, level); if (err < 0 && err !=3D -ENOENT) goto fail; - nofs +=3D 1 + NIDS_PER_BLOCK; + nofs +=3D 1 + NIDS_PER_BLOCK(sbi); break; case 3: - nofs =3D 5 + 2 * NIDS_PER_BLOCK; + nofs =3D 5 + 2 * NIDS_PER_BLOCK(sbi); if (!offset[level - 1]) goto skip_partial; err =3D truncate_partial_nodes(&dn, offset, level); @@ -1257,23 +1266,16 @@ int f2fs_truncate_inode_blocks(struct inode *inode,= pgoff_t from) skip_partial: while (cont) { dn.nid =3D get_nid(folio, offset[0], true); - switch (offset[0]) { - case NODE_DIR1_BLOCK: - case NODE_DIR2_BLOCK: + if (offset[0] =3D=3D NODE_DIR1_BLOCK(sbi) || + offset[0] =3D=3D NODE_DIR2_BLOCK(sbi)) { err =3D truncate_dnode(&dn); - break; - - case NODE_IND1_BLOCK: - case NODE_IND2_BLOCK: + } else if (offset[0] =3D=3D NODE_IND1_BLOCK(sbi) || + offset[0] =3D=3D NODE_IND2_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 2); - break; - - case NODE_DIND_BLOCK: + } else if (offset[0] =3D=3D NODE_DIND_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 3); cont =3D 0; - break; - - default: + } else { BUG(); } if (err =3D=3D -ENOENT) { diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 911c3d336533..2766ced7bef7 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -352,17 +352,18 @@ static inline bool is_recoverable_dnode(const struct = folio *folio) */ static inline bool IS_DNODE(const struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(node_folio); unsigned int ofs =3D ofs_of_node(node_folio); =20 if (f2fs_has_xattr_block(ofs)) return true; =20 - if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK || - ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK) + if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK(sbi) || + ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK(sbi)) return false; - if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK) { - ofs -=3D 6 + 2 * NIDS_PER_BLOCK; - if (!((long int)ofs % (NIDS_PER_BLOCK + 1))) + if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK(sbi)) { + ofs -=3D 6 + 2 * NIDS_PER_BLOCK(sbi); + if (!((long)ofs % (NIDS_PER_BLOCK(sbi) + 1))) return false; } return true; @@ -370,13 +371,15 @@ static inline bool IS_DNODE(const struct folio *node_= folio) =20 static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(folio); struct f2fs_node *rn =3D F2FS_NODE(folio); __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); =20 f2fs_folio_wait_writeback(folio, NODE, true, true); =20 if (i) - inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK(sbi)] =3D + cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -386,9 +389,10 @@ static inline nid_t get_nid(const struct folio *folio,= int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); + int nid_index =3D off - NODE_DIR1_BLOCK(F2FS_F_SB(folio)); =20 if (i) - return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[nid_index]); return le32_to_cpu(rn->in.nid[off]); } =20 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index da97f0f38ea0..75713e639b63 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3890,7 +3890,7 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, stru= ct inode *inode) loff_t leaf_count; =20 /* - * note: previously, result is equal to (DEF_ADDRS_PER_INODE - + * note: previously, result is equal to (DEF_ADDRS_PER_INODE(sbi) - * DEFAULT_INLINE_XATTR_ADDRS), but now f2fs try to reserve more * space in inode.i_addr, it will be more safe to reassign * result as zero. @@ -3899,17 +3899,17 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, st= ruct inode *inode) if (inode && f2fs_compressed_file(inode)) leaf_count =3D ADDRS_PER_BLOCK(inode); else - leaf_count =3D DEF_ADDRS_PER_BLOCK; + leaf_count =3D DEF_ADDRS_PER_BLOCK(sbi); =20 /* two direct node blocks */ result +=3D (leaf_count * 2); =20 /* two indirect node blocks */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D (leaf_count * 2); =20 /* one double indirect node block */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D leaf_count; =20 /* diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 4c9540981db4..9036cc6c2a2c 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -282,19 +282,9 @@ struct node_footer { #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ -#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) /= sizeof(__le32)) #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) -/* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / siz= eof(__le32)) - #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) =20 -#define NODE_DIR1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 1) -#define NODE_DIR2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 2) -#define NODE_IND1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 3) -#define NODE_IND2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 4) -#define NODE_DIND_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 5) - #define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02 /* file inline data flag */ #define F2FS_INLINE_DENTRY 0x04 /* file inline dentry flag */ --=20 2.53.0 From nobody Sat Sep 26 06:20:27 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52B5336E460 for ; Thu, 3 Sep 2026 23:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479804; cv=none; b=sj0LUiF6zg0JM3WCbzuarIkmkk6uGwOrKmuzGUAU5LrEnluW3VJV07c7qbXxpYdxDmJcnIzInJIVEafkR8P99cItQObrlAGzg7260RcEs41LiYWc40UYlEkqwQSQAczIzigV/Na/FGO4nr8WO/sHIMZzm436T7gOsAdamJrjzfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788479804; c=relaxed/simple; bh=FCy3MW2Cwj/at4OOJ+r51ZkU3iUAkKcSmS2VvF3ii/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LYrrBH8HZb1UP9izWUJNcGm7wI2aupHUTZhF2JFVdwX2561djujLkL6F0NfHBhwSh9IGFIdIqpmm28DpstsRUMGKHLANhY/xP/3T7Aj1yciV+xY3hZloTSEfJCg09aK6AEn6dm0/7uSY70U4t9u0rvfO/LfkpXTnIcT6v+fv9ts= 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=K1Gp+UAO; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K1Gp+UAO" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-39b24d114d4so444539a91.3 for ; Thu, 03 Sep 2026 16:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788479801; x=1789084601; 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=1Bbiltid36UiyV1NzlSYq5njw/VDZh2cdDNub5CVBFk=; b=K1Gp+UAO/IGxebWCmwN0HrGwgdCEhI5STeumIWxctSjXFVi0baszkWxi7CUlAEqLuQ Cvdc2Wu1RgyGolEVnY6HDve/CekPEXb/RRxbwRAE7AIyOBdlUqHQxytyYtTPbDc32+wl 2SZJsctrskyqwp3Lt5ourChFTDKd2t5kGdsYW6CoeKA+NJ9ri5buXj7sG0IooGUjJKJS 3dfHg6olrx7yionyOa6bj2AjUzELHsCgusYmEIvahVDVaTDjReUQMTe3umfWBLVKgif/ c63n0KUbpiUA4oWBrcgncMI4BlRjV6GcSUJG/qBliqHtrN4UDjHJvbzUnJ/yVGnZEoLL 1xlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788479801; x=1789084601; 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=1Bbiltid36UiyV1NzlSYq5njw/VDZh2cdDNub5CVBFk=; b=lEA2rpL9lkhNOcn4LO+9htSIVMncYUZclgvYApFVETHvPukS/nvClw93MxubYybtTq 1hgmD5/w9JNwwFd/abUJDDjgQuH3Xyxc+hm/j9cwHpwDj9+beQxp1xF26Yo8sePrt7Mz vjbXnCw3R80dKph7q5GQpgpu2aPyV0/hVwWJOo3Spe3YWHDFcRjGT7KCkBkyewQbN0Ux ALaUMfYTm2DjAM7SxNS2ovzAkz6Jcg1Np5bBCgMMKltBotEmTR7AxVMl1srzYKMT+zuq odorKAT4i2a/V+HzSdA3r29KSI8Vd5vbsvwGmS9mAdYO/mKwAgWIj56gSSSeK8HpHF9j 21NQ== X-Forwarded-Encrypted: i=1; AKwUvBwxuAJzhTJAL4mjs9YKoqbgNeevmGhUN5cm1i1ibAfpRKL2zHGkxWZz/2WJowV90ccnkGzzrkQAey472ug=@vger.kernel.org X-Gm-Message-State: AFuF++mpuVCGfNHYv5NTZWhaByjdsxXRWRnTXFtk4lPJJ0AQYeh7KA3e MyIHu4cFIFlsexeb40g6NQnLK9z/knFe7bcNKY6IKP9N1axRLVQnMow/ X-Gm-Gg: AYBFou1mzjMHWEdxqw6S6R6F/yLTNJT24qsrtw2xSlDlIk61lsu/2yAgojz9yYr6LkX p0mKVy3z5I4bipHMH73jc1AMvHfCMqyCi+/6y/9WSgqMDtzIsDlva3K4xboLORRX4x8azTzOSG/ RcX0iJ+xjT8vHnYMpWFlRrgCddoPwCOcOEGNk1b9ZVJ9C3OpxZqo5E5aPxXrc+U/ARUUrqDHvDU Z0PFYCngG+5iMRWD/o49O0YhTVvXjn08E+oDb4HZ6NqjArtdHcJglys/PTcotUhX7tV9tNSfjeW v7U/G2tzMAEux690y73HgRVWeFQqh3+4CsyU7gMUWLbUxYyHGNdpjgRuCeaaUU5yCx9akKUa4ly 1EJvwIgQFWdkhNXM/ewiQfZ87enSg6yph/pSnfCn6qsXX1spyKA1Na7uEdcobUPR/PJpdPj0QL6 /mnY6Gc47oYMzXXnzPVqIQ24qPT2lDFGcjE/6Ieq+w2fLRWuhy692bdnJMYOtX6AbzAQ== X-Received: by 2002:a17:90a:d44b:b0:396:4cbf:45bc with SMTP id 98e67ed59e1d1-39b26203f11mr3316256a91.16.1788479800472; Thu, 03 Sep 2026 16:56:40 -0700 (PDT) Received: from [127.0.1.1] ([2601:647:4184:b3f0:29c4:4984:db20:3bb4]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1432424d27asm3711961c88.2.2026.09.03.16.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 16:56:39 -0700 (PDT) From: Kelvin Zhang To: linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , Chao Yu , Daeho Jeong , linux-kernel@vger.kernel.org Subject: [PATCH v9 11/11] f2fs: parameterize block size and mask macros Date: Thu, 3 Sep 2026 16:56:23 -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 Reviewed-by: Chao Yu --- fs/f2fs/checkpoint.c | 23 ++++++++++++----------- fs/f2fs/data.c | 25 ++++++++++++++----------- fs/f2fs/extent_cache.c | 9 +++++---- fs/f2fs/f2fs.h | 8 +++++--- fs/f2fs/file.c | 30 +++++++++++++++++------------- fs/f2fs/gc.c | 11 ++++++----- fs/f2fs/inline.c | 6 +++--- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 7 ++++--- fs/f2fs/node.h | 2 +- fs/f2fs/segment.c | 18 +++++++++++------- fs/f2fs/segment.h | 2 +- fs/f2fs/super.c | 6 +++--- fs/f2fs/sysfs.c | 10 +++++----- fs/f2fs/xattr.c | 2 +- include/linux/f2fs_fs.h | 16 ++++++++-------- 16 files changed, 97 insertions(+), 80 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4d1a0544bbf0..712c4508f38c 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); @@ -1133,16 +1133,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; } @@ -1162,13 +1163,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"); @@ -1705,7 +1706,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))) @@ -1840,7 +1841,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); @@ -1865,8 +1866,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 a4006b92da55..ebb0275aa8ff 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1192,7 +1192,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 @@ -2175,7 +2175,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; @@ -2220,7 +2220,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; @@ -2309,7 +2309,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; @@ -2327,7 +2327,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; @@ -2460,7 +2460,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 @@ -2634,14 +2635,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); @@ -4155,6 +4156,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)) @@ -4165,7 +4167,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)) { @@ -4367,7 +4369,8 @@ static int check_swap_activate(struct swap_info_struc= t *sis, out: if (not_aligned) f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) io= ctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)", - not_aligned, blks_per_sec * F2FS_BLKSIZE); + not_aligned, + (unsigned long)blks_per_sec * F2FS_BLKSIZE(sbi)); return ret; } =20 diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 37cf9fa8d537..57217dc5b310 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -904,11 +904,12 @@ static int __get_new_block_age(struct inode *inode, s= truct extent_info *ei, struct extent_info tei =3D *ei; /* only fofs and len are valid */ =20 /* - * When I/O is not aligned to a PAGE_SIZE, update will happen to the last - * file block even in seq write. So don't record age for newly last file - * block here. + * When I/O is not aligned to the filesystem block size, update will + * happen to the last file block even in seq write. Do not record the age + * of the new last file block here. */ - if ((f_size >> PAGE_SHIFT) =3D=3D ei->fofs && f_size & (PAGE_SIZE - 1) && + if ((f_size >> sbi->log_blocksize) =3D=3D ei->fofs && + f_size & F2FS_BLKSIZE_MASK(sbi) && blkaddr =3D=3D NEW_ADDR) return -EINVAL; =20 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index df8d1bfef34c..cf0759262207 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2257,6 +2257,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const st= ruct folio *folio) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) +#define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) =20 #define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 1) #define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE(sbi) + 2) @@ -2311,7 +2312,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 @@ -2327,7 +2328,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 @@ -2976,7 +2978,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 5892247b3622..753ea45e9497 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); @@ -1671,7 +1672,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); @@ -1886,7 +1888,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); @@ -3189,7 +3192,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) > @@ -3275,7 +3279,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; @@ -3293,9 +3297,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); @@ -4589,14 +4593,14 @@ static int f2fs_sec_trim_file(struct file *filp, un= signed long arg) to_end =3D true; } =20 - if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || - (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE))) { + if (!IS_ALIGNED(range.start, F2FS_BLKSIZE(sbi)) || + (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE(sbi)))) { ret =3D -EINVAL; goto err; } =20 index =3D F2FS_BYTES_TO_BLK(sbi, range.start); - pg_end =3D DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); + pg_end =3D F2FS_BLK_ALIGN(sbi, end_addr); =20 ret =3D f2fs_convert_inline_inode(inode); if (ret) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 39fa4776404e..bc22dde1cb30 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1305,8 +1305,8 @@ static int ra_data_block(struct inode *inode, pgoff_t= index) f2fs_put_page(fio.encrypted_page, false); f2fs_folio_put(folio, true); =20 - f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); - f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE(sbi)); + f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE(sbi)); =20 if (atomic_inode) iput(atomic_inode); @@ -1426,9 +1426,9 @@ static int move_data_block(struct inode *inode, block= _t bidx, } =20 f2fs_update_iostat(fio.sbi, inode, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); f2fs_update_iostat(fio.sbi, NULL, FS_GDATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); =20 folio_lock(mfolio); if (unlikely(!is_meta_folio(mfolio) || @@ -1479,7 +1479,8 @@ static int move_data_block(struct inode *inode, block= _t bidx, fio.new_blkaddr =3D newaddr; f2fs_submit_page_write(&fio); =20 - f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, F2FS_BLKSIZE); + f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, + F2FS_BLKSIZE(fio.sbi)); =20 f2fs_update_data_blkaddr(&dn, newaddr); set_inode_flag(inode, FI_APPEND_WRITE); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 73cd9b6ddcc5..3e0b9449ffba 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -448,7 +448,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, = struct folio *ifolio, * Start by zeroing the full block, to ensure that all unused space is * zeroed and no uninitialized memory is leaked to disk. */ - memset(dentry_blk, 0, F2FS_BLKSIZE); + memset(dentry_blk, 0, F2FS_BLKSIZE(F2FS_I_SB(dir))); =20 make_dentry_ptr_inline(dir, &src, inline_dentry); make_dentry_ptr_block(dir, &dst, dentry_blk); @@ -477,8 +477,8 @@ static int f2fs_move_inline_dirents(struct inode *dir, = struct folio *ifolio, F2FS_I(dir)->i_inline_xattr_size =3D 0; =20 f2fs_i_depth_write(dir, 1); - if (i_size_read(dir) < PAGE_SIZE) - f2fs_i_size_write(dir, PAGE_SIZE); + if (i_size_read(dir) < F2FS_BLKSIZE(F2FS_I_SB(dir))) + f2fs_i_size_write(dir, F2FS_BLKSIZE(F2FS_I_SB(dir))); out: f2fs_folio_put(folio, true); return err; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index aa22e457d5b3..82ebcb338b0c 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -165,7 +165,7 @@ static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi= , struct folio *folio) chksum =3D f2fs_chksum(chksum, (__u8 *)&dummy_cs, cs_size); offset +=3D cs_size; chksum =3D f2fs_chksum(chksum, (__u8 *)ri + offset, - F2FS_BLKSIZE - offset); + F2FS_BLKSIZE(sbi) - offset); return chksum; } =20 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 7bb99988833a..68a95d703c4a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -165,7 +165,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_= info *sbi, nid_t nid) =20 src_addr =3D folio_address(src_folio); dst_addr =3D folio_address(dst_folio); - memcpy(dst_addr, src_addr, PAGE_SIZE); + memcpy(dst_addr, src_addr, F2FS_BLKSIZE(sbi)); folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); =20 @@ -1500,7 +1500,8 @@ static int read_node_folio(struct folio *folio, blk_o= pf_t op_flags) err =3D f2fs_submit_page_bio(&fio); =20 if (!err) - f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, + F2FS_BLKSIZE(sbi)); =20 return err; } @@ -3313,7 +3314,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) return PTR_ERR(folio); =20 memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(sbi, i), - folio_address(folio), F2FS_BLKSIZE); + folio_address(folio), F2FS_BLKSIZE(sbi)); f2fs_folio_put(folio, true); } =20 diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 2766ced7bef7..c265739f2105 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -282,7 +282,7 @@ static inline void fill_node_footer(const struct folio = *folio, nid_t nid, unsigned int old_flag =3D 0; =20 if (reset) - memset(rn, 0, F2FS_BLKSIZE); + memset(rn, 0, F2FS_BLKSIZE(F2FS_F_SB(folio))); else old_flag =3D le32_to_cpu(footer->flag); =20 diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index eb27b92fbad8..d186ac01d98a 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); } @@ -4150,7 +4152,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) @@ -4160,7 +4162,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, @@ -4176,7 +4179,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) @@ -4218,7 +4222,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) f2fs_update_device_state(fio->sbi, fio->ino, fio->new_blkaddr, 1); f2fs_update_iostat(fio->sbi, fio_inode(fio), - fio->io_type, F2FS_BLKSIZE); + fio->io_type, F2FS_BLKSIZE(fio->sbi)); } =20 return err; diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 2275404e769c..cc0428b614da 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -432,7 +432,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb= _info *sbi, int i; =20 raw_sit =3D folio_address(folio); - memset(raw_sit, 0, PAGE_SIZE); + memset(raw_sit, 0, F2FS_BLKSIZE(sbi)); for (i =3D 0; i < end - start; i++) { rs =3D &raw_sit->entries[i]; se =3D get_seg_entry(sbi, start + i); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 75713e639b63..f96abecb3c55 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1610,7 +1610,7 @@ static int f2fs_check_opt_consistency(struct fs_conte= xt *fc, return -EINVAL; } min_size =3D MIN_INLINE_XATTR_SIZE; - max_size =3D MAX_INLINE_XATTR_SIZE(sbi->blocksize); + max_size =3D MAX_INLINE_XATTR_SIZE(F2FS_BLKSIZE(sbi)); =20 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || F2FS_OPTION(sbi).inline_xattr_size > max_size) { @@ -4079,10 +4079,10 @@ static int sanity_check_raw_super(struct f2fs_sb_in= fo *sbi, } =20 /* only support block_size equals to PAGE_SIZE */ - if (le32_to_cpu(raw_super->log_blocksize) !=3D F2FS_BLKSIZE_BITS) { + if (le32_to_cpu(raw_super->log_blocksize) !=3D PAGE_SHIFT) { f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", le32_to_cpu(raw_super->log_blocksize), - F2FS_BLKSIZE_BITS); + PAGE_SHIFT); return -EFSCORRUPTED; } =20 diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 811e350a1430..aaca9ed9b169 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1871,8 +1871,8 @@ static int __maybe_unused disk_map_seq_show(struct se= q_file *seq, struct f2fs_sb_info *sbi =3D F2FS_SB(sb); int i; =20 - seq_printf(seq, "Address Layout : %5luB Block address (# of Segments)\n= ", - F2FS_BLKSIZE); + seq_printf(seq, "Address Layout : %5uB Block address (# of Segments)\n", + F2FS_BLKSIZE(sbi)); seq_printf(seq, " SB : %12s\n", "0/1024B"); seq_printf(seq, " seg0_blkaddr : 0x%010x\n", SEG0_BLKADDR(sbi)); seq_printf(seq, " Checkpoint : 0x%010x (%10d)\n", @@ -1889,13 +1889,13 @@ static int __maybe_unused disk_map_seq_show(struct = seq_file *seq, seq_printf(seq, " Main : 0x%010x (%10d)\n", SM_I(sbi)->main_blkaddr, le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main)); - seq_printf(seq, " Block size : %12lu KB\n", F2FS_BLKSIZE >> 10); + seq_printf(seq, " Block size : %12u KB\n", F2FS_BLKSIZE(sbi) >> 10); seq_printf(seq, " Segment size : %12d MB\n", - (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " Segs/Sections : %12d\n", SEGS_PER_SEC(sbi)); seq_printf(seq, " Section size : %12d MB\n", - (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " # of Sections : %12d\n", le32_to_cpu(F2FS_RAW_SUPER(sbi)->section_count)); =20 diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 99c863513725..98059e583b09 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -850,4 +850,4 @@ int __init f2fs_init_xattr_cache(void) void f2fs_destroy_xattr_cache(void) { kmem_cache_destroy(inline_xattr_slab); -} \ No newline at end of file +} diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 9036cc6c2a2c..92a11e984d7a 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,12 +14,9 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log = number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL -#define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ #define F2FS_MAX_BLKSIZE PAGE_SIZE -#define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ =20 @@ -27,16 +24,20 @@ #define NEW_ADDR ((block_t)-1) /* used as block_t addresses */ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ =20 -#define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) +#define F2FS_BLKSIZE(sbi) ((sbi)->blocksize) +#define F2FS_BLKSIZE_BITS(sbi) ((sbi)->log_blocksize) +#define F2FS_BLKSIZE_MASK(sbi) (F2FS_BLKSIZE(sbi) - 1) +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) (F2FS_BLKSIZE_BITS(sbi) - 9) +#define F2FS_BLKS_PER_PAGE(sbi) (PAGE_SIZE / F2FS_BLKSIZE(sbi)) #define F2FS_BYTES_TO_BLK(sbi, bytes) \ - ((unsigned long long)(bytes) >> (sbi)->log_blocksize) + ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_TO_BYTES(sbi, blk) \ - ((unsigned long long)(blk) << (sbi)->log_blocksize) + ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_END_BYTES(sbi, blk) \ (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) #define F2FS_BLK_ALIGN(sbi, bytes) \ F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ - (sbi)->blocksize - 1) + F2FS_BLKSIZE(sbi) - 1) =20 /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 @@ -222,7 +223,6 @@ struct f2fs_checkpoint { unsigned char sit_nat_version_bitmap[]; } __packed; =20 -#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32)) /* default chksum= offset in checkpoint */ #define CP_MIN_CHKSUM_OFFSET \ (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap)) =20 --=20 2.53.0