From patchwork Wed Dec 20 15:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 13500245 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 B596CC3DA6E for ; Wed, 20 Dec 2023 15:27:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CEF86B0088; Wed, 20 Dec 2023 10:27:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 457A36B0089; Wed, 20 Dec 2023 10:27:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 282E76B008A; Wed, 20 Dec 2023 10:27:11 -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 126096B0088 for ; Wed, 20 Dec 2023 10:27:11 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DE47E1A04BB for ; Wed, 20 Dec 2023 15:27:10 +0000 (UTC) X-FDA: 81587575020.14.A918245 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 157002001F for ; Wed, 20 Dec 2023 15:27:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DQvNJziX; spf=pass (imf03.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703086029; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=59LZCmYd65g0ypkperKKK/kJ8MVLAq87LEnhd0/0rRY=; b=vZ6gJWkxc/YrrBpXqfMx/1cmBK5sEpStgwz/v1e9qnl3s1+F4M8uyDRTYz0AF7FWlRX6bd 8PX0YJYEhoaTFeMJFsZKg9ZppZFcOaIcSvuxxcDz+zKFy42fowO7oqkrOZ6I1PXchCu5Am AhGSNTHFkXCaip7m/rgID2xi+Nt9m08= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703086029; a=rsa-sha256; cv=none; b=r8WjAiG3R5gmcOebTqchL9/buXJpPWynG/Zz6lhYeJKkqoq28R6pLzsMsY+H7qRCk5/qCJ hCyZNKgOekY3e3Uqr+tuPxOCTtkxSc4qNPphYYH+ULR0mAISAIpBV4Pet4+uM4yRCt16Nh UYJ7OGJP2SDCbcY55xDNwFmSRQx6Gqs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DQvNJziX; spf=pass (imf03.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3ba00fe4e94so4572834b6e.1 for ; Wed, 20 Dec 2023 07:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703086028; x=1703690828; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=59LZCmYd65g0ypkperKKK/kJ8MVLAq87LEnhd0/0rRY=; b=DQvNJziXPeJmbEriFzjNZzGbUkHmchN8N+tCOqzTbevN8g7uNpX48ZJ/t6HCk7/wfX zsBxFbCBVZdrEPMSOiwBwaZJ0/r5q6ooMB6KZ1Ug60JWEZOgZ/dqfPHJlu71AoBB/fjG BKZu7MNNmlre4gfQ2UV0AyJOXCBkMRy/cQf0wOi42FXGQZQEPlOzIsGmP0tLKxhsBcuB QuB2PRruoNezDGXi7NFZHi8XoIAYZzpRvqKJhp2pJaz+5ov+//RqmKi2MSM9LS75wvvQ KQ9gexyVm2zI15LW9F3naiCgl1p+IPOFLJIFj1cQrzmvclndt78CvWBaC+sr43Qe2gGO G1fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703086028; x=1703690828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=59LZCmYd65g0ypkperKKK/kJ8MVLAq87LEnhd0/0rRY=; b=loElUZW+AlpdZdVxCwNQyl17tOVKfq2GYRto0TG8XDq/eppzOZQfvlAszxS4VAIHbp 7zKwtNecMF4/jSPF+G1qjEX0d479k622y+yYJRcigXhhhK7A7ZdcVIDJyRz2qGsX0R8f 4oZMZ72txPZxVY6XRN39HXcuczDw58utB8wUpXXaVJbK0kQkSBqYsegFvsxVzKd7QRG9 NgN9kPtlpt2V5KeiUi5m18/QLKd0FIX7Z2VJQPXL9qj7X6K4nLZkisU/20ruBMofBjTU IrRH87ibREcc27ACsXCCe7rzw/bmPvrDBXKcQW2GjHtwjNsfi3RS46QPQnIt0ov0RoEA B1ow== X-Gm-Message-State: AOJu0Yztc6Bq2iGV48AoVabY/FXedl7wfXBtQ9DEB6Ic/rDVQzb80RyR b6LQvYyw+MWPJSq+6EJb1Io= X-Google-Smtp-Source: AGHT+IH48x/lOXdg5JUxZV/lLg8CrWcbuR3qeufJmbXflf5jebTrUVeALmaxLuoHMFc2j402sC1Y/A== X-Received: by 2002:a05:6808:16a0:b0:3bb:535d:27ed with SMTP id bb32-20020a05680816a000b003bb535d27edmr4751625oib.86.1703086027982; Wed, 20 Dec 2023 07:27:07 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:1124]) by smtp.gmail.com with ESMTPSA id k4-20020ad44504000000b0067f6a9a446esm743093qvu.136.2023.12.20.07.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 07:27:07 -0800 (PST) From: Dan Schatzberg To: Johannes Weiner , Roman Gushchin , Yosry Ahmed , Huan Yang Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Tejun Heo , Zefan Li , Jonathan Corbet , Michal Hocko , Shakeel Butt , Muchun Song , Andrew Morton , Kefeng Wang , SeongJae Park , "Vishal Moola (Oracle)" , Nhat Pham , Yue Zhao Subject: [PATCH v5 1/2] mm: add defines for min/max swappiness Date: Wed, 20 Dec 2023 07:26:50 -0800 Message-Id: <20231220152653.3273778-2-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231220152653.3273778-1-schatzberg.dan@gmail.com> References: <20231220152653.3273778-1-schatzberg.dan@gmail.com> MIME-Version: 1.0 X-Stat-Signature: umh5goeiog7hpbmmk8sqz6ry1hngk4dt X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 157002001F X-Rspam-User: X-HE-Tag: 1703086028-668571 X-HE-Meta: U2FsdGVkX1/DrNVib92Sc4mvrTD9INn+tSb9rJv4TQWv0EU7J897u3AmH4fuEGmn4+dg91H6hgExXNz5XoAm1SsDPs8dscF3I5+yxCsNUB5ncrgNOOAI0mjwVDi6k2slDWbZJq4rphzlYQ3oT4oKcDNNh2UIgzR6shrf0mwMRfyzt0ubOYAqPyc6wvzhN4lm6rDootrGts5qDCHJDdXv0qtcWIXbmRwGj/41V4+924qc4uCbJK7pX8NyfkLRFdjvvBTln92epAfiBSBsUMv+QdUj2gcXLrpfSVJAJlnCKXafHi56fUoKxVJ4vj8NDrkBdt1yAgPO1n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zAgT+eMCqz7q2qWJ8gnJe9hjpuoWRS1vupQEC1aa/Zmo4LGUF0UXSSMbjPhZcM06r8EiX9alDrmw1q3WLLFnFvhND6zhc/zZY8YSAF18ZegBmAk1b5nZD6c6kPQ1IAfCGioJ2O3SHDyw== 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: We use the constants 0 and 200 in a few places in the mm code when referring to the min and max swappiness. This patch adds MIN_SWAPPINESS and MAX_SWAPPINESS #defines to improve clarity. There are no functional changes. Signed-off-by: Dan Schatzberg Reviewed-by: Nhat Pham Acked-by: David Rientjes Acked-by: Chris Li --- include/linux/swap.h | 2 ++ mm/memcontrol.c | 2 +- mm/vmscan.c | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index f6dd6575b905..e2ab76c25b4a 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -407,6 +407,8 @@ extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order, #define MEMCG_RECLAIM_MAY_SWAP (1 << 1) #define MEMCG_RECLAIM_PROACTIVE (1 << 2) +#define MIN_SWAPPINESS 0 +#define MAX_SWAPPINESS 200 extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, unsigned long nr_pages, gfp_t gfp_mask, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b226090fd906..fbe9f02dd206 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4337,7 +4337,7 @@ static int mem_cgroup_swappiness_write(struct cgroup_subsys_state *css, { struct mem_cgroup *memcg = mem_cgroup_from_css(css); - if (val > 200) + if (val > MAX_SWAPPINESS) return -EINVAL; if (!mem_cgroup_is_root(memcg)) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9dd8977de5a2..d91963e2d47f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -183,7 +183,7 @@ struct scan_control { #endif /* - * From 0 .. 200. Higher means more swappy. + * From 0 .. MAX_SWAPPINESS. Higher means more swappy. */ int vm_swappiness = 60; @@ -2403,7 +2403,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, ap = swappiness * (total_cost + 1); ap /= anon_cost + 1; - fp = (200 - swappiness) * (total_cost + 1); + fp = (MAX_SWAPPINESS - swappiness) * (total_cost + 1); fp /= file_cost + 1; fraction[0] = ap; @@ -4400,7 +4400,7 @@ static int get_type_to_scan(struct lruvec *lruvec, int swappiness, int *tier_idx { int type, tier; struct ctrl_pos sp, pv; - int gain[ANON_AND_FILE] = { swappiness, 200 - swappiness }; + int gain[ANON_AND_FILE] = { swappiness, MAX_SWAPPINESS - swappiness }; /* * Compare the first tier of anon with that of file to determine which @@ -4436,7 +4436,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw /* * Try to make the obvious choice first. When anon and file are both * available from the same generation, interpret swappiness 1 as file - * first and 200 as anon first. + * first and MAX_SWAPPINESS as anon first. */ if (!swappiness) type = LRU_GEN_FILE; @@ -4444,7 +4444,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw type = LRU_GEN_ANON; else if (swappiness == 1) type = LRU_GEN_FILE; - else if (swappiness == 200) + else if (swappiness == MAX_SWAPPINESS) type = LRU_GEN_ANON; else type = get_type_to_scan(lruvec, swappiness, &tier); @@ -5398,9 +5398,9 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq, lruvec = get_lruvec(memcg, nid); - if (swappiness < 0) + if (swappiness < MIN_SWAPPINESS) swappiness = get_swappiness(lruvec, sc); - else if (swappiness > 200) + else if (swappiness > MAX_SWAPPINESS) goto done; switch (cmd) {