Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp311276rdh; Thu, 23 Nov 2023 04:53:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUYo9TtNF1TIEKTzQl9sd+I9puZAhZX1Yt7l6aTcuINYHZv746FEaydoue/azHSIiZ8GD7 X-Received: by 2002:a05:6808:1387:b0:3ae:144f:f99b with SMTP id c7-20020a056808138700b003ae144ff99bmr7269557oiw.4.1700744033110; Thu, 23 Nov 2023 04:53:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700744033; cv=none; d=google.com; s=arc-20160816; b=E1VLwP8wDLUZq0uGENTF+4E0fLUek6fOKwxPFeURPWb74kEHmvPWNloLZQU9QnUbew bByb50SFOJmq0f5pYAZkVyB7Majrdakq/a1w0q+Rp9O3wktcowImk4krPQcdPjB5Tt5n fZh5y4RGmS/88fi25aZO/L8m70wvvNCz7GXdTrfBeRzRjqYW4UKoyMG15Gn0K9iKtudj etPXjaflgQyGZUfh1qGrMnnUGNs5TZJpnN1e8zMbsmIcfQQPH2W97vZeqDQSYNsGP/n/ NOzlUGFU0TZ0BblT4VXHxe19AP8z4Q2nST1nZq0DM12gI+RPcm1svDvn5SxtXyoCUEaP mN+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=u0uZar4BkNFhron/N9d3O17iR9d24fKd8t9L4uwXhmg=; fh=oXgJbFeK1mY0T4jBbK/Fs3Mi9F4SdMRqpoziDljuAF4=; b=LC71Hwjl6mG33GaRaWtRY1MFMy5sYiAUhw8QK/Y5Q0anItwfzghl/Gw7a/bavS+jBA F+QPSymL8RfD7dWMUbKA3GGAFJXcAAHNkKJb8DRdYEVxa6TDJuq1W7/tErLFjUxaiJ/k 66Gzn9X5Gv43G7ztk2WBX+fF/U7nH21xOnpWrYsxdtqGDo9jG/Mf6LQnvwk/jDrZ1N9e QjzCls4kBBrmU5xO399mwCFvHwKXDQoloxRMhoI1+u6PmBWjkTAHgmdX+rODwJrVJVA9 9BNT0m4lA+AlWu4JmoxXmJUl5GjyBzpIrNErwbMyXZWuz+Okdtl/C0vErWOpWyQIcdq0 Y5gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-124-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k26-20020a63561a000000b00578cc8d2599si1214033pgb.211.2023.11.23.04.53.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 04:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-124-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DA722281E10 for ; Thu, 23 Nov 2023 12:53:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 963B333092; Thu, 23 Nov 2023 12:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25B01AE; Thu, 23 Nov 2023 04:52:09 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SbdKv0ZFJz4f3m7Z; Thu, 23 Nov 2023 20:52:03 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 5C3EF1A0729; Thu, 23 Nov 2023 20:52:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDn6xHdSl9lSfnfBg--.20473S22; Thu, 23 Nov 2023 20:52:07 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [RFC PATCH 17/18] ext4: partial enable iomap for regular file's buffered IO path Date: Thu, 23 Nov 2023 20:51:20 +0800 Message-Id: <20231123125121.4064694-19-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231123125121.4064694-1-yi.zhang@huaweicloud.com> References: <20231123125121.4064694-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgDn6xHdSl9lSfnfBg--.20473S22 X-Coremail-Antispam: 1UD129KBjvJXoW3XF4UAryxCw1fCw47AF17trb_yoWxAr4rpr ZIkr1rGw4Du3sF9a1ftF4UZr1Yk3WxKw4UWryS9r1fXFyDX34SqF18tF15A3W5trW8uw1S qF4jkr1UWw43CrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkE bVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67 AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI 42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF 4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBI daVFxhVjvjDU0xZFpf9x0JUQFxUUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Partial enable iomap for regular file's buffered IO path on default mount option and default filesystem features. Does not support inline data, fs_verity, fs_crypt, bigalloc, dax and data=journal mode yet, those will be supported in the future. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 2 ++ fs/ext4/ext4_jbd2.c | 3 ++- fs/ext4/file.c | 8 +++++++- fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 31 +++++++++++++++++++++++++++++++ fs/ext4/move_extent.c | 8 ++++++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 6b3e34ea58ad..7ce688cb1b07 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2959,6 +2959,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); +extern bool ext4_should_use_buffered_iomap(struct inode *inode); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 @@ -3822,6 +3823,7 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) extern const struct iomap_ops ext4_iomap_ops; extern const struct iomap_ops ext4_iomap_overwrite_ops; extern const struct iomap_ops ext4_iomap_report_ops; +extern const struct iomap_ops ext4_iomap_buffered_write_ops; static inline int ext4_buffer_uptodate(struct buffer_head *bh) { diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index d1a2e6624401..cf25cdda7234 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -16,7 +16,8 @@ int ext4_inode_journal_mode(struct inode *inode) ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA || (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && - !test_opt(inode->i_sb, DELALLOC))) { + !ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP) && + !test_opt(inode->i_sb, DELALLOC))) { /* We do not support data journalling for encrypted data */ if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 15fe65744cba..7e3352b3b752 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -296,7 +296,11 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, if (ret <= 0) goto out; - ret = generic_perform_write(iocb, from); + if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + ret = iomap_file_buffered_write(iocb, from, + &ext4_iomap_buffered_write_ops); + else + ret = generic_perform_write(iocb, from); out: inode_unlock(inode); @@ -823,6 +827,8 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) if (IS_DAX(file_inode(file))) { vma->vm_ops = &ext4_dax_vm_ops; vm_flags_set(vma, VM_HUGEPAGE); + } else if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) { + vma->vm_ops = &ext4_iomap_file_vm_ops; } else { vma->vm_ops = &ext4_file_vm_ops; } diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index b65058d972f9..0aae2810dbf6 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 2efa898403f7..33920dc461a8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -779,6 +779,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; @@ -4121,6 +4123,8 @@ void ext4_set_aops(struct inode *inode) } if (IS_DAX(inode)) inode->i_mapping->a_ops = &ext4_dax_aops; + else if (ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP)) + inode->i_mapping->a_ops = &ext4_iomap_aops; else if (test_opt(inode->i_sb, DELALLOC)) inode->i_mapping->a_ops = &ext4_da_aops; else @@ -5185,6 +5189,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 (ext4_has_feature_bigalloc(sb)) + return false; + if (IS_DAX(inode)) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (ext4_should_journal_data(inode)) + 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) @@ -5449,6 +5477,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; diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 18a9e7c47975..23b4b77c5af8 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -597,6 +597,14 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, return -EOPNOTSUPP; } + /* TODO: not supported since block getting function is not switched */ + if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP) || + ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) { + ext4_msg(orig_inode->i_sb, KERN_ERR, + "Online defrag not supported with buffered iomap"); + return -EOPNOTSUPP; + } + if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) { ext4_msg(orig_inode->i_sb, KERN_ERR, "Online defrag not supported for encrypted files"); -- 2.39.2