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 87DE8C54E58 for ; Thu, 21 Mar 2024 19:29:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F195E6B0083; Thu, 21 Mar 2024 15:29:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECA266B0087; Thu, 21 Mar 2024 15:29:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D93556B0089; Thu, 21 Mar 2024 15:29:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C67CB6B0083 for ; Thu, 21 Mar 2024 15:29:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 63D8CC06C7 for ; Thu, 21 Mar 2024 19:29:17 +0000 (UTC) X-FDA: 81922034754.18.00CC3F5 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf25.hostedemail.com (Postfix) with ESMTP id 61AADA0023 for ; Thu, 21 Mar 2024 19:29:15 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Z50WGZ2e; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf25.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711049355; 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=G5fu3/D1V0U/sUln7momvum1HQsXV+7v6dd0Aqxs2DA=; b=inaA2a4Ku/5SWW4PA+lSf3fYMdqfVa1YQhdT2ttT2pkxOvIrjig08rMmXS/1AoqTmHdyka O6Kjj3UrHhVCFUn35EEzkxArUg1IaN8EOjT5FJraZ/kq+HD9xQedg+vogvTz5lw+ZCyuSh AEu/rFhLDMgiGtzmGmFkjcbtV3MdE6A= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Z50WGZ2e; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf25.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.52 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711049355; a=rsa-sha256; cv=none; b=MezIcuY5dtsuC61xvQX53nphCJqYpDCX8m3FPnK90UgFk0XKO0R6k7XONhtJxmTF+tFhf+ 3qjtAKO/Qkd8x6RI4alaGvA1O397WYDL6rXoRiFg8/Shxxy8dShf1iTyLA3/i83RKP0OIJ KvIK05Z6TzazziM5eBVvAMRP2aB66ew= Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-690de619293so8926296d6.0 for ; Thu, 21 Mar 2024 12:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1711049354; x=1711654154; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=G5fu3/D1V0U/sUln7momvum1HQsXV+7v6dd0Aqxs2DA=; b=Z50WGZ2eoJ+VmVRcnxv0YhLCouh9mOKHGQitvWFhnfnKnD4xiLKJ62EO9sg3igSvu0 yGGZk+W2JTDxlXKEYT4uahoT9l7T2FWoG1vxq6Zlako4/3vP97iQ83AaIl3yBOzgGOfF XVKOh22Nw4bq7ZECjK5dxtEjUqmwssr5KK8r4fxWhedE6GZ7XGS8ve4pU7rOi64QlNox uFPC7WyMwLP7FjEjTuvVYJTD3rIllD+lgURyMKfY+mo+EewAU0saxi4Kska83kvyL3V7 LzAkU+52CX0l/fG8BUbKh8ywmFZgvSh5m/JXrFpPZkzrwnRRQQsc+OJGugXVVoBhU/ca bqeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711049354; x=1711654154; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G5fu3/D1V0U/sUln7momvum1HQsXV+7v6dd0Aqxs2DA=; b=UO7lDuBLSovseg3wscGLNNk5ROG/H66vZGYCkjzPd8qvbywFqHJNEmaTjg4oOchvk4 NXJOQ7OGeJhO2o+kahLhLyUIXmgG+onz3wlfH6C/+rtQe/1C21Ex6/HbAMCEMQTGL4gX 3cwxtUoJBeLZ/miq0Q/TmRifCd/xGWMSN4G/dPzIi8Dlh+rTt3lxVHoN89zhwbRpzITh Y5BWdNZgR9+g9bjm3PLqZtL9eKJ7D8Wk2rk8K6YZkpmQSGzdodN/iFb4Fv29/q2xzqy6 7aemtzu7ktwWaM8y/HF6jPDITMRC0N69hGgtS4ZtJnQK6G0AaBc7jVZL/akzH9qTxFDj hgvg== X-Forwarded-Encrypted: i=1; AJvYcCUCkh9L9zD8jEDRgml1ntpsmgv7nQl2c645KSSq4q/J9dOLFTTL2IYFQTCG3PFN8tkAcIZ/iZqptKiNm85/jMY4/WI= X-Gm-Message-State: AOJu0YyD1uS0XQehy2MKSbjBKnEqvf3SsTt9hT1xoWt0nrUpmhhu4lM3 BNxJySsvdbrv7EIB11sIuaB9QTUcfy/0k/FhiT1145kgC03f6Z9eZ0X4LOfzcTY= X-Google-Smtp-Source: AGHT+IFu4rxdYOIo7pj7Ujp8gBse32uUtx5lYpHmhqI70h9Itcz17gahhpq8NyHAtwrdEF4Oxyta9A== X-Received: by 2002:a05:6214:411a:b0:696:4c68:4e0d with SMTP id kc26-20020a056214411a00b006964c684e0dmr156547qvb.0.1711049354301; Thu, 21 Mar 2024 12:29:14 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id gv12-20020a056214262c00b00690f4a73726sm204979qvb.61.2024.03.21.12.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 12:29:13 -0700 (PDT) Date: Thu, 21 Mar 2024 15:29:12 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Chengming Zhou , Nhat Pham , Chris Li , Linux-MM Subject: Re: [RFC] Storing same-filled pages without a zswap_entry Message-ID: <20240321192912.GB3154@cmpxchg.org> References: <20240320210716.GH294822@cmpxchg.org> <20240320211945.GI294822@cmpxchg.org> <7d7b755a-e13e-4267-b1b5-a4e2ff33d6e0@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 61AADA0023 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: e7ocd6ue1humxsyd1kgq88e63zntgnnj X-HE-Tag: 1711049355-908122 X-HE-Meta: U2FsdGVkX1+PbxMarknjEe0Wd68cYVDj+YygI/0cIXIDHlvqjmtLjmqOBQ59c4cw7xzg6sInsLWkutLYfXpw24SZeYlReH1K6xr99XXtS08/vWV43L/3YC1z4IxehA9ftvwqpEPbvxannoZQqdP2M7fHb1OOEo0T5BRzovvpMaOWr8oiDYmK+nXC5QPhnZZmoYPjag+34FRR+sfAjTsvckXj//eLtWXDjXpuQCBG2KQxV3QEZBondNmYnKXdg1IxkOKtszykXqnG0XkRhq+2jqoiYyM4Qkmw+9xF62srqYM7vMQMpiyX3jTt6TZhkW5rc1M4qsSbidtzv1hofkBTOZ8p/TBLwb8A2cH+POosktsWLHV8kT60246bKIXDBzyyuHSV6usI730aTJaOrm0Ho27Zw24Cu6+WZDMjlwNtuHwzBBOCJXUIuE1o/ClNTAH53seUQ3JOStljRAngJzUBU19ZsLRd6oMLtStIkTZwwif+TUbpbTS5Nm8WCVqGCDJf5+p1jfbxgEDVgdMIxhXGV2VfvDB3AWI+14nVDt8tU/OqztvgcyKsHD4Fi/XUdr9SWu8sbakfEKW2VArOUN815/9n2jaRbvJxavW6y+an0Fzk6cC7gkX4iL9v8/rWs9kbTmT7T4w193V7P4q8y8SDNKtm7NzCiTQpreO/QkB2b52gnac8xnE+5siikZg3kDwjfAIgAJpgLxsZ9Du0lcl41SOUcj/APqCOCcYHt5WkEFulREQUulHxcqS/b6YCAreshs5ynTKS462liSbL31zB6bnbcbQVSXmksY19lQ2fkw9pmLOqdVoILs2nswaPCxqL6nIU3A5n5oDMjZ9RLDz18/u0dMgB0v8afQIKTpxUz9GhyYCboHBfXWgPYUU1R4jRcJPF80LIbvdT+BUmKL03XEZm+LoU4HLtKhoTmKs/k7iFI5rH9lR+imVvYn0ikwTIcatufHMZZhOP9CYW96t glMdySSB Tr0QJGUN9oH98glvXfd+ZoZp2DWUUGRZ1Rp4gnub1DHh5qiYY5j7Shj4PseAEqfv8bXwqcWYcWCyTD0VaYc51psJshHLx0QbT+zVC7rmsdwpRCgPEa27DuILaISGk3ClPE/80Qha08puKOmldOPG07yIfvBMp5QDzF4gJ9cfuijqQ+9FYInpvTRuwKg== 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 Thu, Mar 21, 2024 at 06:44:54PM +0000, Yosry Ahmed wrote: > On Thu, Mar 21, 2024 at 11:40:32AM +0800, Chengming Zhou wrote: > > 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. > > For cgroup v1, swap_cgroup will be cleared from > mem_cgroup_swapin_uncharge_swap() before the zswap load. > > I think the current objcg will remain correct as long as swapin happens > from the same memcg as swapout (or if swapin happens from the parent > memcg and the swapout memcg was offlined). Swap readahead will pull in physically adjacent entries that may belong to somebody unrelated.