From patchwork Thu Feb 1 15:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13541311 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 E3A8AC4828D for ; Thu, 1 Feb 2024 15:50:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EF256B009D; Thu, 1 Feb 2024 10:50:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79F2E6B009E; Thu, 1 Feb 2024 10:50:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63FE96B009F; Thu, 1 Feb 2024 10:50:40 -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 520BC6B009D for ; Thu, 1 Feb 2024 10:50:40 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0FFC0120999 for ; Thu, 1 Feb 2024 15:50:40 +0000 (UTC) X-FDA: 81743672640.06.D3DA2A8 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf13.hostedemail.com (Postfix) with ESMTP id 2B26620008 for ; Thu, 1 Feb 2024 15:50:37 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf13.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.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=1706802638; 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=gvHyoQn3NFb3I4D2AD0ZUO5HMDP07d8j0a01bzSQah8=; b=JtaRokmoxBAhsUVgMGBnLSaPYL3y7r2zojrvZO220JTjLf2Dx3f5IkuFhibWsFiiMP8xiR /J2iciWHQyApvAyCmwmRrKJueHInkPuqZ5VbAtgHAIo4YecneKco5kQePIEyp2oG0c5VaK 0FkPCLs65L6bUqb6pmqPGq3wiNkBEew= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf13.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706802638; a=rsa-sha256; cv=none; b=hPg9g8YfKazKfWSN+J6UYN/h4Hphn5rZBuybXPsaW7cYWwzTmLlEGRUQMjaKKy8VxBcInG SfY2nKSxNn9kEqxdNhs8uiNdbzqC4V0Q7dh83oi4uAC1yeQILIS660Gb+tyn0/sm5PB2ih eskMD5WXVELiIRwdvprydXRPY9RmPaU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Thu, 01 Feb 2024 15:49:05 +0000 Subject: [PATCH 5/6] mm/zswap: only support zswap_exclusive_loads_enabled MIME-Version: 1.0 Message-Id: <20240201-b4-zswap-invalidate-entry-v1-5-56ed496b6e55@bytedance.com> References: <20240201-b4-zswap-invalidate-entry-v1-0-56ed496b6e55@bytedance.com> In-Reply-To: <20240201-b4-zswap-invalidate-entry-v1-0-56ed496b6e55@bytedance.com> To: Nhat Pham , Johannes Weiner , Andrew Morton , Yosry Ahmed Cc: linux-kernel@vger.kernel.org, Yosry Ahmed , Chengming Zhou , Johannes Weiner , linux-mm@kvack.org X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 2B26620008 X-Rspamd-Server: rspam12 X-Stat-Signature: 4bbk61mhm9p9cki54n1ownmmk69m7f6c X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1706802637-878207 X-HE-Meta: U2FsdGVkX1834SaVPdWRIoTg8klRDg9uqMGkruJT8Iy8A/B0bTy6TluXwJtowC9dhR7VmdPpQtBdOo/QwSXegnr3YjjmCZFeHuU+ASG2/ao4R/m9QVKO2nyRw1mIht76e1dFI4ikZh6Nl0hDMHyyb3uKtzG5DGZNffrO4ghJhfYLHW+tpIPLGFqAUreQ/Lk0JwJCaYD/6JJqlcVloZSvRFQ67Sq85pAnWUhVDi5tnvYTTWGf7kg+kvc2vLuTu8yNG1Wdf5AqLE2v23tGPC4rxSTIeZyrQkf+SM0Jg+0ambKiAh5wAKCN3MmYl82Mdjrbq/X5IdUAzROZFdKGokFKNJI90CFhABVNh+y16zPtDPb24izXFffsF3uiya0G/1ZP4yM41du60IRbSL39lGuGX5lF10uup5N/t6JdO1lLQ+EnW37Vij6APRWrmZbSU71WYEsY7EgglRgEgtCmyIS1kL/qQd0Kkl0tUcp9FfTPKd1WfnIAfLFzZj44Sl61drKJ+iQm6A+BFGSTki0jDuepBKSHMoez2ByUsiX7rLqeIoEecF93oTNYjLhES/2AuE2Sjk2WJb8uM4b82taQ6I605kI/o84HWqG1hRSOG/Tl93fad6SKEBoBd02dZ+6yhHeLxGGhdZ0lM1lmlLb5YYNic3UiTtJM7UHhAwnm2uR683A8YyouNPYTdwGVDGbyj36WbR31yvXw0qf8987cJUU3QRRD0yb+1gB8G/qHR49WNnqDhczMZXfPGzcs7z2X5eyvxjSsHnaYhf8v4hGmXt4raEalCCy1YEL8x1oPuItcOYi5i6kONch82STKCz3G8vO2MXusdQppu2x0O9S4+4ljU8wkkG+ErSvu2XbJPgVMj4yidBaqtRuVe4TCVEwUinSeiuZ/uC9MolU1I8z8XxBo8RJldUK9UbQmum7ADU+rbFpaTM3c8FbUmuxdo8spxYPVHhgx6EhWPSBecbK9amh E3R5OPCo egqypdUQfDjbk5AY5PHSm45XgYXJI7EEtOjtMN7jV0yk9M9CqJOz2YLsnL1bnLAETD6Q8cd9EWtPSV/8Z/u6tpkuv2hACxKlPTarH2yLKsOW1jmMC8x3vH4fPvzuPVBCRsDMsTrBGsCysReQ1j7ohbtCbdABTv3PKOYhimeGWF1AWh4+nGJdxlzBaQTlmCOiMaXegMBwNFpKSF1EgZC4Am/HrMW5GXOKLkZ3sKtkHqhQsSgnE9Vl6RVIh2V0t4vAsa5Qy/AVtz4styjZa8ldjriKbq7B1zryLl/OwkSkjLzrCNn/8v2cDlgqzvonL/cXtrtAAbLe3FoSHZdW6nJ77EZ/b/wFIOQIE3v6OWG9uHNHpEQCnEhcwgSq0W5o0NoaluAexHs+9OdxxGxGwzMHp3x6Xd6md8SoNBnHP 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_exclusive_loads_enabled mode will leave compressed copy in the zswap tree and lru list after the folio swapin. There are some disadvantages in this mode: 1. It's a waste of memory since there are two copies of data, one is folio, the other one is compressed data in zswap. And it's unlikely the compressed data is useful in the near future. 2. If that folio is dirtied, the compressed data must be not useful, but we don't know and don't invalidate the trashy memory in zswap. 3. It's not reclaimable from zswap shrinker since zswap_writeback_entry() will always return -EEXIST and terminate the shrinking process. On the other hand, the only downside of zswap_exclusive_loads_enabled is a little more cpu usage/latency when compression, and the same if the folio is removed from swapcache or dirtied. Not sure if we should accept the above disadvantages in the case of !zswap_exclusive_loads_enabled, so send this out for disscusion. Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner Acked-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/Kconfig | 16 ---------------- mm/zswap.c | 14 +++----------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index ffc3a2ba3a8c..673b35629074 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -45,22 +45,6 @@ config ZSWAP_DEFAULT_ON The selection made here can be overridden by using the kernel command line 'zswap.enabled=' option. -config ZSWAP_EXCLUSIVE_LOADS_DEFAULT_ON - bool "Invalidate zswap entries when pages are loaded" - depends on ZSWAP - help - If selected, exclusive loads for zswap will be enabled at boot, - otherwise it will be disabled. - - If exclusive loads are enabled, when a page is loaded from zswap, - the zswap entry is invalidated at once, as opposed to leaving it - in zswap until the swap entry is freed. - - This avoids having two copies of the same page in memory - (compressed and uncompressed) after faulting in a page from zswap. - The cost is that if the page was never dirtied and needs to be - swapped out again, it will be re-compressed. - config ZSWAP_SHRINKER_DEFAULT_ON bool "Shrink the zswap pool on memory pressure" depends on ZSWAP diff --git a/mm/zswap.c b/mm/zswap.c index 3fbb7e2c8b8d..cbf379abb6c7 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -139,10 +139,6 @@ static bool zswap_non_same_filled_pages_enabled = true; module_param_named(non_same_filled_pages_enabled, zswap_non_same_filled_pages_enabled, bool, 0644); -static bool zswap_exclusive_loads_enabled = IS_ENABLED( - CONFIG_ZSWAP_EXCLUSIVE_LOADS_DEFAULT_ON); -module_param_named(exclusive_loads, zswap_exclusive_loads_enabled, bool, 0644); - /* Number of zpools in zswap_pool (empirically determined for scalability) */ #define ZSWAP_NR_ZPOOLS 32 @@ -1722,16 +1718,12 @@ bool zswap_load(struct folio *folio) count_objcg_event(entry->objcg, ZSWPIN); spin_lock(&tree->lock); - if (zswap_exclusive_loads_enabled) { - zswap_invalidate_entry(tree, entry); - folio_mark_dirty(folio); - } else if (entry->length) { - zswap_lru_del(&entry->pool->list_lru, entry); - zswap_lru_add(&entry->pool->list_lru, entry); - } + zswap_invalidate_entry(tree, entry); zswap_entry_put(entry); spin_unlock(&tree->lock); + folio_mark_dirty(folio); + return true; }