From patchwork Sat Jan 27 01:58:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ED26C47DA9 for ; Sat, 27 Jan 2024 02:03:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7273C6B009D; Fri, 26 Jan 2024 21:02:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41B1D6B009C; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 159E16B009D; Fri, 26 Jan 2024 21:02:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 01BBC6B009F for ; Fri, 26 Jan 2024 21:02:56 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4C1C1406D4 for ; Sat, 27 Jan 2024 02:02:56 +0000 (UTC) X-FDA: 81723442752.24.1717548 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf14.hostedemail.com (Postfix) with ESMTP id 4EE34100006 for ; Sat, 27 Jan 2024 02:02:53 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320975; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V0qrNBKHUWdDnSnlHTyNTuDS1TnUypLYX4BpeAl7EPc=; b=EooDYkfjHzBR2i5FYRf7SarGHXD8C4w2N4e0PjQbHQCcEwYGKpkddOfWBPFsfeVZw1ZHHo Y9RLHJu38oLJuU2Ql3tGisc6uiw+yQf66AW+RRKXPvCX+ul2BTTo42Km/mnL02FDy22nrT 1LMwf+JXRJSlCzZu8gB8Ie2w01q59zA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320975; a=rsa-sha256; cv=none; b=B9useJ4hKvbz0FyeqVww8iE0u8rLJrONkiQ8Qg3yPkQst8XTsLqPG6uUllQEAUyfUcoSBj 2oDuoJMCkKQpxRw/W3gOTiKvxMhd4ELSTRfzZ2uWPnErF2M/JC7sZ0cIdWHtrnhlFQain8 sllqhHJAHwBfiyAx0Yz89jsNa7aHxv8= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrk4F9jz4f3lx9 for ; Sat, 27 Jan 2024 10:02:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 94CAF1A0171 for ; Sat, 27 Jan 2024 10:02:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S21; Sat, 27 Jan 2024 10:02:50 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v3 17/26] ext4: implement buffered read iomap path Date: Sat, 27 Jan 2024 09:58:16 +0800 Message-Id: <20240127015825.1608160-18-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S21 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7uFW8uw17ZF1kWF13CFg_yoW8uFW7pF 98KFy5GF47XrnI9F4SqFZrJr1Yk3WxtF4UurW3WasxGFyYkrW2gayUWFyYyF15X3y7Ary0 qF4jkr18GF1UArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 4EE34100006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: m4jghdcq7npdu81fs5a6mwm1iriu5p7c X-HE-Tag: 1706320973-586285 X-HE-Meta: U2FsdGVkX1+xOyELBnETsWMUhRA6Z5R0gwmsrTO6JTYIY4nYiSSofKyKxYUUfKCe9DLgzNemUIFdA+6KlZosQhWwtZC3IeHW+ku4KR4V2oGZDCSXmOquYsbo5JHc4S5B9IfEcDN0Xk+JFG82JkplfZRcBiRHSDPPhmuHgXUjQKOovtvzQ/QzsjIIDhdvowEkdNWf+uBbIDAXB/NfbOTqac4T1z0ORVpEhQKC4nF+sZ9GausMekOuKTjkHOFXgSxWuzs3vtt1vqf5NGGOyea3VeWyeb4rjlo9uzaMve8DkNogSsrL7IRfe+TVbW1/fcirQYkuNXDPe7ghzk3mKOP8iqTdoWxGuDBIyLE91TwBwS3TvpwoqrpEu2STkrIwJSLlCIO6kaRCtCR+d7F+gBwNU2WOAxI6Gfl47mlwBOd00Ir7hLxvIdKFQlghm/ZXVpCz+CHju/7fatLQiYous98VQz4xrTvHUkimw+dV9iR3H5UwtGiD/V6O/+dfXxXmYeInWtslkfYrX+68Em/k2rBeKNpeV3l5c4HEZc79oTPt2CKii2wZtWxm+XjCLk2HJfAF/BITc53FV0Xcm8yvH3Qh8lHWUN3KwqkKRYFIpr0yc6znxTAQunFoiWLvcVXHv5d+CNooH/eBso8zrH+DIyVVyGNUxqCmJzyKPNhpcm8N7o71c7G83zR13kitnsZ2BLG0tHK2MKCJRU6GJV+TidEe34+FYd1cHLtBVbqWsV+uNzHe36YxfDFmhR1DphhEtPQlzvjz/pmaGUwvr6pFAYjbeygIB7ec6BXH2fObpNSVY6hBf3Tpjd8EaoaO6Q2TU2C8B6WkYj/GHvrp7UX/BKsHyzf4QJeTSEEGnSziPKi44HKzbyM37XLkO8a9ZEZ/bt/Obvbsb5mUu132IL/h1KPfhsP7ty86YiOfNYL8/fhdhyDftCiqhxWcBtCkrj4V3FdS19AUKMTvRhal9RaM/60 KjZrtBIC 1HQJ9S4nV2yRS3PmOaAl2Imr8ac47O28s2SpukkMnMjIWUZXZMZPdPoc24RB3E1cMirKea/JuTHp7j9tiBtootlAC0Tvd3gsOIMX8RRniRyszlOJ041NpG6debzlgUoEGvn0vS8c5YXrsCt4u19kL9gtTP8m+bU/ZakRX1qT1bZGfxhOkMipGDgMWkeRKVt4DrIr9FhdU6Hr1JzXqDB6PmEj6HUorPrXplZRtNJAIE/jjnFfmiYrH9rnnr5JEsr0Kk95Y X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Add ext4_iomap_buffered_io_begin() to query map blocks, and use ext4_set_iomap() to convert ext4 map to iomap, after that we can convert buffered read path to iomap simply. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index eca9bf5dd255..5d542ce13d2a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3507,14 +3507,46 @@ const struct iomap_ops ext4_iomap_report_ops = { .iomap_begin = ext4_iomap_begin_report, }; -static int ext4_iomap_read_folio(struct file *file, struct folio *folio) +static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, + loff_t length, unsigned int iomap_flags, + struct iomap *iomap, struct iomap *srcmap) { + int ret; + struct ext4_map_blocks map; + u8 blkbits = inode->i_blkbits; + + if (unlikely(ext4_forced_shutdown(inode->i_sb))) + return -EIO; + if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) + return -EINVAL; + if (WARN_ON_ONCE(ext4_has_inline_data(inode))) + return -ERANGE; + + /* Calculate the first and last logical blocks respectively. */ + map.m_lblk = offset >> blkbits; + map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, + EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + + ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret < 0) + return ret; + + ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags); return 0; } -static void ext4_iomap_readahead(struct readahead_control *rac) +const struct iomap_ops ext4_iomap_buffered_read_ops = { + .iomap_begin = ext4_iomap_buffered_io_begin, +}; + +static int ext4_iomap_read_folio(struct file *file, struct folio *folio) { + return iomap_read_folio(folio, &ext4_iomap_buffered_read_ops); +} +static void ext4_iomap_readahead(struct readahead_control *rac) +{ + iomap_readahead(rac, &ext4_iomap_buffered_read_ops); } static int ext4_iomap_writepages(struct address_space *mapping,