Received: by 2002:a05:7412:a9a8:b0:f9:92ae:e617 with SMTP id o40csp106263rdh; Wed, 20 Dec 2023 18:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVqgC2Yy3l1Sx3Y1MUypSsI3IgfPa7NPj2lQS7LB8wVYNo15V+w7LnLIb0Ab0MojerJDIV X-Received: by 2002:a0c:c788:0:b0:67a:a721:7837 with SMTP id k8-20020a0cc788000000b0067aa7217837mr19330302qvj.92.1703124096379; Wed, 20 Dec 2023 18:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703124096; cv=none; d=google.com; s=arc-20160816; b=0H2Kl2LCyMf2XUaI/8q2So6IRBph1Ct1YaffZ27ojzw44eHdkmAvbG5J5jy7zUQpET PIFiemuUSFBvlSQOojF8ChDKwUHt8XDqlhJuEYC1A9ed6Fn489ixlXfI1IsjncnMoX1J 7xahM0XuaZQJ2+PZiIGCRvVB4SKnlPWn/0VZy50MWLHy7/f2SeDE0J65YnhcZxITQ7jB rOKuaWi0SX9AC4gj1FfJHvt27h8aUCeKgA0PdU9Sssz0uQdmD2YW5AkLWungzM9UsVa7 7PSLyqkHRJIwGZM01V1CbikzVzTYcUrZG21yObuqC/4pLDYsxYhTH5FZBBz9CZA+g0so V6PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=7uprnz/jjYuy4jWp8M6YseVkbWg8KRWXhaIAky0jmfE=; fh=6yCUF0GPOQLA3FTISlCxf0eZIMZWOwADStEQCvoDFMs=; b=l/ADBUO6mfuoR6VwVP3ipTEOq9UhPcYXvqWluMRNmXYkb6+Rb/A06+wQetOBOgXQbl IesvxKdpFvSfRC0z3Z9Xxb9xUTE78SEuwbrkZrt/j4fHfZ4fVezhK5BxQlHbNEMthHjy tqHPwQRFj7l0cRzT5X+ZvXLzhH2tQKSQA3ik9HwMKHL8EetSAHZTlG0quiaCodsgcIRm 1HcZagWrLC8JhYaQ+OobmIEV2vwbKBkJPvwyhqsxhE9HidXyPf2jtaHLqLURSo/rQUSi J7Y/DgV4n2w+d3MIKcjLQG20jnf9JwRh4H0zNwP+Ba9+Ros+MtS54v04wzCGlFxyawe0 838g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fvl5fdhk; spf=pass (google.com: domain of linux-kernel+bounces-7739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d14-20020a0cf0ce000000b0067aa5efad4fsi1144897qvl.192.2023.12.20.18.01.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 18:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fvl5fdhk; spf=pass (google.com: domain of linux-kernel+bounces-7739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 15F781C21CF8 for ; Thu, 21 Dec 2023 02:01:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 296C3A947; Thu, 21 Dec 2023 02:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fvl5fdhk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (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 0619C945A; Thu, 21 Dec 2023 02:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7b7fdde8b54so12756439f.1; Wed, 20 Dec 2023 18:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703124085; x=1703728885; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7uprnz/jjYuy4jWp8M6YseVkbWg8KRWXhaIAky0jmfE=; b=fvl5fdhkGCMSY4JACtoE5vZEE0OZ5mvM5hc/zaI0tobA2ZmXV0w5QWqYAXIhfvhdR3 qzee0RVDbtCM6+9YCwFYnS+/mP+MQdmFdg19YU15PCKZC+6VjmXgqkwL/g4KjsfW4Ibk 0odUQKp38Rqic+FTfD+FLUUhzBq3F4lW1DGqJXJpLNI+/g85mA+D2qVwZECHiUhbtbjd 1C4pxbpuBXD+u94iW/HadP649b/wmqI14iI1JJE0cr2YQr9QLdWc8bLcHPbxhF8ZUxQH xoKGZKIgzltMwZMGS6eRkB9B1CcmJkerTpE2ztDeV5dj1kBcszWdZSmXYX7gNDIj7/65 l0GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703124085; x=1703728885; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7uprnz/jjYuy4jWp8M6YseVkbWg8KRWXhaIAky0jmfE=; b=QmkDB2coY1A7hecqxdYSm8mnXFiM4d6nQDmU7iktU+AYFQPiQjuSxiGzPRXIyb2nn6 E0r13MTApr1wtySm71cq0kTYVojFFlRjFb7yVfTqf2Oq7Vu6fCRrtXa+1cjB2j6dJwQT iP0hl1pUVFDg1H3mPCudWX6vnXRR25qwx2TI/aJU3xwjtH1wIrTAdAWyuOe4Zsdb4wpt IfAbBVnare7cGOAWHQ/dwnfaBV+rzi4Nj52epboRdRkUyFD+5TVi8WqkPZwO1POF0fvL 3bbAUcw9gbI1KVCH8xAuT3b4eiZGRofXBGtttYVGjbLJmximCtfejLWYGJRvGpQYFtjU wsjA== X-Gm-Message-State: AOJu0YxPh0MDMn7wQPtygLkLttPWqW/4j5+Znwrg3YO0Iz20hAsxTtq7 ztzT3qrV6rf6lDYokq4K3l6PhDFMkU/zz0XMqX0= X-Received: by 2002:a6b:3f56:0:b0:7b9:232c:eeb3 with SMTP id m83-20020a6b3f56000000b007b9232ceeb3mr2763300ioa.6.1703124084910; Wed, 20 Dec 2023 18:01:24 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220152653.3273778-1-schatzberg.dan@gmail.com> <20231220152653.3273778-2-schatzberg.dan@gmail.com> In-Reply-To: <20231220152653.3273778-2-schatzberg.dan@gmail.com> From: Nhat Pham Date: Wed, 20 Dec 2023 18:01:14 -0800 Message-ID: Subject: Re: [PATCH v5 1/2] mm: add defines for min/max swappiness To: Dan Schatzberg Cc: Johannes Weiner , Roman Gushchin , Yosry Ahmed , Huan Yang , 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)" , Yue Zhao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 20, 2023 at 7:27=E2=80=AFAM Dan Schatzberg wrote: > > 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 > --- > 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 zonelis= t *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 *mem= cg, > 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 cgrou= p_subsys_state *css, > { > struct mem_cgroup *memcg =3D 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 =3D 60; > > @@ -2403,7 +2403,7 @@ static void get_scan_count(struct lruvec *lruvec, s= truct scan_control *sc, > ap =3D swappiness * (total_cost + 1); > ap /=3D anon_cost + 1; > > - fp =3D (200 - swappiness) * (total_cost + 1); > + fp =3D (MAX_SWAPPINESS - swappiness) * (total_cost + 1); > fp /=3D file_cost + 1; > > fraction[0] =3D 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] =3D { swappiness, 200 - swappiness }; > + int gain[ANON_AND_FILE] =3D { swappiness, MAX_SWAPPINESS - swappi= ness }; > > /* > * Compare the first tier of anon with that of file to determine = which > @@ -4436,7 +4436,7 @@ static int isolate_folios(struct lruvec *lruvec, st= ruct scan_control *sc, int sw > /* > * Try to make the obvious choice first. When anon and file are b= oth > * 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 =3D LRU_GEN_FILE; > @@ -4444,7 +4444,7 @@ static int isolate_folios(struct lruvec *lruvec, st= ruct scan_control *sc, int sw > type =3D LRU_GEN_ANON; > else if (swappiness =3D=3D 1) > type =3D LRU_GEN_FILE; > - else if (swappiness =3D=3D 200) > + else if (swappiness =3D=3D MAX_SWAPPINESS) > type =3D LRU_GEN_ANON; > else > type =3D 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 =3D get_lruvec(memcg, nid); > > - if (swappiness < 0) > + if (swappiness < MIN_SWAPPINESS) > swappiness =3D get_swappiness(lruvec, sc); > - else if (swappiness > 200) > + else if (swappiness > MAX_SWAPPINESS) > goto done; > > switch (cmd) { > -- > 2.39.3 > Sorry for being late to the party :) Was preoccupied with zswap convos. Hmm these are all the occurrences of 0 and 200 (in the context of swappiness) I can dig out. So, FWIW: Reviewed-by: Nhat Pham