From patchwork Tue Jan 28 18:55:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13952397 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 C4D16C0218A for ; Tue, 28 Jan 2025 09:55:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16E772801E4; Tue, 28 Jan 2025 04:55:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11F262801E3; Tue, 28 Jan 2025 04:55:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F294C2801E4; Tue, 28 Jan 2025 04:55:50 -0500 (EST) 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 D47A72801E3 for ; Tue, 28 Jan 2025 04:55:50 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 53D97140F30 for ; Tue, 28 Jan 2025 09:55:50 +0000 (UTC) X-FDA: 83056404060.21.31E1E92 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf03.hostedemail.com (Postfix) with ESMTP id 8E4CE2000A for ; Tue, 28 Jan 2025 09:55:48 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Y7vszG8I; spf=pass (imf03.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738058148; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=aR73JREcMM77cKYf1hrqQ2m37JiPwgtQb91oVMX/AGI=; b=iVtHv3NWy8mh0RlgXo1l8R1wj4kWYA2b47KrB6qb1hMB0eibdYt7aYiY9VJI55yV2ONE2c X2qGdeix2GBTaa33gonEK2hznocsi//eIIBlQ1cSFmJmX/9zgPiqe0dgd11RWVipedc6GJ 5jNbAhWH9grHeGI/aHMVwy4zlLOls48= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738058148; a=rsa-sha256; cv=none; b=T0jXMO3+w1zZBvhNHNlLII1NOSqmHnpF7C6xJryzZUdYj2PU+J1LSahdYuy7m0k7YdF2pG 5iphBG2+KGwp1AdhtV3p8ho0xAvAeaXDiwFGIdCSUcPL5UqtxC4Bl4dUPSyrs78/LHtF22 E6LzMtqeTbpFibRC2HukkRNRixyuia4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Y7vszG8I; spf=pass (imf03.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21644aca3a0so125375645ad.3 for ; Tue, 28 Jan 2025 01:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738058147; x=1738662947; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aR73JREcMM77cKYf1hrqQ2m37JiPwgtQb91oVMX/AGI=; b=Y7vszG8IRVqkehHJddHFc2L5Yq2Zd/krIVt0WndxSf+HYkKd4PsCugFBy3gIWaOK7E HSm1bqHUXnGPgUP1BK4x7NJtrjcmpB3OaCGqy3Uw6uxhhfvLvXA5ENYAs8dsN32TuCPV ulwTd4FzvslANOAQk1gxLfC/gjxJRXLONcjW1ng94f7Epd91PHLcjRj07Gvw2SrlAn2v 6qnqNW9bYy1pvXro3HbbPpevyAeTIk8CnEfLC0mL7JliGtkXEgiTrhmG7gGmjDbaoLwB YUYytyAUYnyqDZt7CiCUUd/d+AfCUqlTsKxUKikGv1NIWDtbVcC4D57ITQTBeLXrTOG4 GwqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738058147; x=1738662947; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aR73JREcMM77cKYf1hrqQ2m37JiPwgtQb91oVMX/AGI=; b=Uft0lPVdqKSRWUpedn0nmXWGqOpDFkQvjcEfggHk8OsDjYb9F2H+be/q0a3H/52oCs /CVmAoDvlvclbyA32NH4T4usRNqIUA4CTCr4NZOkv9zQb/C7ONzvsXafOoFVlCT/yLii MeDoMf2ZteAzrMzclBUMpKZ4saPS3zTSrTiX1PeBCiokhzel2Pp3x1pbkhBbe6ACDj8Y cCzMFGEpuEEgpj+1t5Hajlpl1M+fsVZWLLaAX3yDHBIuD6Mg6LThsJCGiKhXPsfBPLvV ns3bNTRib88Dnn9dVYwts26vz+3aqE7rb5j9zNMXE3CZ6glXUgVWPp7Y/to2/isnRjaI pDRA== X-Gm-Message-State: AOJu0Ywgw4fnRK+hhJnvOUYfofsRqflyLtt3eFwot6Q9cW+wDny2oQpL RBCmbI16xDeqUZL8rVbQz52lBEekmbJPpfnzAIBnOXnYMvqOw2pD X-Gm-Gg: ASbGnctid6uN072jlplNF7GmWg3htOPsWrBzHe4/uTXg/B3EklT6e2QX5e7jpTVjBCi 10G3nKD4xowyw8w+4WLi1CkkspYSkqBpm2K5BVckA75W3QofwKVwPvYRwL1bOGD8hY0XuVf+J0e prjJcGhQxxw5QgDA24yGno6Fb2LrgDpGQKssuU3qEyy/wyD95fqjn7NG0m5BlF7iM8EzCz+Na9q zLldFOtsJg+ypO86Dwy8YnD3y/TQKXwrLw/Q2x3MMZaIsJzxMvOtTEPgiXn6dEeq5Y+bQlJlUZc 3K66aH29uI5QuhJE6bt+Y04zNoLrLoiIIF0= X-Google-Smtp-Source: AGHT+IGF+2R5lm3XFjfG4YmOPjpOVRqm1WJ/6wHrONmPyCPM9NFm8WFCD7ChZkvpHZELLWRSX8qHVA== X-Received: by 2002:a17:902:e802:b0:212:615f:c1 with SMTP id d9443c01a7336-21c3540a0admr729176155ad.14.1738058147018; Tue, 28 Jan 2025 01:55:47 -0800 (PST) Received: from hyeyoo-laptop.localdomain ([221.160.193.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da424eea4sm77697845ad.238.2025.01.28.01.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 01:55:46 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Kanchana P Sridhar , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Andrew Morton Cc: linux-mm@kvack.org, Hyeonggon Yoo <42.hyeyoo@gmail.com>, stable@vger.kernel.org Subject: [PATCH v2 mm-hotfixes] mm/zswap: fix inconsistent charging when zswap_store_page() fails Date: Wed, 29 Jan 2025 03:55:07 +0900 Message-ID: <20250128185507.2176-1-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Stat-Signature: wtibbk9sjayc4i88wpqnpnkz8y4kku3n X-Rspamd-Queue-Id: 8E4CE2000A X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738058148-581733 X-HE-Meta: U2FsdGVkX18oJP9BPyDjUcArP8FnmRhpbMuLKr1qOb8dxTcE1lgUnW38xxg7qfx2xjB1GwUXPHue8kS7JcyKbzG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PSwr7+sQHBnTbbptRZTJnrj218QJrOKSWFrvn2bzskHNUpSZwh/LNE5RsJr0S+ZVvYxdsqeYUqa7jvxwcuLKWK3CS5HxX5y5OGFa14wM6iX2x5FuUUsFMy/2ignNpW7q+ZeyLNYDSlOqpRfd8gtevhbg6Mozo2TQHf85pKwCnu8AlHX6rF9dBGKETA3Zp4oo49WbnIdqEuELEr1ibRyanspKJym/G/dWrgFtMnIdQd9yjeQFSm6Np6jUPguWAG12XdlIzIyww9oTcfLFz4QckqhX/05P5IISI8nXnhHFmqJKQKtbRpjzdL8Cso9WMmB0mA8x4Kacc58kOzM300Q4NvGCedo1p4KuJPwoAhhml9kLznHJfZxiyd3tNPqN5auVtWCId1LzAsHia1JlmaI7f48= 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: Commit b7c0ccdfbafd ("mm: zswap: support large folios in zswap_store()") skips charging any zswapped base pages when it failed to zswap the entire folio. However, when some base pages are zswapped but it failed to zswap the entire folio, the zswap operation is rolled back. When freeing zswap entries for those pages, zswap_entry_free() uncharges the pages that were not previously charged, causing zswap charging to become inconsistent. This inconsistency triggers two warnings with following steps: # On a machine with 64GiB of RAM and 36GiB of zswap $ stress-ng --bigheap 2 # wait until the OOM-killer kills stress-ng $ sudo reboot Two warnings are: in mm/memcontrol.c:163, function obj_cgroup_release(): WARN_ON_ONCE(nr_bytes & (PAGE_SIZE - 1)); in mm/page_counter.c:60, function page_counter_cancel(): if (WARN_ONCE(new < 0, "page_counter underflow: %ld nr_pages=%lu\n", new, nr_pages)) While objcg events should only be accounted for when the entire folio is zswapped, objcg charging should be performed regardlessly. Fix accordingly. After resolving the inconsistency, these warnings disappear. Fixes: b7c0ccdfbafd ("mm: zswap: support large folios in zswap_store()") Cc: stable@vger.kernel.org Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- v1->v2: Fixed objcg events being accounted for on zswap failure. Fixed the incorrect description. I misunderstood that the base pages are going to be stored in zswap, but their zswap entries are freed immediately. Added a comment on why it charges pages that are going to be removed from zswap. mm/zswap.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6504174fbc6a..10b30ac46deb 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1568,20 +1568,26 @@ bool zswap_store(struct folio *folio) bytes = zswap_store_page(page, objcg, pool); if (bytes < 0) - goto put_pool; + goto charge_zswap; compressed_bytes += bytes; } - if (objcg) { - obj_cgroup_charge_zswap(objcg, compressed_bytes); + if (objcg) count_objcg_events(objcg, ZSWPOUT, nr_pages); - } atomic_long_add(nr_pages, &zswap_stored_pages); count_vm_events(ZSWPOUT, nr_pages); ret = true; +charge_zswap: + /* + * Charge zswapped pages even when it failed to zswap the entire folio, + * because zswap_entry_free() will uncharge them anyway. + * Otherwise zswap charging will become inconsistent. + */ + if (objcg) + obj_cgroup_charge_zswap(objcg, compressed_bytes); put_pool: zswap_pool_put(pool); put_objcg: