From patchwork Tue Dec 26 15:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13504905 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 B5839C46CD4 for ; Tue, 26 Dec 2023 15:54:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 076116B0074; Tue, 26 Dec 2023 10:54:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 000416B0075; Tue, 26 Dec 2023 10:54:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE2086B007B; Tue, 26 Dec 2023 10:54:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D08126B0074 for ; Tue, 26 Dec 2023 10:54:52 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9FFB8C013A for ; Tue, 26 Dec 2023 15:54:52 +0000 (UTC) X-FDA: 81609417624.06.DDCDDD1 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) by imf21.hostedemail.com (Postfix) with ESMTP id CB1FA1C0011 for ; Tue, 26 Dec 2023 15:54:50 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf21.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=1703606091; 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=7HUld81wKjr1TRbyjzq5xYIWkmaNoBa7by5QpFhFecU=; b=C8l0glQCflF6CeWEF7lTpYJxvN0zpZ1MI2MZwEbOEvu8Arq7ejeoDRF/pgwXiEj+ulFX6c mh9uqz++qolWAaa7xWEIkZ5QPBRoe2FsRUNz2bI7HUefmFGLop0QAQL588K1F9XeG2ALy9 eBhhsJUzwQJ8g1G+2dUDXF6KeqITzbY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf21.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=1703606091; a=rsa-sha256; cv=none; b=fqqu1S2DZkpTqHpyG3al/sdwzpyriks45+A9viZX+eVXnaQpGv8N2HHe8lchZCltqFI8dT 19r7NWZnuR92u0adejFEQwNjorVoOvsUAXqU7DingFsGOlW7iYivyzWcH6SCD02v8EI7il +x744KJe9wxh6hlVAZi5hLfcG+gig4E= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 26 Dec 2023 15:54:08 +0000 Subject: [PATCH v4 1/6] mm/zswap: change dstmem size to one page MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v4-1-f228b059dd89@bytedance.com> References: <20231213-zswap-dstmem-v4-0-f228b059dd89@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v4-0-f228b059dd89@bytedance.com> To: Andrew Morton , Seth Jennings , Johannes Weiner , Vitaly Wool , Nhat Pham , Chris Li , Yosry Ahmed , Dan Streetman Cc: linux-kernel@vger.kernel.org, Chengming Zhou , linux-mm@kvack.org, Nhat Pham , Yosry Ahmed , Chris Li X-Developer-Signature: v=1; a=ed25519-sha256; t=1703606082; l=2061; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=AFQJqRTNy44iATFj1RKZvqHU27WPg0GQMTPIPLqlpaM=; b=vEekGORU58JK/Xo7doVi9/xQDqn1SRUlc3hL7E1KvYToyqnm/hNB5CBcjOCkuqUuNL67fzR90 Z+hf+n1SDUGCIkh8qx1cZk4a0ATT8In1GnwVY+KqUFhinM4gqqu4nFg X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: CB1FA1C0011 X-Rspamd-Server: rspam12 X-Stat-Signature: 47qqqr3o4qiitfquuwicf64oksabxwfk X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1703606090-465440 X-HE-Meta: U2FsdGVkX1+Ig7wi/4x6eVa515XQQonciFssn6GtKN4QEV5YO/fJd1m+36j9OlU3JGi2OmyVa0y7tD0Z0wfP/qz/LS3uFhrILiB0J4z/qixOj1z9cIOrQ2xlxG6q3ra2vyVESSg9sBZCKWPzO37rGtMHXewjKo1yf5l6f9qElyu2DAjN9RylKrBJgQwMRtZfLCKWzJRQSIqntERhvLbEejXVtvS+655GwscR2CGJxMIPF0zGxXTl/tWONX1pDcwH0FhPjF6OqMo53IezRwIm98gGsSkIQAnHBisg/xjo7j06wCSOY5VOxqUtMpDq9P+Gt1BiSgIcnyzPkEfg85cKfpSlEMv3HE08BQHB+SC3tDAAJIOyjlNKQ5UEITmHsmxjPa9ETGSkGY5DlGqllEMFyxcXf+wxbZHmU3IH33QeiuwxR8UkAAQ/ishqh+/2EeWTitlu7BwWnc0Sys2Hs+3j9z8+VVOs4JluF9CqGH/+eQ1t5T5u+aV8HOmliN4+0J9ZzK3MtcWlagFxNAP1hJ9RCWdk7OtXY8s9XtmkiroO3EI1xio662cXs8YrfRC+3kjqBOrPIk7WWrMti0o7jo9cp9ykf6WQUenT/TEci/An12XB1k9fq2C/BFgMgV0jQKkJh7m4CygROtlmoWwdqQyM1vWXY8Kh4sFOzAigpoPXlqcCsHpOcCEopZadEARKmV64mWzZEqXO8gQv/TWBbdw0lo5SEO/FzrahK4wgmuo4gIVlGRImvqcdneU9XyW2SDXDVWylU+ZvRMGv828H8fSLcrd+Bj4lBByWr51zgPBwyfPmZrsGpMuB2+NmjwEwdA1HaeyVXa4yGEpYzHDEktlHqPQ7ZJp65zDXJ9NVkOSOmlPByXQDXYqHpgeuYCrXr21qo07fXM1SF+IwplAFWIixG0OSWT9rkYrIIWNNr2y/6wcw8Jfv957XhreTc3zYuXOZTtiBo1H3wHgm8Q3TDXg Gw6gf2Na Ww7t0RzEtR/VoYgFv0yAQHRyUzdGH+WvGU95r9e406aepOS0IxfLefEXIFV7F4i4kDNkgdOc9GKLdSocPVQFfS7L+7izxb80iYDHMiYRUPyQAa1tEvMCOMiVfyw1wJ9S4wzEOE8f51fla66CSEx9FXFhSRzW6m/ouJmLEPtp4C4jiD30nnVTBjG/8JIUYG70eYqIlsVxZM2fUdUREPW4zFMRt+v9VdZgKU5OunUgnqbOb4kqbloltNJtFpg6+fn1jCXXpKQ0hJJU2VFu4f6MscHvpE3BrF6JDIRGGEHgxlRgQG/hsIOE3amF6zM58WaMJsBnJMjRNNykYWABPb3S9eav2Od7GpDtlseTJD+m1pT5uhpYpyIAtfwn+G0LlWmuJyj+7zx7L7Zd+7u45/SzZpfQabWlBkTct90tHuuqUV2qCdF3m1Qz2wfwhF1KkxHVW2l5tIgt8sDhnHulP5nVFZPJPjsd8ryXuCNGQ 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 Acked-by: Chris Li (Google) 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,