From patchwork Wed Jan 3 16:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 13510248 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 2055AC3DA6E for ; Wed, 3 Jan 2024 16:49:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C27C6B00B7; Wed, 3 Jan 2024 11:49:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 872118D006E; Wed, 3 Jan 2024 11:49:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 713F68D006C; Wed, 3 Jan 2024 11:49:19 -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 5D6486B00B7 for ; Wed, 3 Jan 2024 11:49:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 289DD1207AA for ; Wed, 3 Jan 2024 16:49:19 +0000 (UTC) X-FDA: 81638585238.17.3F05D3E Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf28.hostedemail.com (Postfix) with ESMTP id 670B8C000C for ; Wed, 3 Jan 2024 16:49:16 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VbymiBEv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704300556; 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=lwZZYWh+e0yk/cuTVxoiseyhi+aiBF9zz0tdKJ/4vMs=; b=Zci87C0J3irTr6k/iNbd/yTCTcALoanh7ukkMtRqZXxRILAV5sclL5g5QDzDqMJ7IgwBYP sowbKJPQVLqoX/C8g5FYs6gC3PCIEcj3J06+a5YedxipFJYQm0EEsRvDRst3F/g5lHD35/ gbTIlXpaLDgPAMkg0OiKX4Vzshc+pMQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VbymiBEv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704300556; a=rsa-sha256; cv=none; b=dR+jgX/1ds08QOWqKKHRYOdNjYIXmjPnBT6pSYvjJjomMkhLfc2ixZQk01dDEs+98F56vU oCAduwd7v7476nd4Q2RDrDcjEJK7TrD5cw9H5YEAQbfxQ8wpSaTsw8kEKHDsAnEu3bnrht yQkuniiyBeufA+WHkXxqbPyVUDhbI/I= Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dbdc52f2359so6672888276.3 for ; Wed, 03 Jan 2024 08:49:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704300555; x=1704905355; 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=lwZZYWh+e0yk/cuTVxoiseyhi+aiBF9zz0tdKJ/4vMs=; b=VbymiBEvOgoeOt101oaJzM+/Qo/BPKAgh/2Oc2iO0FUpFjljpzeNzyUr1wnZ3gs6JU JimS/pGDY3krJoLZoGVMALB3P6HSwjHbWtCx9JVV44PJEI/q5GyvinPeYQa4rmqMK6rv nIT0vMldfL2QPF5mQoQGKW+2H+kWW4Zw/NpQ2bLjMHaygvTUJkBihgtNF4RkDSZMZ4hq ApqK7qCnz9BtNRM5p9qb+cRq+EKaGMOQmnZNIi0X0P7USiuvtvvciVV1GCPQ0QixFnRT q5rm9pscQUWLFfQ8RLscyQMUM5ce3VK+V8PaDi+z7YNrJ+/J+VCI13X1nPUG2OH+l8/3 HHBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704300555; x=1704905355; 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=lwZZYWh+e0yk/cuTVxoiseyhi+aiBF9zz0tdKJ/4vMs=; b=RiUP3dsv7UobhtCzYvTvRCucp//UC2sJsjcQGx99VNk5iEEc6SKYvojKNUxS6iSwlB 7AHY/6QV/cl04a9RJbQUFqZKkArQ4VQcDZWB8mpUQ27IBc2bqbC5t632OwhfQ+2YVlcz ffUh1FZYaGKUBt/l26sosXrmnVheP0cI2iFl0qiTFtyfMcjXs6qyiWR53tHz9rdFWm2d XI9TbEWQO55zizoPJ/tJ/OrIhXv6iM9NLBwGktf207J+h1FWjkkj3lRH0N2gO3+JZQN7 gR27wif3p4wMYfnyj6B+yuSOkxeoqrg1QPYg5FeT7H2eo6bS0qP3QxfjDT3MgGgIBxes cORA== X-Gm-Message-State: AOJu0YxG0ASOJMjQlzUtGJf2j3DBEJHfgedYNtjkisr69+iq+Oj3ASCh gj2xjchOrNd6i/k4csRiguE= X-Google-Smtp-Source: AGHT+IGe4cxlLsn+e6P2JdgSr5WbR+2RuPxygGamlYxVp3FhQSYsh7zg529zAFbjlkOVWnvfCaAsxw== X-Received: by 2002:a25:ef52:0:b0:dbe:a003:a24a with SMTP id w18-20020a25ef52000000b00dbea003a24amr971520ybm.56.1704300555318; Wed, 03 Jan 2024 08:49:15 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:fcab]) by smtp.gmail.com with ESMTPSA id ci10-20020a05622a260a00b00427f1eeddccsm7362030qtb.38.2024.01.03.08.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 08:49:15 -0800 (PST) From: Dan Schatzberg To: Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, David Rientjes , Chris Li , Nhat Pham , Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , David Hildenbrand , Matthew Wilcox , Kefeng Wang , Dan Schatzberg , Yue Zhao , Yosry Ahmed , Hugh Dickins Subject: [PATCH v6 1/2] mm: add defines for min/max swappiness Date: Wed, 3 Jan 2024 08:48:36 -0800 Message-Id: <20240103164841.2800183-2-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240103164841.2800183-1-schatzberg.dan@gmail.com> References: <20240103164841.2800183-1-schatzberg.dan@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 670B8C000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7sn699d85ozr1yjm4g1xtr3zfxtikyhx X-HE-Tag: 1704300556-513520 X-HE-Meta: U2FsdGVkX18lqHnrSF0J2y5L9WZmgRgz1W52dJlQY+wRPy2XbQB8SMhFroPjHjb24l0QtgbeFrEkC41kCps9+DlxU9f8nuurHIRhcAu4BJVWwWs244q8Vc/yeqB8JawQ7Hjg1qZz7quDmFXsTSSFt3Sjthss8LBamqpOufnrzjFts9R6kW8b424oLSb9W5IEAVYeMYBLNvOmjolwWueP2HeYAWw5N6w4I+Mom1Ww7m0eXMBTYXFmgDR7CLmMr1iiA//yv9HGquM5cqNx6CHXcL1ORNRpIHgts9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+m5I+A3sWYERzhlEZQYPGlIWmXoKtJzqY3cDPQc1TAbBU0HipkKKuG7XGVcdGHQ37RIcBpDdmj6cOCWnDeyQpaG9yfKk1HTw1JPQoPmKxtLKJhnNFYHgwpml/ZWkhv30noZnbDiVXmxCVPglOKGr0VoD8Sm6zDUu4J6n87x0AQgHuxtp1CPoWf2Ud3mfgPP7L6Vf2lg23Pr9InopfF+X70n1vp128i6xQEEix6jilYvBCwrrWQkuCfTJVtG9YkMJJ 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 Acked-by: David Rientjes Acked-by: Chris Li Reviewed-by: Nhat Pham --- 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) {