From patchwork Fri Jan 31 08:20:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Harry (Hyeonggon) Yoo" <42.hyeyoo@gmail.com> X-Patchwork-Id: 13955115 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 69E68C0218D for ; Fri, 31 Jan 2025 08:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B96296B0100; Fri, 31 Jan 2025 03:21:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B45D26B0101; Fri, 31 Jan 2025 03:21:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0CF06B0103; Fri, 31 Jan 2025 03:21:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 81A456B0100 for ; Fri, 31 Jan 2025 03:21:28 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 99983C0986 for ; Fri, 31 Jan 2025 08:21:17 +0000 (UTC) X-FDA: 83067052194.10.EC517A3 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf28.hostedemail.com (Postfix) with ESMTP id BF65CC0003 for ; Fri, 31 Jan 2025 08:21:15 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=klivkdiu; spf=pass (imf28.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.47 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=1738311675; 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:in-reply-to:references:references:dkim-signature; bh=nCL0wtmRWRPZZpWzeuDA+ELPUzoFfTk+lS58nQgiEzw=; b=isrs1xiTrWV6k547WntoYTc2hC0cv75Zi0D5QDOWupLKuDnC4vYhrB0sc5vlygWMNWAKmP LO0d1ITn0pTuObwiEMjBzIq58bz0fCFSsDrWJo9ntAhAxAl390ICG6FfOv8ypUHUOBUAPV J7+2U+u8BT8zV7DvlcQ6W6ttBmVuBm4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=klivkdiu; spf=pass (imf28.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738311675; a=rsa-sha256; cv=none; b=hlzQv0QLq/DGTP5FHScAxnDNnlpCQ1B0hHKgVw5+VTMdUEcubT/IgWdc1cGi0ojZtEiLzw DSrsunZlKHe/K9tTAdPcsdslIieo05RsMdhHtn44iL4RfsLBj68rOFuoM7pDl4yRRyTIi+ p2e21uU6a4Fm7qgpjD5fjF6MBiNCiiE= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ee74291415so2242551a91.3 for ; Fri, 31 Jan 2025 00:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738311674; x=1738916474; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nCL0wtmRWRPZZpWzeuDA+ELPUzoFfTk+lS58nQgiEzw=; b=klivkdiua/xDTIqBflk3Ewu5wvfnjIWetI/0aI+z6S7eEsdR3Eat7oDSLYBvcP8LwJ O8sZPfyuTphXa82fJYUrtoNRfA+Jj/EGFafbA90TIiGrWOBO96t3J1CgGHxoQdirB0G2 9UJGjenZJ8QhTgwP0KVhN3+pmUa33zB10rqWg2IJbMBlxgbF8KLwbGvsJQ9BAw4ZdDbT i20x3A0Zf4xNUWBcWbQmhfFzeprhPfxrgHXW5ICnnFCqYlhIGS+0zUP7goAWd7/I+iVn CRew3Ll/2KkBCij0J9LmyEVbpGIrpH/L1riD4AlWn2sOQsIaz/etks53dkUW5k4bXPWX TaYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738311674; x=1738916474; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nCL0wtmRWRPZZpWzeuDA+ELPUzoFfTk+lS58nQgiEzw=; b=V/UF0BsEwd7KZky3X+8c2jhu1oxUabCyx0VDIAYN70XyMPLWwlYdiFnLzv49ah/ew6 JJJAayTcjoB0NQ7STRa75BooQjsseihLQypmqwHy8kwPVZDAW+6BPLGFTGwy4p2qM/vM bei8jsKSzY96vyKNe4+ADGmRfWT+DlALDpPy0xhepyE2Bysqsz7R8vriyRDN58RCqAnC 75PvdsYTtgDdLkz8Nul/AghLOldmGlCYyYEGFGRqi/uc9zlSEp2enrL25kxDSm+4e3tn HRMuni8nLKBkQm4RYKS4griQ1tkN/Nu7DfNX2Uod+G4iVyJkB9BGXIJhZ3mDl78AyHzO droA== X-Gm-Message-State: AOJu0YyYemAFdW7xMe4WUOT0kwXX23GPI0iejaOZ1i3pg/wto4SFrysl 21AcojRHsRSaEIOKPAhLytO1ow8PVD4QFkwem38UioI8oFr+6xZB X-Gm-Gg: ASbGncvrQaNV2M7jdGLSWHRDODjBlf81vZLl4TvG5xlMRT4pHOCYMz58Rh7c0F86LO0 ZxMq7qLMzjkaL7jjmJe1qQr+SAPdUBBjUwCjFrL40ydxulLuOSx6m64jWmy+J9kKdjfklLvaaFE qR2dQ3og88TZqLdLod65ocfBhNsX5/+ZmDIHtc0k0suogzOHJUvmIwUV8t2QGhw6Kv1b/yakVoZ 7DXWM0s0Bz8/ZdZNTVsfCRKXC7R9IVyDjkI2TevWN10fTdNC0jwpvNoBx0qFlOUXW7JnxFQOJea kl/RiNi4FRxaK8CK1XIIp3sjrgwEVHGe99o= X-Google-Smtp-Source: AGHT+IEdB4zmzJNGbI417JYJG8V56wVsHtoanBd22Z+40bjk70NNNWJeg7ZdHUPc8nCwABuPHcTfhA== X-Received: by 2002:a17:90b:254d:b0:2f7:7680:51a6 with SMTP id 98e67ed59e1d1-2f83abab7f0mr14269589a91.6.1738311674218; Fri, 31 Jan 2025 00:21:14 -0800 (PST) Received: from hyeyoo-laptop.localdomain ([2001:2d8:701c:c995:fada:39c5:7b5d:2c15]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f83bfc0ddbsm5296283a91.45.2025.01.31.00.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2025 00:21:13 -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>, Yosry Ahmed Subject: [PATCH mm-hotfixes] mm/zswap: refactor zswap_store_page() Date: Fri, 31 Jan 2025 17:20:37 +0900 Message-ID: <20250131082037.2426-1-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: 20250129100844.2935-1-42.hyeyoo@gmail.com References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BF65CC0003 X-Stat-Signature: j1mcmxzijs7n338moh8hf56etpdtduaj X-Rspam-User: X-HE-Tag: 1738311675-754731 X-HE-Me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VQBBt6Sy55jAl4TsMefuI3mGFxyz7hQAni3xQPZCN0owy/mhrQxSXmofbaANim1HR4FOje2uNI++iD+C5rLjSzIilou2KOw6LfBiWRJ1B6xJ5SgsQByUIKSLnxzDItU5eU+xfLjHAdfjCtpKcLdzMqBsbTEjWiujozcCARreKlLot26i5Dj2YYJa8jfFaO9kuBpWb4jfNMRwQuupjskKPDDOcPQCN+uMHQa73vSI2ZFt5UOJyJjxvNmewrrMvR7zyKzO1w6K/eLgxikdM8ZPivAm0v1L0G3AltEpVRIyGlRKAymm8BseSVPdQUtGS5vySfYJn/HlZF55WnRZgDcNDUEhs6oG7UDqLw51uSi4RPQJ7LPaiqvrBAVJNczeTvOEe4JiF7WisnSA6zyzX5JhlLYbii+xA17phnOYny/DXsn1k+gRwK0V2zEbSKSvPoo4mfA== 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: Change zswap_store_page() to return a boolean value, where true indicates the page is successfully stored in zswap, and false otherwise. Since zswap_store_page() no longer returns the size of the entry, remove 'bytes' variable from zswap_store(), and jump to the put_pool label when it fails. Move the objcg charging and the incrementing of zswap_store_pages just after the tree store is successful. At that point, there's no chance of failure, and the freeing path will certainly uncharge zswap memory and decrement the counter. Suggested-by: Yosry Ahmed Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zswap.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index f0bd962bffd5..ac9d299e7d0c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1445,9 +1445,9 @@ static void shrink_worker(struct work_struct *w) * main API **********************************/ -static ssize_t zswap_store_page(struct page *page, - struct obj_cgroup *objcg, - struct zswap_pool *pool) +static bool zswap_store_page(struct page *page, + struct obj_cgroup *objcg, + struct zswap_pool *pool) { swp_entry_t page_swpentry = page_swap_entry(page); struct zswap_entry *entry, *old; @@ -1456,7 +1456,7 @@ static ssize_t zswap_store_page(struct page *page, entry = zswap_entry_cache_alloc(GFP_KERNEL, page_to_nid(page)); if (!entry) { zswap_reject_kmemcache_fail++; - return -EINVAL; + return false; } if (!zswap_compress(page, entry, pool)) @@ -1483,13 +1483,17 @@ static ssize_t zswap_store_page(struct page *page, /* * The entry is successfully compressed and stored in the tree, there is - * no further possibility of failure. Grab refs to the pool and objcg. - * These refs will be dropped by zswap_entry_free() when the entry is - * removed from the tree. + * no further possibility of failure. Grab refs to the pool and objcg, + * charge zswap memory, and increment zswap_stored_pages. + * The opposite actions will be performed by zswap_entry_free() + * when the entry is removed from the tree. */ zswap_pool_get(pool); - if (objcg) + if (objcg) { obj_cgroup_get(objcg); + obj_cgroup_charge_zswap(objcg, entry->length); + } + atomic_long_inc(&zswap_stored_pages); /* * We finish initializing the entry while it's already in xarray. @@ -1504,22 +1508,19 @@ static ssize_t zswap_store_page(struct page *page, entry->pool = pool; entry->swpentry = page_swpentry; entry->objcg = objcg; - if (objcg) - obj_cgroup_charge_zswap(objcg, entry->length); entry->referenced = true; if (entry->length) { INIT_LIST_HEAD(&entry->lru); zswap_lru_add(&zswap_list_lru, entry); } - atomic_long_inc(&zswap_stored_pages); - return entry->length; + return true; store_failed: zpool_free(pool->zpool, entry->handle); compress_failed: zswap_entry_cache_free(entry); - return -EINVAL; + return false; } bool zswap_store(struct folio *folio) @@ -1566,10 +1567,8 @@ bool zswap_store(struct folio *folio) for (index = 0; index < nr_pages; ++index) { struct page *page = folio_page(folio, index); - ssize_t bytes; - bytes = zswap_store_page(page, objcg, pool); - if (bytes < 0) + if (!zswap_store_page(page, objcg, pool)) goto put_pool; }