From patchwork Mon Dec 18 08:22: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: 13496350 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 0812FC46CD2 for ; Mon, 18 Dec 2023 08:22:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FB6E8D0006; Mon, 18 Dec 2023 03:22:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 585638D0001; Mon, 18 Dec 2023 03:22:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D6D68D0006; Mon, 18 Dec 2023 03:22:35 -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 2BCC58D0001 for ; Mon, 18 Dec 2023 03:22:35 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F382AC07F1 for ; Mon, 18 Dec 2023 08:22:34 +0000 (UTC) X-FDA: 81579247428.20.25E9EBF Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf14.hostedemail.com (Postfix) with ESMTP id 03084100010 for ; Mon, 18 Dec 2023 08:22:32 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.182 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=1702887753; 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=mqJOJAoE2p6GymrQKWTSEq+6gsVwP2MZp4E/KH0qZcZ4hhuczllLckKEYvTj8hI04geYxH n44gI2j3cpBV4gdPUl90Ec4IIefkZWN9JFyy12dTU8Nr/VXbNfYSEgd9JCm9rW6Gzv1c+t ejAnFlxJb+3/cRqn5gvbSY4lX5Fowec= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702887753; a=rsa-sha256; cv=none; b=qun/c9ntVot4aDOJl6MfUCIjpGTkCGqi/fZtoCCPRN1hYTeAvRHlW9SriRi0VRKTKYvcJH uPS74TpVaDsOLQB9Sh5jpJG/6kR/2/hf1C2izgWpe4ykusIXq83JUgWWtSSspQDxmTL0z3 6JB/Z8wqiv6qqb6fIlZAdpG1N8QYTzQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.182 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: Mon, 18 Dec 2023 08:22:00 +0000 Subject: [PATCH v2 1/6] mm/zswap: change dstmem size to one page MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v2-1-daa5d9ae41a7@bytedance.com> References: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> To: Seth Jennings , Dan Streetman , Chris Li , Nhat Pham , Vitaly Wool , Yosry Ahmed , Andrew Morton , Johannes Weiner Cc: linux-kernel@vger.kernel.org, Nhat Pham , linux-mm@kvack.org, Yosry Ahmed , Chengming Zhou , Chris Li X-Developer-Signature: v=1; a=ed25519-sha256; t=1702887745; l=2012; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=knbPWkl1sBJOnq5pAv9yoWZfZi+/5lFRxFAsoTFiAeI=; b=wLIslRILYEE+m1faC45+NiuKmvx2YOrqYhYxcwRKSBnB/cOfAH9ePkRU4ZggKvwoWRd8ApqOE G59vRbwGIL6Cj27KS5MZI/t6FgZ7RE6FdEjYEhi/qQPb2ilNgqbCYBz X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Stat-Signature: jhyirgt1ojxo5gt4ddif8qaj76k88pbd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 03084100010 X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1702887752-101800 X-HE-Meta: U2FsdGVkX1/RQbGTkYbuE3XAM9QZbHfsTZ5XRaDe8jXAFp0cOSGeDIOS05ZRtVDT3Rmd/bm6MbHXN0yz1QNZfALXf4/EFE/X2bh5EuGhfK6+Jdd54jN7QWJalG0aId8HRHlkLVosf5RFLhkLWjl/YkzvpYiLWHa15jKQJ8jw0t4ht4MHoSy/PyGc/dJPkGAnsdM1/cxTPKnnS1Gg/ZKV0XJ/uBfqnnARbmRxFIBhYms0Yg/oI5tGJYGy/KB6u9S+whxc4QCA8ZIREOGds4k8T8AMEqU0Uo4qz5HcYf2h3CzSOdUFgHqUcTIB6hV0qPlJNRH7J0qFfRCKQvqM3iITebMvbHwpwX7lfsVBDmQLb9zLoPbux4rHdobJve34Z62Dr3ZFliCoejd8dUcZmG9V4sqP/tV7rLGrwdM9tF2ciiA9ZqxgE4bUvIaOEYnG+ru/NnTTtewLMFdD4y2VZfhcQTWLz10cXFakx2wAerQFT+ipAUM/lbevvkyiZgjOX5HweZvlTuywJRIqtm9awlaNqtEfpNoBk8dlS14h0/5aFI3xQ5gctZPzP9fRxaRcdOcIgA1Unbnk/EmVYqMT+lwT+I/Ckq9XSKsGVduIWig4fUf4BxpyWujLX93NAw6WJlH4lS7QUwWDmWe82YUwNpkdRyW1R2l/z6MuDqSC7guDnLCQLlcuKAR2D8lEP1tWCLGXghLxVzw3gjDI8NB4peY0hlR2UkUDfco5lwrPvtc7Cn0GZBMzxlrw8byCPT6S+OR5AbXey+uvGll8LZ3M6AbaDDyhWnjwLUgp96P4flmZ49JNHAey2naihXbmfrZkCmohKjLdSEUicClm5Q2uvE2d6aXbZFAWgZE7d7jrAkO2isC/uFvypbkfSY9y9Rt3Mv24VFBVIcVCXElaF/qZG3CxdkectG+CnzJ5ei7ZjB3H/88Vwm2JMl2iAvwwpkztAu+380OtreT74FjVpfitRdy RjDY4hmM lhkpr32Mm1QxWVetW+LFmUxYhYWjL1ZbxCP6T4504rxAZgM6jmzv3yxtCVY0BlLl9ClDAsylvZvhrqvQ+Xi1RTpS0h8DAC1TuOz20tW6N683z3T/zn4T2ffakqVwJaeHWY2DYTGA1oxf4aJk6K7Ie2LaWlOywJ163busqUn1Gd1DpFstMOuuOPPEj8M05B5H91YbwUz0W1BOCsVxBjRv38dLJn7uVpfwSWgoWMPURB8ufHVGfXtDbjbniCz8yhRdpztVWuKGGCBzs1mSmtrY48hPiSH+ui1U5U2fSX1kNkHQfDKixzOmy9pDJyCKmbrXpN4D6iG/f9Q+fXpvARELBF9bHsq5sqeBRaZmNhu3uWVsRYyfeQq9VZm1LIuaYa1PHH1XBxO4NOLNhGA6nAhL58JvqiA== 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 Acked-by: Chris Li (Google) --- 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,