Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp438682lqp; Thu, 4 Apr 2024 19:45:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjjXmz+NydnqU790ZASiYaq3Cz0A3OJ8KCt92eaz4CWPWItrWZL3G612A8CX6kfM1vXpU9jvoxCA3lry+YvPhuboXMXkCcOxeJzoF6WA== X-Google-Smtp-Source: AGHT+IFf3AHf0qO0I2Ued352y1vxGXXBOTUm+W4Oj1RFdtVsSfl1pFJtFrphjWt7q4garnIUEdpx X-Received: by 2002:ad4:5961:0:b0:696:481a:e2ec with SMTP id eq1-20020ad45961000000b00696481ae2ecmr133174qvb.22.1712285111630; Thu, 04 Apr 2024 19:45:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712285111; cv=pass; d=google.com; s=arc-20160816; b=LSuSADArj9RPWtu7OUOrZpTZ7ODeq2NGZryKQ8686cp7+eDLvXi8M1mxcfCfAQvh3r dWI7tGhZJKktdGTiD/tqDdEezX5MF1xvNVgS7EzbhmC89nlbczPoc8W0jiFHNBv3H07G xuJxzmHnQweRJ2Hfmc940WF5g7oTPsda9lCrvx4F68zVLyTUur5IRGMoyQLyAE0H5Y8m cyrUrZrk1vDP6pvZfAEQ6I+PcK5avMm9uaDFUEccRL1O0Y8/uPc2423QVtlkyl8eNJuV vzEy/PuDtVf/lOkBM4lCAMG24Ly/JMGCvaXxTCMnvlirh03dhgUzczIGe0Px49bD4C9u 5OTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=14/Jmqw/F513fEFD4zyhSbn6EUBGIv7v5bPF2RRkA6k=; fh=c5thvWwW8qET7qVYvCjARdXjROibssDS7bv9Lvwu0oM=; b=EoCoZc2xYBWhiLRSUfZ68Lf7wJd7UoJVcJ5jETB5NCt+Y7XQ/wFqrJWQipyy+0WWrL ap4a9oXeDO7okO7B0iuP6sqekiIabjTYqJnhJkP2c40NUtgqcs53qM6oe38KHrvB353W lSF9XvAKLdIxEdecInxUla4nlxvo5u6ymAOzR1P2eUsHdENu/7o2q9w/7sgn7tkanoNP /E8cqhb1jEA882MSctALYjCWtTrZfDSOyHXj0wpms1CISGkqWQBFMUCvz+CyfNWojgyc 1kfh96nA7MXFebWFXEa2AtLH0E/HHGGkAuGXVQiACr86t0XAJmHIQ+RlOFU1q/rbbqgt 8tLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=h0UaRVHj; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-132335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132335-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t18-20020a0cef52000000b0069921262cafsi786642qvs.225.2024.04.04.19.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 19:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=h0UaRVHj; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-132335-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132335-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5DE4B1C215F4 for ; Fri, 5 Apr 2024 02:45:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 067DC171BB; Fri, 5 Apr 2024 02:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="h0UaRVHj" Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FCA3BE4D for ; Fri, 5 Apr 2024 02:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712285105; cv=none; b=WoXNc4nDwVLtuNDRzFwkj9YPUTV6MwJpGfyWfpVZtzDlGfgdsVMfRsEEpjI7EWPOLpPePl518wDgCaa38V2DNbWHJ9J1iSc/RrSAXLImKL5rOqJcex15Fdpvy5Hy6lup83JsRnK9UFVM4gGaQy32CQDX26YB/7W3Q/BeAAr5HX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712285105; c=relaxed/simple; bh=64W2UQQFPjouK1278dNE6r4EnUBen8IgVNpaRRS1OFA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oXaNOeTusOg8aLefGzzVtOEdcYfJeqMRiBnyIwjYsmtymkAvcqyn7GWcDuaUVkm87olnLA81aBencrPOei9z7xOXYuGwkftx7oduznm48ME3CUERzTC4f3o34xgiGQd+X09rLtrW61w4tWW6qpS3D7mhftWrID7tAoyFCz8vYfw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=h0UaRVHj; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-43182c2457bso8665701cf.1 for ; Thu, 04 Apr 2024 19:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1712285101; x=1712889901; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=14/Jmqw/F513fEFD4zyhSbn6EUBGIv7v5bPF2RRkA6k=; b=h0UaRVHj7/9Eg834KAq7B1dZv+1F5kx9It9XiGOKZ29VQyyEf0dLogRWoFYExlV5DD Dgd2ATYIsShAej+PRqxjrY8sUWRr/19M+qf3b9KFMdsH1pKi+P/SeyXxE4A/LDo4+AY3 CZf6fKw9wzseKDdM6ZDiTid4ofqPl0XvXyPH0Cm0UtKyGD/KHvbFsxRPhuo2pIr/EhnT QZSr/IsMlGIu81Ojotkoo7Dbr9DJZJqnHN8WEp1jhEsWXH8aSUUPhDg/Ga3wZcgYyB/d TmLlk2fukM0Zf9dLgiEYe5Ch9MbTQrFfYE85wKm+8CjlQ7WNqL1clu4kcwcB9Fk2LpJJ KyAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712285101; x=1712889901; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=14/Jmqw/F513fEFD4zyhSbn6EUBGIv7v5bPF2RRkA6k=; b=HgK37wtwffIHCTh9d3LJtsRuW8B0n+TDvrjGrzL43UgYLb112kjGePqk8c/+xu6/+v dTsCDKnt8VX0qDUjWgFwJffqKl56RYHkyjmycy03U7NjxWqgVKzQlwiM4sCAN8SEfQnf S0BZm9YmC5xwFq2v3bicRonyYCddXJAGwMDt7CR5CA8hjKyJRHYYRF/lXdIiW1hmBJzb 0ZFqPtRk9KQmNWKJCDAbDCx+7ij27xq00EVtnHX0l2YD/gIfRDgMLmFkk2mn6UjGqIWC ZOmzWjKrOAmOJmYJKqza7WItIW1vTdIWEy8zEu8TtaydRaxiAfat1aVeqS7ktdXHH8qW NKXg== X-Forwarded-Encrypted: i=1; AJvYcCVHYjzL+RMXTVeLxRRkb6xGwxRB988SY/GGUZGbHMR9JOs75BcD5zNQYa6cNbuyh3K2FGH1fD9zywG61Z/gNeuynuSUN9RVhQjOnZRw X-Gm-Message-State: AOJu0YzvWiWzIXeaE8Af1s/BgmyualYNwy+LgPusiFX5+JFPpUDDFKKv eKvPEf0dWyKqyFeizPIo9iN818XqbciK6fuIiaM23CJDlSczcM2zf2/WkBZt1qs= X-Received: by 2002:ac8:5dd0:0:b0:434:515e:4120 with SMTP id e16-20020ac85dd0000000b00434515e4120mr110174qtx.42.1712285100819; Thu, 04 Apr 2024 19:45:00 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id c12-20020ac86e8c000000b00432cf894d57sm322016qtv.48.2024.04.04.19.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 19:45:00 -0700 (PDT) Date: Thu, 4 Apr 2024 22:44:59 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 2/5] mm: zswap: refactor limit checking from zswap_store() Message-ID: <20240405024459.GE641486@cmpxchg.org> References: <20240405013547.1859126-1-yosryahmed@google.com> <20240405013547.1859126-3-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240405013547.1859126-3-yosryahmed@google.com> On Fri, Apr 05, 2024 at 01:35:44AM +0000, Yosry Ahmed wrote: > Refactor limit and acceptance threshold checking outside of > zswap_store(). This code will be moved around in a following patch, so > it would be cleaner to move a function call around. > > Signed-off-by: Yosry Ahmed > --- > mm/zswap.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 1cf3ab4b22e64..fba8f3c3596ab 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1391,6 +1391,21 @@ static void zswap_fill_page(void *ptr, unsigned long value) > memset_l(page, value, PAGE_SIZE / sizeof(unsigned long)); > } > > +static bool zswap_check_full(void) > +{ > + unsigned long cur_pages = zswap_total_pages(); > + unsigned long thr = zswap_accept_thr_pages(); I know this looks neater, but it adds an extra division to the very common path where the limit hasn't been reached yet. It should really stay inside the branch. Another option could be to precalculate the max and the accept threshold in absolute pages whenever their respective module param changes. That would eliminate both divisions from the hot path. > + unsigned long max_pages = zswap_max_pages(); > + > + if (cur_pages >= max_pages) { > + zswap_pool_limit_hit++; > + zswap_pool_reached_full = true; > + } else if (zswap_pool_reached_full && cur_pages <= thr) { > + zswap_pool_reached_full = false; > + } > + return zswap_pool_reached_full; > +} > + > bool zswap_store(struct folio *folio) > { > swp_entry_t swp = folio->swap;