Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp581196imm; Fri, 27 Jul 2018 02:21:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdqskGgW53ScRQziTYoKf1Lv8PvHgJpT3qvqYvVKlTYKcj7j1HtsXsXtlsdEIubhTc9BQ+E X-Received: by 2002:a63:e206:: with SMTP id q6-v6mr5361661pgh.223.1532683274047; Fri, 27 Jul 2018 02:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532683274; cv=none; d=google.com; s=arc-20160816; b=08GL1/IuOHWiMszdOjFFe4lQ5zyWnv8ht/6hl6XqwpaZFrrA/GdofD9Z1GAfeGYCvj G49Z0RtOefV5XjXTb0vaULKVLjuE4KGCAV43YmTv7/GT9XLWTRF/JyetzpPOmf+c/LU7 hbCH+SbkT9PuoNnEy/AbSl/iIQ3Bj31WGLOVn92DxMpc10U5qtZUYRv3+HkMeONAx6nL +vf7FYKd/JZI6IHymrtr5c4bJLQjtBAXWI++pDlVMQXhdPRH0CDRR0aY/e07yxrIxiuE ctTErJ4ceOjKyk2kKPvzoqa3o4Qg9zzDV0AryGY4sDDxZNZtDjX8kg5VAR1lS2KfZVJD Zk+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=20Wx9riSuDYbJooR8gj1Ouq+57hcSNEZmF4g+H3EHxs=; b=gt6fq4YkpoIc+rW0Fjm6ReMDGMGmQo/QdHj8k9SdjqB7WkNOKijk5ztLdz9uC6oP0Q j+jQcp3wxG0dAPEN92IEsfBOQskmt0UcH4X7ixhKGwMQkjlCcu1BmhLqhOdqZ2nOvo9T q0EkQ3fQp6WD+oXVmADvQYXXusjfksXWyU/h/a25hIv9z9cRfoWENHHwHK0S1yjbZB5W 3paGI/s7uPItcGL4C5fQQn7woQfFJOSNucrlghkEr11s2apV78AqJbzY7+Aw5Dzm98Qb P8RUJL2pvd93N7YoYYkxPYmiMqj9BMtMP2Cf065Q2JAk/1GkRPaFhIr1rbq9J6+pGNmG HzwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e2rMDtEk; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21-v6si3460196pgo.272.2018.07.27.02.20.59; Fri, 27 Jul 2018 02:21:14 -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=@gmail.com header.s=20161025 header.b=e2rMDtEk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730632AbeG0Kkc (ORCPT + 99 others); Fri, 27 Jul 2018 06:40:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40927 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729491AbeG0Kkc (ORCPT ); Fri, 27 Jul 2018 06:40:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id x5-v6so2890686pgp.7 for ; Fri, 27 Jul 2018 02:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=20Wx9riSuDYbJooR8gj1Ouq+57hcSNEZmF4g+H3EHxs=; b=e2rMDtEkaTMhRkwGBH4pMtreT6YY8ui4QaGZO+xI/9u/t5mslk9Lt93CNrZ1X5A6wM 494AHDoqkYoHJv/1m8uDm6lqnHfh8arH7sifWEHv8N9XmA5Cnskd7G7R1zE8FBhm9GcJ gtOppsLABQvGzBOmKnxV7Ssv5xFDH2I3iNN8vy9374bCBUamgCK+17oJqNkjozS1XkYk ZoIy2bkwR5vElrWf60kV2hXLQ+faV+QIoCUKpHNyucpo6OFc/Y6JFc5KER98eEGToiQ6 6WlACmEBPNPKL6VVDatdRtHS1123uQsStejZZhjwNRuz1BE4pMXotCCzjZEuTdLRdzTv EJYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=20Wx9riSuDYbJooR8gj1Ouq+57hcSNEZmF4g+H3EHxs=; b=FN6osPa3cviC8ClxDe28LFfyiPhSGm7Nh0jFxygM51SJK0fGeAfrEC8fMbAn5O4LDq G9geZWpfO8XhGCYQnKL8EOUpJAKYxxgyAer+S/97yDdkEKBSJ2iYIUdmRKodeK7I2Xr3 g8jfImAPk2ooRJ+Y/WBK9JRNCeOGlvAMuB3De9FNBTW9l5QaJCBkQlWvc9ByGmdiN9xy xz8lePheo4jcPYqVzrbFlVzAWuOAPgBQCjECI/t5ST12xVf/8dA2Kv+DtP6pCAWLI2zG EofStQZvBE+lLLEfM0Zg9e/huxyhQ7M9lNwgmSmP7p7t+m6Ks5Cnyj9ZIzVKgKUAyB3S MLXg== X-Gm-Message-State: AOUpUlHqgEsCC+r9CqnJmafiEYs24YcYoUIEiaiuma603nw6ZJRKLQEJ POqHVBeEWMZoKSwWgZEJcC8= X-Received: by 2002:a63:1015:: with SMTP id f21-v6mr5396346pgl.354.1532683172936; Fri, 27 Jul 2018 02:19:32 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id r1-v6sm9955933pfi.17.2018.07.27.02.19.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Jul 2018 02:19:32 -0700 (PDT) From: Zhaoyang Huang X-Google-Original-From: Zhaoyang Huang To: Steven Rostedt , Ingo Molnar , Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-patch-test@lists.linaro.org Subject: [PATCH] mm: terminate the reclaim early when direct reclaiming Date: Fri, 27 Jul 2018 17:19:25 +0800 Message-Id: <1532683165-19416-1-git-send-email-zhaoyang.huang@spreadtrum.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 6c6fb11..cdf5de6 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_sflimit(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..4e38223 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_sflimit(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..77fcda4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2518,12 +2518,36 @@ static bool pgdat_memcg_congested(pg_data_t *pgdat, struct mem_cgroup *memcg) (memcg && memcg_congested(pgdat, memcg)); } +bool direct_reclaim_reach_sflimit(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() && !should_continue_reclaim(pgdat, + sc.nr_reclaimed, sc.nr_scanned, &sc)) + return true; + return false; +} +EXPORT_SYMBOL(direct_reclaim_reach_sflimit); + static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) { struct reclaim_state *reclaim_state = current->reclaim_state; unsigned long nr_reclaimed, nr_scanned; bool reclaimable = false; + if (!current_is_kswapd() && !should_continue_reclaim(pgdat, + sc->nr_reclaimed, sc->nr_scanned, sc)) { + + return !!sc->nr_reclaimed; + } + do { struct mem_cgroup *root = sc->target_mem_cgroup; struct mem_cgroup_reclaim_cookie reclaim = { -- 1.9.1