Received: by 10.213.65.68 with SMTP id h4csp465959imn; Fri, 23 Mar 2018 08:22:29 -0700 (PDT) X-Google-Smtp-Source: AG47ELv6jqiF+Is+vpttNKAKrXZEF6RrhTO2xDhQXwBnUymFmIQe8dg6WNKJpd8VKr3nDMaQSQQO X-Received: by 2002:a17:902:7401:: with SMTP id g1-v6mr30259188pll.4.1521818549867; Fri, 23 Mar 2018 08:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521818549; cv=none; d=google.com; s=arc-20160816; b=1DJghmAOhJf2kdo+VOSC4Eanhoxa9SW6mFRhfYcLDoUOPcDeCih09YMsneiTPizt4F +y0N0W+8kaMr7ihvceCAmyAwUx4+zCp4jVE/xNay+OSDNEpW7hYAaIRGfnKz+iCwnKJ9 lttB5n+xnMw+3tn6f0aU8PUOhGMTqHNOKosWHYwUsCqB0cy/qxU6olju7qTVIbB6iFvq 9UbMEDCOznMAM1J2gddJYCTamrBdOzR+5i2qjbTlD/U/6wXU+AslTgRNS8Jz/KgIgOBj 3D27D1R5NOWi0X+Jkit1JGET9FDKZgEY5z6aA7KiQ+hOTZ41u18cN+NMXKpYYALhzZ4/ I+6Q== 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=9mbpX2ObVjZPWRHWPKCicH+SGSlWtmXQRRF6ecKDTeY=; b=mj8u1xDic6x9m8IMp/cnT/EJe42BD+FK+Cwom8eP7q9RaI8/Lfis2YXWGv8IwOvOi9 yZ9EkALI3lxj7Jk82brdP6KOvFwq7Lr3cNrJ3osINqkggpG9iuN8EFdGtp6hUjvHnWAZ I/nkfGQjeIpWicWREQ6mvGtshoHO3GKwB78/4Cz+LX2ZbWP8BEmz/8ytfrkkjNmrJeFr D19YKnjjTHrK7z0+lj1VECTUejQI+GeX8jmYbJKRC0QvF9bBfcGCMR65AeBcG/o7HEep zVExJHuIvzVHHTp4on+d2uRIMwho/uZwHBDnYfSwUBxQ8uO8zlvqrpYRWy39S/uYF9HP BHHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=M7jopaKG; 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 n4si5259870pgt.450.2018.03.23.08.22.15; Fri, 23 Mar 2018 08:22:29 -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=M7jopaKG; 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 S1752145AbeCWPUy (ORCPT + 99 others); Fri, 23 Mar 2018 11:20:54 -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 S1751551AbeCWPUH (ORCPT ); Fri, 23 Mar 2018 11:20:07 -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=9mbpX2ObVjZPWRHWPKCicH+SGSlWtmXQRRF6ecKDTeY=; b=M7jopaKG2wF4hPg1lL9vxm7oBSLtPKLuckzrMvpG5hHu1vwpq0+ZsNSGuTnS7NiHDjYCwQcn4fEKDqSvfeNnxCeGNH8P1mkb6a1Chb94xyOQFdcOh9Q9GlI3/oC8hWGrGcaAGj1RU6u2wdkocZaHZJShL+y5La/a7izS5NGpc08= 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:01 +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 3/4] mm/vmscan: Don't change pgdat state on base of a single LRU list state. Date: Fri, 23 Mar 2018 18:20:28 +0300 Message-Id: <20180323152029.11084-4-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: f72fea96-9ebf-438d-81e9-08d590d18c94 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:JXaANmOMp3vjpyvMiJ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94bfuBhhzriZOPVjwqViQJUSXEzREz3MnCRcv2Q2XtVuk686buZ/L7K0wGfMFRHGiu8HqoOYPO8f35x6kv+no6gYFqDd5AKmol51BUbZ/Rbw854NA+q6obWkkrdPobKyxWKvCHQCyFjO9yyM3fCY/PHQbbCl+eExAeLd0yYt0bKb8ibxEn3VwR4WkaTpMYfYrbbL2ejjMxXhEINM9bRjxJo6lB3vKXQIBJ6+w0NXlioBT5FgiEVEAzBigjUl1WT7UBjo5v/ssOYB8uUDYWq87URA052HjcZyRIhLyDnuNUq/59RuhzJjWKsT8LQlbuVOrk+;4:OZlVddVM8sjLmwOXx8VAtG8WHodcNaWLG3P9CuJIklqpR58WB79Al6JqGAFmiWYjfmWu3712UrmJwR1Q7SA/MB0RbevGfsdGoXOSfIAyN56vSjO0pWKTnTdglaf0RZFa1TcjkH8CUM8uoYOscFkwSQyHTirex6j2DlOqxLA85wbEg1/mVaGLMpefoq3NpzfEO9LXsaMGtEpv4v3CHN/HemezRz0mmIm21Egfs58iIyzblPksapOwTBHtJkrrThdx4Dbr0Bhgxh3U4vewx1nQvQ== 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)(81156014)(8936002)(52116002)(6666003)(54906003)(76176011)(81166006)(386003)(86362001)(6506007)(7416002)(2906002)(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:51YyV6JCdOERJxbBDV2omvG8/uIOo3uIYdyyo18U6?= =?us-ascii?Q?IzqhCddlz4WCropuJfDLQihOhslKxr2MiwVuj/FIGNUniGu/sY6FUiTcfSC8?= =?us-ascii?Q?ZfqIfxfyXPxoD6fi7ulmFJ1jI4rv/jlPzXKKzxk3XZUbJahduSrooLbJH4oc?= =?us-ascii?Q?25iq1bXnHAaObTjYAzeIvGtmFcFPmxPq3RSlyibJ0ixawfLKfSY3HWXbTNQe?= =?us-ascii?Q?8y/uBR+kh3Y1N70fg5p7IKoZFWIiP0fjevwqJbQiJnaZLA+WuNPkxYlFJ+fG?= =?us-ascii?Q?Ez6/zu6l41AqK+wihkb8FdF2Tlz2gE2ZWBtAgPDuir0Bmpi5+d4mfIBSA89/?= =?us-ascii?Q?kyEzhkgp6RYR3/Sm3+hJcix7VzzSNbH6CZuEfrhq9sGHh+ad5zooOo4p3iI/?= =?us-ascii?Q?oU8bke4qSeTk9PC6xRj3rBDfjVJpu0gleO4HsKXqcb83V//0kA3M6sPWkbVv?= =?us-ascii?Q?tZVFXcWOPInIWpW8HSSyZIhy9lghgKo43SzWdtyXNbvRgP71yUf/Twig7Oo7?= =?us-ascii?Q?u0h3Vzjdefouhz+ejv3DyZZP4+QXKXUKepBS8Q8vUV95dUtZw1jp28zLeweZ?= =?us-ascii?Q?4nITQ89cc4wpyrbCgfDej1JNm5NiyGen6n4+iLhWdrM/90myJlQa7TJscigq?= =?us-ascii?Q?bN5yGfhSI6O/IR7U0A9WlDkBTb/L5aqoMDOQ1bG5JfI8fLTlc5oix/Sb4Cxo?= =?us-ascii?Q?2bJBYGQC/3RWzX+KwvPKrsLODDkHGxKvDp5M22eJ/QktzFzs36jz2YfWRBNy?= =?us-ascii?Q?fBJtZ8D16lMjp5kxlMK4uZgmBXNvm8aKI+cquczvrEI2+Wm1Ns9iP0NA9NUT?= =?us-ascii?Q?gJ5qi0w7afkUjHl5iVeamDoS/GCSQOpTX2tr3Mlt2VMqn2qRMrbDnN3mRLNv?= =?us-ascii?Q?YUoLISQNUdlfSNCfuU0lGQF84cfl9KrmErkxE6gE/UOd/rUDeBf8iygu4F0i?= =?us-ascii?Q?q/gI8tQ2C1XP5HTSbtyHfA73z4y9bHGU+04TSKymeS+hDllAcO6aMuAQjaW/?= =?us-ascii?Q?vDYosX1CFzn2CgApFlm/NFz22Sex/bkTmuB6mfdQF0FtnEnrYujuP07AIOvf?= =?us-ascii?Q?CeMVNDBbNZxN8hwUwSlVgyidm9Vq/Pur3Jj1KW/2fy6oHbBcQD7t18Pbuhev?= =?us-ascii?Q?mjedrjD84esZcvis1iORzh3OpAAo8dmko67txMYlbwgxofE2LeibHo8uh83x?= =?us-ascii?Q?CNN7V0nkBWPCqeJOS56FEZUs6GBGy+/9n5J?= X-Microsoft-Antispam-Message-Info: J0pZcBxEXrnf/rrVWI3q0ACePaacnkjhzccOP93D+6hnIOF6T6nu5Z/IqQsb2p1olA48PFWi+0iIyJYheg69zLW7HAo1+7BL9ajdsNdmjj6mTMYaNxSXVsyDt7/6w5AQXVtDRHdNxJFo3AHf8BPUaLqK6k+sCS331HAcZfuU6M3rHmD1kfNY2iPUt7w9+FqP X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3253;6:gPr0vEp0T9Acx1mAY/EP84U6mv/9ROglzKvFYOwTJWA2DeiOEpm83i/ZM7nNSFvhk7+EeEqht/CEVSKaVS0z2gKe6G0hNW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mGiv3A45+Fnb0MOFYCP00mTmSLm8DVMyGEtCZq8UdHbGqwQwzBxTbBG043wNtOfxtldgMM5ecOzVYQsOXYWGc8sqjVAFk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2018 15:20:01.6400 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f72fea96-9ebf-438d-81e9-08d590d18c94 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 We have separate LRU list for each memory cgroup. Memory reclaim iterates over cgroups and calls shrink_inactive_list() every inactive LRU list. Based on the state of a single LRU shrink_inactive_list() may flag the whole node as dirty,congested or under writeback. This is obviously wrong and hurtful. It's especially hurtful when we have possibly small congested cgroup in system. Than *all* direct reclaims waste time by sleeping in wait_iff_congested(). And the more memcgs in the system we have the longer memory allocation stall is, because wait_iff_congested() called on each lru-list scan. Sum reclaim stats across all visited LRUs on node and flag node as dirty, congested or under writeback based on that sum. Also call congestion_wait(), wait_iff_congested() once per pgdat scan, instead of once per lru-list scan. This only fixes the problem for global reclaim case. Per-cgroup reclaim may alter global pgdat flags too, which is wrong. But that is separate issue and will be addressed in the next patch. This change will not have any effect on a systems with all workload concentrated in a single cgroup. Signed-off-by: Andrey Ryabinin --- mm/vmscan.c | 124 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 51 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 403f59edd53e..2134b3ac8fa0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -116,6 +116,15 @@ struct scan_control { /* Number of pages freed so far during a call to shrink_zones() */ unsigned long nr_reclaimed; + + struct { + unsigned int dirty; + unsigned int unqueued_dirty; + unsigned int congested; + unsigned int writeback; + unsigned int immediate; + unsigned int file_taken; + } nr; }; #ifdef ARCH_HAS_PREFETCH @@ -1754,23 +1763,6 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, mem_cgroup_uncharge_list(&page_list); free_unref_page_list(&page_list); - /* - * 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 (stat.nr_writeback && stat.nr_writeback == nr_taken) - set_bit(PGDAT_WRITEBACK, &pgdat->flags); - /* * If dirty pages are scanned that are not queued for IO, it * implies that flushers are not doing their job. This can @@ -1785,40 +1777,13 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, if (stat.nr_unqueued_dirty == nr_taken) wakeup_flusher_threads(WB_REASON_VMSCAN); - /* - * 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 wait_iff_congested will stall. - */ - if (stat.nr_dirty && stat.nr_dirty == stat.nr_congested) - set_bit(PGDAT_CONGESTED, &pgdat->flags); - - /* Allow kswapd to start writing pages during reclaim. */ - if (stat.nr_unqueued_dirty == nr_taken) - set_bit(PGDAT_DIRTY, &pgdat->flags); - - /* - * If kswapd scans pages marked marked for immediate - * reclaim and under writeback (nr_immediate), it implies - * that pages are cycling through the LRU faster than - * they are written so also forcibly stall. - */ - if (stat.nr_immediate) - congestion_wait(BLK_RW_ASYNC, HZ/10); - } - - /* - * Stall direct reclaim for IO completions if underlying BDIs and node - * is congested. Allow kswapd to continue until it starts encountering - * unqueued dirty pages or cycling through the LRU too quickly. - */ - if (!sc->hibernation_mode && !current_is_kswapd() && - current_may_throttle()) - wait_iff_congested(pgdat, BLK_RW_ASYNC, HZ/10); + sc->nr.dirty += stat.nr_dirty; + sc->nr.congested += stat.nr_congested; + sc->nr.unqueued_dirty += stat.nr_unqueued_dirty; + sc->nr.writeback += stat.nr_writeback; + sc->nr.immediate += stat.nr_immediate; + if (file) + sc->nr.file_taken += nr_taken; trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, nr_scanned, nr_reclaimed, @@ -2522,6 +2487,8 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) unsigned long node_lru_pages = 0; struct mem_cgroup *memcg; + memset(&sc->nr, 0, sizeof(sc->nr)); + nr_reclaimed = sc->nr_reclaimed; nr_scanned = sc->nr_scanned; @@ -2587,6 +2554,61 @@ 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); + + /* + * 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 + * wait_iff_congested will stall. + */ + if (sc->nr.dirty && sc->nr.dirty == sc->nr.congested) + set_bit(PGDAT_CONGESTED, &pgdat->flags); + + /* Allow kswapd to start writing pages during reclaim.*/ + if (sc->nr.unqueued_dirty == sc->nr.file_taken) + set_bit(PGDAT_DIRTY, &pgdat->flags); + + /* + * If kswapd scans pages marked marked for immediate + * reclaim and under writeback (nr_immediate), it + * implies that pages are cycling through the LRU + * faster than they are written so also forcibly stall. + */ + if (sc->nr.immediate) + congestion_wait(BLK_RW_ASYNC, HZ/10); + } + + /* + * Stall direct reclaim for IO completions if underlying BDIs + * and node is congested. Allow kswapd to continue until it + * starts encountering unqueued dirty pages or cycling through + * the LRU too quickly. + */ + if (!sc->hibernation_mode && !current_is_kswapd() && + current_may_throttle()) + wait_iff_congested(pgdat, BLK_RW_ASYNC, HZ/10); + } while (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed, sc->nr_scanned - nr_scanned, sc)); -- 2.16.1