From patchwork Wed Apr 10 13:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624585 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 0752BCD128A for ; Wed, 10 Apr 2024 13:38:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A0C06B00AD; Wed, 10 Apr 2024 09:37:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2515A6B00AE; Wed, 10 Apr 2024 09:37:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07BB46B00AF; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DBF106B00AD for ; Wed, 10 Apr 2024 09:37:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ACD68140654 for ; Wed, 10 Apr 2024 13:37:17 +0000 (UTC) X-FDA: 81993723714.10.CDD0016 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 377C2100005 for ; Wed, 10 Apr 2024 13:37:09 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 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=1712756231; 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=RZrNAfKqPKEAjMF5Y3M7foneYQpwHm5h4BORCNdEvbw=; b=MxpibkIMa2EMfSPO8tazoGeDCPVUM5J+zrKHshFe1kVr2SqzFsKQxFeRqO5V8e3B5YKy0z 0iptd6sx/scRCIlzw9zCax1eiSmj7Nw23Ia0EeJixPhFoHKnlRdqZQI6bOUJKVtrFy3v4V B630+S5nIfNRZvSmSeWEJZnV+sa906o= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756231; a=rsa-sha256; cv=none; b=nRNH1GYyezCqZPBZpW9aKEQ5x+grqqNUWibk134Q6Rh8KI0TbjXVhKAPdbT9odPOf0IGik mH+44oQ2ZQREO3qKsXMFpmSmzmjnjAV8HZoLCXB/zkppIAxLxZ33FwT9hMrJNYkkc+QVK7 eFdqQdndRvE7ULwUyPDhv1D8G3MAHgg= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lf0fnfz4f3jZd for ; Wed, 10 Apr 2024 21:37:02 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7F4291A0568 for ; Wed, 10 Apr 2024 21:37:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S34; Wed, 10 Apr 2024 21:37:06 +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 v4 30/34] ext4: partial enable iomap for regular file's buffered IO path Date: Wed, 10 Apr 2024 21:28:14 +0800 Message-Id: <20240410132818.2812377-31-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S34 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kKrWrCw1DtF43GFW7Jwb_yoWrGr4UpF ZIkryrJr4Y93s29a1ftF48Zr1Sv3WxKw4UG3yS9wn5XFy8J34SqF1jyF15A3WrJrZ5ua4S qF4jkr1Uuw43urDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6r xdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AK xVWxJr0_GcWlIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdYxBIdaVFxhVjvjDU0xZFpf9x0JUArcfU UUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 377C2100005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mrwo86d6desr6ndnz1rsnjdpzokfo66z X-HE-Tag: 1712756229-88437 X-HE-Meta: U2FsdGVkX19jt8uoVR0MZf8/UDXxzgFMizK2BCC1dSVqZJd1rFeIdkqNCcSsxrMs7bTdiBM2PhzYD6m7akpu2UQrO1YGMCropuEo4XgCLiznRw3IBKuSP3+7oW8d0K/eXQSrQ1exQuSasEt0ieB//i2eCS5BWAvvrzPZ45tnHkxJQnC4c0z82+LmhmR2x7y9rg5DRH1aYcHi1dbx5mKKVoY/+cEsfAUV5QQuYlEW7wfs5TqZwSYAm/SWLwzXjATiXuXQDalorUl7WiIHMyX1MSAUvM840VxuSyDau45jRTxX6zYxHAI/ovpHxCfufUUzkryirEKqjLD70uwgP1hGsaj5hlEKVN5CKyAeXaOhlcLDCiAIK246dU7GfdCH0yZW9R7XzgEvGPI6E9+oCVNizaAN6Wdlf8vwxRZUvPtwcfY4Hls/jK8JRB8kmvgtYkVPn54P5mvdZIyMz3EKzuxgxsF0onwQthNYbq2Rbg58t0uz+rVhAzkfFIRTx7p/8KskLhIWk4TI2mDuiqkkYGoSO7oUHH4TBq8HS6KAxx+f+wUN9w++PjTTNkMjF+6JZ7EgaLgDa5ggi99Nci8EWQ/udYl90tU9mSMNYUywawrcNkiHIXsUIDcMA6AqDCQs4KY0dsusOpNWueGNuH3U/qXGHnc86tYBuqL55VnduLCSm90r6eVeDe7+izcSywHYkTwLOh87v0A+IklcCVOi9E7U8uV2i2qN3WxHGtl0TWXCbyTyABZeEKzzW5w9PumqZVpGOJOvrYyBda+w381J8yOmmpShu+PR4cF4Rlf+JSr69V6zfqcNTgxBs1fzxwGN4q11MzaNCHQYhGFCUcSTNdKqdKu1HkoDnpeMxLyGs7FFqtVmO4bXT8IGFYQ1ZtZNHRslghDM0581qdyUoX+o3eBC0GDtQDwNbejfBvSZxMAajhBeRhPkMHnndnz+OTehKUsMXEzfEqihHa9k5D3NONg 9FDRo3IA 3Rfz52nUkeQnbK9mKBPtJRXhy9JKv0x4INLFP7r5gUnaCvHofhQXAUJOJFp57mscj04+Z9OZO3lCE7cV5IQkmDelV53WrE5n6YVIFFWoXu8Bk0ibW4DLKnmyyRRUGLFcyA+1BF/ac6XbWXp+UlK7qQti3lTsQsyumH7a0IIQ3CpTgCTHqMPdNe3L+OdyQ0VZ/PtmnwfKDY7QUMXgcrtsP8XoUB890R4suArI5n4iBBmnSpwq5+P0yVAmvSH1QPxqLLj7J 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 Partial enable iomap for regular file's buffered IO path on default mount option, support default filesystem features and bigalloc feature, doesn't support inline data, fs_verity, fs_crypt, defrag and data=journal mode yet (these would be supported gradually in the future). ext4 will fallback to buffered_head path automatically if these options or features are enable. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2ec6c7884e9a..4e7667b21c2f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2972,6 +2972,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +bool ext4_should_use_buffered_iomap(struct inode *inode); int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index e9bbb1da2d0a..956b9d69c559 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,6 +1336,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; ei->i_datasync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5af3b8acf1b9..624eac0cc705 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -770,6 +770,8 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, if (ext4_has_inline_data(inode)) return -ERANGE; + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; map.m_lblk = iblock; map.m_len = bh->b_size >> inode->i_blkbits; @@ -2567,6 +2569,9 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) trace_ext4_writepages(inode, wbc); + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; + /* * No pages to write? This is mainly a kludge to avoid starting * a transaction for special inodes like journal inode on last iput() @@ -5107,6 +5112,30 @@ static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) return NULL; } +bool ext4_should_use_buffered_iomap(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + if (ext4_has_feature_inline_data(sb)) + return false; + if (ext4_has_feature_verity(sb)) + return false; + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (IS_DAX(inode)) + return false; + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE)) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) + return false; + + return true; +} + struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ext4_iget_flags flags, const char *function, unsigned int line) @@ -5371,6 +5400,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations;