From nobody Sat Oct 4 14:33:04 2025 Received: from mta21.hihonor.com (mta21.hihonor.com [81.70.160.142]) (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 D79E0225A4F for ; Fri, 15 Aug 2025 08:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.160.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755247481; cv=none; b=T+Su7B5iCUSW+ySNkoLpJJiTGpICK3yG5nynCEfkOgPS7bMXxjrilBYAaHwYRm4CGouBq+OI9TcU4wPlZr1mMZ4ddM9IesF5Uf0H54A4G+ttw9Caev2ZaNQL/xZJe+T4vRw/Iq5PDEEGaxUBF7+Bo2YWxFJs8VPkUCPdmzpg0NI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755247481; c=relaxed/simple; bh=vs3F8XMODuBJXP26XM8SiJiomSjtbAoSC7LNBgrpNmw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rERBgHDOIl4MG2ZKzsxhx/JVV2tFBi4USbBA5b5HgFsRF9kTblDObWg585fFg94XEawqiNuepS2lOu5GnV4dG1nh+QsbK7TXCZ6N9+PABVP1QSS0M3upxdTib75FDy1k1JshAKeQI6bkoaEK1G4xyZAif4UIjQu+qSrPn2YPYfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; arc=none smtp.client-ip=81.70.160.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Received: from w012.hihonor.com (unknown [10.68.27.189]) by mta21.hihonor.com (SkyGuard) with ESMTPS id 4c3Fys37nxzYl7Cm; Fri, 15 Aug 2025 16:44:21 +0800 (CST) Received: from a011.hihonor.com (10.68.31.243) by w012.hihonor.com (10.68.27.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 15 Aug 2025 16:44:29 +0800 Received: from localhost.localdomain (10.144.23.14) by a011.hihonor.com (10.68.31.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 15 Aug 2025 16:44:29 +0800 From: wangzijie To: CC: , , , , wangzijie Subject: [PATCH] erofs-utils: avoid redundant memcpy and sha256() for dedupe Date: Fri, 15 Aug 2025 16:44:28 +0800 Message-ID: <20250815084428.4157034-1-wangzijie1@honor.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: w010.hihonor.com (10.68.28.113) To a011.hihonor.com (10.68.31.243) Content-Type: text/plain; charset="utf-8" We have already use xxh64() for filtering first for dedupe, when we need to skip the same xxh64 hash, no need to do memcpy and sha256(), relocate the code to avoid it. Signed-off-by: wangzijie Reviewed-by: Gao Xiang --- lib/dedupe.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/dedupe.c b/lib/dedupe.c index 074cae3..bdd890c 100644 --- a/lib/dedupe.c +++ b/lib/dedupe.c @@ -162,18 +162,9 @@ int z_erofs_dedupe_insert(struct z_erofs_inmem_extent = *e, if (!di) return -ENOMEM; =20 - di->original_length =3D e->length; - erofs_sha256(original_data, window_size, di->prefix_sha256); - di->prefix_xxh64 =3D xxh64(original_data, window_size, 0); di->hash =3D erofs_rolling_hash_init(original_data, window_size, true); - memcpy(di->extra_data, original_data + window_size, - e->length - window_size); - di->pstart =3D e->pstart; - di->plen =3D e->plen; - di->partial =3D e->partial; - di->raw =3D e->raw; =20 /* skip the same xxh64 hash */ p =3D &dedupe_tree[di->hash & (ARRAY_SIZE(dedupe_tree) - 1)]; @@ -183,6 +174,15 @@ int z_erofs_dedupe_insert(struct z_erofs_inmem_extent = *e, return 0; } } + + di->original_length =3D e->length; + erofs_sha256(original_data, window_size, di->prefix_sha256); + memcpy(di->extra_data, original_data + window_size, + e->length - window_size); + di->pstart =3D e->pstart; + di->plen =3D e->plen; + di->partial =3D e->partial; + di->raw =3D e->raw; di->chain =3D dedupe_subtree; dedupe_subtree =3D di; list_add_tail(&di->list, p); --=20 2.25.1