From patchwork Tue Jun 11 02:45:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13692774 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 5D542C27C5F for ; Tue, 11 Jun 2024 02:45:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E650E6B0095; Mon, 10 Jun 2024 22:45:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEA0D6B0096; Mon, 10 Jun 2024 22:45:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD9386B0098; Mon, 10 Jun 2024 22:45:23 -0400 (EDT) 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 AEFFC6B0095 for ; Mon, 10 Jun 2024 22:45:23 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6C8561C1DAE for ; Tue, 11 Jun 2024 02:45:23 +0000 (UTC) X-FDA: 82217066526.23.F48169F Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id A1133100010 for ; Tue, 11 Jun 2024 02:45:21 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I9MmHc30; spf=pass (imf14.hostedemail.com: domain of 3QLpnZgoKCI0F598Fry3vux55x2v.t532z4BE-331Crt1.58x@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3QLpnZgoKCI0F598Fry3vux55x2v.t532z4BE-331Crt1.58x@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718073921; a=rsa-sha256; cv=none; b=0MYfmMGcAk6udNyACi0jfMtdVndEapx1qNg07+OIuWh6l/HVMLZuW6lRORc5/0KnJUNj9T Vq652sMi52fOxh/ZWenlO0uJfqrGMSVbsW+Be13qG84v6eUzqnu3H/ee1BjsTYVF0bF6BX 34jxroZBoUZaWFiZOo0KjXCkAes1fm8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I9MmHc30; spf=pass (imf14.hostedemail.com: domain of 3QLpnZgoKCI0F598Fry3vux55x2v.t532z4BE-331Crt1.58x@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3QLpnZgoKCI0F598Fry3vux55x2v.t532z4BE-331Crt1.58x@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718073921; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S76m/1rcjZ7HVm5h/HFj338IB29Gnxtti7cDrtc8pbk=; b=rwnUr9DvfJ8zm/sD8azrIyXZQ3Pi+aPGfLuPzq9Gvd27eEZDgYKKR6fslTJW13hQXNRLOR ZxCaeuCEjFLzhpPFuu/MftMDQIHaEToTqN+9Wxvr4wMjzkFpT+9HdnDzD0r2K2zQa/9BgK b3jWmIb2JW7I4pWVkHj+bZRgS7hbLsg= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-df7a6530373so9547466276.0 for ; Mon, 10 Jun 2024 19:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718073921; x=1718678721; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S76m/1rcjZ7HVm5h/HFj338IB29Gnxtti7cDrtc8pbk=; b=I9MmHc30MWayGktYkxHmoBVFjUGa1VB2f/cPg0jL1iS/P0FPjAXLEw2kfX34mO6bf2 XEHtyC37rdFx1FUqcUzNQHhh5gFTDiwasNPibK5udEOPPvQwtN4tYEP+A3yEpbYS78Fi 579NB07v05PRZEDcaMSTUlUgLZ8KPub9Qn8x4qoiY/3txN5IIyL6V0W+wpz92285RmYM MlbRu3Pp6/30a6s/XbQlNC+eLgiHVwRJ61wrGKUzku5Yj1M1MTVWe6ap4SVJeByqT0eJ ooSfYL8lt4HDdTOlgsEvE+ow4l/xC58L0aPsq4w7NTtXndyTJCk7gOmQAZTxzkxtU3lh XrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718073921; x=1718678721; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S76m/1rcjZ7HVm5h/HFj338IB29Gnxtti7cDrtc8pbk=; b=fTWOkL2JHECREp1kF2cHSoj5IGWCr7MP3gwhZpLCuonEHGf2Q7l7HdEdyi32+Cg9cC Lzlbgopla2PQeDuXsvTzEWd+tWUfEV9mUdsFszRPbc3F8hdqnMvuBT+zJj/Zr6SxhU6y K2axMuIBK8pJ2c7JEtAkICxDQZjh+MgTW9yM0sSxbx3/5OSK/it8v8qpBGUIwAuR4mat kMS6s6c7g/M/mR5NV0B8e7yVEMID6TjAid0EMF+c/rwBY81KxSIoBc3mKM9lT+N99i4z QEcu26DGKSHltyBWnStxIohs5wVpJ2iheO8XjzovZFXZFg+Nx79/mZo8q8mM1vBmghcj 6HMQ== X-Forwarded-Encrypted: i=1; AJvYcCWzRarXLlRYMxxMXEjfqlj5Riz5FV+sZeh6Rh2jXLmkuRlnbIHJEvrWJ9/BWPuFwRpGcMcUFqP/x+4/IdJQIGawSUU= X-Gm-Message-State: AOJu0YxPGZEdGKZG9E4oTp9aTsTKAzYwkCiqYnXyVY4B5VYOBya3n6Gx W02yzKCY1LpSqB8keo4Sr+GW34JAMUXRq+dseg3zWpfA2YXnh3UdKaSWfmb1d04n1JM8la833Zn U/kMwPNOjCh6bdgeWOg== X-Google-Smtp-Source: AGHT+IH5AQc+Bn7MfrfWCQXqQIKB8mEd8d/y+h/Fxfn5heT9g/iCYqCbw9tsru+N/kEoD61LHDAlNGuosVHNQIrd X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:70a:b0:dfb:230f:6c40 with SMTP id 3f1490d57ef6-dfd9fd42548mr435502276.4.1718073920696; Mon, 10 Jun 2024 19:45:20 -0700 (PDT) Date: Tue, 11 Jun 2024 02:45:15 +0000 In-Reply-To: <20240611024516.1375191-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240611024516.1375191-1-yosryahmed@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240611024516.1375191-2-yosryahmed@google.com> Subject: [PATCH v3 2/3] mm: zswap: add zswap_never_enabled() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Barry Song <21cnbao@gmail.com>, Chris Li , David Hildenbrand , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Stat-Signature: xhhk7drpm96xedugd6y841e4bgg7j1fy X-Rspamd-Queue-Id: A1133100010 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1718073921-470317 X-HE-Meta: U2FsdGVkX1+Hj6xbV7si3XCyYydvvmfQQIsDug+rxNoRKY3buiDAWadC4DN2KV0fDqod5wdNu6u9o+8f8s010PV4P96EnOAM3DKAu+1QapBy4c8e5gZd7zNLSP+k1AiC5vA7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J5JsGUjj0idjuQm8U6JEWJqqbPtWcKO12Sm1VU3ZSQRifvfjyaXc5zlal53iXdsFicgC6rkLHAnEJJkhgzXV76j/UjmZ5ySzxEOM8RcvrBcvjSnR6MJ9QJxkQ+8eKutC6vbjkFaEBbmzX9KG5TiYfeVtZsqdq23yrhX8eSK9f8Dyw/RQfdgui/HGtUfRheI3AR5fN+MIhdACePF9HoqK8LKV/qGVqeHdJpmHqx3VQCaFuB6Dq/s7dwaE/jtWyY760cvMq5CPqwvRxM5IfC0D9NqHFyhpz0u7IDkHqW1FNjRnbGRBqhHBj29SdKN1VtG+L5w7prAAc522LVB9gxCzHAqhCmkBNJew== 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: Add zswap_never_enabled() to skip the xarray lookup in zswap_load() if zswap was never enabled on the system. It is implemented using static branches for efficiency, as enabling zswap should be a rare event. This could shave some cycles off zswap_load() when CONFIG_ZSWAP is used but zswap is never enabled. However, the real motivation behind this patch is two-fold: - Incoming large folio swapin work will need to fallback to order-0 folios if zswap was ever enabled, because any part of the folio could be in zswap, until proper handling of large folios with zswap is added. - A warning and recovery attempt will be added in a following change in case the above was not done incorrectly. Zswap will fail the read if the folio is large and it was ever enabled. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/zswap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index a8c8dd8cfe6f5..7fcd751e847d6 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -83,6 +83,7 @@ static bool zswap_pool_reached_full; static int zswap_setup(void); /* Enable/disable zswap */ +static DEFINE_STATIC_KEY_MAYBE(CONFIG_ZSWAP_DEFAULT_ON, zswap_ever_enabled); static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON); static int zswap_enabled_param_set(const char *, const struct kernel_param *); @@ -136,6 +137,11 @@ bool zswap_is_enabled(void) return zswap_enabled; } +static bool zswap_never_enabled(void) +{ + return !static_branch_maybe(CONFIG_ZSWAP_DEFAULT_ON, &zswap_ever_enabled); +} + /********************************* * data structures **********************************/ @@ -1557,6 +1563,9 @@ bool zswap_load(struct folio *folio) VM_WARN_ON_ONCE(!folio_test_locked(folio)); + if (zswap_never_enabled()) + return false; + /* * When reading into the swapcache, invalidate our entry. The * swapcache can be the authoritative owner of the page and @@ -1735,6 +1744,7 @@ static int zswap_setup(void) zpool_get_type(pool->zpools[0])); list_add(&pool->list, &zswap_pools); zswap_has_pool = true; + static_branch_enable(&zswap_ever_enabled); } else { pr_err("pool creation failed\n"); zswap_enabled = false;