Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1295738lqa; Mon, 29 Apr 2024 04:42:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQDY+0z1YAcKQ6P98FV1r1eoJfzkzjYlIjsbikGCPUFr52VYJOEXIUKkyWwhNSwrPcWHd21vtMwq5CQIXe/y3M7QIGi2udeuR2yozn/Q== X-Google-Smtp-Source: AGHT+IFP96ewT3mNxaJcJBqm/gDuaAa41G+CgFV1d0tRfI0KL/7iel+zrAlb2AyQcXV48qYQvcbC X-Received: by 2002:a17:90b:1809:b0:2ad:3688:de80 with SMTP id lw9-20020a17090b180900b002ad3688de80mr10413066pjb.30.1714390966829; Mon, 29 Apr 2024 04:42:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714390966; cv=pass; d=google.com; s=arc-20160816; b=nPQzRrYG/Ti092vXrMUpcGbq9+WLALgPrHh0f3teydosP+H+lzVTro9uDvz/jxNA56 uxRoojtWIC+Uf10RZuMLPwu9tZTfldbuGHajwTscsbrox3q6CnZloWd4nsMsJz0I8hPa dzrZspNgy1Of0IQRGpjOWBLWjslkmZcKUZnwSifzbpfV7Cnbj1RokXrf8c+Fd6uL9PEY kvGqGJKi1tMxKW2veHAYLjxlCaC6o82SDQd4ruQDCAsU/AwCqid7hIXgokOrrEFLlbGA oECYUCxdjLFMuf71jeU3qO3m+kh9yuM2ITjEJjahv8XV+AGfnRvx+oX++Eox+n7SkymN gGNg== 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=EkLmsUWrg1Em/WvrA/+5hYmO/TeM9WE6fb0I09wilU8=; fh=1Q5tS/thi59I9xbGZKEqGxYYQ5q707YuZZQ8vq+R+eo=; b=v/wg/KpVMcFUX8uMwFQLUXlSxWSiVrDNXb+v/CYQXJNROyyQOPAWb3WbruJLs9ghWu HzKvWbHoH3J2wCgrnVPWzaBNM72w9QirqzJQkcMjaG5REa7E/SOrWkGDgP9Zgtqeak6x 1RqDcyAQ9c3YSiY3FIcXONmLaXOb81fYm74pE/ghocVuikNt/cTQA48VsHL1L8A3ppiv Rf2rYuaDBpea6inndzDXXmbKL6S6f3NALQxyfjiXvA4vEHXa4r3k5hxu+KD93lWHNsUb TrNViE2sl7IvebkuMXPM9VjauLH49vXL8nozMDp0nuSQTN9PztMucmfXvk8LLuZPCA9i DZJw==; 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-2232-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2232-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 ay9-20020a17090b030900b002b1be6da42csi1409494pjb.55.2024.04.29.04.42.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 04:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2232-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-2232-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2232-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 06E77B25645 for ; Mon, 29 Apr 2024 11:30:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFA584502A; Mon, 29 Apr 2024 11:29:04 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [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 C8367537EC; Mon, 29 Apr 2024 11:29:01 +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=1714390144; cv=none; b=NjN4Qxm+0s5XajKPyEjJnK1rL1VaDfDGrPdFSDUbtMvmSGPmIkl6tLBV1AlwoX/V8H2sRa/OksZlI/Mtx+SFXtDyPi6B6QLH+BAJ1f1CH92PKymsQYFVem1crCImH3psByDiJTnVrQc1uEGBPwP6KQjFkdprcaFXYWc30B4hQjo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714390144; c=relaxed/simple; bh=Q4YhIWurI1eqly+A5hDZxZhbfpMnuu6xWDxs0fo7FOI=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=N8zBLJNoFeeZYVQlyIDbsR+GvA64mjfyKhE21QSCHVWQC53I112E+Zhoz5Z4XArecn87IWn/o1CMNpO2aVvhOLRhzXhexgBPN0gzwB2bTLrxfj3QbGP/cXw6oIFVUBB3BiPS6MfzS1dxKTxwrGkOxsglyWTH9XDv42/MksFBtDI= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VSh110pF6z4f3k5r; Mon, 29 Apr 2024 19:28:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 23F2E1A0175; Mon, 29 Apr 2024 19:28:58 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgBHaw54hC9mo0AoLg--.8933S3; Mon, 29 Apr 2024 19:28:57 +0800 (CST) Subject: Re: [PATCH v2 3/9] ext4: trim delalloc extent To: Jan Kara Cc: 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 References: <20240410034203.2188357-1-yi.zhang@huaweicloud.com> <20240410034203.2188357-4-yi.zhang@huaweicloud.com> <20240425155640.ktvqqwhteitysaby@quack3> <20240429102550.sx4vdl75whxovmc2@quack3> From: Zhang Yi Message-ID: <9d4d958b-7b70-c8f5-e091-174a99f506b6@huaweicloud.com> Date: Mon, 29 Apr 2024 19:28:56 +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: <20240429102550.sx4vdl75whxovmc2@quack3> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgBHaw54hC9mo0AoLg--.8933S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZF18JFyfAr13GF4DXFW5Jrb_yoW5Ary3p3 s2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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! > Current change log is not clear enough now, I will put this explanation into the changelog in my nextn iteratio, make it easier to understand. >>> 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. > Sure. Thanks, Yi.