Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1329597lqh; Mon, 6 May 2024 04:45:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXC3G1xbghS83qZNkpcddVqC6WsKJ8Do3gjChw8LwZu4zZyDS4L9/tt8FBjuBl7a83JOGrhJ8iPbeL+VYQAUePirnq1rAFyYDCYqLysHg== X-Google-Smtp-Source: AGHT+IEicunxOwEntgaKnCdNI4evx8hz/4W45twazR2qpevs8gOTwU0aguB8Obnz79HslWgVbX3I X-Received: by 2002:a17:902:db08:b0:1ec:bc3e:84a3 with SMTP id m8-20020a170902db0800b001ecbc3e84a3mr10896315plx.14.1714995906645; Mon, 06 May 2024 04:45:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714995906; cv=pass; d=google.com; s=arc-20160816; b=nP00Dz4ZBTRGzbKJ4eAUKEjaOZqlmdO4+PkWcuCkp2X+AzLKSskLzBR4tApePqqndj NrGYRKYi90JkRu9Kx7I0a9RA+K9ur9GwvuDPAOLTEmprUOkzDXwMeaJkLV4TmNEq306v AGV5pDw0SbwL88jIoci+pquBMkBzI1umLmPTkWgWZbmMw/ym3GHMRw+ak4YPH+/5OQLy 7KDaEV1bi8j6mssU4Nl7KKEvqIvR4qw9CJ8ilrSsMjy+Q5OFUs3y/yhsUY1Z+IW6adUk cpkPkES5uZJAeTY8Cy5TnU9m83ScMKfOWGizmNaTWxFtMJgrsBc7+fWiN6GDCK0rLg6C U5aQ== 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=JqAqpz7lkVIR8Hx5IvRjWXDdbz8vAHlNRwjktYA90ic=; fh=Osh4uBb3kdyegO/YWwQoGUhCgrrzgbnUvsz5EKu0a8s=; b=HAhk6oM6Lm0wcTnW+OtM/zuHh7eshB8+pkaMBblFCKExiwEnXbK4WVZSYVLmm04vKr bP77mrdnCYpKKHcTM7cS5v6ZnspF5pj8SRLDoriAg+akdSliTabpxC4bqeLB3LcdWMRX rKzZMKK5s+RA6m/0H02O6TKT0kf/W9/qglDaobHfk17XAt8LtXjYV7ea1KSWl2yb5sd/ d5pO/aFaL1zfHJ3mFIBiH4T8swGW6eqAgRadOu18o2WkwDUsw6b+a6DHebQ8raJ5Awxu nAKUjSope0VdSuex6+Lva3oaSSdViehWWkUE5xRqw2flH3eRqz8L/D7EXAdlWdOMRefJ k1LQ==; 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-2309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2309-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e16-20020a170902ef5000b001eb3d68805csi5783974plx.29.2024.05.06.04.45.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 04:45:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2309-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E53A3B21D97 for ; Mon, 6 May 2024 11:45:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09CA3143738; Mon, 6 May 2024 11:44:54 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 2D7591DFE4; Mon, 6 May 2024 11:44:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714995893; cv=none; b=ggAvtEKVJB1qdvMZQmsA/ciGoIodb5ni+jkZLikm9pWXiiziyRPYtwArSsvm5L5D9a4nTkY6nCtun2W+bbjkm5tn3jRD18Rcs3oLjwB+hVtehWDrFEJqnojNvDPf9ePa1QrC/s9cfztB6KTfaHehonWriKyz9ej3W2oAUZku4fQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714995893; c=relaxed/simple; bh=vVX8ey54S/LNAFujtNUW9wAhLyLI3G3H+odAJkJ87V0=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=ueJAM5uhJT284QvF+/j0pKBwJVbWUfznpKgHn6cYRkEzhNtlAAY1hS/XFRd649b60Gvgv9w7uL/DRQLXXFOc307srDel5CTik/hUvaodGkPb83zlQB68nPtDvKO5albCjwaZ6cwbKsNy5Kk0cjm0/USbFrARwkHTa38mOwQwD28= 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.51 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.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VY0215r8Yz4f3m8v; Mon, 6 May 2024 19:44:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 148D51A1072; Mon, 6 May 2024 19:44:47 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgDH6w6swjhmHsDLMA--.57384S3; Mon, 06 May 2024 19:44:46 +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: <96bbdb25-b420-67b1-d4c4-b838a5c70f9f@huaweicloud.com> Date: Mon, 6 May 2024 19:44:44 +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:Syh0CgDH6w6swjhmHsDLMA--.57384S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZFWxCryDXFyDtw17Cry3Jwb_y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rote: > On Wed, May 01, 2024 at 06:11:13PM +1000, Dave Chinner wrote: >> On Wed, Apr 10, 2024 at 10: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. > ..... >>> +/* >>> + * Drop the staled delayed allocation range from the write failure, >>> + * including both start and end blocks. If not, we could leave a range >>> + * of delayed extents covered by a clean folio, it could lead to >>> + * inaccurate space reservation. >>> + */ >>> +static int ext4_iomap_punch_delalloc(struct inode *inode, loff_t offset, >>> + loff_t length) >>> +{ >>> + ext4_es_remove_extent(inode, offset >> inode->i_blkbits, >>> + DIV_ROUND_UP_ULL(length, EXT4_BLOCK_SIZE(inode->i_sb))); >>> return 0; >>> } >>> >>> +static int ext4_iomap_buffered_write_end(struct inode *inode, loff_t offset, >>> + loff_t length, ssize_t written, >>> + unsigned int flags, >>> + struct iomap *iomap) >>> +{ >>> + handle_t *handle; >>> + loff_t end; >>> + int ret = 0, ret2; >>> + >>> + /* delalloc */ >>> + if (iomap->flags & IOMAP_F_EXT4_DELALLOC) { >>> + ret = iomap_file_buffered_write_punch_delalloc(inode, iomap, >>> + offset, length, written, ext4_iomap_punch_delalloc); >>> + if (ret) >>> + ext4_warning(inode->i_sb, >>> + "Failed to clean up delalloc for inode %lu, %d", >>> + inode->i_ino, ret); >>> + return ret; >>> + } >> >> Why are you creating a delalloc extent for the write operation and >> then immediately deleting it from the extent tree once the write >> operation is done? > > Ignore this, I mixed up the ext4_iomap_punch_delalloc() code > directly above with iomap_file_buffered_write_punch_delalloc(). > > In hindsight, iomap_file_buffered_write_punch_delalloc() is poorly > named, as it is handling a short write situation which requires > newly allocated delalloc blocks to be punched. > iomap_file_buffered_write_finish() would probably be a better name > for it.... > >> Also, why do you need IOMAP_F_EXT4_DELALLOC? Isn't a delalloc iomap >> set up with iomap->type = IOMAP_DELALLOC? Why can't that be used? > > But this still stands - the first thing > iomap_file_buffered_write_punch_delalloc() is: > > if (iomap->type != IOMAP_DELALLOC) > return 0; > Thanks for the suggestion, the delalloc and non-delalloc write paths share the same ->iomap_end() now (i.e. ext4_iomap_buffered_write_end()), I use the IOMAP_F_EXT4_DELALLOC to identify the write path. For non-delalloc path, If we have allocated more blocks and copied less, we should truncate extra blocks that newly allocated by ->iomap_begin(). If we use IOMAP_DELALLOC, we can't tell if the blocks are pre-existing or newly allocated, we can't truncate the pre-existing blocks, so I have to introduce IOMAP_F_EXT4_DELALLOC. But if we split the delalloc and non-delalloc handler, we could drop IOMAP_F_EXT4_DELALLOC. I also checked xfs, IIUC, xfs doesn't free the extra blocks beyond EOF in xfs_buffered_write_iomap_end() for non-delalloc case since they will be freed by xfs_free_eofblocks in some other inactive paths, like xfs_release()/xfs_inactive()/..., is that right? Thanks, Yi.