]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ext4: Use folio_next_pos()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 24 Oct 2025 17:08:12 +0000 (18:08 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 31 Oct 2025 12:11:37 +0000 (13:11 +0100)
This is one instruction more efficient than open-coding folio_pos() +
folio_size().  It's the equivalent of (x + y) << z rather than
x << z + y << z.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://patch.msgid.link/20251024170822.1427218-5-willy@infradead.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/ext4/inode.c

index f9e4ac87211ec108c58f5e313a374647e0cc2e03..c18465265ce679df2b0eb5229d7a9ed7c16c2d06 100644 (file)
@@ -1319,8 +1319,8 @@ retry_grab:
        if (IS_ERR(folio))
                return PTR_ERR(folio);
 
-       if (pos + len > folio_pos(folio) + folio_size(folio))
-               len = folio_pos(folio) + folio_size(folio) - pos;
+       if (len > folio_next_pos(folio) - pos)
+               len = folio_next_pos(folio) - pos;
 
        from = offset_in_folio(folio, pos);
        to = from + len;
@@ -2704,7 +2704,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 
                        if (mpd->map.m_len == 0)
                                mpd->start_pos = folio_pos(folio);
-                       mpd->next_pos = folio_pos(folio) + folio_size(folio);
+                       mpd->next_pos = folio_next_pos(folio);
                        /*
                         * Writeout when we cannot modify metadata is simple.
                         * Just submit the page. For data=journal mode we
@@ -3146,8 +3146,8 @@ retry:
        if (IS_ERR(folio))
                return PTR_ERR(folio);
 
-       if (pos + len > folio_pos(folio) + folio_size(folio))
-               len = folio_pos(folio) + folio_size(folio) - pos;
+       if (len > folio_next_pos(folio) - pos)
+               len = folio_next_pos(folio) - pos;
 
        ret = ext4_block_write_begin(NULL, folio, pos, len,
                                     ext4_da_get_block_prep);