From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E11C0C54E67 for ; Thu, 28 Mar 2024 08:12:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 484336B0085; Thu, 28 Mar 2024 04:12:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 433C56B0088; Thu, 28 Mar 2024 04:12:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 321676B0089; Thu, 28 Mar 2024 04:12:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0EF836B0085 for ; Thu, 28 Mar 2024 04:12:44 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C718CA15F5 for ; Thu, 28 Mar 2024 08:12:43 +0000 (UTC) X-FDA: 81945731406.18.7409894 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf12.hostedemail.com (Postfix) with ESMTP id B48264000E for ; Thu, 28 Mar 2024 08:12:41 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=E4z2wUN7; spf=pass (imf12.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711613562; a=rsa-sha256; cv=none; b=EpoMgcxsCoRWFGxICJJbdpCBUkfYG1PhYvUOQUlQscpqLKMNuEUj+GqjD+tQo+rTbjJIm/ GTaGxeYeEUvTQBlno46hBXZa/V6m1xooz64WWr8SaE/TKQK5RnloJL75xxwthQu+ph4Ljb irSFltwt60a2GtsD6Kj2SVbx9zjprHU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=E4z2wUN7; spf=pass (imf12.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711613562; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+z86Nxu+WnBrjtSTW47HkgM2M7XmIhiMD7Mp8KdBeRU=; b=oJb9qRFKZIuFoYTs+UKu2ibeMqnA2yBoA32r8L8Y3VO8qH6oXCp3QT/WRyPiVHtkdHoNy1 WUt8xoV1SZMSaI3ULt1U48xM3in8CtVR/6cNMsVTsbaT0PdVXEv/K0HUpU/cjgy16U/pOi sRq9ROajM1iQyUb2+F2y7wmMWXeAn4g= Message-ID: <098bfa48-75d5-45b5-b81d-a2a84b394352@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711613559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+z86Nxu+WnBrjtSTW47HkgM2M7XmIhiMD7Mp8KdBeRU=; b=E4z2wUN7Sx3Tt3DqFMxB2tqqJACJcSfpHfhXm5Sonb0EWOesDfpI9WYWmmVmtcR2n6omSs QVjfIZUZoHljMcySgJHhu+52Tdn+uVmT3yuARaa3wsZ5hTlQBv3b07wsfOxKOiiLfoJXM0 7ZgNghLmGreRRgQrZnP0Zbea29codik= Date: Thu, 28 Mar 2024 16:12:14 +0800 MIME-Version: 1.0 Subject: Re: [RFC PATCH 7/9] mm: zswap: store zero-filled pages without a zswap_entry Content-Language: en-US To: Yosry Ahmed , Andrew Morton Cc: Johannes Weiner , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240325235018.2028408-1-yosryahmed@google.com> <20240325235018.2028408-8-yosryahmed@google.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20240325235018.2028408-8-yosryahmed@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B48264000E X-Stat-Signature: a3mitm5fqgoqanktzfny8sd9ng8pwms3 X-Rspam-User: X-HE-Tag: 1711613561-433269 X-HE-Meta: U2FsdGVkX190P2RO2t/pMl6oBudtZA9fbX39XOAPs2331N6uLtD50AIU4kpbK2UKYJHsBWXmHZJX1woseGbumXHDLhbmMTWzACuBiHJ6YUZ/zX2+Vc1zn6UZaIQP6GTU0BqxDsKF3w49h2h6SlnW8j4DhQY9IrpHeYlAfxnsP/WwcAUYcqbe9fDAaK524Pv5QXEftxRaMj3nB8XDAVnhaQf6Jp2hW+HcmNVukchpUUfJ0JQpMSb4OOW4u7m4OUYN2JjMEHCfVs/WNY+oL45VoT3J9xAi1GBH4fXXIzGf/oVg/2c7Nv9EbvuVIByWQkJbUlWAB3zFAWjlMHNABmat2tThZyJQ209us1SmeGJid9ZQVtXebGyNjrJR+eqbew8oARJabxy0zrIvB5KE0P5UcP3GCMSDEnV6G/rE+E9lUdCaHXBsV05/f9wYZ/II38zWWiZFTK3bCAahgqkROOQFOTUolBrcO0qtqQWcVDt4biKgApxFTzY4eL1yZiXb1c8sTyXBDwrYg9Z9tt6uOP7d+OxjZYN+Mh+FodoDKzGX20tXIvvgk6X9M2YbsT6xoEiJIodF6IF2aZoblURUlPLNbw2U1E8wB0gickdAlr976Y2jrQWbwXgpR4Qb7nm1t2SNsYXBIKK7YFLMiEbr5aoEFNvsXJ91J9ouYIg/Vb94/vmZp8t7XP8WJ/Tk5NNzWkporieVSR45Uk6bGgsAlU889WWOfv2J5mJFZVz/8Pzx7aSux1Yw5P7bXWCzZmYb5CznjDk3JYLlljyQU7YxnyfJQ163MISnwrO+XpA4yYuKOR+/geKkvmLwDIsZleuGQxFCKa8oPVMp+q4SFKfDXYOV9t7G19I43yRFTZINj4uCr3ZQx5oacKvkzn9HULQ+zO6+KmFJIv5Wb0vEjnGwcP7/BCbbv/b7djiyoh1dMAxuXlfL2YNvUckbhisu23dpbmSFjVp2/m5yENjB84I3VA+ +DXqBq6o +Xav39SGRm3qTEBEkw03KzX3ALrIrP9H74B4Zt9xYVDcIhdXe4Q69+2wz98D0lk0tLf1NZZcECTnCrrawuCmjFGkWnXRrSal+2xjCh+5oTw3z8nuctSDba2+4Mr96zS6yTYelqhaBtf0c4UNkulcmskHBeXbXUOPHUzQ1SzWyQI/ecvFOZZC0voShXqIJXz1fHOFd0Qhk4d4u+/1MeB6zoEVbpdR1UDQbuApP0n4TJrT+6wty532TTc8eeVRfm1+3AOU3ovHXsRWyrjBlzmObcNdVKg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2024/3/26 07:50, Yosry Ahmed wrote: > After the rbtree to xarray conversion, and dropping zswap_entry.refcount > and zswap_entry.value, the only members of zswap_entry utilized by > zero-filled pages are zswap_entry.length (always 0) and > zswap_entry.objcg. Store the objcg pointer directly in the xarray as a > tagged pointer and avoid allocating a zswap_entry completely for > zero-filled pages. > > This simplifies the code as we no longer need to special case > zero-length cases. We are also able to further separate the zero-filled > pages handling logic and completely isolate them within store/load > helpers. Handling tagged xarray pointers is handled in these two > helpers, as well as the newly introduced helper for freeing tree > elements, zswap_tree_free_element(). > > There is also a small performance improvement observed over 50 runs of > kernel build test (kernbench) comparing the mean build time on a skylake > machine when building the kernel in a cgroup v1 container with a 3G > limit. This is on top of the improvement from dropping support for > non-zero same-filled pages: > > base patched % diff > real 69.915 69.757 -0.229% > user 2956.147 2955.244 -0.031% > sys 2594.718 2575.747 -0.731% > > This probably comes from avoiding the zswap_entry allocation and > cleanup/freeing for zero-filled pages. Note that the percentage of > zero-filled pages during this test was only around 1.5% on average. > Practical workloads could have a larger proportion of such pages (e.g. > Johannes observed around 10% [1]), so the performance improvement should > be larger. > > This change also saves a small amount of memory due to less allocated > zswap_entry's. In the kernel build test above, we save around 2M of > slab usage when we swap out 3G to zswap. > > [1]https://lore.kernel.org/linux-mm/20240320210716.GH294822@cmpxchg.org/ > > Signed-off-by: Yosry Ahmed The code looks good, just one comment below. Reviewed-by: Chengming Zhou > --- > mm/zswap.c | 137 ++++++++++++++++++++++++++++++----------------------- > 1 file changed, 78 insertions(+), 59 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 413d9242cf500..efc323bab2f22 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -183,12 +183,11 @@ static struct shrinker *zswap_shrinker; > * struct zswap_entry > * [..] > > @@ -1531,26 +1552,27 @@ bool zswap_load(struct folio *folio) > struct page *page = &folio->page; > struct xarray *tree = swap_zswap_tree(swp); > struct zswap_entry *entry; > + struct obj_cgroup *objcg; > + void *elem; > > VM_WARN_ON_ONCE(!folio_test_locked(folio)); > > - entry = xa_erase(tree, offset); > - if (!entry) > + elem = xa_erase(tree, offset); > + if (!elem) > return false; > > - if (entry->length) > + if (!zswap_load_zero_filled(elem, page, &objcg)) { > + entry = elem; nit: entry seems no use anymore. > + objcg = entry->objcg; > zswap_decompress(entry, page); > - else > - clear_highpage(page); > + } > > count_vm_event(ZSWPIN); > - if (entry->objcg) > - count_objcg_event(entry->objcg, ZSWPIN); > - > - zswap_entry_free(entry); > + if (objcg) > + count_objcg_event(objcg, ZSWPIN); > > + zswap_tree_free_element(elem); > folio_mark_dirty(folio); > - > return true; > } [..]