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 88A4FCF9C71 for ; Wed, 25 Sep 2024 00:53:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D7956B008C; Tue, 24 Sep 2024 20:53:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 986ED6B0092; Tue, 24 Sep 2024 20:53:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84E9B6B0095; Tue, 24 Sep 2024 20:53:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 67F2E6B008C for ; Tue, 24 Sep 2024 20:53:25 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 10F85805F3 for ; Wed, 25 Sep 2024 00:53:25 +0000 (UTC) X-FDA: 82601437170.09.E43BA2B Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf04.hostedemail.com (Postfix) with ESMTP id 38C6F4000C for ; Wed, 25 Sep 2024 00:53:22 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=llZ9s4lv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727225471; 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=/C9gXTKiKhXSAsoWF7SRVuxbBkuFhBiScsDmep1YlmQ=; b=DWrb6fO73UmiC3fZySV9h7b1kU2G29HvpAYicKFh9Y6nz2DAF+k9eXUVP9avS+/aACpKB+ lhpB2o3hf18k5W/yVZIm7pM/90zsmCHr6YZaNjq5MN3PhWnFbyHX94XivrsMJU6h6S6KDO wJzKbnlKCX4CRo8nmoiU2Ixn+6x+jcg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727225471; a=rsa-sha256; cv=none; b=LqGRHuhxpbuXQyJ9kFWnl7gGIn5lIJPNX0Qq/Klef0imVz/9UmvFhT4ijLKVPnOoAJPvaj YY1foAcU4NLqjhZ/0yX+WM9EfYetfXiO9gIzePQL7L2J+GBTakOR1deKRemRGuhdcfnTRv xMbejYzd9suas1IKMawLNizuVvdK9jk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=llZ9s4lv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5c245c62362so7461566a12.0 for ; Tue, 24 Sep 2024 17:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727225602; x=1727830402; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/C9gXTKiKhXSAsoWF7SRVuxbBkuFhBiScsDmep1YlmQ=; b=llZ9s4lvKf7JR8hlLQfb0uHM8MneXnZ7q8NKNCbByXTWxV8nig4wzgMtV00zCoU0La TGJDfhlZ3QRyUxxJXoLahECOaSjN9ihSDIrzXwUYM5yAODYJY2X5m8L+gzH5WgfqPd6F abuTe07hnW+BsDJaxBI2ykSyBc3TuK7Pl+88P/1meE5WdU0N0AgOQx3lPV3zTibSD4LF Jd82++J+Juh72ykDVCQqCaADMfKbh8BqQzGYpNGy7ounVWgzgGAFwrM2ZkFnrlINuCDZ zA12wqklHIGVXY9yH/UZx8xVCwY/9Xv2mNfqMnYe6XcrkmiFhja2osduJnDw5HaLimZ0 og+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727225602; x=1727830402; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/C9gXTKiKhXSAsoWF7SRVuxbBkuFhBiScsDmep1YlmQ=; b=tZefTU598qMn1J3HY1BNh1+odzOylHtcAqIpRDf9oHt5PSnicCAyje+aMICeeADp/h /NxdQZ/BFQQLlbQzn8uDqKPobi5CW47h+qGfupVfgZuuH1mByWmjSFsi2mfTcalHcvdf DODuc8i1l/rRpAPR2VoepcwJ+arl5lIc1cIBUeW8jS415LNkDnUK7pifGdkaRWiucuV+ oZXUknwWjRgg7bybRJm+k9Uf7whI5AXclFYP8AIz4Vnhvm3mHqRF6t/hxHShcR32pxpH s157IaA861X/qF0+crZYXlLuAV5tqydqK2ZeCJz/w6RNTCwnH0/zlmSxEgkLElVQ6ZlP bX2w== X-Forwarded-Encrypted: i=1; AJvYcCXJpfJeCShoxKG+SNMMcNqPw7YMPMY1PeA7ehlw4HOXlm07ZR0tEUHvs5rPr02aY3t34jJwPUj3Bw==@kvack.org X-Gm-Message-State: AOJu0YxdGPGQm26ayAix2+lEiZFTnqcMnirZHXvbrHrs0Dg7R6Z+vkDu IQ0/hGNShFETRZRhe4pSEDQHI2GMn4BIkvFBrBfUQo18g00AcSZcN0caJGCGcij8+SSpSJzGlWI Siwuw4GWKknkNq/7NKqVMgNJHCVc/aE1UqMSX X-Google-Smtp-Source: AGHT+IGVZVslwLOc/ZLHTgwX0urxOIsPrhUDpzOCoFQYuYbrgCQ558+RspYWQ75mMyu8A2pRVHqyJAYIovN9ZyGb+eo= X-Received: by 2002:a17:906:4788:b0:a80:f81c:fd75 with SMTP id a640c23a62f3a-a93a0110333mr69872966b.0.1727225601351; Tue, 24 Sep 2024 17:53:21 -0700 (PDT) MIME-Version: 1.0 References: <20240924011709.7037-1-kanchana.p.sridhar@intel.com> <20240924011709.7037-7-kanchana.p.sridhar@intel.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 24 Sep 2024 17:52:45 -0700 Message-ID: Subject: Re: [PATCH v7 6/8] mm: zswap: Support mTHP swapout in zswap_store(). To: Nhat Pham Cc: Kanchana P Sridhar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, chengming.zhou@linux.dev, usamaarif642@gmail.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, joshua.hahnjy@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 38C6F4000C X-Stat-Signature: 8987qdpis46af87rqwt9rswkei3u6bhs X-Rspam-User: X-HE-Tag: 1727225602-855334 X-HE-Meta: U2FsdGVkX19E/YrqjFaOViyNvw/PANL5pKZ5mtkwegFD2146TwlbHzJZT2pBvl0mwMHSMWAUGQ1mxE9t6NxipuOflgGB7yB4zyKfgVoowzjcuDgBxJgeog6DCHRLi3I7q1xh/moDHLF/hLsmfy+RAV+gd0CFFjo6MQvp5dmjSH/N4w6SHT4jfzhAXLYHB5U/KA/YlZjzVhvAnPNuNOHD4f7AxhszjNu8E/YL3AHK0DIYU+yaM5XeRVsR771TskNtB6F1E+wvTF/vQJzoNTPnqnZBlt2AfcYrpQQheaMdAYejbSy299mx6vFLPAWDMMrJxFjjq2mwFCjovvINNGePN8VHLHEIS8HWiRzNC73Q4P1DdocDzz+dXMaBpiRfF+hPs+h/XRb9NJr85oaw15j761o5KNXy9WrnY2QlojeEj7z+B1AnIxs6UdnzQI8Skm0rx9VqV14t4FbiyxGocmrCgwziJZed5lEyKtFL3Lpa+XrZXP+hCILBZ/jeseXNqWZbS1GxsES8At/oRpGzmxUOyIUb2zf5WylULJPygVVoU/KkrQwPaOPaOpmwESfrmNOcZqQnIbyTEoAaKy8kTDnkgfiPGjsoK2ERkQAIELIPBqJaUasn3N4/EkfDM6GMHYfhlWOJCtJjK04x7sgWOAwVcGPnjwU0rSdKJT1EIi+0JOG9SEmFkcD70Ic0FJ1QCGhnknpfDWCmdH4JIIzijHw29hX9daFi3vyEjxOuQVvHYxsgnPMfMnmYsBoQ07povnHUb/6nduPuGwFhVLIB/AN+EXTUqds3f/8MZID7l7JkScVCpd6vbY/KJQWeQNRaPkyUlSJ01RRU/59NADl6G/yC61Z/6OwSlZtEfdSuaGjNMgTwPQDQUuHhNvbgwI9loAYHM/oun8irf5nYYGRt52sOPOA/pCWo/AWd8rcH1j0eBK2ynLa24ey1YXzsId9cadarrSynPYmLwuZYSnZSRl7 /UqdV3E4 LPI5ZhurgIbcGNlhsxIv7cZUznm5BoHY+FSgfEkGYejV/LQNrmFNC5R9Cy7U6x2v7wVIHCHauDP1SR0LEir0wEXaNo9U2zB7X7y/zdflMDHwB662Um3VIydzxnlLqH/jKSkNibjA1g0CD7mE8U4xsl4vZ5/PV+O8YeLr7HZZmAZzGrsI4YyJE0oeyiNPeltle6buWfYYVZTwS7WxMeeofM2lab9DR1FjKvQDtTIu7aMX0lqZl3osXv0jEIQVUMOELG4zzVH0H0GFHieAxvuwwksiUNyhHw6JbPlhNm/Sqinr4DGXNIzPgqFjIKXdNNqKo7ySAGobECiHT5wcZzXnI56mtlrPb0iHaLnCCEJ732zK8zAQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.185893, 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 Tue, Sep 24, 2024 at 4:11=E2=80=AFPM Nhat Pham wrote= : > > On Tue, Sep 24, 2024 at 2:38=E2=80=AFPM Yosry Ahmed wrote: > > > > > > We can also do what we discussed before about double charging. The > > pages that are being reclaimed are already charged, so technically we > > don't need to charge them again. We can uncharge the difference > > between compressed and uncompressed sizes after compression and call > > it a day. This fixes the limit checking and the double charging in one > > go. > > I am a little bit nervous though about zswap uncharing the pages from > > under reclaim, there are likely further accesses of the page memcg > > after zswap. Maybe we can plumb the info back to reclaim or set a flag > > on the page to avoid uncharging it when it's freed. > > Hmm this is just for memory usage charging, no? The problem here is > the zswap usage (zswap.current), and its relation to the limit. > > One thing we can do is check the zswap usage against the limit for > every subpage, but that's likely expensive...? Ah yes, I totally missed this. > > With the new atomic counters Joshua is working on, we can > check-and-charge at the same time, after we have compressed the whole > large folio, like this: > > for (memcg =3D original_memcg; !mem_cgroup_is_root(memcg); > memcg =3D parent_mem_cgroup(memcg)); > old_usage =3D atomic_read(&memcg->zswap); > > do { > new_usage =3D old_usage + size; > if (new_usage > limit) { > /* undo charging of descendants, then return false */ > } > } while (!atomic_try_cmpxchg(&memcg->zswap, old_usage, new_usage)) > } > > But I don't know what we can do in the current design. I gave it some > more thought, and even if we only check after we know the size, we can > still potentially overshoot the limit :( Yeah it's difficult because if we check the limit before compressing, we have to estimate the compressed size or check using the uncompressed size. If we wait until after compression we will either overshoot the limit or free the compressed page and fallback to swap. Maybe a good compromise is to do the check before compression with an estimate based on historical compression ratio, and then do the actual charging after the compression and allow overshooting, hopefully it's not too much if our estimate is good. We can also improve this later by adding a backoff mechanism where we make more conservative estimates the more we overshoot the limit.