Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5434893imm; Tue, 31 Jul 2018 10:49:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdZLhCsM+krnBPmzi60Cvgva1MIboBS3mT/2cDSmjSdROMC1jpLP6SOqAgx7hT/uEq+IeDX X-Received: by 2002:a17:902:7898:: with SMTP id q24-v6mr20848206pll.222.1533059388726; Tue, 31 Jul 2018 10:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533059388; cv=none; d=google.com; s=arc-20160816; b=M2Q1j48dtLDifURtfXZ4zrvAaFUN5DyGNSVdthsgyhzfa1yEcVprb2vPTWh+I34mLx KBER7yGNT2uLzIn8mU9XXIN1h+FH1UP9qzmw4NhuMnBI+F50nxdsYSk/5eoF/b5lXHLH AqxzgRnotn7cH19Lckdm00FcorzBBsRT0+ZUW+Pev6jy63g1DX+l0+4SIXGrd8Mpdag/ /cQvOFTTzVfigyeZYyjiXc1bWnVN4KVFmhSSZaWM60xwIMSRFUaDqT6N0Zm4ipsPdl4W o9/qE1zXQJBrIwd95MvWFeWL4PZKHFKGnzP1jUX2kpb/zzAfU2U5Pl+oJETNhg18iFhu AZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=SVe9hcyFwhLf6K6lt9pcEGSB7DPyqiY6bwyA75H/X18=; b=eCtPyccmVYFXapVXtppEDT3TBEK+jGRFsttIOT5Zr0emNWp9APvf3nH3bN9pHaJhyD lJQb3jAZx2hEpvCNAmDk7V+vs6WTUVEVrcERA5coVedt4K2yMFmFlm9f2sL3rstMaPAB iseOHF2IAVa7yQkMfvLVb2Jq/axh0aJzUzVFkIFe0BwM2UqQQxbaglATiXP01RiNxqnq uTVPCuboKiSIIKPkSfkeLjIgrfT/dc8GNJ7G5B6CGbaV+EO4MNB9/wzUYbDTmhJITFOK B+O3KGEfhq6IsXGSMYxghkYZFC7H/1bJm2CkC0WnLXzQX5FNh9T/iv+L8piSiwa7XyLn 19mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=h78zMBxQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w185-v6si13256338pgd.133.2018.07.31.10.49.34; Tue, 31 Jul 2018 10:49:48 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=h78zMBxQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731905AbeGaT3V (ORCPT + 99 others); Tue, 31 Jul 2018 15:29:21 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:43755 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729645AbeGaT3V (ORCPT ); Tue, 31 Jul 2018 15:29:21 -0400 Received: by mail-yb0-f194.google.com with SMTP id y3-v6so735130ybo.10 for ; Tue, 31 Jul 2018 10:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SVe9hcyFwhLf6K6lt9pcEGSB7DPyqiY6bwyA75H/X18=; b=h78zMBxQqwJu2tIZYP5CaMj6k0uOK2slaAdcgG4BeWo3qS4FfBj+GYJf+drn44qiK2 qKwWFkGKzE/Po00hgsVUxxUpQ9lAIPnw7xwLIjddERsfoXz5XUcaRN87hLC1N38npQZp RTtsmdUjwLYfCNrPxx2NGezyWcnFpZygCMd7F1rVhvZkQ2/BOavdTnisUis02fXObVPW OLwo1hs0U7ojBt00UI/NiwsgSVOqzc+vY//MvUWoo6sTTq1AzPRG1BWkyZAFCbe5bzK3 Lkf6vmWBmzNYLgOn0zrel+w8yKdhuha/cY5Jkocm01i1jLVg1W78ty2squdHnWpYTfi6 9UxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SVe9hcyFwhLf6K6lt9pcEGSB7DPyqiY6bwyA75H/X18=; b=dB4QfLajzz9CuLKlEHr7RDwcuCD/tx/C4dFXdsjWZulO2/0gXfFe4Sk0HCqYjmUIij J9jbFXNCiUh8ASw+tzQKxeuHKXH9gDUJGhCf6mM8kD2cRhzR1GBg1dxLyB4X9GHYj1ym /B+fdTvWp1C9HDP+MjxbFUem5F7aq5G3pyPY7XEUkO2JSf3L+lsjtUwvJMk6xcxEM/25 /G7GYUzVFNh5LoANqbz++phjYMX/1ZdHxESHDd/Vh0v2XmGxFWFDSnC7gaPHf3Y74GDk 4m1grzL3XCMVlzVWF384X06Grj/DHm74TjO2YKFI8JPoUpylWWqYWA0m0yKwLjjfhaol xm/w== X-Gm-Message-State: AOUpUlFzoTo8kIwxV8l2GaGqOq2UhKFh4RsMrHYPIt+5v61cb2FXZCEI 1UkdvC1G8Bp3tvoSEofqSRXbIA== X-Received: by 2002:a25:fc01:: with SMTP id v1-v6mr475449ybd.406.1533059276566; Tue, 31 Jul 2018 10:47:56 -0700 (PDT) Received: from localhost ([2620:10d:c091:200::3:e414]) by smtp.gmail.com with ESMTPSA id l4-v6sm6269229ywk.47.2018.07.31.10.47.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Jul 2018 10:47:55 -0700 (PDT) Date: Tue, 31 Jul 2018 13:50:50 -0400 From: Johannes Weiner To: Zhaoyang Huang Cc: Steven Rostedt , Ingo Molnar , Michal Hocko , Vladimir Davydov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-patch-test@lists.linaro.org Subject: Re: [PATCH v2] mm: terminate the reclaim early when direct reclaiming Message-ID: <20180731175050.GA31657@cmpxchg.org> References: <1533035368-30911-1-git-send-email-zhaoyang.huang@spreadtrum.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1533035368-30911-1-git-send-email-zhaoyang.huang@spreadtrum.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 31, 2018 at 07:09:28PM +0800, Zhaoyang Huang wrote: > This patch try to let the direct reclaim finish earlier than it used > to be. The problem comes from We observing that the direct reclaim > took a long time to finish when memcg is enabled. By debugging, we > find that the reason is the softlimit is too low to meet the loop > end criteria. So we add two barriers to judge if it has reclaimed > enough memory as same criteria as it is in shrink_lruvec: > 1. for each memcg softlimit reclaim. > 2. before starting the global reclaim in shrink_zone. > > Signed-off-by: Zhaoyang Huang > --- > include/linux/memcontrol.h | 3 ++- > mm/memcontrol.c | 3 +++ > mm/vmscan.c | 38 +++++++++++++++++++++++++++++++++++++- > 3 files changed, 42 insertions(+), 2 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 6c6fb11..a7e82c7 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -325,7 +325,8 @@ void mem_cgroup_cancel_charge(struct page *page, struct mem_cgroup *memcg, > void mem_cgroup_uncharge_list(struct list_head *page_list); > > void mem_cgroup_migrate(struct page *oldpage, struct page *newpage); > - > +bool direct_reclaim_reach_watermark(pg_data_t *pgdat, unsigned long nr_reclaimed, > + unsigned long nr_scanned, gfp_t gfp_mask, int order); > static struct mem_cgroup_per_node * > mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) > { > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 8c0280b..e4efd46 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2577,6 +2577,9 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > (next_mz == NULL || > loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS)) > break; > + if (direct_reclaim_reach_watermark(pgdat, nr_reclaimed, > + *total_scanned, gfp_mask, order)) > + break; > } while (!nr_reclaimed); > if (next_mz) > css_put(&next_mz->memcg->css); > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 03822f8..19503f3 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2518,6 +2518,34 @@ static bool pgdat_memcg_congested(pg_data_t *pgdat, struct mem_cgroup *memcg) > (memcg && memcg_congested(pgdat, memcg)); > } > > +bool direct_reclaim_reach_watermark(pg_data_t *pgdat, unsigned long nr_reclaimed, > + unsigned long nr_scanned, gfp_t gfp_mask, > + int order) > +{ > + struct scan_control sc = { > + .gfp_mask = gfp_mask, > + .order = order, > + .priority = DEF_PRIORITY, > + .nr_reclaimed = nr_reclaimed, > + .nr_scanned = nr_scanned, > + }; > + if (!current_is_kswapd()) > + return false; > + if (!IS_ENABLED(CONFIG_COMPACTION)) > + return false; > + /* > + * In fact, we add 1 to nr_reclaimed and nr_scanned to let should_continue_reclaim > + * NOT return by finding they are zero, which means compaction_suitable() > + * takes effect here to judge if we have reclaimed enough pages for passing > + * the watermark and no necessary to check other memcg anymore. > + */ > + if (!should_continue_reclaim(pgdat, > + sc.nr_reclaimed + 1, sc.nr_scanned + 1, &sc)) > + return true; As per the previous submission, should_continue_reclaim() is really not an appropriate function to use. It's for the compaction policy. You might be able to hack around it with faking the reclaim progress, but this will fail in subtle ways when people change the compaction policy in that function in the future. If you use it only for the watermark check, check it explicitly. Other than that, I agree with Michal that we need much more data on this; what the configuration is like, what the memory situation is like when your problem happens, how long the stalls are, and how your patch helps with overreclaim etc.