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: 193795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp947316dyb; Mon, 29 Jan 2024 18:00:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnJ9uwPVU/ERteHn/UEY/g0KzUdaj+Yf8uiefOwnjgwYWMH2qDT+Q8U9iYO5mPXxCcMnQV X-Received: by 2002:a05:622a:7189:b0:42a:a348:7cad with SMTP id jd9-20020a05622a718900b0042aa3487cadmr432463qtb.65.1706580005866; Mon, 29 Jan 2024 18:00:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706580005; cv=pass; d=google.com; s=arc-20160816; b=koj483aP5Z5mNnJh70M7zw70AaWFdLdg2nqU1hk121gnT/eIxOReZeRnFPDnbtuvh0 Pd4rK4rUFcqMDKxB7v/UESOzkneRrLes5eJf/fZGQ7u5VmZIyixnMSEaUhof89g+x9Hy ESQSa1TT9skWu9xODPbxXxtbiH4AAP5c1CeQj0Vm/z/5NfAS9AmK/hYlXLe4DtdPuSEM ivs2qEpw2WB8RtWIDfiqxH7AnNseWzlDDLjTxLGpfeS1tKkHq7nkqdkWvD38lrGQHEaw zwj/4xE0D6An2Dx5cT8j5BwqsAxCXQ82DgxZjcHlgF+8tMvPuWc2Yj8ZotrKXtGXoGoy DlHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mALgLaCiaIzpkji8oSjATmvxJWj+cS9YMUqWO4u+ZHc=; fh=pEdtrChUTDmvuLILGSavwskaPZjBcM3e1cB9O4e7o4U=; b=dxNOO9e5q5TnrfQ+JxKO6sZqGA8ROvv+PPBTEFQlOmZ1VYOiQJwZWEAmIlei3QYjfw 6I96/vqCHaHjy6ztXnlzLgfr9Z1U2cJkzn43NPBRCQ/V8ghttkpTKIi5d1tcqtWa7/6Y qIS/66PylcrxYGCQlGrhf9sqpm4KUjHLQ7nO/xZhrYkKWLRSejrjz5bgKiNTWDV+q1Ee xD2ZErE8C/NAloEi1CLfOUjQL83rbTRuSTfMx0hTXuhhos/nDFxTgeCz7SH0DKHB6Tld A3VYy2Li+OhwxlqngGTcdPjyH39AlodyAkKckKoGfuMpW56Li+guEfYFbBWCLR8/7l61 hT5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Lwj5HmQz; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-43747-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43747-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e17-20020ac85dd1000000b0042a1c4da40asi8639715qtx.301.2024.01.29.18.00.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 18:00:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43747-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=Lwj5HmQz; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-43747-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43747-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 912601C23D95 for ; Tue, 30 Jan 2024 01:44:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BC4F383AE; Tue, 30 Jan 2024 01:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="Lwj5HmQz" Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 937CF3770E for ; Tue, 30 Jan 2024 01:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706578946; cv=none; b=UVtxNSAnBqHTaMp6KU1GNNun0xmZj5KpQaP5H2tnYsAhojm4wA0yxhyMIKfpApNwONe/bdE3qWY3DNIYVFjp0t6puy71g4wgHbYTBY0yWo4pyvMTeDKt4id1PPDJZomz7/ThClgkESCHRIymRSn9t3sBNOW+UHWMXZQNt+Q8kpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706578946; c=relaxed/simple; bh=meDiOpiwOmc5O23emXHPLEn8CVIgwW9U83t0CK4mvi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HUwhXmceSLlUgojuS9UMpYyZkFJTC3GmZ+Z4rIJzurlVM28Q01Z7h6Zum6QLCNcdhxHv7UAgNWpLtOFDIanIBZwLJqOscQ/2gwrZEXah4INmPqWSTc7Llg+40R9utQ61yQbvCMmyY1ivrCWsQUM0ogUOeDxPp4q0HPUhC3CWpN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=Lwj5HmQz; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-680b1335af6so40905566d6.1 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=vger.kernel.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=Lwj5HmQzaNZV1GAT993BnYTbUhU3xPr8WSOTpH3j3s4SprsujIy1uT5omNbOtEsNz5 Gmb6u0AoqasnDz8CGBb60mDBicPeQeZ5mGcroAFhXNe6K6ayjekIDdoRbiP4+G1SFGhP jiGSH0oNl0bWtEuL3aXR59hjxSAOegTbqpv1HM91+sDZUMFiv5dN67kYoLdtlePb3kWc V+CWO7CJ5Mn7R0iHy36csu+O14L6wFB1D5AbHMlt8o+xVLhPaoiGyPZ6NFQjNlbLnL19 tk1tptLt/0cp+elRpyTjhMwONJuV1YldB3cJfcDjl/ZdhyVoq0fM8JMpsU6PHVZA3EsY Nebg== 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=HkV2a0dxKyRGGG5GrT47NlUWOfVAf6JsNsuRdCVueUNO5bBxgNOF47ktC62Wp+PRrJ u6wt4HSNo2Iw0l4t+1vAJN66NA6+zCvaUgticaBaNIEdWXhk3851hkLUHWJ/qOcx0LIl yFxyZ8TvZcXiPUoaWUOkih4NTokh4kML/orviL05/4dHtrseOJeNDDxanDHC/7wirxsd HI36AB9tDoMIpI7TxSUNMs+Ad2mFTgQRGYKqlKD3skFFD0g1ZEy9xhPZAoGYopoYdGdG 2uxbo2uyULCHrWa720Lfu9RftmVIYpl57Lc7o8ubOg4tLaklyPzaJXq3/0fldDVGTvdN V+dw== X-Gm-Message-State: AOJu0Yz94PsfzjfzRVdUDgMw0VYe7qG1zd2EvildiNUyxJooyZJKla86 5wpeGUUXMjixtPbtp3PU8TDFMMpdkIYsGEGxsXNWQADC06RrZRCiPrCdYmbcBfo= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789478835759880370 X-GMAIL-MSGID: 1789478835759880370 - 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; }