From patchwork Wed Dec 13 04:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13490331 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 2366FC4167B for ; Wed, 13 Dec 2023 04:18:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B798A6B043D; Tue, 12 Dec 2023 23:18:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B2A3F6B043F; Tue, 12 Dec 2023 23:18:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A18CE6B0440; Tue, 12 Dec 2023 23:18:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 91D466B043D for ; Tue, 12 Dec 2023 23:18:26 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5168CC0ACD for ; Wed, 13 Dec 2023 04:18:26 +0000 (UTC) X-FDA: 81560488212.12.1389EF2 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf22.hostedemail.com (Postfix) with ESMTP id 53D27C000A for ; Wed, 13 Dec 2023 04:18:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702441104; a=rsa-sha256; cv=none; b=IJrxh6LYMvtcgVesyh886TVmDKVn4gLLeU4mFPrIpK2VLSZBEliT5KHpkErzgroo7dtxEj 5/nrGa//ewQcGSYQsL0VfZRWsUMlcOtYjDrWuqOQHiETmnulMFwIvBd/0VgrCE5/4BOUjA zpzV8Nv+vvxqUP2jIoFAguzV/c9Ru5U= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf22.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702441104; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5EA/+QLKKJRAwRxL5HzdYaYuPEdViyrUrcmPc+WPWw=; b=Y5Sc9twZk+/85QMqF225S+XZSCCFCSO6NGM6P4GhKbp4DmXhXag9IMFjxLdw2KFgng56W3 /ffS2+RD2Rg+1GcTF2n3De/uOvKCd6JqeU7hB0XRr5HV6T/zX0cYKw/s9UqqXUAS75/lNu rUolkgQVPWBMADp0U9RVY5rqKYklJhI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 13 Dec 2023 04:17:58 +0000 Subject: [PATCH 1/5] mm/zswap: reuse dstmem when decompress MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v1-1-896763369d04@bytedance.com> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> To: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , Yosry Ahmed Cc: Nhat Pham , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1702441093; l=2420; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=4hmeraw6zxa25WbpK1ECDI7EvpvobxeRhEkruBDznLg=; b=mbsWJQiE+cXMa66hJjNiMeb6vb0c2Wd9Q8gByBTeYUg30xknG8Mp4sD3keTJZ+y7+jzNC8l+X ujPVN2QVCJ9BZB6v/vneplbZq2p6q14W2exDJ4xuhzyTJtIF+0z++Bz X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 53D27C000A X-Stat-Signature: ec59gndgpnucwyr4hk41uxh8pa561b58 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspam: Yes X-HE-Tag: 1702441104-723952 X-HE-Meta: U2FsdGVkX18h1RNpprfwwNnMIjs5rzE6j0ZyQuZYdOU3FwjoS/KUQ/Izss+XZmxFqTheMtawuy2i59MF2OgWeLvyuCA1RSfFUZYC25xXqY0vGLCpMFKrZPwZ0EIJp4wtPysSACbgYYac7g4ZntfgmP+hJXGPzVFmrR4O+JF6Snwudws+L3imqWwygWEV7zRsFxJdzb9gqENloyUQhde4aWYsoq7XzSjl0U1P2Uf141AMfiyrQsEkak0lbV5nU+QLsM0yW8wIa646MTOElfr03/5B34BddeK0ig/dXY5fZNe6yeb7xJej5xpOZa85QGjMEsg2l1oKtuAC4sW8k+oyBVtx3wHYwkstn+L1933AIbtw/XYSAwB9ZodxVTkebGbfc/BSTTL0ziizhEwTjSbBWmqdrGtyqy3ElRDN7MCng4LvhfNakhcMjmytaJki1xF49NH2L1YgKzBN7W9WRGy9MFXrQ2bZV8MtGEHiiHz0lSumvOKfO4CwEe6Flxw/bAlNnPTMv4CRR4EFuH9jCMb4HuxDuyjqn5Ky/HhoUf9HLwetjU4bycGCra4bcFKiecsWe6lwE29+XczY2XpQt0daWv4+Zmb2QOLaZ+qKj7M2TwaoB3FX5mVpAad/BsisFjEVI8eT0XRGDm6enVzPd8Qeb7Kd5CMInikVhiUEtsHKRBz7CUzkCKTE84R1G4HgoYJPWWqFbFxfoiy5Pa7YCbdQXXOqTB6SGzyLS/m+x/rHOoBoF1L6bDn4sYCKEYTqIGi1SMWlOI2xDR+5uuiCWlrghvUtekb30dGWCLWv5eRrkMqvHiSlX2e6E3odJzYcZP/Ip2EL3T+yZOIY3wfPMIf1nody8zsHQkQODtJi93/rK8NE/KUfkogWB+dLhJLZ6t4pqcDQS+BcQaI+YkXOoUjjHHbxftKFNObcujHwUj8+mTOfmFwQ2B+anJkhMaE2Ak8E8zntztsvpmU5wd+hf4g d7LQdlYq M48gRn78trMIinEVilgWBjgRJzh3qPeI0n6zfSHcwD1na3aXF+SnhSjhUWqXIiaxOksBVG6bU+jTaYHkmuwrRW/P35xq41KG78h5ysR6zJIGm2RNxsCBRTzCGN2zUdN45E0iy9bDz4Shi6xIDJ9jcfx3bj9ElaTc2G9H+ht+cZa3D8M+pumYRASwrfE0a+3nw4BnVTFDSbre0WR0hNYemUVQqB65sAguGX/giNH/quZMny6GYUz/zoVYMjra//t4wHxEakGbSbIf9qWqGsi9yRXWR9NeXSJDzvas7D4GcZ5SAZE6+KtpfEqth9iXOg3KSnl+xE/YKHZtrgfVFgPT38fPpw8SyEJLHwS2J 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: In the !zpool_can_sleep_mapped() case such as zsmalloc, we need to first copy the entry->handle memory to a temporary memory, which is allocated using kmalloc. Obviously we can reuse the per-compressor dstmem to avoid allocating every time, since it's percpu-compressor and protected in mutex. Signed-off-by: Chengming Zhou Reviewed-by: Nhat Pham Acked-by: Chris Li --- mm/zswap.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 7ee54a3d8281..edb8b45ed5a1 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1772,9 +1772,9 @@ bool zswap_load(struct folio *folio) struct zswap_entry *entry; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; - u8 *src, *dst, *tmp; + unsigned int dlen = PAGE_SIZE; + u8 *src, *dst; struct zpool *zpool; - unsigned int dlen; bool ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1796,27 +1796,18 @@ bool zswap_load(struct folio *folio) goto stats; } - zpool = zswap_find_zpool(entry); - if (!zpool_can_sleep_mapped(zpool)) { - tmp = kmalloc(entry->length, GFP_KERNEL); - if (!tmp) { - ret = false; - goto freeentry; - } - } - /* decompress */ - dlen = PAGE_SIZE; - src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); + acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); + mutex_lock(acomp_ctx->mutex); + zpool = zswap_find_zpool(entry); + src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); if (!zpool_can_sleep_mapped(zpool)) { - memcpy(tmp, src, entry->length); - src = tmp; + memcpy(acomp_ctx->dstmem, src, entry->length); + src = acomp_ctx->dstmem; zpool_unmap_handle(zpool, entry->handle); } - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - mutex_lock(acomp_ctx->mutex); sg_init_one(&input, src, entry->length); sg_init_table(&output, 1); sg_set_page(&output, page, PAGE_SIZE, 0); @@ -1827,15 +1818,13 @@ bool zswap_load(struct folio *folio) if (zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); - else - kfree(tmp); ret = true; stats: count_vm_event(ZSWPIN); if (entry->objcg) count_objcg_event(entry->objcg, ZSWPIN); -freeentry: + spin_lock(&tree->lock); if (ret && zswap_exclusive_loads_enabled) { zswap_invalidate_entry(tree, entry); From patchwork Wed Dec 13 04:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13490332 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 39C06C4332F for ; Wed, 13 Dec 2023 04:18:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C15E66B0442; Tue, 12 Dec 2023 23:18:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC6106B0445; Tue, 12 Dec 2023 23:18:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A90256B0446; Tue, 12 Dec 2023 23:18:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9AC236B0442 for ; Tue, 12 Dec 2023 23:18:30 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 691A0140B68 for ; Wed, 13 Dec 2023 04:18:30 +0000 (UTC) X-FDA: 81560488380.22.B44FB44 Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) by imf29.hostedemail.com (Postfix) with ESMTP id 8A013120013 for ; Wed, 13 Dec 2023 04:18:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf29.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702441108; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ISzr+oekeSfzbnuB/pdKP7H6OO3hIZGytqj6U6LgedM=; b=Cr5Ifo9IvwH4uXvYgBcWifkH11UqZGW3WKUwBP8I7OimP/KWnCNop7xgUw3MablKEDyLWI xNCH+l5yuub2HTHtou6UDSLVLPTO4lG3XUY6OK4XDgN2+rD16Uuxle2L6J536MEXy09BpW pMS4otaIPB96HenGQKjn0qdNRmf28jk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf29.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702441108; a=rsa-sha256; cv=none; b=6dB+25omV3kw61qywYzJ5ssf/B5136EwgJ0oztfTLoV2IXslIHsq+IMqJ6IiwQlasytcEv +k5Hn5KCMG9IdqvqCipdDGusd2HJKDSPUidVZvJVrI8O7lX0Ic8jRhF2ZcUQ8m5zWCSY9P BsVQa+Z2Y26bPges8/42F4sv1sAqQlQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 13 Dec 2023 04:17:59 +0000 Subject: [PATCH 2/5] mm/zswap: change dstmem size to one page MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v1-2-896763369d04@bytedance.com> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> To: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , Yosry Ahmed Cc: Nhat Pham , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1702441093; l=1331; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=SLwC/l/d7alrAZPMCA93CoRFuL9N61Dk4roVdlkjgAA=; b=FqWQBihVstOvjrBfPRgfiP9wgadr1XURWEFeQL4WfiDUcr3D21m8m/22XnhX+6BfBtu8xruQ4 Mq4yNgcfV1aAyr2EQ0oZOFiKr5LalUHvp2MuUSb5WHaHk5Paq/AcXW5 X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Queue-Id: 8A013120013 X-Rspamd-Server: rspam05 X-Stat-Signature: 6at1bd1ujir9xttcmt4jyzy4dyi3gqtz X-Rspam: Yes X-HE-Tag: 1702441108-606478 X-HE-Meta: U2FsdGVkX1/GElEOeAn9SsSQd/0sEj8LyuPhC44Cim0jW6Tc6v/jeQWUYoOx2sfP3OXAHxiQUHnW38th8xUnX752bKmQlf8auos+zS5FWiGqOrgl27j+gy0d3dwO0FHIJ2w4t+sZpBTjLcMZwl+nAcmUMZmid0h+sVGbfX9BpavbAaSU4B+1Uyzi3sdTwUXbLCoIS18uCtLlzwT13u9p+/0liY8DWrm3keDDtIwk8n6ED5mAIlD7wlolwBchO8x0Xf19V2JWlfkj/auhJKdIhldelbZI9Q1MSjvyHYlWlEvN0L14oHPR9wA/IDzFKJuzCtIzQcqyfC10H4b56sTUZnjoR6lNX6V4KgVSWPtF9mt9ZIZoM5CoZwR0MnvDyxcz2INvZ4cd4FvAhT0Z7lTjR6FhM13vwdzLce+DaHlKK/rVy99sGcRwS0en8dd21yJSRHVmV1piYnEe3JXqQFDVKHUxFsoOnMMo+LmWeJi5OFSYZT3xP1d1Lq6UQxO9TcpxuR7fNPt9QUGOAiMu0wjK0FXwapI7xkhiEIWkuc719Oe7u6Ws5SWrdfauWJ85/eXzmYX07Bbcp4QhmqlIDY7ko4vd6qz+XZrZ+QggzT+nud1uxvrB3uI2qkeFLm0g/63TDGXtUXEpIV2SVCmOvcgtA6BokKV0svCqaSOoOgWqAme0QcQaQ+YWHTsABKTURaAVHvgNdPRFtE2Al/jYmKrX9uz8Se+kdTxk7Fb3Q/7RZ8M1CQzkypS9HiWuBdFikBbQNWBB4xn7MNwUHwYiqEeAUTIpCJVSofqno/nCJgjLqjXestrZxFtqo3R+ry5+rhL72w/GGdgVqiYviFbp0Q82VAa+Z/s5n4qBnm+h8Of8xLBzGxX4dSlGWAheA20apX+aa3AaEXPlJ5S8ajHEtGyhTzR1f14iw3ugxdTCIRsK4IzoehiwHdW7kY1/81rTbYzhU3WW2Of+cQsuCKNTAIb AkRfRMlI vSREG57NEODLqYJW3+urqnH3e9+HpxTIKXxuCJnZwzuBnjAtF4JkfY87sVxuLR3LYgw0W4FrYa5imKQPXJOs7/SnB+LQvq6J/AVaG/C5K8MhMXAm89gEGHf04OSc8oVfGagnDrnrXKAfuLQACidnQMUSSydVLNPXOYzMHF6fK87ogQAABrhXSTOr61SslGkyS2UvPPgLlcId/K8pqT3jWpOpe23UAHNFZ+Lhaqxk/VtqBpa87bj1SdXD7dPGrLTG0pz3M7QLGYhyuiUm3ZQonh6jW4pXkvdF835Cgh2k0MxdwtR7PxVpu0zKRnHJkHEgTS/A824s9qMkhYEU= 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 the dstmem size from 2 * PAGE_SIZE to only one page since we only need at most one page when compress, and the "dlen" is also PAGE_SIZE in acomp_request_set_params(). If the output size > PAGE_SIZE we don't wanna store the output in zswap anyway. So change it to one page, and delete the stale comment. Signed-off-by: Chengming Zhou Reviewed-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/zswap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index edb8b45ed5a1..fa186945010d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -707,7 +707,7 @@ static int zswap_dstmem_prepare(unsigned int cpu) struct mutex *mutex; u8 *dst; - dst = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu)); + dst = kmalloc_node(PAGE_SIZE, GFP_KERNEL, cpu_to_node(cpu)); if (!dst) return -ENOMEM; @@ -1662,8 +1662,7 @@ bool zswap_store(struct folio *folio) sg_init_table(&input, 1); sg_set_page(&input, page, PAGE_SIZE, 0); - /* zswap_dstmem is of size (PAGE_SIZE * 2). Reflect same in sg_list */ - sg_init_one(&output, dst, PAGE_SIZE * 2); + sg_init_one(&output, dst, PAGE_SIZE); acomp_request_set_params(acomp_ctx->req, &input, &output, PAGE_SIZE, dlen); /* * it maybe looks a little bit silly that we send an asynchronous request, From patchwork Wed Dec 13 04:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13490333 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 3FF4EC4332F for ; Wed, 13 Dec 2023 04:18:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38D368D0014; Tue, 12 Dec 2023 23:18:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 13FDE8D0009; Tue, 12 Dec 2023 23:18:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D74688D0014; Tue, 12 Dec 2023 23:18:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B408E8D0009 for ; Tue, 12 Dec 2023 23:18:35 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 89DAA1A0ACC for ; Wed, 13 Dec 2023 04:18:35 +0000 (UTC) X-FDA: 81560488590.27.076E675 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf11.hostedemail.com (Postfix) with ESMTP id 9009940003 for ; Wed, 13 Dec 2023 04:18:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf11.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702441113; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eWTcvUoAbhOuj/P4MajoZT7YM/4SfCwmWZFBpVxrlRw=; b=w/uOBLkTg/wkGAgmUE0TePIpxzVRfzBTSQ2j4ahGCsCBTSJotZh69MSwigJMuBiJhiRGPH 1k0rGdoQyMNUBY0U/u5Z3LewVSKRMNyuqQyY/IR9vZLODXcB9bQbAEEGJMSILqDhDEg0Lh +O2H5tq9g/02brcR3iGvCE9MZQSXhms= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf11.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702441113; a=rsa-sha256; cv=none; b=dsJShULm03X13OmFlzksdY/HTRPTd6Y5RHUWPknC/SkJ43n6reMU4THFZyOd5JTq8QS/Q1 MRRQx/WHw7u3ODly64urL6lGP07K/sb2OmaG7oJsTxbTJ8FuC09J4OrwjBFfRFsgyYhw1v WfBJsPzy+d2eHixo9d0ZuO/2wcV1VPM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 13 Dec 2023 04:18:00 +0000 Subject: [PATCH 3/5] mm/zswap: refactor out __zswap_load() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v1-3-896763369d04@bytedance.com> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> To: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , Yosry Ahmed Cc: Nhat Pham , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1702441093; l=5311; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=LVsWNjlGxO7eWZ2spAo/8MIeJF4v6Hli6085n3PpW7s=; b=ijQ9/feCc3OfwRSCbwZHiaWMvVlGwOYR72XX1nEbxryfbyqXRUY9fmMy48+fedmJ3WU1+lzPx h1PB4sHPNCpCvJRMoxnF1fNULuTW9QjfqI+tpyflPewkKZ77sQTkEtj X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9009940003 X-Stat-Signature: 7ywwccqxjrig5whyj56wd4itddp3abjp X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspam: Yes X-HE-Tag: 1702441113-864698 X-HE-Meta: U2FsdGVkX1+FXzs3NDha7DGPhoIE+/djIETsrCGfUyGAWZmWrnE5dNMYsGBwxEGxYva0HE9jLZkIs8pLFnFcAZMygfEIjeVnh13fv1CoQF+7sGT9r1W2OwsgMmugl60PYQ+NjP+co+Is8A7RYvIcWGZvGPgA01g/sblNyXEr1lpEImOHqjfHC+uDDSwV9qRp9/ibnh6Fi/ELsAuyvOXegkKKweyL/7PzJsJaoWeH1074vTjL+gQiyCeFKhlUXokis9k7UbYUuN8YjP6n58E8P49WL2jHiapOuuUMDydcDAmFl1G9qaoJAtWX+ii2HPlTg9FCfoBDbC90oLTCQjNY0QsFe5uYnw9m23BJbDMNdXuq03sKcX4QJT5A2YylJmOhhTaKKpX3KdauTk5rviaOvvFzaqVlWOFh5Ut/i3Ll1MvSWouYVmqQDpIMjgMjw8r1gNbDuPQLFEsK982g4l0QKAdwIpZf9JOrBYiB2QLwIH0m1BCO4ZxbhI/xz7TR4BHRYAH4vR/lncWKNW9Fv4SxdzhBBXju3oI+q5FCNg9vYTndXn41n2vu1oKFyjhSvVj7/cC/W345MgDRICKYMT2zpm3U0ndXVzthG1fImz1v5EICOoTmQpsbjx/g3BiAdJycihTUKruc+5llsPDar5I66PW1mDFWJ+NEydtkY+YS2oZU4NVI2umRbOWIVXXwiHYieTsO8uWuESb5GVexmWkWCtz+AZKr2+J9i5nIGeCA6pbzavg4z5EdPD1mVjYPZNfnk3I+NspRv2cur9QpDWqQz8nmbsto0XA8zQTOdGQvi6D+KQc+rYMeys+MLvg1WT34YQRxQd4MajrPV+bFjNB52Db6OwaT3NPnDNxALsbm+0jXUOS8OExarcuDaMq9BHD9FVpYHAtqrtleo0S6lnwZA6hd/m4aQdOc5ulW8iVwcsYUT8NQzgCE2YdCsEXvRvfEt8zq1Tb/UFz8jNGZxN2 ALoPxmKi gNA+ds5wUJreNbqaYkVhPRIO6lQSPXgtlGqAZwf1p7PyPt9e4VZuBZokq1K45D7nDk8sxk/hceG2NPf/QCdZylegJeSXy+SuNNB5hTn6bi3UKPf+nl0qW7rqUQqB9NcE/vZumYkG5mJzzxPv8GLi+ly3Xbio2LnOF3sUxkDhytpcvRwwmrG5X2v/xBe1bSZN2gUgwfTAeKa9TPJDb24vkPQTmuCFQFFc2DXBSqVryD4LsHuM9XLRIQ5GdjD8TFwRQXzNFi4nfAlmi0TyLOruDIVRzpkMitR3E3Z/zcHwZo8oRaA0kAHumryQ0ihPMEi9nHJP4fHPA0eRvssvRKf9F7cYwmUsvOrIX5SwVFOfYMZsUxUF+Ah7abrsfr0eJ/lFdSmthS3axDmobJxA= 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: The zswap_load() and zswap_writeback_entry() have the same part that decompress the data from zswap_entry to page, so refactor out the common part as __zswap_load(entry, page). Signed-off-by: Chengming Zhou Reviewed-by: Nhat Pham Reviewed-by: Yosry Ahmed --- mm/zswap.c | 107 ++++++++++++++++++++++--------------------------------------- 1 file changed, 38 insertions(+), 69 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index fa186945010d..2f095c919a5c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1392,6 +1392,41 @@ static int zswap_enabled_param_set(const char *val, return ret; } +static void __zswap_load(struct zswap_entry *entry, struct page *page) +{ + struct scatterlist input, output; + unsigned int dlen = PAGE_SIZE; + struct crypto_acomp_ctx *acomp_ctx; + struct zpool *zpool; + u8 *src; + int ret; + + acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); + mutex_lock(acomp_ctx->mutex); + + zpool = zswap_find_zpool(entry); + src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); + if (!zpool_can_sleep_mapped(zpool)) { + memcpy(acomp_ctx->dstmem, src, entry->length); + src = acomp_ctx->dstmem; + zpool_unmap_handle(zpool, entry->handle); + } + + sg_init_one(&input, src, entry->length); + sg_init_table(&output, 1); + sg_set_page(&output, page, PAGE_SIZE, 0); + acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); + ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); + dlen = acomp_ctx->req->dlen; + mutex_unlock(acomp_ctx->mutex); + + if (zpool_can_sleep_mapped(zpool)) + zpool_unmap_handle(zpool, entry->handle); + + BUG_ON(ret); + BUG_ON(dlen != PAGE_SIZE); +} + /********************************* * writeback code **********************************/ @@ -1413,23 +1448,12 @@ static int zswap_writeback_entry(struct zswap_entry *entry, swp_entry_t swpentry = entry->swpentry; struct page *page; struct mempolicy *mpol; - struct scatterlist input, output; - struct crypto_acomp_ctx *acomp_ctx; - struct zpool *pool = zswap_find_zpool(entry); bool page_was_allocated; - u8 *src, *tmp = NULL; - unsigned int dlen; int ret; struct writeback_control wbc = { .sync_mode = WB_SYNC_NONE, }; - if (!zpool_can_sleep_mapped(pool)) { - tmp = kmalloc(PAGE_SIZE, GFP_KERNEL); - if (!tmp) - return -ENOMEM; - } - /* try to allocate swap cache page */ mpol = get_task_policy(current); page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, @@ -1462,33 +1486,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, } spin_unlock(&tree->lock); - /* decompress */ - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - dlen = PAGE_SIZE; - - src = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(pool)) { - memcpy(tmp, src, entry->length); - src = tmp; - zpool_unmap_handle(pool, entry->handle); - } - - mutex_lock(acomp_ctx->mutex); - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); - ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); - dlen = acomp_ctx->req->dlen; - mutex_unlock(acomp_ctx->mutex); - - if (!zpool_can_sleep_mapped(pool)) - kfree(tmp); - else - zpool_unmap_handle(pool, entry->handle); - - BUG_ON(ret); - BUG_ON(dlen != PAGE_SIZE); + __zswap_load(entry, page); /* page is up to date */ SetPageUptodate(page); @@ -1508,9 +1506,6 @@ static int zswap_writeback_entry(struct zswap_entry *entry, return ret; fail: - if (!zpool_can_sleep_mapped(pool)) - kfree(tmp); - /* * If we get here because the page is already in swapcache, a * load may be happening concurrently. It is safe and okay to @@ -1769,11 +1764,7 @@ bool zswap_load(struct folio *folio) struct page *page = &folio->page; struct zswap_tree *tree = zswap_trees[type]; struct zswap_entry *entry; - struct scatterlist input, output; - struct crypto_acomp_ctx *acomp_ctx; - unsigned int dlen = PAGE_SIZE; - u8 *src, *dst; - struct zpool *zpool; + u8 *dst; bool ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1795,29 +1786,7 @@ bool zswap_load(struct folio *folio) goto stats; } - /* decompress */ - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - mutex_lock(acomp_ctx->mutex); - - zpool = zswap_find_zpool(entry); - src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { - memcpy(acomp_ctx->dstmem, src, entry->length); - src = acomp_ctx->dstmem; - zpool_unmap_handle(zpool, entry->handle); - } - - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); - if (crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait)) - WARN_ON(1); - mutex_unlock(acomp_ctx->mutex); - - if (zpool_can_sleep_mapped(zpool)) - zpool_unmap_handle(zpool, entry->handle); - + __zswap_load(entry, page); ret = true; stats: count_vm_event(ZSWPIN); From patchwork Wed Dec 13 04:18:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13490334 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 8E1F6C4167D for ; Wed, 13 Dec 2023 04:18:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70EF88D0009; Tue, 12 Dec 2023 23:18:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F3DD6B02A6; Tue, 12 Dec 2023 23:18:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 362EC8D0015; Tue, 12 Dec 2023 23:18:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 152378D0009 for ; Tue, 12 Dec 2023 23:18:41 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D329380B9A for ; Wed, 13 Dec 2023 04:18:40 +0000 (UTC) X-FDA: 81560488800.07.9F41D00 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) by imf24.hostedemail.com (Postfix) with ESMTP id F3BE6180020 for ; Wed, 13 Dec 2023 04:18:38 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf24.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.173 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702441119; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7X6sO4QEs0CdCbHgDwct+75aKQI1ePv0U68eCa5kaA=; b=ag/bZ5T98NV4xGnPPRVqN89qsUHsUOoLAB9bYnNyj1+axXpwl+XSSuvi29U46maoImQvf6 KEg28tI3cux7KEwUWyfX3M5FQ/7yqspIUmi055alszsGZJr1xmKLbUkvcWCzCs1dWR73sh RxHPRsfj486nI5PxKmSi2ccEwjdKMvY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf24.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.173 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702441119; a=rsa-sha256; cv=none; b=VZifEDr6dzPHuqtNhaRlSf5mdB2eJCKJthLlmxozs0KviNMZpNT/WSKUBTh9SShvh0H7RO D7nRbC/Gb5WVJTZAMc6WXhdqQahmoA/fspxl/tvNQoAy2A6cl2qQ73yf4XHyiI7P85pgCE ujiFTbO9zG4ty1nwD3ewPP/Oc+0tA64= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 13 Dec 2023 04:18:01 +0000 Subject: [PATCH 4/5] mm/zswap: cleanup zswap_load() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v1-4-896763369d04@bytedance.com> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> To: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , Yosry Ahmed Cc: Nhat Pham , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1702441093; l=1420; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=gHk9F7eN5VVpt8CHpkuzKmAhJem3BWIWL9xkZea1e1U=; b=Mq7ZVygwDSg26fqcIH0lgGs33EOIphxRRADgWgY+gCZsSYodcZU12+MAMo+qu+v55RREfVaQD qasMy8oE2aaBeXRlyCau99fMz3B22hGNgTkHN3IdyqWLfrnbHDZ9MEG X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Stat-Signature: dmqyu3i8g5wssxg1g1ajbmzcw3hu5ccn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F3BE6180020 X-Rspam: Yes X-HE-Tag: 1702441118-960852 X-HE-Meta: U2FsdGVkX1+yEa6RQo2hEOpajDyqEpPqc4VlMSVcdSVlEzQQD81i5uxJV4x4Dv7ndG3xSzZ7ZRKkaloucuGtDi5hFbZrruwCKHJ9/EXtLXIzxxoK2Js3Ly4gy4KUquZC2j/HvpyEV74hP+pCLd3YlcsbUFyNa4/Kjhue9B47V91hP8ZWOV5Eb4WhxY4DwJRUTmwYSSGuPSjL3hN7FRDTG/kuxEBOtNxzihF9AKZz/UURzcE7MPZTj3eeysE+RjXb50Ln55ncjEHI1CX03FKxYHIehxQev7kv/XEnFMRRXKqzae3ZUoSGTM29VphNhxie+kFt/JDuaRUrLBQuwRBjxLfVazZPSqEyW4ZWEDdRbw6r69wAEo1xZdtKfPX699QwBSehWHsAIhJjJzr6RDrmuZSWLwWlGVBFqT4J2YuWiNhgqftr79qhXi4QcRKxDxmrS2MVSKY/xDLVXFJoG+dWOTcDHU9pygo0lO631rnD3Y8co2EMZ1BWHJdZX6EwXgCsktkSoVFQ1Ut6mzmOYIwPE6mgMY2J5dfo0N2g4+JwqifvOHMK0RDYfwjt6rkMpigDTEO8dfRTQxjjXKRNvz07glS7fteVMYllsJvX6wqNAQQIsRh49isKyApRbF+0dhqb5iiInyZGqDzXANQrYRwpGnGZy8tmv+SAfuO5Heq2Al7u5UScmpKRtysspkxt+Nx/IASonCjeqSUNEHNs4AuFlFj11TvXYOIyhEg05tI/7C+2dbS8EFmOCS4GMRTf5LMMnFNznW7FHiyPbvYhmaZIaS3tt0e9QrsW7uAfbg1i81SKbUbI5RNxaGeM4f+sWbMdRiyoUdWD+Yhtvi2+OW6Gg2kjO+PA3/y14DfRRVDvAHMvWvBurpY244gqoeRbvnanK+YvYZJehGMvXpmulzjSz1QLVBP6g5z29aa80n0m2IMMZ5rwDsSQ8zRtV+xpVa3hDV0ZcnCkoQYpSET/Rcn y0N+2wn1 9L2ogVP7RORIQzUQSr0g+0ziRA0A69SwGoZMkKBgrqjtTm6AcMZW/V73xp9AjtiOn9XDtnPTqnnO3KMTHnThBtnB1zTj8YEh3w0Z5Mvc5kPFF6C8ITlGk/K3UvrMduXelzN3WlX+ViwOq71HsRBxSqKO4g9q3NXMhy12C4kV48Me1O8MqTEO0YlumsuM8rgRX5jXeKTs9F9a2rYbDFiRD6osBlaiBtxg1LYW6l1OHRN2IzOPX3AxP9a+iZOOYV7NhLkMvo9VR8MEVkyGpS8JWMSyw8ay7wlxAfDh0lV6FAuyubYLlg49jIs0/MYaCCAqhZOpg/6Cv+QIYLYDCmOqThWJaawYqQs9cnqSpsvOILLAoDur5dHSkDkpN3Q== 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: After the common decompress part goes to __zswap_load(), we can cleanup the zswap_load() a little. Signed-off-by: Chengming Zhou Reviewed-by: Yosry Ahmed --- mm/zswap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 2f095c919a5c..0476e1c553c2 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1765,7 +1765,6 @@ bool zswap_load(struct folio *folio) struct zswap_tree *tree = zswap_trees[type]; struct zswap_entry *entry; u8 *dst; - bool ret; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1782,19 +1781,16 @@ bool zswap_load(struct folio *folio) dst = kmap_local_page(page); zswap_fill_page(dst, entry->value); kunmap_local(dst); - ret = true; - goto stats; + } else { + __zswap_load(entry, page); } - __zswap_load(entry, page); - ret = true; -stats: count_vm_event(ZSWPIN); if (entry->objcg) count_objcg_event(entry->objcg, ZSWPIN); spin_lock(&tree->lock); - if (ret && zswap_exclusive_loads_enabled) { + if (zswap_exclusive_loads_enabled) { zswap_invalidate_entry(tree, entry); folio_mark_dirty(folio); } else if (entry->length) { @@ -1804,7 +1800,7 @@ bool zswap_load(struct folio *folio) zswap_entry_put(tree, entry); spin_unlock(&tree->lock); - return ret; + return true; } void zswap_invalidate(int type, pgoff_t offset) From patchwork Wed Dec 13 04:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13490335 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 F1CB8C4332F for ; Wed, 13 Dec 2023 04:18:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FB4A6B0306; Tue, 12 Dec 2023 23:18:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 781346B0307; Tue, 12 Dec 2023 23:18:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D3B26B030B; Tue, 12 Dec 2023 23:18:45 -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 472306B0306 for ; Tue, 12 Dec 2023 23:18:45 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1812DC0B1C for ; Wed, 13 Dec 2023 04:18:45 +0000 (UTC) X-FDA: 81560489010.19.59DFED0 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 3A7484000E for ; Wed, 13 Dec 2023 04:18:42 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.172 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702441123; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tT1emKgYQM0+F4uJHP6P+57UiBL/0RPI31P/wvcqXbc=; b=XJoeKRjCQPULotp/qp5ebJKiNBbBrZSPJYZMbWBqaKMabooXpjoJQIc9Zo1mylPyCk6NAJ vRonQ1OLiW55937g/JSAXA4lS0bgg5VOndUO1aXoFvoxyIQuZ1U7uQjfzWpG6CNnyBCu3N ibo3ZDwlcmt6AiHESPm4kmPnALn8/Hg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702441123; a=rsa-sha256; cv=none; b=f4uEC4XTyzaULSko5wDRntbd2mmEjwOvTK45iWMXS8pim21ac8ibXizVb7tBGGzMJghP5s nBZXMxME0Q3Z4Iid1riyR1GMf4/CQX13ZimhetpZuMnEZ/iqaTvGWpbZBwfrDyLqNrXNJY CMuoQEeJ9UEPA0bp/pPW2uvn3JK2RyU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.172 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 13 Dec 2023 04:18:02 +0000 Subject: [PATCH 5/5] mm/zswap: cleanup zswap_reclaim_entry() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v1-5-896763369d04@bytedance.com> References: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v1-0-896763369d04@bytedance.com> To: Andrew Morton , Nhat Pham , Chris Li , Johannes Weiner , Seth Jennings , Dan Streetman , Vitaly Wool , Yosry Ahmed Cc: Nhat Pham , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1702441093; l=1963; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=XtUmsKxEGZDM6rCPaj7hU7R0sVQDeXZ+79WRnhx41L4=; b=daDp6iGtf2E6cgWllBKZRMe+XLcYJPeNFS2p+GHbNKI/dAonKm2M1/DQ3KX+qO/v3iXSgap41 5xxgLXMKxrsDJFAkHGGJmnbdCOdDUZdM+O8ekdbB4ml4twb8Nf1Erxz X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 5todb3qm163kada3f7ecdmzdktw179yk X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3A7484000E X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1702441122-257257 X-HE-Meta: U2FsdGVkX18pNTEqAmuPSJ0urfbl1iV0g7SCzxP/8yh1qpuLmOXlEdN0ey48jNoWHdwL9qcafX1mgDrQZmGChS5mI9eYjv/IICN1d7MqcKxr5TjF9JUEvRlWCozacu77Ufrz9orta1Xjp/WZ2/C04oTHZqzBt8/eO1tCMYOMJ7N+cbJYGNCx/A7XbNsNwxKpA+ZUpLGMxNTJruViPT9pGvd0mMN2HINY6GYqUvGjop9yoNIX5XaBRZ120Tlmj4FgEH2rRXQhAjkCCtKRz3s9WA3m7tSDPfxCRG83ivzEkJ2FygZeXqtLUYkUYTFdwm0EuIIqIVHjyaND3lBNWK8iM0UKVu38XGAqKuZIZ/tx9Xvatxw0lEKRNGycjbX+/mr5NapthoF0QZtIcOF0kBoOOh0a/ZTxrcsuC+H2fTys1euT/iOyfACfPujWnklsrrGuRNbM2HGq2nfBoFj9c8f3K57iJihH19C8ycx/XtVEeJ3qc3Y+dADnSc9dSUUcy6tTmAOcVD89d0B8UgLsqX6o4vnUrcYACXJfRRCUnfF7zPMxWhAbhPVhz9SMcmH8Uq8P+7gNDOIfpmsg3h72FfaRcAMHmtwf7efpFuTXmT0L8kLsYaFBhMmtFJsexgjyec7OSrRZmp42HoNwUtAs55pyulgtajz2pZqpMm4XzvP9Bwv7vk3VQG+nkem/KlQWFXgTdgjLjP26LWaJ8+AyfE2My8LQsH1y30VK+6aOjAMdujjFNZk90xK2Fya1xMpx56cMZDDTIdFvtzp8Cgk2ujtLgY0IRmLwCDtzixECGu3ZHZHguIbjIXWDHeLoly5FnhBTsFKrKBkRuj0fun6hn8+rxT0YuU4TfVwpvFtE81n//V6kyVjFn4uy09ZraNVMxaAveBBJo0XZQBenE1igwu8uvtB36GC742/knK7keLU4hjDj08utTmeEDpdB9cdYX8VdWYs/LwptqZ23sW4kwyK SkA4K2/D oFnRkvEEZBE7AuSz2qj61TvbCoJ5OaCpw/gEkNaSr3Xj9A+Ie+CpvWMPFsZuNL2vB6PCkpkEVMeTiG9iYc3zqI8DxSFwzgjCSZ3PFxAAILSVs9kGp6XlPNftpOq/u1GgYfwjgSC9nWVV1lnRJ4c/PR5ROGjiZRydHZNEZoMxlDhR33TuV1GThnzQcGvWctM/caEK+NnxBgTg38zz98LhG102oA+jmhecJC5j/pXoOAxmaZ4ep5I5Kjmthzbgw9deglY7tgCT0AaV8DOm1+tFF1p7ke9WVL65MUApACTTSkhovmMYSjt7YSrD3cOTYmOGzDyXZC4Hcl7b9LQXCJnX+aB9pCdMhLAGs66525pC87SChx5rys3ay7ISJ4Q== 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: Also after the common decompress part goes to __zswap_load(), we can cleanup the zswap_reclaim_entry() a little. Signed-off-by: Chengming Zhou Reviewed-by: Nhat Pham Reviewed-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- mm/zswap.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 0476e1c553c2..9c709368a0e6 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1449,7 +1449,6 @@ static int zswap_writeback_entry(struct zswap_entry *entry, struct page *page; struct mempolicy *mpol; bool page_was_allocated; - int ret; struct writeback_control wbc = { .sync_mode = WB_SYNC_NONE, }; @@ -1458,16 +1457,13 @@ static int zswap_writeback_entry(struct zswap_entry *entry, mpol = get_task_policy(current); page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, NO_INTERLEAVE_INDEX, &page_was_allocated, true); - if (!page) { - ret = -ENOMEM; - goto fail; - } + if (!page) + return -ENOMEM; /* Found an existing page, we raced with load/swapin */ if (!page_was_allocated) { put_page(page); - ret = -EEXIST; - goto fail; + return -EEXIST; } /* @@ -1481,8 +1477,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) != entry) { spin_unlock(&tree->lock); delete_from_swap_cache(page_folio(page)); - ret = -ENOMEM; - goto fail; + return -ENOMEM; } spin_unlock(&tree->lock); @@ -1503,15 +1498,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, __swap_writepage(page, &wbc); put_page(page); - return ret; - -fail: - /* - * If we get here because the page is already in swapcache, a - * load may be happening concurrently. It is safe and okay to - * not free the entry. It is also okay to return !0. - */ - return ret; + return 0; } static int zswap_is_page_same_filled(void *ptr, unsigned long *value)