From nobody Thu Dec 18 14:46:27 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7206C4167D for ; Wed, 13 Dec 2023 01:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378221AbjLMBiq (ORCPT ); Tue, 12 Dec 2023 20:38:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378215AbjLMBio (ORCPT ); Tue, 12 Dec 2023 20:38:44 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A32D5; Tue, 12 Dec 2023 17:38:50 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3ba10647a19so1859136b6e.3; Tue, 12 Dec 2023 17:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702431529; x=1703036329; darn=vger.kernel.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=yjbQsD2zw+AVOTOAO2gfbyL0vE9tzy1c44w2jRTtXIc=; b=WHLzrZunC8cATHiUYn8D8eRS3C9cwhfVmuPw5KeTC3zRyOIbvI1ERwrBKmmdTvQx5y D1lwqAA1Vv6K897KAMWcU3qO7aSa6f78EJv5eLxnLPWT3Rs93OiCryY+jHfQ9KDbn6n9 nt2u+A6bpdOS4SvUnka4m20YgH3UEw3UMTKfG7cCic4m09sn0+2f8e72BqudPiw3Hhh8 k/0vzhCdwCaX8t8BKQYMC8D1d/WdKkWmxeoQJlXIibezwNZs4PMbwnrfNbCx7TnvzT9z 3CDD00YRdOX1fDWSJJ+GYofbjrkpzJSkDVvViWru07xTNPicfGPOJ9X21LiZ8AYnlrWP JRRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702431529; x=1703036329; 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=yjbQsD2zw+AVOTOAO2gfbyL0vE9tzy1c44w2jRTtXIc=; b=RpHFdqe6r4CH15vRGpqSDCt2xM2FrO4ubllxqLyHmW/rd0RmX+B5RbKdraiH3wMq7k Jcn5UEUF8ghIGc16dkdIywOHJYTlKcxXd5qzTk0NJiLs0pUEtHx2wa4QHXsu+9mhDCZj hWrM86+eWpqf6cxEWk2L29UD9grnzyeZXBZoM25csFM62XRYerXml4Shcgn2rNIgHzzF JFr7QZLgypjREfBqS9dgodpcajiRs5yo1eeYldJrDns3NYC6DFg86BTyT+32wYkL54yR /wTZPccI+FWSKRotcB1+1XfSfQD2D+BjmZtF6jGN3jlnoR70hEN4+YO6Ysk9cW0vWX63 5UQQ== X-Gm-Message-State: AOJu0Yy3drsKXisipyZDWPP2f/Jwx45ANtpF8XTgT1QgGSK09pDQOxU2 mE5UFS16MwOOnhKdgVllTz4= X-Google-Smtp-Source: AGHT+IGgXLdoPr2KB+fyLYZzAHHRmPQQCEoDPHrM7vuygKI9CqqksVCR1GKYIffLffbC2ftpntZpnA== X-Received: by 2002:a05:6808:16a4:b0:3b8:b063:6bae with SMTP id bb36-20020a05680816a400b003b8b0636baemr8604954oib.93.1702431529213; Tue, 12 Dec 2023 17:38:49 -0800 (PST) Received: from localhost ([2620:10d:c090:500::7:1c76]) by smtp.gmail.com with ESMTPSA id u23-20020a62d457000000b006ce781f6f85sm9148130pfl.43.2023.12.12.17.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:38:48 -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 , David Hildenbrand , Matthew Wilcox , Chris Li , Kefeng Wang , Dan Schatzberg , Yue Zhao , Hugh Dickins Subject: [PATCH V4 1/2] mm: add defines for min/max swappiness Date: Tue, 12 Dec 2023 17:38:02 -0800 Message-Id: <20231213013807.897742-2-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213013807.897742-1-schatzberg.dan@gmail.com> References: <20231213013807.897742-1-schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 | 10 +++++----- 3 files changed, 8 insertions(+), 6 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, =20 #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 1c1061df9cd1..9748a6b88bb8 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 =3D mem_cgroup_from_css(css); =20 - if (val > 200) + if (val > MAX_SWAPPINESS) return -EINVAL; =20 if (!mem_cgroup_is_root(memcg)) diff --git a/mm/vmscan.c b/mm/vmscan.c index 506f8220c5fe..2aa671fe938b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2403,7 +2403,7 @@ static void get_scan_count(struct lruvec *lruvec, str= uct scan_control *sc, ap =3D swappiness * (total_cost + 1); ap /=3D anon_cost + 1; =20 - fp =3D (200 - swappiness) * (total_cost + 1); + fp =3D (MAX_SWAPPINESS - swappiness) * (total_cost + 1); fp /=3D file_cost + 1; =20 fraction[0] =3D ap; @@ -4400,7 +4400,7 @@ static int get_type_to_scan(struct lruvec *lruvec, in= t 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 - swappiness }; =20 /* * Compare the first tier of anon with that of file to determine which @@ -4444,7 +4444,7 @@ static int isolate_folios(struct lruvec *lruvec, stru= ct 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); @@ -5368,9 +5368,9 @@ static int run_cmd(char cmd, int memcg_id, int nid, u= nsigned long seq, =20 lruvec =3D get_lruvec(memcg, nid); =20 - if (swappiness < 0) + if (swappiness < MIN_SWAPPINESS) swappiness =3D get_swappiness(lruvec, sc); - else if (swappiness > 200) + else if (swappiness > MAX_SWAPPINESS) goto done; =20 switch (cmd) { --=20 2.34.1 From nobody Thu Dec 18 14:46:27 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51AA3C4332F for ; Wed, 13 Dec 2023 01:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378200AbjLMBi5 (ORCPT ); Tue, 12 Dec 2023 20:38:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378215AbjLMBix (ORCPT ); Tue, 12 Dec 2023 20:38:53 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE1710A; Tue, 12 Dec 2023 17:38:59 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b9ef61b6b8so3762595b6e.3; Tue, 12 Dec 2023 17:38:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702431539; x=1703036339; darn=vger.kernel.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=auvI36LUE8ejZAXPToUPGGocmqelYA9bY8VJoyIN2tw=; b=IwnO7soVBEqSAkQjjLNK/g5JAiebyrJxg7X998cLfg5aD/GClhDXTHiD+e+R//4Mc+ SJNnItClH9NV/Vjs9btJBOsFuZSCd+5arXhHGX+OOCFLX8iO+fIgMDzZOtvtLuaX9k2K zEC2j0QZqrIphcStjf3yGlSWZAke+dOjJ6Cq7je5xxGBOuZ4S6yL8Z2ukJniH1/VwiVL iIOICXpQjWFFQhLOi3E+cEh96bEwK8nl7KsXix4oVuRBgc/RyI6NRYCINfXZo4zmQr4z c/LvduMGEbuWPtDNmwAW7GbKYIAktnb3DDyl3M8DXUBummVp6sceg9Ok2yrbCaZawq2K VRLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702431539; x=1703036339; 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=auvI36LUE8ejZAXPToUPGGocmqelYA9bY8VJoyIN2tw=; b=IwNGIVy6yqFOw+ZT2Dri6dJg8I7ijvMMugou754jYQve0Brtq8cMxSsW7DcCYGW7f4 qbv6STlF8IiNclzXzpaRg+dGXVNTG3dwo1l2zSVXaxyaCU9qdUWjAQDqbNpBWlLwYLqY CuQb+Wuj7buMREYmjFgbsz3GyPDnZa49u26XwR+ATzhbd/1wBNtcZSCJeBq81nG3UueV B8ltUvwYPzvZan1MQ/roNC1JDKr6F16mxgLNHPDYDEJQCBU7Qf2sbHdVdlZahmV2cxFf x4bNLLURh2IcTni2APfDw8DcOlRrn1pH5PFyih0lE05Luk2r2RjSHS0Ilzix8ybo+xWr PIWg== X-Gm-Message-State: AOJu0YzsB6AJD2SezbDTJQG18jGVhWRcxevpFKbgUukb5LuczGEurMNc 4gm/FVQMhA/zqv3myhvqsLRQbG3AMSKhYw== X-Google-Smtp-Source: AGHT+IEPRFFkdSriOP29xRP3FC7OLv6jCpNAM8KRiqnpSneN+mERl09dXemtdfLzfx721QtwIbEe3Q== X-Received: by 2002:a05:6808:1998:b0:3b9:de63:f514 with SMTP id bj24-20020a056808199800b003b9de63f514mr9078746oib.12.1702431538693; Tue, 12 Dec 2023 17:38:58 -0800 (PST) Received: from localhost ([2620:10d:c090:500::7:1c76]) by smtp.gmail.com with ESMTPSA id z3-20020a1709028f8300b001d0242c0471sm9256526plo.224.2023.12.12.17.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:38:58 -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 , David Hildenbrand , Matthew Wilcox , Kefeng Wang , Dan Schatzberg , Yue Zhao , Hugh Dickins Subject: [PATCH V4 2/2] mm: add swapiness= arg to memory.reclaim Date: Tue, 12 Dec 2023 17:38:03 -0800 Message-Id: <20231213013807.897742-3-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213013807.897742-1-schatzberg.dan@gmail.com> References: <20231213013807.897742-1-schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Allow proactive reclaimers to submit an additional swappiness=3D argument to memory.reclaim. This overrides the global or per-memcg swappiness setting for that reclaim attempt. For example: echo "2M swappiness=3D0" > /sys/fs/cgroup/memory.reclaim will perform reclaim on the rootcg with a swappiness setting of 0 (no swap) regardless of the vm.swappiness sysctl setting. Signed-off-by: Dan Schatzberg --- Documentation/admin-guide/cgroup-v2.rst | 19 +++++--- include/linux/swap.h | 3 +- mm/memcontrol.c | 61 ++++++++++++++++++++----- mm/vmscan.c | 11 +++-- 4 files changed, 72 insertions(+), 22 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-= guide/cgroup-v2.rst index 3f85254f3cef..06319349c072 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1282,17 +1282,10 @@ PAGE_SIZE multiple when read back. This is a simple interface to trigger memory reclaim in the target cgroup. =20 - This file accepts a single key, the number of bytes to reclaim. - No nested keys are currently supported. - Example:: =20 echo "1G" > memory.reclaim =20 - The interface can be later extended with nested keys to - configure the reclaim behavior. For example, specify the - type of memory to reclaim from (anon, file, ..). - Please note that the kernel can over or under reclaim from the target cgroup. If less bytes are reclaimed than the specified amount, -EAGAIN is returned. @@ -1304,6 +1297,18 @@ PAGE_SIZE multiple when read back. This means that the networking layer will not adapt based on reclaim induced by memory.reclaim. =20 +The following nested keys are defined. + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + swappiness Swappiness value to reclaim with + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + + Specifying a swappiness value instructs the kernel to perform + the reclaim with that swappiness value. Note that this has the + same semantics as the vm.swappiness sysctl - it sets the + relative IO cost of reclaiming anon vs file memory but does + not allow for reclaiming specific amounts of anon or file memory. + memory.peak A read-only single value file which exists on non-root cgroups. diff --git a/include/linux/swap.h b/include/linux/swap.h index e2ab76c25b4a..690898c347de 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -412,7 +412,8 @@ extern unsigned long try_to_free_pages(struct zonelist = *zonelist, int order, extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, unsigned long nr_pages, gfp_t gfp_mask, - unsigned int reclaim_options); + unsigned int reclaim_options, + int swappiness); extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem, gfp_t gfp_mask, bool noswap, pg_data_t *pgdat, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9748a6b88bb8..be3d5797d9df 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include "internal.h" #include @@ -2449,7 +2450,8 @@ static unsigned long reclaim_high(struct mem_cgroup *= memcg, psi_memstall_enter(&pflags); nr_reclaimed +=3D try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, - MEMCG_RECLAIM_MAY_SWAP); + MEMCG_RECLAIM_MAY_SWAP, + mem_cgroup_swappiness(memcg)); psi_memstall_leave(&pflags); } while ((memcg =3D parent_mem_cgroup(memcg)) && !mem_cgroup_is_root(memcg)); @@ -2740,7 +2742,8 @@ static int try_charge_memcg(struct mem_cgroup *memcg,= gfp_t gfp_mask, =20 psi_memstall_enter(&pflags); nr_reclaimed =3D try_to_free_mem_cgroup_pages(mem_over_limit, nr_pages, - gfp_mask, reclaim_options); + gfp_mask, reclaim_options, + mem_cgroup_swappiness(memcg)); psi_memstall_leave(&pflags); =20 if (mem_cgroup_margin(mem_over_limit) >=3D nr_pages) @@ -3660,7 +3663,8 @@ static int mem_cgroup_resize_max(struct mem_cgroup *m= emcg, } =20 if (!try_to_free_mem_cgroup_pages(memcg, 1, GFP_KERNEL, - memsw ? 0 : MEMCG_RECLAIM_MAY_SWAP)) { + memsw ? 0 : MEMCG_RECLAIM_MAY_SWAP, + mem_cgroup_swappiness(memcg))) { ret =3D -EBUSY; break; } @@ -3774,7 +3778,8 @@ static int mem_cgroup_force_empty(struct mem_cgroup *= memcg) return -EINTR; =20 if (!try_to_free_mem_cgroup_pages(memcg, 1, GFP_KERNEL, - MEMCG_RECLAIM_MAY_SWAP)) + MEMCG_RECLAIM_MAY_SWAP, + mem_cgroup_swappiness(memcg))) nr_retries--; } =20 @@ -6720,7 +6725,8 @@ static ssize_t memory_high_write(struct kernfs_open_f= ile *of, } =20 reclaimed =3D try_to_free_mem_cgroup_pages(memcg, nr_pages - high, - GFP_KERNEL, MEMCG_RECLAIM_MAY_SWAP); + GFP_KERNEL, MEMCG_RECLAIM_MAY_SWAP, + mem_cgroup_swappiness(memcg)); =20 if (!reclaimed && !nr_retries--) break; @@ -6769,7 +6775,8 @@ static ssize_t memory_max_write(struct kernfs_open_fi= le *of, =20 if (nr_reclaims) { if (!try_to_free_mem_cgroup_pages(memcg, nr_pages - max, - GFP_KERNEL, MEMCG_RECLAIM_MAY_SWAP)) + GFP_KERNEL, MEMCG_RECLAIM_MAY_SWAP, + mem_cgroup_swappiness(memcg))) nr_reclaims--; continue; } @@ -6895,6 +6902,16 @@ static ssize_t memory_oom_group_write(struct kernfs_= open_file *of, return nbytes; } =20 +enum { + MEMORY_RECLAIM_SWAPPINESS =3D 0, + MEMORY_RECLAIM_NULL, +}; + +static const match_table_t tokens =3D { + { MEMORY_RECLAIM_SWAPPINESS, "swappiness=3D%d"}, + { MEMORY_RECLAIM_NULL, NULL }, +}; + static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -6902,12 +6919,33 @@ static ssize_t memory_reclaim(struct kernfs_open_fi= le *of, char *buf, unsigned int nr_retries =3D MAX_RECLAIM_RETRIES; unsigned long nr_to_reclaim, nr_reclaimed =3D 0; unsigned int reclaim_options; - int err; + char *old_buf, *start; + substring_t args[MAX_OPT_ARGS]; + int swappiness =3D mem_cgroup_swappiness(memcg); =20 buf =3D strstrip(buf); - err =3D page_counter_memparse(buf, "", &nr_to_reclaim); - if (err) - return err; + + old_buf =3D buf; + nr_to_reclaim =3D memparse(buf, &buf) / PAGE_SIZE; + if (buf =3D=3D old_buf) + return -EINVAL; + + buf =3D strstrip(buf); + + while ((start =3D strsep(&buf, " ")) !=3D NULL) { + if (!strlen(start)) + continue; + switch (match_token(start, tokens, args)) { + case MEMORY_RECLAIM_SWAPPINESS: + if (match_int(&args[0], &swappiness)) + return -EINVAL; + if (swappiness < MIN_SWAPPINESS || swappiness > MAX_SWAPPINESS) + return -EINVAL; + break; + default: + return -EINVAL; + } + } =20 reclaim_options =3D MEMCG_RECLAIM_MAY_SWAP | MEMCG_RECLAIM_PROACTIVE; while (nr_reclaimed < nr_to_reclaim) { @@ -6926,7 +6964,8 @@ static ssize_t memory_reclaim(struct kernfs_open_file= *of, char *buf, =20 reclaimed =3D try_to_free_mem_cgroup_pages(memcg, min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), - GFP_KERNEL, reclaim_options); + GFP_KERNEL, reclaim_options, + swappiness); =20 if (!reclaimed && !nr_retries--) return -EAGAIN; diff --git a/mm/vmscan.c b/mm/vmscan.c index 2aa671fe938b..cfef06c7c23f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -136,6 +136,9 @@ struct scan_control { /* Always discard instead of demoting to lower tier memory */ unsigned int no_demotion:1; =20 + /* Swappiness value for reclaim */ + int swappiness; + /* Allocation order */ s8 order; =20 @@ -2327,7 +2330,7 @@ static void get_scan_count(struct lruvec *lruvec, str= uct scan_control *sc, struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); unsigned long anon_cost, file_cost, total_cost; - int swappiness =3D mem_cgroup_swappiness(memcg); + int swappiness =3D sc->swappiness; u64 fraction[ANON_AND_FILE]; u64 denominator =3D 0; /* gcc */ enum scan_balance scan_balance; @@ -2608,7 +2611,7 @@ static int get_swappiness(struct lruvec *lruvec, stru= ct scan_control *sc) mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH) return 0; =20 - return mem_cgroup_swappiness(memcg); + return sc->swappiness; } =20 static int get_nr_gens(struct lruvec *lruvec, int type) @@ -6433,7 +6436,8 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgrou= p *memcg, unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, unsigned long nr_pages, gfp_t gfp_mask, - unsigned int reclaim_options) + unsigned int reclaim_options, + int swappiness) { unsigned long nr_reclaimed; unsigned int noreclaim_flag; @@ -6448,6 +6452,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem= _cgroup *memcg, .may_unmap =3D 1, .may_swap =3D !!(reclaim_options & MEMCG_RECLAIM_MAY_SWAP), .proactive =3D !!(reclaim_options & MEMCG_RECLAIM_PROACTIVE), + .swappiness =3D swappiness, }; /* * Traverse the ZONELIST_FALLBACK zonelist of the current node to put --=20 2.34.1