From patchwork Mon Dec 18 11:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13496758 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 AEB7AC46CCD for ; Mon, 18 Dec 2023 11:50:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 479F48D000C; Mon, 18 Dec 2023 06:50:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FE768D0001; Mon, 18 Dec 2023 06:50:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 251F48D000C; Mon, 18 Dec 2023 06:50:46 -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 06FE48D0001 for ; Mon, 18 Dec 2023 06:50:46 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 887911210DA for ; Mon, 18 Dec 2023 11:50:45 +0000 (UTC) X-FDA: 81579772050.07.6DF57CF Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) by imf17.hostedemail.com (Postfix) with ESMTP id A041F40009 for ; Mon, 18 Dec 2023 11:50:43 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf17.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.177 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=1702900243; 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=UFtS65bQK5h5w9cm85RbKzaORRgbOq0Q5FLRevBhnWM=; b=OiWOnMqQPKSmqeltikLZN2fHtlTqgfDM2QvY0dHMRhFGbuXZnswNqDhEfgL0Tx/Oj7rhLd +gvPGXkn6IkaeRlkH3ZW+Fh9A2gbZkQLafx8/Vfv5m6Hi7+3UHdmuwG4mztMeDUoyR/jeT kaOsk8BR1dJTmb5DFDWhVWLTlxDRiL0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf17.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702900243; a=rsa-sha256; cv=none; b=kQYM4uNGAJrBmD6GVw8AgrI8Uh7nOOtgl4bgR8kW7tx5K5yAUdjEgnXiSmEk5hqCyoGBOk /6WbOW4mGOEP2ogi7IaHPrntQJTl9wK25jee39t6KDS0UOTKSPFHRjsNulixf1vkDQfBzj ShyFNf8+KKlNwcdiuR51hdbjZHLGWSE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Mon, 18 Dec 2023 11:50:31 +0000 Subject: [PATCH v3 1/6] mm/zswap: change dstmem size to one page MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v3-1-4eac09b94ece@bytedance.com> References: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> To: Seth Jennings , Yosry Ahmed , Vitaly Wool , Dan Streetman , Johannes Weiner , Chris Li , Andrew Morton , Nhat Pham Cc: Chris Li , Yosry Ahmed , linux-kernel@vger.kernel.org, Chengming Zhou , linux-mm@kvack.org, Nhat Pham X-Developer-Signature: v=1; a=ed25519-sha256; t=1702900234; l=2012; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=knbPWkl1sBJOnq5pAv9yoWZfZi+/5lFRxFAsoTFiAeI=; b=Skf5BWIwB7K3APRmPY9IP+iewRS012Hs6COguVdU5PIlg7L+x04yE80HEjpOimgwkl6cW+uik 96/4hLYrUTUCrBSCuMhN8meBpFS79yrWTNl5P7OeI56K+kia94TKabn 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: 1pddom7q7tfk7uccdn4d9j1fs6zhi8xx X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A041F40009 X-Rspam: Yes X-HE-Tag: 1702900243-69912 X-HE-Meta: U2FsdGVkX1+zAvg3NFNupycCBVAlBnBkSbhN/xNcLM72XTfvq1zLdlc4aWPzP4YMMKOI+a2HhjSIyBAWG8+QWAnMDMyFvQjsYj+q0m8myy/v8OlgoQf6RIY0b3oK4YI8uvGmE6vm9TQ/bML29votECsuz7ASSTUamTims19hbejIf0vfVsKG4nEasON/urF4KLLVCKsb6nEKUWCkxbQGN5W5+VaZZ/p7Z3AcQwVGW82ZQJyV1ZbIiw15EVHYFxU2vm5TX9nEV2IXuBdTDiiBbxEN3YBWRCAHCwi5snV5vJIQ71Pb5/durprYbQ4EoyVT0ychVfPDLTXmcU51JHLeavkiOXsENtQnnrRVKo3iZevrWDvCOxRI9aSJttOwZ89jCYhumpdpaRBw1NFWPcIH+j0A8KxYk4jUA0ur826eeqDgjishxRUWv45swSTrIA2jTqBeL278GxPy6ISpN19osxruwsfNehD4oVScV4wZuQ5gvJL5Mrwck6TIhK0cInAE/RuZy/RhwmgJaKlIYx2bAYF9F8xleKKbbVIBbJcMmn/FRcpOt7gMInFgSyDMciwlh+tuDSKccVvQmkfyMFdOGRZlcKqTEMbWw0HIU3Vi2qOLIXf1e6fYKtVKWdrYZcMcb1pd/y9PboTaDruWhMX3d6lD+5/nodmvldxlJSAGpIpCeeLtsBSYrXzhVTePvWh+vtpCJA1UOr/3wAfPFq4LiDPoLLnQk46xTKzgYSVK9UXb8Zriq/8/Sb2/DBwvKLeC/0wvCNQPWH9dtCKFh12g1eFVXDWWOaWyhDo7Mlg2BTJGVkf+U8ZaptTTQam2KeqMZmNaFYU9V4+Izhf6UxXpVnMB7syS3Txmcc9N3ruKkLnDmmU3goASNA37Z0oNmLusWOWVFqDdoQv1MsINRfFum493RDJNF6PVlEOamzlrmDlq5Bv1w37TKq44BwmfvEyjtrzUTia2Yaa8W2GtuT+ L35F9OeU J3JKXmXWYVkkBmcG/S47iGBxruxZfcGpTlP+/XjfRiZpj6pdnziPEL1y65nJgTFFg9rifQ6IpKtrBTZoIYLOJmuqS5KS25yeVY03wl+9vKNPFL/4f3hHRq4UOVYPD4b8nZzZn2UPLa6jUYSwvw3o5Btn7/8xwzuHfl/c4C7FYgZhly9EDEaOJ8Nk47IQlXEdWeYU90lGHjjHR9N8CXbBZ+UajrRU1t5tgRKnG63zrKzH+0wwq2GVU2LGnIk1GC1x4v9RrHIs7XFpl9U8d5ST7PxULLMjTl55KOfQRjDNsIdkyyELk8JwrTIEsDIZd6+P7qlaSdDPCnOZVL7IBEt0IVNnuPfyW+kuNSnkxJ9jxExyixAkwu5TAsS+O8Q== 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. There is no any history about the reason why we needed 2 pages, it has been 2 * PAGE_SIZE since the time zswap was first merged. According to Yosry and Nhat, one potential reason is that we used to store a zswap header containing the swap entry in the compressed page for writeback purposes, but we don't do that anymore. This patch works good in kernel build testing even when the input data doesn't compress at all (i.e. dlen == PAGE_SIZE), which we can see from the bpftrace tool: bpftrace -e 'k:zpool_malloc {@[(uint32)arg1==4096]=count()}' @[1]: 2 @[0]: 12011430 Reviewed-by: Yosry Ahmed Reviewed-by: Nhat Pham Signed-off-by: Chengming Zhou --- mm/zswap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 7ee54a3d8281..976f278aa507 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,