Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp585313lqg; Fri, 1 Mar 2024 14:33:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVb+4BX0zwv61pLn9oPRlQ16eKexEEuAJtxMep8bqd/WTnjgqxkgd8JuCScRTcWy17rN6DoGlbgxvR7UUYsE4yChzHopZ+khyYUtMcgAA== X-Google-Smtp-Source: AGHT+IF0ZS7qHkELw5m9MosG5/vYeXrbI5gKaaPpvpcIkmiPeUFWyEBEr4QeXu66OIkwziHktuLb X-Received: by 2002:a05:6a00:4f8e:b0:6e5:7a4d:1849 with SMTP id ld14-20020a056a004f8e00b006e57a4d1849mr3638460pfb.3.1709332436699; Fri, 01 Mar 2024 14:33:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709332436; cv=pass; d=google.com; s=arc-20160816; b=li/vRoPbXTaZSVizHT5hsorr58C048fR3lYqF1vhc+JwVGfP+XHo8xUZLdJO4YBr3z ma4mabKnmYVL8w5OtlXo1MopQDDhRVRRhjMVUpAKuA7Y/00k4d4hpXvI0FbHT5G8ydcz lIYLPcJSU5pjBjkBRV/dZAbYXGg4xqjF2KVrv5IIwnQ0+N3/JpKn16/CKbObEeb5FVrb rjQRclmZuIZdLkJEllUTCcHT2NIDuVzyVT41rZUAGIAXpN3mTo9Uf/ZkecbEdvPSe+Fp By7TJz15u2Wip6erQL67slYd566qnstWSJSHUvAQhNTPE6MDqrxrRQugBe4dg5bJgjIW lo9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Xmq8TeQQrb8mpdPSk45UUwi4Ba5qix3gX7GUStmGdD8=; fh=4+axPVxFo+ChxD5HWvg5+jNF4bqjxfNb0PvqkCE8a3Y=; b=fLL4a6xdJVXLblRw8BUO7aixHVifNPqPLSVEvSl1tq58oZRp7Sb/pj1wp2uhJnpOUa B1XPJWuoHWhhw2nOGvHraQN8MPMtZohxln5h0w4eqAOv7djv/ZdV+jUk2Z9a/ZZWQS3+ zV/7jfGJWDybz2PB8S2XC+IIuN1ZDTT1BJqjWf001S3of7JokfE2on9+N/wksjZZ0PGX zGXIWB82A3NRHSuoftxDNh3B0w0nDEmUjCirf87vy9xu+ic/hmYuLKWwLFijV2/2rvkx AHD9DxnjtjHpu0vdot3DNoYZ2/N1XqtFmQPKF0VBxAZE0/rSJr2AoQokxlCeVBFYr+Pu dRzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rsHsVdBB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89200-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 q132-20020a632a8a000000b005dc423d758dsi4214146pgq.116.2024.03.01.14.33.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 14:33:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89200-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=@kernel.org header.s=k20201202 header.b=rsHsVdBB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89200-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 62F652837A3 for ; Fri, 1 Mar 2024 22:33:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B19645E22B; Fri, 1 Mar 2024 22:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rsHsVdBB" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DE58958AC5 for ; Fri, 1 Mar 2024 22:33:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709332431; cv=none; b=HBDXaGMjNXHjDf2wkuWWf2zXiIFnqCaQ9pCBLPxkuWDDsNKj//Y8yI9UQFA8T0unxf6yIFouUJeBqaQ3LQeVgGTHCr5YQLpgFn4B1TAHksQHzzx+dP3N0r8OEls0wcIaNPu9sZCRNwvLP7e1I9ANxMgUJF7JJo67rYC9Qj+iuI0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709332431; c=relaxed/simple; bh=Xmq8TeQQrb8mpdPSk45UUwi4Ba5qix3gX7GUStmGdD8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=WXLu+ROh4Sj+zrauqsj3japSak6LBka1eDVHTdcYBhHwdFMbXLoackBObhllame6joQyjOaSBtvO0kNRMHdDkNRNoANZd0WnnhxYCWTA1snHaL9NqW9p5JUdsbD5oKpv3/aXZSjMfZDgsJcTUQykUW76jtLHqKP/X0gnwNw/SmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rsHsVdBB; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79477C433A6 for ; Fri, 1 Mar 2024 22:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709332430; bh=Xmq8TeQQrb8mpdPSk45UUwi4Ba5qix3gX7GUStmGdD8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rsHsVdBBlQePLwaK8JhC86Um7jNpfuGJ0aFzucCLgVuuzLbFzbSqnvg5wBFvV9qBa oFhvn6WGLIC3rFWIwld3UwyNISGhZokVFOFGWdIKQFTddF0Ne+kXSKKwbAiCtQFVi/ MvRbvbd13f5jLOjsirvyiurlKzgyxacg1v93KelEIUr+5hfyM8TFLiNNmeUuxAYSca 37imKfBF9pzTO8W9316eizPpehHytkta7ka7C2JnzeNoh8eXyDRI8+T11jkv4T1S0a U2AepUxfM2BM7CCumno7v7uLMqyNVzmME8UX63mgBjopeM0+H8w80D5CI8oE4EzJfB MeIYh65Pt8trw== Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-365c9d37995so8797515ab.0 for ; Fri, 01 Mar 2024 14:33:50 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWBLlrUwHtfNKNu8wGRQEkLWR3vOKHXdJbFh1zoPqUshuEVMpgy56udL2Y5enWtCt8vv/16AwivtJD20CnfLV/FOEKqocfcVmScdRHO X-Gm-Message-State: AOJu0Yzg/CxiQo0vTSgbhPvCGgQSXk+5vWS/sLVlVB2rMhNr5VBfSQNd VkNzXXuEacU7NJIdgSwXtvI3gPgerNTrnUDv2yfEkpI4UQqQ/jN5KHopkPGwvQdbO0cLVy0JIw5 3gF5F2uHIs8Ual1QyB7LFZr6GxblW/uDpQHIy X-Received: by 2002:a05:6e02:154d:b0:365:bff:adfa with SMTP id j13-20020a056e02154d00b003650bffadfamr4172675ilu.17.1709332429778; Fri, 01 Mar 2024 14:33:49 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240229-zswap-xarray-v2-1-e50284dfcdb1@kernel.org> <26e77602326d4e169a9484314cac2465@AcuMS.aculab.com> In-Reply-To: <26e77602326d4e169a9484314cac2465@AcuMS.aculab.com> From: Chris Li Date: Fri, 1 Mar 2024 14:33:37 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] zswap: replace RB tree with xarray To: David Laight Cc: Andrew Morton , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Yosry Ahmed , Nhat Pham , Johannes Weiner , "Matthew Wilcox (Oracle)" , Chengming Zhou , Barry Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 1, 2024 at 1:58=E2=80=AFPM David Laight wrote: > > From: Chris Li > > Sent: 29 February 2024 08:46 > > > > Very deep RB tree requires rebalance at times. That > > contributes to the zswap fault latencies. Xarray does not > > need to perform tree rebalance. Replacing RB tree to xarray > > can have some small performance gain. > > > > One small difference is that xarray insert might fail with > > ENOMEM, while RB tree insert does not allocate additional > > memory. > > What is the difference in kernel memory use? > IIRC someone pointed out (in the rosebush thread) that xarray > uses a lot of kernel memory if the items are randomly distributed. Do you have any suggestions on what script I can run to collect that information for you? If the swapfile is fully utilized, then every 1G of swapfile space will save about 4M of memory using xarray compared to RB tree. Every swap entry saves about 2 pointers (ignoring the intermedia xarray node) Every 1G of swapfile, fully populated xarray pointer uses about 2M of memory. The RB tree node (left pointer, right pointer, color) will use about 6M of memory. In the worst case, you are wasting at most 2M of memory on xarray for every 1G of swapfile. Hope that calculation helps. Keep in mind that the swap cache is already using xarray, using the same swap entry offset as index. So whatever memory waste caused by the sparse distribution of the swap entry, you are already getting that in the current swap cache. Chris