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 0F8EEC54E68 for ; Thu, 21 Mar 2024 03:40:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96C886B008C; Wed, 20 Mar 2024 23:40:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 91CC76B0093; Wed, 20 Mar 2024 23:40:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80BD26B0095; Wed, 20 Mar 2024 23:40:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7230C6B008C for ; Wed, 20 Mar 2024 23:40:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 456701208F6 for ; Thu, 21 Mar 2024 03:40:47 +0000 (UTC) X-FDA: 81919644534.20.E43580E Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) by imf23.hostedemail.com (Postfix) with ESMTP id 56A0114000C for ; Thu, 21 Mar 2024 03:40:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=heG2Kq7A; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710992445; a=rsa-sha256; cv=none; b=N1rpoGtGbRxA3R3i07X+GyXItEVeA7WX0C40zea9n8VKHQnpfO7UjGo1m3MaW0BOnURO/T +BNlIZF612lUaSqswYe8vAbkI0/qBHxBt70rL3XhssqWED37aTia3/qZABVI3m0CLrnyzv mRbDigpz1JJcYnH2JVozvClEnL0M1vY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=heG2Kq7A; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710992445; 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=dRwueHgJid88tpq8w8u2B9rQqGGsv1LnWh11jx+DBw8=; b=SqO5JV2hXGQoD4+dBINwOdmsjHxWYPtFVEu2dAYsuO3jTQRFRdm6f7MXK+3VzrCWdARTTx OArQd673xyicgE3bbEvbqj5XLNB5j2rr1CKk0nTh6D+DGfha2pMziYmis3CWH/qSiYBX4N ya8aA8jVOTT2gOGOC3KzhZTQKuRX89E= Message-ID: <7d7b755a-e13e-4267-b1b5-a4e2ff33d6e0@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710992437; 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=dRwueHgJid88tpq8w8u2B9rQqGGsv1LnWh11jx+DBw8=; b=heG2Kq7Ayp2yuwqI7c1fA3Q2bbTi+708iOWOFxSM9Mq5cpFw+eZn9OxrngAZ/mhJtztyOr uD2KibB6UrVk8puyrF6oWXmNdYFrVgixJyManW0SZWDj8Mso/nHPnpYJHEXajLEZQQQUPx JbWPU+6D+9PItlfchzpjo1/IBZt8DD4= Date: Thu, 21 Mar 2024 11:40:32 +0800 MIME-Version: 1.0 Subject: Re: [RFC] Storing same-filled pages without a zswap_entry Content-Language: en-US To: Yosry Ahmed , Johannes Weiner Cc: Nhat Pham , Chris Li , Linux-MM References: <20240320210716.GH294822@cmpxchg.org> <20240320211945.GI294822@cmpxchg.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 56A0114000C X-Stat-Signature: mc1ni5c1bp4iggcap71rkiqa6akrbw68 X-HE-Tag: 1710992445-570690 X-HE-Meta: U2FsdGVkX1/wyalKuaSQYGd4vHOIi3b+PFGXxTvJpPXsK7JNMyxWR+4JBCXgEDq4v+tZcqpsf7p0zhb/ABcMk+BdE3d49pRPlmoRzBynuxvncD6qdEiG4pVLf9SHX3P0GSm6R+fSdvkNry+f6MZrjEAbFA8qQGi/Mj+2sQu+52K036DQg24Z2gR7iU+1GeeIcVeo81/fo9BJSevUMt+Mclbl0KlNGQwrudlRiPNIGynSVKKqBN2cK4vNpL5ztfLgoWEhGrJCuZ86Usxir93f/LL31TSpuKZNIQ694FuMOakBGbWHKga9a0BTEf0FwJRBXqpqUKqsvlYac+FwMXdFcVm1Qa8b4OYV07Jg11sVBA+Fr1V2+NoUJkaua24HMKzDq4qLMSSvMWQTCQfxykU0JPObskMx++kBcUA6SDylND0w1+GKIyjsJtnrnXE2DVCFVX3/wjhJd+1jXOTwdP7gOStT2Cu0jnOHWpKns93K+Oe0egPHrflBDO+rTFAZXGw9XUQvemXI+uayZL5dc5cn1vj90d6mdc4mbB4tZiIQtA1c8+srcuRH4s8DbFTE7DYsLbVPZu/r4XxOOiThk+o+lDSFjRM+gjzlU4NSn3Umhj3UF+imJd/qM3GixTDwDgsrQmHdOV27/fXrhHVIeX+P3rsQwvScgoD6nCRchy90O7sQ4k9ietRULyyld6AQu4CRpiD4jCoEQZt8OR+Y6V6j7MPzEMEiHV1B+mJJfI6Vw/5VPIHAO+FhkeqwDEyv2pbmiYNoKSM2s6PQcAEy1Bf4OaA3L2vDdVQ+UoffwEqyScHbOAYzG5a+IV6FZrLjBZix1LSIeBlVAZJmrJR9/IsxSetuLBwNx8qj3jAgZdsgt9DzSDtxdQYe8TinoZTqFOZ+I3JgMRcxdx3JMSakYFFdHlZuDiNIIFsXWXqfpoT1RKs+XHQV4zC+hiZmb8lgVcV513z0jV1ck1pTrrq7jGq FcKy8XlF ncsE/qDY0uULO07KXcx4cjIRB3XYJgNhlj1g7AOAao3edpXvUIeFsif0zZWAx4av6Kry/7wwNu5XKz+yThIP0YLigQVfw/K1nmMqYK4wlQSflqJfnwvOzL1S0TGDcE2A0mE4jZYmke0XTBjECZTpJ9r3dWQU1qMaEx1ESx5czXRx//ckTjCL0p5PEwOCtPw8CBwR4nNyd6UdhveqQHjD5NxNcLbIWAViu8vkk6CwZbMm0M4COyao9bi3vJMy7+ggq/gLS 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/21 05:31, Yosry Ahmed wrote: > On Wed, Mar 20, 2024 at 2:19 PM Johannes Weiner wrote: >> >> On Wed, Mar 20, 2024 at 05:07:21PM -0400, Johannes Weiner wrote: >>> On Wed, Mar 20, 2024 at 01:49:17PM -0700, Yosry Ahmed wrote: >>>> Hey folks, >>>> >>>> I was looking at cleaning up the same-filled handling code in zswap, >>>> when it hit me that after the xarray conversion, the only member of >>>> struct zwap_entry that is relevant to same-filled pages is now the >>>> objcg pointer. >>>> >>>> The xarray allows a pointer to be tagged by up to two tags (1 and 3), >>>> so we can completely avoid allocating a zswap_entry for same-filled >>>> pages by storing a tagged objcg pointer directly in the xarray >>>> instead. >>>> >>>> Basically the xarray would then either have a pointer to struct >>>> zswap_entry or struct obj_cgroup, where the latter is tagged as >>>> SAME_FILLED_ONE or SAME_FILLED_ZERO. >>>> >>>> There are two benefits of this: >>>> - Saving some memory (precisely 64 bytes per same-filled entry). >>>> - Further separating handling of same-filled pages from compressed >>>> pages, which results in some nice cleanups (especially in >>>> zswap_store()). It also makes further improvements easier (e.g. >>>> skipping limit checking for same-filled entries). I also think this is a good idea. :) Which could simplify the code too. >>> >>> This sounds interesting. >>> >>> Where would you store the byte value it's filled with? Or would you >>> limit it to zero-filled only? >> >> The dumb thing about objcg is that for same-filled entries we really >> only need it for bumping ZSWPIN. Nothing else. entry->length is 0 for >> them, so even though we call the charge function, it doesn't actually >> do anything. >> >> Loading them is cheap and doesn't involve decompression. An argument >> could be made to exclude them from ZSWPOUT and ZSWPIN entirely. >> >> Or cheat a little and bump ZSWPIN for current->objcg instead - >> probably good enough to make excessive thrashing discoverable by the >> workload that's directly affected. >> >> Then you could get rid of the objcg pointer and use the xarray slot >> for whatever else you'd want. > > Yeah it's only useful for the stats. Using current->objcg would work, > and should be ultimately pointing to the same memcg in *most* cases, I In some cases where the current objcg is not "correct", the testcases in test_zswap.c may break? Maybe we can use swap_cgroup info to charge the stats to the correct memcg? Not sure if this is feasible. > assume. We still wouldn't be able to store a full word as we do today, > because the xarray needs 1 bit for its own usage. So the same-filled > implementation would still need to change from repeated words (8 > bytes) to something smaller -- or we can just allocate a separate > struct for same-filled pages. Yes, this seems an unavoidable limit of value in xarray... Thanks.