From patchwork Tue Jan 30 01:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13536674 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 0AF79C47DA9 for ; Tue, 30 Jan 2024 01:42:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 605296B00B0; Mon, 29 Jan 2024 20:42:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B5896B00B2; Mon, 29 Jan 2024 20:42:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42C1C6B00B3; Mon, 29 Jan 2024 20:42:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2FB926B00B0 for ; Mon, 29 Jan 2024 20:42:26 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 00CE514065B for ; Tue, 30 Jan 2024 01:42:26 +0000 (UTC) X-FDA: 81734277492.17.072DC42 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf28.hostedemail.com (Postfix) with ESMTP id 46597C0012 for ; Tue, 30 Jan 2024 01:42:24 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=VkirtGcu; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.48 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=1706578944; 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=mALgLaCiaIzpkji8oSjATmvxJWj+cS9YMUqWO4u+ZHc=; b=pZ+FnK1AvdgYTqGONxzaajdwAEaDRTjPE389NfEue2lp6xCxZdfvfFM/sJqrhFmJh9dCqf D6pfZR84qawHANFYhSK6ibv/d4iNGd5vRXTAnCEq9KUG877K0lcU5jdXh1P+KN8CDnnDy8 D/FfHa/LUtpnnQ+FTuol25HR0twLEV8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=VkirtGcu; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.48 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706578944; a=rsa-sha256; cv=none; b=ttL5N5ues+yNcDmIxycA14htZVbmxJpmcSBth92cm3iBasVN11Rc/SEfJLWP7kTHzuPlzR ipCN0NzGwbFuoYAQsX4anF0BqpMVI/K3050jxoixcsRrBrOOY0/U/Is6BEtOLjn5xTasJb Lmkf4jT6rdUThStyhLx45kGyX0XPBdo= Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6818aa08a33so25063496d6.0 for ; Mon, 29 Jan 2024 17:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1706578943; x=1707183743; 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=mALgLaCiaIzpkji8oSjATmvxJWj+cS9YMUqWO4u+ZHc=; b=VkirtGcuXNWJzb5ATQX8e/rufmJpvEaGfep0CwT6owOigDKgDrsxfMHLKcyOi/CMsK KgTLk0WS9NZ7FANxrAFDtr7qelLJEWklVSTVMozPuQpauS9RYpJlykcXPwB7SnamEgUE nz+hWf49ANkVzwd2a83rVSngfcDoSGqTyVPnKAZfB6NTgoGaUaQ0MV/2V1kpy2Q/1aYZ fr0wKIvZvwrphzZJfR7X3ZYV7qdkbKqi+PyMzjbkjo1gtH2RdOXnJbN3utZ3paZJdGQt NQigX8VzdIdaVch1uatoc6b5VCtcCjK4wIbhWvA9ZLOwb29XlRIseZSEflboYWm1xoaH tfPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706578943; x=1707183743; 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=mALgLaCiaIzpkji8oSjATmvxJWj+cS9YMUqWO4u+ZHc=; b=aRV8PCIquwok5riWYR6f8nOHw2wc+mnJIZvbZzlmMfg3wtxHvLBySRkMMNmPuWKl6y Ojm/a3hEND8fBoJQ0R/IxP+ZZkUfu8z8krYzjzL6MGef+0bYVhaEGIfre29Jmb3+lz+M xLjuewNhYpj9QqqVdNay1Yv9D9mlkI9Ux6E2v2l1m7r7WnDO2n7LJffYlGeCPpcPswoy XeI+WWMPG55AjzpfS2wfJfi4awDnM3pv/LatOHiuZqCz76sv1ElsqVd14+TcS8+i7y97 MjanuB4o9dRf7BMS78lCKH4EuMv6M6aKBtJGJBHElhE7PlrXF3EyiJCDiqClDVxSkO6E w7qQ== X-Gm-Message-State: AOJu0YxC44QIY4KlFlMmekpiMxlm2EdzQsR4rr22N6nPxgp5PetVDqyw J02nCb7xlv0zL2Eeur4vepTkU63qmE4GMayQ+Nkr7UIUnoOFQgTeAYOZeI9R3NQ= X-Google-Smtp-Source: AGHT+IGoErOj2bpl9IZ9knv+7JV64kZmN0sJ9QZ4US8bA45j2Rdf3yjU12SQ8udCU2m6baBLuq016A== X-Received: by 2002:ad4:5aa5:0:b0:68c:5c8a:dc7b with SMTP id u5-20020ad45aa5000000b0068c5c8adc7bmr396936qvg.13.1706578943526; Mon, 29 Jan 2024 17:42:23 -0800 (PST) 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 pc2-20020a056214488200b0068c4aefa96bsm1889828qvb.69.2024.01.29.17.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:42:23 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Nhat Pham , Yosry Ahmed , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/20] mm: zswap: further cleanup zswap_store() Date: Mon, 29 Jan 2024 20:36:44 -0500 Message-ID: <20240130014208.565554-9-hannes@cmpxchg.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130014208.565554-1-hannes@cmpxchg.org> References: <20240130014208.565554-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 46597C0012 X-Stat-Signature: np15b1qgiyjmj9iascwue8t4xnyjessx X-Rspam-User: X-HE-Tag: 1706578944-315449 X-HE-Meta: U2FsdGVkX1/FxgzrCwTFTBigA7WuTmMmuJ93N0OuKR20LJvuaSelKfhwphqT63giEDILA39oDRt4Ly6/olud5JFpCFl9EwrpPSMYXqqVsvatqLwATn3xnqeEzCaeL9V6n0jZm3LUz+6SI7f78AgfVSDy7WvzHemhLce0Qm0vrDfhdnlE0RtJoqAGRsiGk/bzxlKvLrWXJciz46FdWk4TL6P62O62vUmfnxwTWc9uXDt5/Eu467hWgd7cDXdnNTbZUdwiouLzF/aDMyixc3BoMnokagL21CTCE8f+ZlWyigVFW+mfI3ApKwnE2YHXiZhaeKGk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ity=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: - Remove dupentry, reusing entry works just fine. - Rename pool to shrink_pool, as this one actually is confusing. - Remove page, use folio_nid() and kmap_local_folio() directly. - Set entry->swpentry in a common path. - Move value and src to local scope of use. Signed-off-by: Johannes Weiner Reviewed-by: Chengming Zhou Acked-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/zswap.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index f9b9494156ba..cde309c539b3 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1542,14 +1542,11 @@ bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - struct page *page = &folio->page; struct zswap_tree *tree = swap_zswap_tree(swp); struct zswap_entry *entry, *dupentry; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; - struct zswap_pool *pool; - unsigned long value; - u8 *src; + struct zswap_pool *shrink_pool; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1567,10 +1564,10 @@ bool zswap_store(struct folio *folio) * the tree, and it might be written back overriding the new data. */ spin_lock(&tree->lock); - dupentry = zswap_rb_search(&tree->rbroot, offset); - if (dupentry) { + entry = zswap_rb_search(&tree->rbroot, offset); + if (entry) { + zswap_invalidate_entry(tree, entry); zswap_duplicate_entry++; - zswap_invalidate_entry(tree, dupentry); } spin_unlock(&tree->lock); objcg = get_obj_cgroup_from_folio(folio); @@ -1598,17 +1595,19 @@ bool zswap_store(struct folio *folio) } /* allocate entry */ - entry = zswap_entry_cache_alloc(GFP_KERNEL, page_to_nid(page)); + entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); if (!entry) { zswap_reject_kmemcache_fail++; goto reject; } if (zswap_same_filled_pages_enabled) { - src = kmap_local_page(page); + unsigned long value; + u8 *src; + + src = kmap_local_folio(folio, 0); if (zswap_is_page_same_filled(src, &value)) { kunmap_local(src); - entry->swpentry = swp; entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages); @@ -1637,9 +1636,8 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; - entry->swpentry = swp; - insert_entry: + entry->swpentry = swp; entry->objcg = objcg; if (objcg) { obj_cgroup_charge_zswap(objcg, entry->length); @@ -1684,9 +1682,9 @@ bool zswap_store(struct folio *folio) return false; shrink: - pool = zswap_pool_last_get(); - if (pool && !queue_work(shrink_wq, &pool->shrink_work)) - zswap_pool_put(pool); + shrink_pool = zswap_pool_last_get(); + if (shrink_pool && !queue_work(shrink_wq, &shrink_pool->shrink_work)) + zswap_pool_put(shrink_pool); goto reject; }