From patchwork Tue Jan 28 17:49:38 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: 13952319 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 DD5BBC0218D for ; Tue, 28 Jan 2025 08:50:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71C0A28020F; Tue, 28 Jan 2025 03:50:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB8E280209; Tue, 28 Jan 2025 03:50:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BAA728020F; Tue, 28 Jan 2025 03:50:29 -0500 (EST) 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 3DC47280209 for ; Tue, 28 Jan 2025 03:50:29 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B9495B0B20 for ; Tue, 28 Jan 2025 08:50:28 +0000 (UTC) X-FDA: 83056239336.18.B5B7499 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf01.hostedemail.com (Postfix) with ESMTP id EB01E40004 for ; Tue, 28 Jan 2025 08:50:26 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="kc57/yGX"; spf=pass (imf01.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.171 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=1738054227; 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=fe/jY1AIBq99Rc24VTdN61cmwo2SmNqIaaukdWS9bVs=; b=4WIA6V56M5vgNjUalxE4Zw1yqLSKryouLXse8/M4GC5tLs68w8xsAJzp9AD7X8KIT1klmN NpvrMLMhUtgNAyW802mqymmruV4NaUm4d3Eq3qIA1imX4EBpy606mPvGXICw5Rf8lDkrKD 9Wot1xy9dYArMJMkmcbrsksXIgzycd0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738054227; a=rsa-sha256; cv=none; b=iwPb2jvmfx16Q8HkSVE/xqVPEhqAw2TmG2hIK3hb/uoR2121VkOWjfRA7t7iyXZ7+4fl3v 6EoKvvORfW3ybRylZ8My7be/vHhs7i0UIf8LVskKmmZ4H65SjT/VBX2JOhx3xFdHMRvRHJ aHxfCmZQ3vUsyh+htT1BtpB8jgI9P1w= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="kc57/yGX"; spf=pass (imf01.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21680814d42so87589555ad.2 for ; Tue, 28 Jan 2025 00:50:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738054226; x=1738659026; 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=fe/jY1AIBq99Rc24VTdN61cmwo2SmNqIaaukdWS9bVs=; b=kc57/yGXXMY3ItI+mT4vD7F0umJmhkob0+4+8KXqIslQC91blf0bJJsq/e3YZopGp6 ZM4MlLB8hFeiPYc/rbpNGtA5JxED/5GI9V46JwEG1sIcp3MlMMwg7LERfojkMrs1RNRZ okquC952BfTGTHITJZTDZsmf5kPItNDtitCvqZdH4JLFcB98raxgZMERsCMOmRlN8ocJ zqhjFvvTsJL4SsBS+L5r6b9DuQyT3WdQ4dHHMetYWAtQZ12lAn4Q5XTotmVsPlDMV61D MPyG2FCdZczzR7HmNG6496KWcm1xdBicEbBLbSAEtt73ZCAxr+9FHMzcPztDbvEqpbkZ 6aOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738054226; x=1738659026; 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=fe/jY1AIBq99Rc24VTdN61cmwo2SmNqIaaukdWS9bVs=; b=szGQFPy8zrpXeEmNRM0suSLviB2495jFMi2jV9HyO6H9Z8U87xXAANRS8yBmCAhr3R 8s99qM6sJHt6VDS3OHuut2Z+4jQlIPdx0gc2AZ4XToW/F2yofxwb72xYBI3fUdwHcsRt Ifwiivi4L7WwTty1rnabszn16aVYPfjcpUPZTMeYUHZ6iZ+E8/gO+VqYfyvltN3LmBT5 AfcyW/Xd5R1UQ4pHYTYDKwDcDGXA0vfmf4JeeQ/RYOSjUJaliBedcq/bFuSTj8KchYZk ZdPwST3ht7ybkfZiiU+Nq5aH57PrFYB61UQUWGbbwQaJMCOrDKprSbKqtsegDj3f3fhJ +7Hg== X-Gm-Message-State: AOJu0YxITGV0VRJ9To9U88BtR0hYc78aEA3LtT2XYCX4XkdZ/bQ3x2VR +siZjawnD1nZUdZxSIMJmpX6UgiVAA1uZQbgVSj45tJs/JF1gdgc X-Gm-Gg: ASbGncuMh7M3aKHzMGajlcl1RFkeM9rcbEUJa+CQ9nXVadpdcn1yGi+XTDzOtzpo7R/ X9V+n8eAK7/xXlor84Wy/bS5C7MQwqTRwS6utNuCpTPjOcDPQWtxFgLUQ0itImAU01tVHZ9bjb4 kBDre86X+yFX+2WR7AN9RBqy42fyxcNvMBjYaBlj9BdCAPOX62m/sLR7HqhMKuu0l0w6cdIjP2D 4JHXcVMr4kJ2vPC9oo/WcdH08s+tYyxHaHzDKALiWdBkF5Jrfq03/p3reDBhqSB/zxZ3FBsEp8h 000qS/NCIwpR7rZSRJXIg4YXA+6vtjKh4FM= X-Google-Smtp-Source: AGHT+IFZH2gS9hh/6mdITfgOnKqyTWBhhHC56tkrEmCloyR4KXqQAkvIyl7s7vDagrRTmTe/Y46X2A== X-Received: by 2002:aa7:9317:0:b0:725:e37d:cd35 with SMTP id d2e1a72fcca58-72dafa7c471mr68080721b3a.18.1738054225494; Tue, 28 Jan 2025 00:50:25 -0800 (PST) Received: from hyeyoo-laptop.localdomain ([221.160.193.110]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a6a07ccsm8538343b3a.28.2025.01.28.00.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 00:50:24 -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 v6.12 hotfix] mm/zswap: fix inconsistent charging when zswap_store_page() fails Date: Wed, 29 Jan 2025 02:49:38 +0900 Message-ID: <20250128174938.2638-1-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Stat-Signature: 3fpzppdpun65n1tu6nxgm9f1kyn3gzy5 X-Rspam-User: X-Rspamd-Queue-Id: EB01E40004 X-Rspamd-Server: rspam03 X-HE-Tag: 1738054226-914575 X-HE-Meta: U2FsdGVkX1+OkLKbYiWZ28zP+0StVMzmWqE31ktV9e6kUzgKbFwRjEefez2SUwmqG2GmBE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ctOJ0ipsp46tDfKPivQ1E4++LNJNu2pGtxIl2IXgDeG1/5niLs6s6HKdjj7gjs6ZOs78lqpCCWbG6eGigQn9T4zvJUrvQkQsowBx6UZZwVwuHxuc3Kqka70AL4PC+Cp6gjZwtdtoUYt6Hl/pAUHUBZ1GR3+DG4Wcbq6PVa3RK00HKuIMHikY73VpoGnjTsfNZCSUUcZQZPZeR3heCApSQWrx57EvjHlHBos0EupLaYIQwu1kKq0Alvl44/183iDFhMcbwfEuQGVTzy3eF0xrPn8/qqvcxIDPbHivkLufUO+7ATVrw5fr04s/0hy+bMDVTly90AkUFaITtWkZ+X/Nerfdgi8tXX0DHen6ageZqDz6Rg2jH7NahcXqsRNoreY3cp2GnKX1pboG9Ue9Bmt69HcBzkr5iUV30HZ3OIiU= 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()") mistakenly skipped charging any zswapped pages when a single call to zswap_store_page() failed, even if some pages in the folio are successfully stored in zswap. Making things worse, these not-charged pages are uncharged in zswap_entry_free(), making zswap charging inconsistent. This inconsistency triggers two warnings when following these 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)) Charge zswapped pages even if some pages of the folio are not zswapped. 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> --- mm/zswap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6504174fbc6a..92752cd05c75 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1568,20 +1568,20 @@ 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); - 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: + if (objcg) { + obj_cgroup_charge_zswap(objcg, compressed_bytes); + count_objcg_events(objcg, ZSWPOUT, nr_pages); + } put_pool: zswap_pool_put(pool); put_objcg: