Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1263688lqa; Mon, 29 Apr 2024 03:28:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUR0YGC2tr5aF2dBwcwDhA5n7tPnyTATFDr18wx3N/nwOONj0LG5m19QzoAWQ7eV5O+hy9oEyLvb70Qdyuv3Zr9AW1XfbYKL9Rnb0AwCg== X-Google-Smtp-Source: AGHT+IH7NAgiPu2nCgKmzGfOMS7Vh42bMMUAAADG90pLbNgHpjyEWITqJnW3MZ8pg7J0kkhquolM X-Received: by 2002:a05:6a20:dc95:b0:1a9:ac49:ea94 with SMTP id ky21-20020a056a20dc9500b001a9ac49ea94mr9543647pzb.61.1714386514307; Mon, 29 Apr 2024 03:28:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714386514; cv=pass; d=google.com; s=arc-20160816; b=pE1MOAihlpp8k/EbDA/t/HR3PB5DAVK2Jt9g8ClHfClHuiJpNGpfplJDL7uyKGHhgO J5jlRbGnnpU/MbQTbe1zRDFIZFRaWk2lyVSdpBmrdAXoqnnqkms084onDYgz6gm+CG9K Zv4KUruUz9ac45wH+FdD2HPdIecWZwwtllsdm7NikEBIDT2auRQyL5biJjUc7evFdBXs i75nTPz8XfjRYBammuC3xG8koZDevjuzGGTDc1C03/f1cRZEx+nWxEpBWCXXvMMYhf15 5Mjo3ib0eRjfCILr/j7mU7Q3u58qc+qG0+DZcuczcFbW1kHud2EbuPgGr4Aa13EV/B1+ ncHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=wdguafLdAH4AdttvIwHOB3Ush9+rDDpiVxU7qZjO9K0=; fh=ovAgdFVieY83eUtAxqNKHARa80ahbuasIVUXxZnTEmc=; b=Igzw0MM4ol/AMJDN33g3mFHahdgC5/b459qUQOdrJPzWhdxU51GTuaU3Y4Om2o5mZX VmOmujt9JJxGBOnD7iSryXBBVF6d/b0jV7HrBt/61h/jln7q1HHLE+KdPVOfE0V0gspM kiizZLZgfJ8m9Q3p9R6WWUQnaPc+Yl93qAHc8neKv7uWglsLrvVjdmMdezj+GopdZt1r MXQgjii6ICabDVSEQFdmZZLqwOuYYLOu14zpi/RIP0JqbvJ7jT0TN58kGyE1+VNUFv5E 9er/DvHT9gYIAuUVLCa4sTVgdTH+SYLv+/PPazrs7fcBKyjSC/XhvehFUg/BbZiGs4lc eafA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=J3YXv5De; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=J3YXv5De; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-2230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2230-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 y23-20020a056a00181700b006eccebb90bcsi20107762pfa.143.2024.04.29.03.28.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 03:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2230-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; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=J3YXv5De; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=J3YXv5De; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-ext4+bounces-2230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2230-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 7DDF8284969 for ; Mon, 29 Apr 2024 10:27:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBB1F39AC7; Mon, 29 Apr 2024 10:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="J3YXv5De"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="NUUTHm6H"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="J3YXv5De"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="NUUTHm6H" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8074C383BA; Mon, 29 Apr 2024 10:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714386359; cv=none; b=JYLTuBg1Fom8cjGi6sPvN+7gCSKoAeIHrDSaRg+csHd/kpF8Czml5gMm8jx8cK0yLnmHtjY3wiWEbOSPboe0jTe4VQ0fN7Lx4Sz8cr2sU2VkgAsObB2XMM/nKK84hTQfgGj3WukFYLEI58ICnqqdggU93LvqtPKK2Zz62TmwUNA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714386359; c=relaxed/simple; bh=cADUwdCDxPZT/pSB/dKjxUYhDiMPjw+O+Xt5ZtJsSKA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=prfR6T7K8WZ1jZ2UyLbzg1Sw2kaPEI8PO7UD48VUbWBfmjOaIviKvSHKzJyr/WQJUr9C0rnFk6o+HiWFfucYwYoF1QKBGBEuLFgXsyVb+6VZ+malvTc/0myzWvgmrv3Udq5pPahDr8RLzMkaC0KoUaJzf2AT52ZoG7IdH8eSZYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=J3YXv5De; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=NUUTHm6H; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=J3YXv5De; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=NUUTHm6H; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 629FF225FA; Mon, 29 Apr 2024 10:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1714386355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wdguafLdAH4AdttvIwHOB3Ush9+rDDpiVxU7qZjO9K0=; b=J3YXv5DeF63aric9ZS4jrCwDLLyL5Gq4Shk2YyT+Cya0zsUwL7pKrSSitNgXGs+RV1ZGWC 0kYRSIhPo5CMhMiF+p/2Hz+0LwG/wKbpIZF9l0HuihtmMMLJz1/Z4SLd9oI0O3dqQGmQ3K UUP7LFJyJY0KUj9sGX+xOO+/MXJ33Og= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1714386355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wdguafLdAH4AdttvIwHOB3Ush9+rDDpiVxU7qZjO9K0=; b=NUUTHm6HmvLhAvbA7nKESwcZ7fFHCyQ1QcYJ2Ssh0q+Xqwhpm/gmTFmJf/Y5sYnxWaTnnf l9B6UU9FJCapryBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1714386355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wdguafLdAH4AdttvIwHOB3Ush9+rDDpiVxU7qZjO9K0=; b=J3YXv5DeF63aric9ZS4jrCwDLLyL5Gq4Shk2YyT+Cya0zsUwL7pKrSSitNgXGs+RV1ZGWC 0kYRSIhPo5CMhMiF+p/2Hz+0LwG/wKbpIZF9l0HuihtmMMLJz1/Z4SLd9oI0O3dqQGmQ3K UUP7LFJyJY0KUj9sGX+xOO+/MXJ33Og= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1714386355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wdguafLdAH4AdttvIwHOB3Ush9+rDDpiVxU7qZjO9K0=; b=NUUTHm6HmvLhAvbA7nKESwcZ7fFHCyQ1QcYJ2Ssh0q+Xqwhpm/gmTFmJf/Y5sYnxWaTnnf l9B6UU9FJCapryBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 59148139DE; Mon, 29 Apr 2024 10:25:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2cTIFbN1L2blMgAAD6G6ig (envelope-from ); Mon, 29 Apr 2024 10:25:55 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 01A2EA082F; Mon, 29 Apr 2024 12:25:50 +0200 (CEST) Date: Mon, 29 Apr 2024 12:25:50 +0200 From: Jan Kara To: Zhang Yi Cc: Jan Kara , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH v2 3/9] ext4: trim delalloc extent Message-ID: <20240429102550.sx4vdl75whxovmc2@quack3> References: <20240410034203.2188357-1-yi.zhang@huaweicloud.com> <20240410034203.2188357-4-yi.zhang@huaweicloud.com> <20240425155640.ktvqqwhteitysaby@quack3> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Flag: NO X-Spam-Score: -3.80 X-Spam-Level: X-Spamd-Result: default: False [-3.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_LAST(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.cz:email,huawei.com:email] On Fri 26-04-24 17:38:23, Zhang Yi wrote: > On 2024/4/25 23:56, Jan Kara wrote: > > On Wed 10-04-24 11:41:57, Zhang Yi wrote: > >> From: Zhang Yi > >> > >> The cached delalloc or hole extent should be trimed to the map->map_len > >> if we map delalloc blocks in ext4_da_map_blocks(). But it doesn't > >> trigger any issue now because the map->m_len is always set to one and we > >> always insert one delayed block once a time. Fix this by trim the extent > >> once we get one from the cached extent tree, prearing for mapping a > >> extent with multiple delalloc blocks. > >> > >> Signed-off-by: Zhang Yi > > > > Well, but we already do the trimming in ext4_da_map_blocks(), don't we? You > > just move it to a different place... Or do you mean that we actually didn't > > set 'map' at all in some cases and now we do? > > Yeah, now we only trim map len if we found an unwritten extent or written > extent in the cache, this isn't okay if we found a hole and > ext4_insert_delayed_block() and ext4_da_map_blocks() support inserting > map->len blocks. If we found a hole which es->es_len is shorter than the > length we want to write, we could delay more blocks than we expected. > > Please assume we write data [A, C) to a file that contains a hole extent > [A, B) and a written extent [B, D) in cache. > > A B C D > before da write: ...hhhhhh|wwwwww.... > > Then we will get extent [A, B), we should trim map->m_len to B-A before > inserting new delalloc blocks, if not, the range [B, C) is duplicated. Thanks for explanation! > > In either case the 'map' > > handling looks a bit sloppy in ext4_da_map_blocks() as e.g. the > > 'add_delayed' case doesn't seem to bother with properly setting 'map' based > > on what it does. So maybe we should clean that up to always set 'map' just > > before returning at the same place where we update the 'bh'? And maybe bh > > update could be updated in some common helper because it's content is > > determined by the 'map' content? > > > > I agree with you, it looks that we should always revise the map->m_len > once we found an extent from the cache, and then do corresponding handling > according to the extent type. so it's hard to put it to a common place. > But we can merge the handling of written and unwritten extent, I've moved > the bh updating into ext4_da_get_block_prep() and do some cleanup in > patch 9, please look at that patch, does it looks fine to you? Oh, yes, what patch 9 does improve things significantly and it addresses my concern. So feel free to add: Reviewed-by: Jan Kara Maybe in the changelog you can just mention that the remaining cases not setting map->m_len will be handled in patch 9. Honza -- Jan Kara SUSE Labs, CR