Received: by 10.213.65.68 with SMTP id h4csp465244imn; Fri, 23 Mar 2018 08:21:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELt3IrTd+wA6WUom5dUfTb0NF3+asSox2cboSTidxpoXO9H4Sz2akYjjb9OF0Aj/+3l8/8q1 X-Received: by 10.99.124.1 with SMTP id x1mr21019796pgc.318.1521818500958; Fri, 23 Mar 2018 08:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521818500; cv=none; d=google.com; s=arc-20160816; b=qn65yY1Bo6qXPHxYy1qFtKJ4C8Gb1CDa051C6Qk3nye16AcfvPaA5zOpv4U1zSqvYk 3wHjTQHDlsB0FAz6LhiGQ/3f7eNrv1ibnQAl+tDJtUo9qeuGlYFOSAPiEJjcd+Txml73 FWs6gMLMjsfXLhje5IwoOLv6Z7/gkRglSEHkbCb7loUgbTECz+oPMDxP4BZKHBPIRMLP QCRZ4ypLQO/hFlGjX9Drb/iSWD4ly089O71cv7vL2XbJZ2wtiNZzxn1RnLveaPTgMqnM zZdeVvbx+cC8GaUBFMzngqnOFlquszT8TWNEMKX04YbD9WAkvqQIvAUvnGUc1geSxkPV BqXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tFswJKZn2xYr8/Ksl/EFVFlpKBm1NfyvMU4bfGM7uIw=; b=FvP1fQIVxSK5T1JsMYF1uSLOkoV6AA7fTVogjY/u7vcOQcnOqHxNIZz6bf4FvGF9gp Saz7aF094leXhLLNEH9v4vTbb5cLKd7+LFZQmGjft0mGWeY2Yb0TYq/aXh6LsPBnY5jn SWdLHxuDEeLChzAPqpZDKxVL2XTlNBMGvpFrdJXYmU9y1TcOpojYHtmJzKg6SFJOnyXh XLHa0vSoozQvLCR1vMbTABLUqlLWisyOuUn8dt0f6njDXgVG+XVtxOIbk26tHvHtcUUV mZngm3yMB3aS+ZZwRJqERvtefIdYJUsJC/0eLKebPu/TVgeapiZHPRdUMDqfKYNKMVKm 6egw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=KbSWUby8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si6711289pfh.197.2018.03.23.08.21.25; Fri, 23 Mar 2018 08:21:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=KbSWUby8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752077AbeCWPUP (ORCPT + 99 others); Fri, 23 Mar 2018 11:20:15 -0400 Received: from mail-he1eur01on0107.outbound.protection.outlook.com ([104.47.0.107]:19840 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751686AbeCWPUK (ORCPT ); Fri, 23 Mar 2018 11:20:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tFswJKZn2xYr8/Ksl/EFVFlpKBm1NfyvMU4bfGM7uIw=; b=KbSWUby8F53pdPJxQHgNfKvH8Dpsc8W1qoBw0RmudvyS2/9dAW0AIc00eKIjgjXt5F7t1SEY6lplXgzHKbxRzfM4uWO6iu+EjJ4GmkesvFY1OfhVsYiLWRewvTFIFFq0KxN/XnQxpXAFHmSNzzBKYZUOMNt33EN0RiW7cV4gpp0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aryabinin@virtuozzo.com; Received: from i7.sw.ru (195.214.232.6) by AM6PR08MB3253.eurprd08.prod.outlook.com (2603:10a6:209:47::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Fri, 23 Mar 2018 15:20:03 +0000 From: Andrey Ryabinin To: Andrew Morton Cc: Andrey Ryabinin , Mel Gorman , Tejun Heo , Johannes Weiner , Michal Hocko , Shakeel Butt , Steven Rostedt , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: [PATCH v2 4/4] mm/vmscan: Don't mess with pgdat->flags in memcg reclaim. Date: Fri, 23 Mar 2018 18:20:29 +0300 Message-Id: <20180323152029.11084-5-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180323152029.11084-1-aryabinin@virtuozzo.com> References: <20180323152029.11084-1-aryabinin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0101CA0011.eurprd01.prod.exchangelabs.com (2603:10a6:3:77::21) To AM6PR08MB3253.eurprd08.prod.outlook.com (2603:10a6:209:47::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a2ce2df-7c32-401a-8b1d-08d590d18d80 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:AM6PR08MB3253; X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3253;3:h6eD6XXGglMVg/zV/L8FYYY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LkhkKHWVHi8y+tLHd4k46T6qKQprHZl/GwKc/Rxp+6aB9uz3jporAEB6vzM0gR8LMbXR6Gn2NaMJV+5Gjc4HTwNutfBiQdr/lbIPejg08mv26jgW92+MX1lI9iPfUCI5iY6tlT4NDJ37qbdVuD1OwIYzBqnzVdkKhAJR7pd+CJxnCykGFy07F1Oc0B/IRTSSW2ZlD6OgC8t4Hba2Ak3rj/RiV/2KUzhL3jToYlfjGoq6xmsIhbA481tRTyP7brsz4+EYx+TcOUg1VTY8/6krUnrA0FRs4kj1ogH3P1TMuKSRDn4i9qhOL46BB5n2voUPUpezAeu/;4:rkq0J54HLr1sAR89OH3hg+aUYzVYorl6dsLpozKBcZpKO4T0civNy7QSwfGPXbPQYYrUfvCLBITfSC9PlYiilFZElH9MQgG7MjBLl3/FvQpv6cdkURP3A2Q/sZKMP6zb34VTSOQ5orAeaE2KT89KB/thWskl9KXg/vnV/TvFEmUsByFrKXRXYkdl4/2B/y3LoBRsFFBFm5tSTwFcxADggsecIn9r0TwPIs3SE3P/Y4NF6JbpfOJWHZO18cZw4uljZVb+dq71GIAw7OVuiLRPJQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:AM6PR08MB3253;BCL:0;PCL:0;RULEID:;SRVR:AM6PR08MB3253; X-Forefront-PRVS: 0620CADDF3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(39850400004)(39380400002)(366004)(396003)(376002)(189003)(199004)(36756003)(25786009)(186003)(97736004)(1076002)(3846002)(53416004)(478600001)(48376002)(11346002)(50466002)(66066001)(47776003)(105586002)(106356001)(53936002)(305945005)(6512007)(4326008)(7736002)(50226002)(575784001)(81156014)(8936002)(52116002)(6666003)(54906003)(76176011)(81166006)(386003)(86362001)(6506007)(7416002)(2906002)(59450400001)(51416003)(316002)(68736007)(55236004)(6486002)(446003)(6116002)(6916009)(5660300001)(16586007)(8676002)(26005)(16526019);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR08MB3253;H:i7.sw.ru;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM6PR08MB3253;23:+FEZRthZUDeqs8XlLjiNmqT/O7iq38oV0yj7jMUpB?= =?us-ascii?Q?MDouzUYbS089J/x7M99ve66h8VjSdPUg42TjVBUtFIsbniApiTe5lQvMWHL3?= =?us-ascii?Q?oPoCzVhJlXjx///Fbu4FIwb+6FEzwhgKfV9rRAUA/pGAjTNSehretenA5u1I?= =?us-ascii?Q?4z9j0D8IahdLHsbCsZbq7xc+LG/C1+Du80zKdaNIHKSnASqEp15+vOQNTyi+?= =?us-ascii?Q?1DBDu8koiMb4JhDQc/ZTfmahqWTecE7YKwxmZon+RxkOHQ36hD26NmwuJ7oW?= =?us-ascii?Q?qCQXj568K4isMQnp1lQwi4oWILJvi2EhQaECtRX0uJMbF+aGkfAE5BKa6JhO?= =?us-ascii?Q?Kd/X0FAaKRe1HK3dakj1oZ+CZ60bqR9xKTVJF8buHbfIkLWYPeXmOYNqA7LJ?= =?us-ascii?Q?2QcWeQ2By5/qTyWFn8FVPtrK59pLIMD9KYY8gN4N+1URrhnWh38FCL4Iw1Bo?= =?us-ascii?Q?Fw3lj/utJNK8qV/axqE6Gv2nPOtkVkXLLG22IoH4dtAC3kzws7WzFFsKX36R?= =?us-ascii?Q?CyhQxOHc39JQcqbrG95rvEFJrgmft1gkghBsYS3ERZif6x/7yk9O5TSgc6XD?= =?us-ascii?Q?qskrjxtEhTcQlak8GXYyEXZN7P7QVeyYXBA1/7w3HIFHag5cO7crHa3pUu4y?= =?us-ascii?Q?l01ncStR4rpIBNhhvu5hHHFDumhSSWyrdTBGYtsm/xBoF3z/HHdE5L4UEC6q?= =?us-ascii?Q?P0m75I2qBpNTCTyrLcTp/XFxEHhFRjQhICKWSiMObL6FUX97N4TVaB4qVl5j?= =?us-ascii?Q?TgbWsKHxx2z79or6K7h1URU8lJ0WdKfUhtR+w/FX0n4xo5kRR0F6f5/XXkSc?= =?us-ascii?Q?w21AKlg45JSwobuC/je4bVok1tLgRkpUxej13mee5dP50AOLBUVOZCZGTodU?= =?us-ascii?Q?HlIjZMBTpkFIGvtpQktvIaU2ooQQQJyfDs/g8tW0UYu36+/VArqEd/ESFOD8?= =?us-ascii?Q?Iy5rc1J6pmctMPuBQ6lyawp9v6FyOWdsmYcSdRC6xYYoX8AfgpN+9Jlp+uwc?= =?us-ascii?Q?gpdXFe9V0LRWpb7mSw+XvSRLcfjdJXJ9NOkrEXdZ13UegMuB84T6fx3xLbNS?= =?us-ascii?Q?RKMnHSPDvFiXMe078gQF+R4AHZZXvFwUr6Z1K5/ckVLcSPaMgEy8RONjUAyM?= =?us-ascii?Q?Bnd6DB0QbOUAyT+BkdvXbhR7RD4G2Q51WgIgTQUm4VChZ5LUYkVJFYEMkD1Z?= =?us-ascii?Q?lmyrHJDHWlazcRgkqczBmpImu8JtCWDWBeBWmTSfsLreMImE2o5GbKwJ8b6G?= =?us-ascii?Q?ceVrYZjRh6p663AygdWUSZLtxNG7HShle0qbPDC?= X-Microsoft-Antispam-Message-Info: IE5clFF7/OY7o67EH+JarRgFnJLMsg+SPSuwLdg0YQioVboy2Ea9wECQvcyL7FGYiwOA8suIM2NHtidHxgzExvwix6js4hYLI1ec7x7jGx3bOSmDoW1S1/I15MVBZ++DcypFvQxN55103uLw3LeqUZXPCYDAXd+Cn2YbSKYGU31GahS1r4LubNMu6HjYKFey X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3253;6:z52v2ET7jX2beN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VYzFeMLjoha+DECcqx9I58qijLsI7Rzje/hpD/jffFmWdP79ExQFYW36C/ddQckoGCgS3gSeM/NUJ66WVtDjcsvSDhHpWURHAtMIUeOKfxim4TxffWOv6rOoH3TWVq111CTvZ6H2lofv5QOHMCWGtPG0HwcLIxVzI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2018 15:20:03.1869 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a2ce2df-7c32-401a-8b1d-08d590d18d80 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3253 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org memcg reclaim may alter pgdat->flags based on the state of LRU lists in cgroup and its children. PGDAT_WRITEBACK may force kswapd to sleep congested_wait(), PGDAT_DIRTY may force kswapd to writeback filesystem pages. But the worst here is PGDAT_CONGESTED, since it may force all direct reclaims to stall in wait_iff_congested(). Note that only kswapd have powers to clear any of these bits. This might just never happen if cgroup limits configured that way. So all direct reclaims will stall as long as we have some congested bdi in the system. Leave all pgdat->flags manipulations to kswapd. kswapd scans the whole pgdat, only kswapd can clear pgdat->flags once node is balance, thus it's reasonable to leave all decisions about node state to kswapd. Moving pgdat->flags manipulation to kswapd, means that cgroup2 recalim now loses its congestion throttling mechanism. Add per-cgroup congestion state and throttle cgroup2 reclaimers if memcg is in congestion state. Currently there is no need in per-cgroup PGDAT_WRITEBACK and PGDAT_DIRTY bits since they alter only kswapd behavior. The problem could be easily demonstrated by creating heavy congestion in one cgroup: echo "+memory" > /sys/fs/cgroup/cgroup.subtree_control mkdir -p /sys/fs/cgroup/congester echo 512M > /sys/fs/cgroup/congester/memory.max echo $$ > /sys/fs/cgroup/congester/cgroup.procs /* generate a lot of diry data on slow HDD */ while true; do dd if=/dev/zero of=/mnt/sdb/zeroes bs=1M count=1024; done & .... while true; do dd if=/dev/zero of=/mnt/sdb/zeroes bs=1M count=1024; done & and some job in another cgroup: mkdir /sys/fs/cgroup/victim echo 128M > /sys/fs/cgroup/victim/memory.max # time cat /dev/sda > /dev/null real 10m15.054s user 0m0.487s sys 1m8.505s According to the tracepoint in wait_iff_congested(), the 'cat' spent 50% of the time sleeping there. With the patch, cat don't waste time anymore: # time cat /dev/sda > /dev/null real 5m32.911s user 0m0.411s sys 0m56.664s Signed-off-by: Andrey Ryabinin --- include/linux/backing-dev.h | 2 +- include/linux/memcontrol.h | 2 ++ mm/backing-dev.c | 19 ++++------ mm/vmscan.c | 86 ++++++++++++++++++++++++++++++++------------- 4 files changed, 71 insertions(+), 38 deletions(-) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index f8894dbc0b19..539a5cf94fe2 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -175,7 +175,7 @@ static inline int wb_congested(struct bdi_writeback *wb, int cong_bits) } long congestion_wait(int sync, long timeout); -long wait_iff_congested(struct pglist_data *pgdat, int sync, long timeout); +long wait_iff_congested(int sync, long timeout); static inline bool bdi_cap_synchronous_io(struct backing_dev_info *bdi) { diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4525b4404a9e..44422e1d3def 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -190,6 +190,8 @@ struct mem_cgroup { /* vmpressure notifications */ struct vmpressure vmpressure; + unsigned long flags; + /* * Should the accounting and control be hierarchical, per subtree? */ diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 2eba1f54b1d3..2fc3f38e4c4f 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -1055,23 +1055,18 @@ EXPORT_SYMBOL(congestion_wait); /** * wait_iff_congested - Conditionally wait for a backing_dev to become uncongested or a pgdat to complete writes - * @pgdat: A pgdat to check if it is heavily congested * @sync: SYNC or ASYNC IO * @timeout: timeout in jiffies * - * In the event of a congested backing_dev (any backing_dev) and the given - * @pgdat has experienced recent congestion, this waits for up to @timeout - * jiffies for either a BDI to exit congestion of the given @sync queue - * or a write to complete. - * - * In the absence of pgdat congestion, cond_resched() is called to yield - * the processor if necessary but otherwise does not sleep. + * In the event of a congested backing_dev (any backing_dev) this waits + * for up to @timeout jiffies for either a BDI to exit congestion of the + * given @sync queue or a write to complete. * * The return value is 0 if the sleep is for the full timeout. Otherwise, * it is the number of jiffies that were still remaining when the function * returned. return_value == timeout implies the function did not sleep. */ -long wait_iff_congested(struct pglist_data *pgdat, int sync, long timeout) +long wait_iff_congested(int sync, long timeout) { long ret; unsigned long start = jiffies; @@ -1079,12 +1074,10 @@ long wait_iff_congested(struct pglist_data *pgdat, int sync, long timeout) wait_queue_head_t *wqh = &congestion_wqh[sync]; /* - * If there is no congestion, or heavy congestion is not being - * encountered in the current pgdat, yield if necessary instead + * If there is no congestion, yield if necessary instead * of sleeping on the congestion queue */ - if (atomic_read(&nr_wb_congested[sync]) == 0 || - !test_bit(PGDAT_CONGESTED, &pgdat->flags)) { + if (atomic_read(&nr_wb_congested[sync]) == 0) { cond_resched(); /* In case we scheduled, work out time remaining */ diff --git a/mm/vmscan.c b/mm/vmscan.c index 2134b3ac8fa0..1e6e047e10fd 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -199,6 +199,18 @@ static bool sane_reclaim(struct scan_control *sc) #endif return false; } + +static void set_memcg_bit(enum pgdat_flags flag, + struct mem_cgroup *memcg) +{ + set_bit(flag, &memcg->flags); +} + +static int test_memcg_bit(enum pgdat_flags flag, + struct mem_cgroup *memcg) +{ + return test_bit(flag, &memcg->flags); +} #else static bool global_reclaim(struct scan_control *sc) { @@ -209,6 +221,17 @@ static bool sane_reclaim(struct scan_control *sc) { return true; } + +static inline void set_memcg_bit(enum pgdat_flags flag, + struct mem_cgroup *memcg) +{ +} + +static inline int test_memcg_bit(enum pgdat_flags flag, + struct mem_cgroup *memcg) +{ + return 0; +} #endif /* @@ -2472,6 +2495,12 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, return true; } +static bool pgdat_memcg_congested(pg_data_t *pgdat, struct mem_cgroup *memcg) +{ + return test_bit(PGDAT_CONGESTED, &pgdat->flags) || + (memcg && test_memcg_bit(PGDAT_CONGESTED, memcg)); +} + static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) { struct reclaim_state *reclaim_state = current->reclaim_state; @@ -2554,29 +2583,28 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) if (sc->nr_reclaimed - nr_reclaimed) reclaimable = true; - /* - * If reclaim is isolating dirty pages under writeback, it - * implies that the long-lived page allocation rate is exceeding - * the page laundering rate. Either the global limits are not - * being effective at throttling processes due to the page - * distribution throughout zones or there is heavy usage of a - * slow backing device. The only option is to throttle from - * reclaim context which is not ideal as there is no guarantee - * the dirtying process is throttled in the same way - * balance_dirty_pages() manages. - * - * Once a node is flagged PGDAT_WRITEBACK, kswapd will count the - * number of pages under pages flagged for immediate reclaim and - * stall if any are encountered in the nr_immediate check below. - */ - if (sc->nr.writeback && sc->nr.writeback == sc->nr.file_taken) - set_bit(PGDAT_WRITEBACK, &pgdat->flags); + if (current_is_kswapd()) { + /* + * If reclaim is isolating dirty pages under writeback, + * it implies that the long-lived page allocation rate + * is exceeding the page laundering rate. Either the + * global limits are not being effective at throttling + * processes due to the page distribution throughout + * zones or there is heavy usage of a slow backing + * device. The only option is to throttle from reclaim + * context which is not ideal as there is no guarantee + * the dirtying process is throttled in the same way + * balance_dirty_pages() manages. + * + * Once a node is flagged PGDAT_WRITEBACK, kswapd will + * count the number of pages under pages flagged for + * immediate reclaim and stall if any are encountered + * in the nr_immediate check below. + */ + if (sc->nr.writeback && + sc->nr.writeback == sc->nr.file_taken) + set_bit(PGDAT_WRITEBACK, &pgdat->flags); - /* - * Legacy memcg will stall in page writeback so avoid forcibly - * stalling here. - */ - if (sane_reclaim(sc)) { /* * Tag a node as congested if all the dirty pages * scanned were backed by a congested BDI and @@ -2599,6 +2627,14 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) congestion_wait(BLK_RW_ASYNC, HZ/10); } + /* + * Legacy memcg will stall in page writeback so avoid forcibly + * stalling in wait_iff_congested(). + */ + if (!global_reclaim(sc) && sane_reclaim(sc) && + sc->nr.dirty && sc->nr.dirty == sc->nr.congested) + set_memcg_bit(PGDAT_CONGESTED, root); + /* * Stall direct reclaim for IO completions if underlying BDIs * and node is congested. Allow kswapd to continue until it @@ -2606,8 +2642,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) * the LRU too quickly. */ if (!sc->hibernation_mode && !current_is_kswapd() && - current_may_throttle()) - wait_iff_congested(pgdat, BLK_RW_ASYNC, HZ/10); + current_may_throttle() && pgdat_memcg_congested(pgdat, root)) + wait_iff_congested(BLK_RW_ASYNC, HZ/10); } while (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed, sc->nr_scanned - nr_scanned, sc)); @@ -3047,6 +3083,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, * the priority and make it zero. */ shrink_node_memcg(pgdat, memcg, &sc, &lru_pages); + clear_bit(PGDAT_CONGESTED, &memcg->flags); trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed); @@ -3092,6 +3129,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, noreclaim_flag = memalloc_noreclaim_save(); nr_reclaimed = do_try_to_free_pages(zonelist, &sc); memalloc_noreclaim_restore(noreclaim_flag); + clear_bit(PGDAT_CONGESTED, &memcg->flags); trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed); -- 2.16.1