From patchwork Fri Jul 27 09:19:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 10546799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5514139A for ; Fri, 27 Jul 2018 09:19:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B46AF27BA5 for ; Fri, 27 Jul 2018 09:19:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8B4D2B74C; Fri, 27 Jul 2018 09:19:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7025627BA5 for ; Fri, 27 Jul 2018 09:19:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03CA06B0003; Fri, 27 Jul 2018 05:19:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F064E6B0005; Fri, 27 Jul 2018 05:19:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA6FF6B0007; Fri, 27 Jul 2018 05:19:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 98F476B0003 for ; Fri, 27 Jul 2018 05:19:34 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id f91-v6so3178546plb.10 for ; Fri, 27 Jul 2018 02:19:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:subject:date:message-id; bh=20Wx9riSuDYbJooR8gj1Ouq+57hcSNEZmF4g+H3EHxs=; b=cZleU7qtDCPRle1dp+8z9+C9qPO4IKalD9jzl78ZfnArQeYR2pzWlde2dft0hwnedq OH+X1IUtYayrMU5aArAP0ZL+3YzKPHR1sGJ/hTcb9TFn8nkOQkzVvUYOUSKHzWaJgJ7V 46ER9eMwkUtskBsUFmTi4RN1IjrVuvWSDEyHUuu1HTOXfwT2HM69la+MgGyiP2Qd5oz/ MTJeCnU4V9GL8zlVSIeCMbVer73EIwqcIt0rAktBo56sfCzJAjHRMz6ch88WukLkqXBA AnwaAVgcMMIW3fqzkZmX/YiClA7U5lkmuY1L3ZuKPpwNSJNonm2sDmbYEouS70ATLSCn E4pQ== X-Gm-Message-State: AOUpUlFBOHq28eNbryboj6yoVA9P6F6IAvA14U6K+ZppWI52ReC1QywT IHiYkfWZaRGpL+QICqU3Ebll5ttJMrqftxNisuSdYSGDEHHszbk4C14/G+/Ssly812crCikjSz9 FPcey83mB973Q/k9fCc57ky9xpdkUGbr/Gsf3/EPPYuBM6XrRTvze2upkZrRpAQdmFeqRmzYZuQ nvJYxJt7JFobJRDeGsWRlzthDgzKmnjDpHc0Tf9IVSzW1ytc04S8SE74wXGX5xv1dhaxEqU1Gwt e9STuT3tm+X28qkGTKMZgzrD+0xvcBmnuyFNJzWyApl8WUD3CjTl7H5XEpWESdQ9paVBpU8gJSy RSeIFGxcF+F99WvEZy6HlaqvYpkDjO5ipOLWjxTigPllw4C5GCjUwC/jOQUR5gzCPqQ4/WbSNac c X-Received: by 2002:a17:902:b902:: with SMTP id bf2-v6mr5192574plb.160.1532683174274; Fri, 27 Jul 2018 02:19:34 -0700 (PDT) X-Received: by 2002:a17:902:b902:: with SMTP id bf2-v6mr5192531plb.160.1532683173371; Fri, 27 Jul 2018 02:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532683173; cv=none; d=google.com; s=arc-20160816; b=aTESQQH5hzlfRVbAFlYp3QchVvcfcXMawFik4MQORm6ZnHnjlrjEjQyAtYnCoUdROZ fmF29gpnjY1vZWpetj1Ao4z/kjZTCYR/YEeW5FLV1hoMvV2JQxnlx9FiTnagUiA5NCj8 VEhGwAuHui6nqXYwY5c8IS8GiOvplw214o3+38vVV+CePz3JwHdOkjAR/YLhlY6trlTk 3aIWCMDp2RoqLqdLnAGkJKgvalKJwYm5BzihFJVru4KEuhHlcxmV43fKrOmImGO8CPLS gSG7gv+OphetJc6i36lq5NydFfvK3AzLzdQKPMTzilQGW5UA5Si+Su340zWtNDS4DTE5 yggw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=20Wx9riSuDYbJooR8gj1Ouq+57hcSNEZmF4g+H3EHxs=; b=gYdxFZ528SQAuCluIOVWfcRda/d0hU6U/vRU9TnTrZzPBBOG/XmcMc2DJkLCxzpppF CsUTFjqhYDRsvdXUDNC/iwxdr0Ir356ngvJuntXTU+2QtddklrJarboXz0mFyjRiaJpl KPmKNDNFY0MjqFruGgqYaxZAI6RqcYbftXu9U7m+DXrwlstncqgG5kJj2D6uY1po/Z9w Y0PKDHt5zFPhMHaI7Gk0TDteoBgblN4IpNL5lQVev4tn0NPX1LPZb81VUOWQhuXOzvjB ZWJW3iAEYVfvBU7Dy0wSlsStiYbM/NpwgIIOhiBUynVJ6MlYWphBvOrFFN4f32r1IYZX WfFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e2rMDtEk; spf=pass (google.com: domain of huangzhaoyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n1-v6sor977361pgf.110.2018.07.27.02.19.33 for (Google Transport Security); Fri, 27 Jul 2018 02:19:33 -0700 (PDT) Received-SPF: pass (google.com: domain of huangzhaoyang@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e2rMDtEk; spf=pass (google.com: domain of huangzhaoyang@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-Smtp-Source: AAOMgpfM6wKZOHiPhU+7+RVDJ41pulix73tIcyxzXYlt2BziphI1F61s8xbVQWxXKZ7KCztETMeXtQ== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 = {