Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1319491lqh; Mon, 6 May 2024 04:22:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqu4IJZDnP7J6kUCWEvfiR2XtQZoo3Ij0xt38mWTyjzouJiS/8AHMgasJ8/Gin6++BT4YsUJgwV91YnKiCqaPM2rEGAx/rhAGZHE7xVw== X-Google-Smtp-Source: AGHT+IG+rTt5urpNR6E6bqa8tw0K29ZL+j9Wrf+xEjYyi5ZVK1Z7JF7OG0l2RQQTAUDmK/rzZ/Zi X-Received: by 2002:a17:902:e752:b0:1e5:c0ee:a7f9 with SMTP id p18-20020a170902e75200b001e5c0eea7f9mr11301136plf.14.1714994532221; Mon, 06 May 2024 04:22:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714994532; cv=pass; d=google.com; s=arc-20160816; b=dwwPiHZUSl72vNMYdWAM8IFT6FOrHC3+QOt+9V+opp+wSqt+zKx+5r9+BbGSEJSu/8 CUGyY4NTw+6VcbU7tXYbaSWRsQxL3Zi56NHeOW5UjC0Rnm3R0VLfJf8TA/UmnWEcyCic /F+hSP250aSmpSY4s93MoWtUu8OgfE4E03z+2SYMIcmAo2r45Y9rLwvTIsSRuuJGULb5 agJp9Te8DFJOqt1G9bV89354qyWyJzZALAqwb90oNfTul1o5i3drfrkRznAjj8HtuhNo ulw46i3qdhszabeJPQnDIRKH7Hd/MK4QvnU1aR3GG2TonAAcRnzBRR62J/a4IP6VbcS0 klkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=VsOqscvfUuxLlH8DOc7L91e3OAXP1LaiQA06+AN+VL4=; fh=Osh4uBb3kdyegO/YWwQoGUhCgrrzgbnUvsz5EKu0a8s=; b=LdAPt9Fa7Rq2ICwMzeMBKzDuG3/RiuG7i60bhzvwFPiJWzC3nEhH/O8C2M55dHnjys C2iv/av22GGI4NvhhUGB+78uLjvpZOHB4zVfZAb/3pUqrPfcBS+W8trPGzP4/BsZgdIx CuEuKOuq+uxdMoa2fmirsiQbK/RuDwfqnQhwaas/174U8FpcDNgCbr1DsXfZXTREbE/7 Fjp4MxZxeC8HfEls+wfaUDV8jGz7iLM99wOz6cQz2oGBqooNMxJgUPoRpO1fBbPWuTZt qpYDef+40Up9kEKW9iIllG/FNv0HWh+1t1/aD8zqC9qmS8ZnndLixvPwWhTlN3L0/NWP u2sA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2307-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2307-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q6-20020a170902dac600b001e9c3c69866si8483008plx.336.2024.05.06.04.22.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 04:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2307-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2307-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2307-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 C12A7283038 for ; Mon, 6 May 2024 11:22:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03C34142E97; Mon, 6 May 2024 11:22:01 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B477514262C; Mon, 6 May 2024 11:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714994520; cv=none; b=An8FmfSTMzt1F5krzRo52X/o2pLuE6a8hg1fTnqQQAT5kIB+cfevDKmVPGJAHO2VW13baFPRxsL+lkmo+SlANP6G1zDoTuJShAgsH4TGpqfSeMhd05fZ5d4kBhjOILhz0JcganL6W0hymy5Vh2BHyJjnX6ijqm+v4YqtXgvWfjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714994520; c=relaxed/simple; bh=DzA1qNG1rre/xnKZN/arluttKfjtjS8U924sZWRNitU=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=RYdG0+qsDM2PnA2uY6ySSvg2hSOgyhKKxN6QhEnWSkZUhqqdSk2Ez0zB68B817FPwGPGJ57iJQvum3multbFzarwLbKXJ5m82NVCRDNTtDMudskMFguJWOJi0FMBkozNQbEOO10jao8VPUKWFtE4PTUTeI5cRIFICPFcI8CbgW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VXzWY1kNdz4f3jR7; Mon, 6 May 2024 19:21:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 69BA61A017D; Mon, 6 May 2024 19:21:53 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgDnCw9PvThmHTPKMA--.36325S3; Mon, 06 May 2024 19:21:53 +0800 (CST) Subject: Re: [RFC PATCH v4 24/34] ext4: implement buffered write iomap path To: Dave Chinner Cc: linux-ext4@vger.kernel.org, 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, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> <20240410142948.2817554-25-yi.zhang@huaweicloud.com> From: Zhang Yi Message-ID: <4adbf8aa-e417-1997-c83d-90e7623f2916@huaweicloud.com> Date: Mon, 6 May 2024 19:21:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgDnCw9PvThmHTPKMA--.36325S3 X-Coremail-Antispam: 1UD129KBjvJXoWxurW5Gw1UXw48GrW3tF1kKrg_yoW5Kry8pF ZxKF45GF4aqrya9F4fXr48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:29:38PM +0800, Zhang Yi wrote: >> From: Zhang Yi >> >> Implement buffered write iomap path, use ext4_da_map_blocks() to map >> delalloc extents and add ext4_iomap_get_blocks() to allocate blocks if >> delalloc is disabled or free space is about to run out. >> >> Note that we always allocate unwritten extents for new blocks in the >> iomap write path, this means that the allocation type is no longer >> controlled by the dioread_nolock mount option. After that, we could >> postpone the i_disksize updating to the writeback path, and drop journal >> handle in the buffered dealloc write path completely. >> >> Signed-off-by: Zhang Yi >> --- >> fs/ext4/ext4.h | 3 + >> fs/ext4/file.c | 19 +++++- >> fs/ext4/inode.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++-- >> 3 files changed, 183 insertions(+), 7 deletions(-) >> [...] >> +#define IOMAP_F_EXT4_DELALLOC IOMAP_F_PRIVATE >> + >> +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) >> + struct iomap *iomap, struct iomap *srcmap, >> + bool delalloc) >> { >> - int ret; >> + int ret, retries = 0; >> struct ext4_map_blocks map; >> u8 blkbits = inode->i_blkbits; >> >> @@ -3537,20 +3580,133 @@ static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, >> return -EINVAL; >> if (WARN_ON_ONCE(ext4_has_inline_data(inode))) >> return -ERANGE; >> - >> +retry: >> /* 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; >> + if (iomap_flags & IOMAP_WRITE) { >> + if (delalloc) >> + ret = ext4_da_map_blocks(inode, &map); >> + else >> + ret = ext4_iomap_get_blocks(inode, &map); >> >> - ret = ext4_map_blocks(NULL, inode, &map, 0); >> + if (ret == -ENOSPC && >> + ext4_should_retry_alloc(inode->i_sb, &retries)) >> + goto retry; >> + } else { >> + ret = ext4_map_blocks(NULL, inode, &map, 0); >> + } >> if (ret < 0) >> return ret; >> >> ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags); >> + if (delalloc) >> + iomap->flags |= IOMAP_F_EXT4_DELALLOC; >> + >> + return 0; >> +} > > Why are you implementing both read and write mapping paths in > the one function? The whole point of having separate ops vectors for > read and write is that it allows a clean separation of the read and > write mapping operations. i.e. there is no need to use "if (write) > else {do read}" code constructs at all. > > You can even have a different delalloc mapping function so you don't > need "if (delalloc) else {do nonda}" branches everiywhere... > Because current ->iomap_begin() for ext4 buffered IO path (i.e. __ext4_iomap_buffered_io_begin()) is simple, almost only the map blocks handlers are different for read, da write and no da write paths, the rest of the function parameter check and inode status check are the same, and I noticed that the ->iomap_begin() for direct IO path (i.e. ext4_iomap_begin()) also implemented in one function. So I'd like to save some code now, and it looks like implement them in one function doesn't make this function too complicated, I guess we could split them if things change in the future. But think about it again, split them now could make things more clear, it's also fine to me. Thanks, Yi.