From patchwork Mon Dec 3 08:01:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 10708723 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 1768E13BF for ; Mon, 3 Dec 2018 08:01:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C03D2ADE2 for ; Mon, 3 Dec 2018 08:01:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A5582ADE9; Mon, 3 Dec 2018 08:01:40 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY 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 9405E2ADE2 for ; Mon, 3 Dec 2018 08:01:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B1066B6803; Mon, 3 Dec 2018 03:01:38 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 937676B6804; Mon, 3 Dec 2018 03:01:38 -0500 (EST) 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 801C16B6805; Mon, 3 Dec 2018 03:01:38 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 460666B6803 for ; Mon, 3 Dec 2018 03:01:38 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id a10so9628678plp.14 for ; Mon, 03 Dec 2018 00:01:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=c4Qv9Gm3O0+AcCdsYZx4NZiPFV4kztTlVCRvfv2cNgU=; b=npqfQcI48dLC+nqjAcEAbU8C+lUvUWDmzCxE7oZM/WX04EVLOzIskA6Z6tsE6qWxsM ndwTUB6XaQZ11wlbetw77NcSRs55LGXCioenm5+G18UyujdnTUWleFUX5+UIQghuddBs oMbK9RU5irqNr8GJ9tmwpayo8F/QWteYt+cBeCvGuqeKSRJC7b1vRLgdJxU8VffaHZZt /2GZiPm430rSROkdfcp+z4CrLFBATVT1FBDUo421yKujEJJ4UYNp2YHL+qC0Q9hkWZdn NVvQV3yWd2r+dRtsY6s5kuXxjgRpZCNdQQz9PMZEECfeygCoAGX3mf/1UD1UPB4lrlgR pFJA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AA+aEWYZTXS/vRHpa9FEzkjDEVX80G9BEy17gLF8F70lUEMk4QMRzJ+L o2R4BHg/xl/pw0aULPhF2SB9DXUwVtr7KAsMTA+CUmvXELcdzQq6pYDhEXzIdr4oRsT81QhvjeO sDtCO3gyOQxfG3vlLS5nGj9PUhxODlHRmyq59b0aRubz6B34t3qEjuKE+a+ZtppxVvg== X-Received: by 2002:aa7:8286:: with SMTP id s6mr14561140pfm.63.1543824097963; Mon, 03 Dec 2018 00:01:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/U2wUJL9NjuUGbYkV0b+NNxg7Ge2SpmboasTT07qmCGyxaSJacvsZDM7oF5C+RyoyRvYEJB X-Received: by 2002:aa7:8286:: with SMTP id s6mr14561083pfm.63.1543824097044; Mon, 03 Dec 2018 00:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543824097; cv=none; d=google.com; s=arc-20160816; b=Hr3AJbWVzquzi7JDSJTXEYCXCCamMN3ne2YJoDsUxxgkvZ30P7G0Yxk+ixg2gsxRPL wnwI8/V7qflm6kZBXh2uTu+7Y7UTuMcnwDP2CWxkpA09H5r2Rogp/1Oq+wdGw2RqsYHp JftoKGmWyQ10MHOkxLEGg5nn3cmolBUHw9NXCa5lysEvln5AWK5LjNqtbVMbGenHBNjJ T4pDKWhFZROVKr+nN0V0PqNP0TtLQLVFSl74UCM4DI13DAlIo17llU9+s5cuIsLfynpl VSehbL1HHKuXLRZMEfYj5b+pkM/kSUbSKCorgViGjzXv4F9mpIA61VIiPVman7piRx5Y T3fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=c4Qv9Gm3O0+AcCdsYZx4NZiPFV4kztTlVCRvfv2cNgU=; b=w8PWVfjKBRLBoB5mj+Mw6kPwZXhTkey/T7SzZLvwicMAH1Yuf9AWtU1tz3cjX9o/kK QrTo6YUWgsuJhCxw3W4iV5x+7PPyKESP097V7idWvrPPB1dumjeieIpyoiEQVDZaAOyu EpTQOfxgo6x9ii3uhIfvK9rD+W3g2RLS/wKPicCW+IQXwyv4lgxqdFfAk0ESO3c4uHbP ndxxffksqlaYFqgsEg3pA9UNlfNdCkEhU5ZKZ3OitlhxEe+afmIQSnSo31vd88Q9cB1X 24ZeDrXAXJNH0LIYQKv/UwKfUoN3euxO0CjHyn2luuEh/Jw5CJZYMnWZvNyGw+nT4bfk n0iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4437.biz.mail.alibaba.com (out4437.biz.mail.alibaba.com. [47.88.44.37]) by mx.google.com with ESMTPS id g6si11884244pgn.57.2018.12.03.00.01.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 00:01:37 -0800 (PST) Received-SPF: pass (google.com: domain of xlpang@linux.alibaba.com designates 47.88.44.37 as permitted sender) client-ip=47.88.44.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0TEiqOm6_1543824079; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0TEiqOm6_1543824079) by smtp.aliyun-inc.com(127.0.0.1); Mon, 03 Dec 2018 16:01:20 +0800 From: Xunlei Pang To: Michal Hocko , Roman Gushchin , Johannes Weiner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] mm/memcg: Fix min/low usage in propagate_protected_usage() Date: Mon, 3 Dec 2018 16:01:17 +0800 Message-Id: <20181203080119.18989-1-xlpang@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.002030, 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 When usage exceeds min, min usage should be min other than 0. Apply the same for low. Signed-off-by: Xunlei Pang --- mm/page_counter.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/mm/page_counter.c b/mm/page_counter.c index de31470655f6..75d53f15f040 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -23,11 +23,7 @@ static void propagate_protected_usage(struct page_counter *c, return; if (c->min || atomic_long_read(&c->min_usage)) { - if (usage <= c->min) - protected = usage; - else - protected = 0; - + protected = min(usage, c->min); old_protected = atomic_long_xchg(&c->min_usage, protected); delta = protected - old_protected; if (delta) @@ -35,11 +31,7 @@ static void propagate_protected_usage(struct page_counter *c, } if (c->low || atomic_long_read(&c->low_usage)) { - if (usage <= c->low) - protected = usage; - else - protected = 0; - + protected = min(usage, c->low); old_protected = atomic_long_xchg(&c->low_usage, protected); delta = protected - old_protected; if (delta) From patchwork Mon Dec 3 08:01:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 10708719 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 A330113BF for ; Mon, 3 Dec 2018 08:01:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9835029289 for ; Mon, 3 Dec 2018 08:01:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95FD12ADA2; Mon, 3 Dec 2018 08:01:27 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY 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 131952AD8B for ; Mon, 3 Dec 2018 08:01:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9BA96B6801; Mon, 3 Dec 2018 03:01:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A213C6B6802; Mon, 3 Dec 2018 03:01:25 -0500 (EST) 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 8EA236B6803; Mon, 3 Dec 2018 03:01:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 498AE6B6801 for ; Mon, 3 Dec 2018 03:01:25 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id m1-v6so9635385plb.13 for ; Mon, 03 Dec 2018 00:01:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=kpSHdjsIpdnFrfWLr5GbhnM5za7atIDqubrwM25NgRs=; b=UYLwVumGPV+UNgDQbUPCctNioOgXvrawkWm5VQ/zOntMZTEfp76nhREt+ZP8MiAimF DCb2XrVidToJ3lePj1nWTaKGlV13SNX3OxCm/oHLGi7S3fvZN+myG2Zx11BWLNmEhhD4 RLqZyIWTsmCBhjysFws1Sl54gc0d2rrFDqsCbLTiLbrKmOdqBzzB9W9eVTdnztf9+fCr B0xcwVZL8frrG7NYcAd8/sV0KGHBwO/K9+4Ggba4FZQM7DjASsl6A+IJZ0sd5QtY/hsw cBRe84D20jIN1KiuQM5Jzf3xFPeBxq6kRjWv+vP24LfNPJY/fcnhxsJLqpCmaL6x+JfP em4g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AA+aEWZrPp+lnhM7T+ck/do/SVXAlOhJ3PF3E1id1DOH/XnyoDNcjiqM fXZ2+yNFs2LCFy0r/jIIFMZGm5SgZftmlJR0cDi/d1kEzajx65TSslbPBkhNy3bS0YoC/yQCO8D mUf4wB4edlfW1xHZ2qUpz+niqvby6lrbzLdMnItfIPczEC7//w9xHle0skMNTtsnx8A== X-Received: by 2002:a17:902:2904:: with SMTP id g4mr14838361plb.39.1543824084901; Mon, 03 Dec 2018 00:01:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/VXSpasKQc4H63RhZW/H0+tJR218CyGHgeTGTDG7tdwpVKFVNYpRf9r9PZXP6/r8knXkYCR X-Received: by 2002:a17:902:2904:: with SMTP id g4mr14838288plb.39.1543824083854; Mon, 03 Dec 2018 00:01:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543824083; cv=none; d=google.com; s=arc-20160816; b=SC7iF+7IA4jvKVLFTXKfBw2GfC9I1FfeU5Ifbpux5fXtODQLOA40IWwnsvJ0SmIrxg BBJWGzuNoHO5FYaAREciw/0M+zy33alS5OZ+Y3JN/3WEw+NjtJhbketcdxqCmfmz1hh7 OXmh4VAjcUOSfxhWR/SxYGj+g8zh8851QnAr2FbsO+1CjalMqvLKkoX5S0GEXD7Cf8it 3hovzwk9xaEpA7QXUzfZ3cAIBZSNOyl17Tx6xu9yaq2lHvitr5XfAQILVf9V3xW/61/R OvsXBhan1L+icx+eS1EwF66DBiabx5HGiYaIG/ls7V5PswZkoCbR5LkfQEJFospwef80 +Khw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=kpSHdjsIpdnFrfWLr5GbhnM5za7atIDqubrwM25NgRs=; b=VVXnBNyELhuahsr8HYccfRKAQhfZ40HIuoFhyyuY0G2QAD18pSc5nsFvZudz6vhIwc ayn6YWu5/j6T6EP8Ll4Rbmjy5auBGid3j69Y/oK0Gwxj03UZ3wD6+UE9ApYcPt0ifPnt OsmNVe+zv4PdaYwXopWh0rkX4CVe2C67yLcYyvRhdvxGsUn99mt17ctleQSfv5G328kU BeyiwmJ+RrcIL9U9rofN78OBbC0bZshaSoQBsW2ojtfARu+uHbYVpqAnOsnZPY5RnxOQ zRNw2oB5Ujpk+DBP2L9zHsdf8UJdrecIM8eawFIST4FZZ9bEqbyYw5Pal35Rg1KRkcvU /alw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com. [115.124.30.130]) by mx.google.com with ESMTPS id b10si14271752plz.233.2018.12.03.00.01.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 00:01:23 -0800 (PST) Received-SPF: pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.130 as permitted sender) client-ip=115.124.30.130; Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04428;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0TEitRAJ_1543824080; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0TEitRAJ_1543824080) by smtp.aliyun-inc.com(127.0.0.1); Mon, 03 Dec 2018 16:01:20 +0800 From: Xunlei Pang To: Michal Hocko , Roman Gushchin , Johannes Weiner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] mm/vmscan: Enable kswapd to reclaim low-protected memory Date: Mon, 3 Dec 2018 16:01:18 +0800 Message-Id: <20181203080119.18989-2-xlpang@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 In-Reply-To: <20181203080119.18989-1-xlpang@linux.alibaba.com> References: <20181203080119.18989-1-xlpang@linux.alibaba.com> 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 There may be cgroup memory overcommitment, it will become even common in the future. Let's enable kswapd to reclaim low-protected memory in case of memory pressure, to mitigate the global direct reclaim pressures which could cause jitters to the response time of lantency-sensitive groups. Signed-off-by: Xunlei Pang --- mm/vmscan.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 62ac0c488624..3d412eb91f73 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3531,6 +3531,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) count_vm_event(PAGEOUTRUN); +retry: do { unsigned long nr_reclaimed = sc.nr_reclaimed; bool raise_priority = true; @@ -3622,6 +3623,13 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) sc.priority--; } while (sc.priority >= 1); + if (!sc.nr_reclaimed && sc.memcg_low_skipped) { + sc.priority = DEF_PRIORITY; + sc.memcg_low_reclaim = 1; + sc.memcg_low_skipped = 0; + goto retry; + } + if (!sc.nr_reclaimed) pgdat->kswapd_failures++; From patchwork Mon Dec 3 08:01:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 10708725 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 0544E13BF for ; Mon, 3 Dec 2018 08:01:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDCC12ADDD for ; Mon, 3 Dec 2018 08:01:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBA7A2ADF5; Mon, 3 Dec 2018 08:01:49 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY 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 524F02ADDD for ; Mon, 3 Dec 2018 08:01:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E4BD6B6805; Mon, 3 Dec 2018 03:01:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 36B666B6806; Mon, 3 Dec 2018 03:01:48 -0500 (EST) 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 233F56B6807; Mon, 3 Dec 2018 03:01:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by kanga.kvack.org (Postfix) with ESMTP id EA8C26B6805 for ; Mon, 3 Dec 2018 03:01:47 -0500 (EST) Received: by mail-io1-f71.google.com with SMTP id k4so13455293ioc.10 for ; Mon, 03 Dec 2018 00:01:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=QQYeTUdf8tT5eXiloDRVhLfCVIjtieL3mXHecRpvzQo=; b=lyGA2uPvVC1rlCB3iQolhkuuao+hvA4HO0goWUjAlg0m5esOkNV8cS6ZSlPYU45Cyo FeIvfgAsnkYJ8saMN2TyZbAiq1MTYGTwxxudq68GMyFgcjIhQHQFFTY9ttP/K71oc6uQ D5GZosW9hHrM23vx9TM6Lu5yvkecoLrlejx2kNEgRkmBBwqGFaLYA+k+43EXa64PVnv6 FmKqewb8i72fcSDlyZY/mJfVw5soLGSl7fr8s2iUSuWeGjHRhiKptXVLlPUcYHIkt9WN tfnbrhjOqTjVG4Rju/+4bibWQ6FhEzkbNUVF1HXwwBvILUha/zg06LGwt56d3I3PiC67 PY+Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AA+aEWZNP3rvSCJebaFHkfHQYRpk/ik/MbX4Jw6KQq6t6N0Bsdgt2EGP auqPEopfkAYF+kHiRzw/vQ+jmm2S3kgG+uunDmL7gt0OmEl+gStdQtpH9GTyqwhhjw5SNx2DEaq 3pmoIT7nf6SuCnzl3Q86e3AzK9LBdRbtBQuxSDuhqi/TyQP2i5Ixe8FFQ+ITFMpaszw== X-Received: by 2002:a6b:3705:: with SMTP id e5mr13296540ioa.240.1543824107669; Mon, 03 Dec 2018 00:01:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/UQwCMUjcbSBuFbAhBBVqkR2wGTgwenjImdjy55z1GLmTUKmzSPCQmIagbM0S69FmBDAa/H X-Received: by 2002:a6b:3705:: with SMTP id e5mr13296482ioa.240.1543824106501; Mon, 03 Dec 2018 00:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543824106; cv=none; d=google.com; s=arc-20160816; b=0XEk7VOPVo2ofNlAy1d9Ai1fOLoqqKB7JnPryGmI4TwWlcf6e9NfLlzWXTOgSL02CD eGAW7qv8RiqCVn32m8zO0v+Mqsv7EwCceD9v9AYEOvPdriMJV2OZ0FFy+weZOadKHFc8 jEtzjtx1rHY8TNjt3V8UPkxRtL680Obbt5oSXOtplBTx1nVU/NnVGIzkhbdcTnrKS2pm uxLU8zGILHDB8WIKr3XtKHKFFl99lyQt5UL6JJX7F6T42PG/qiAoUka8sTtFKwQqLFZR LTqkrXqF5SAMJ3+AqLOKwmMgiMco9Zz+l+yZUrYySyEDnLy6GmGmqeyIjE8XYdQrVsUr g6ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=QQYeTUdf8tT5eXiloDRVhLfCVIjtieL3mXHecRpvzQo=; b=zkbe9XOV6sdEiO1arg3IadUUdxTndwUlUp0NTE6H5YpKn6dG1K3MiOKNH7RWbD++ig qh+piKF0igR+PFpXYjgGSd1krXS6XhcdVdQ5tUOPTORuYc5DXgyQCD1ugNX7s9KsiXp7 i542Omvtpjx8LdLgcb8DSgJAoLyg/Vk0J1pBQlhOorOgOt4m/jbmLyOcBomS+1kRB8Yd Qu6GC7NqNjep/BvsOn+tjTwfHtc37Bdl/ufHR06/D1JHMRQiZ3wv0QgWlTeMF1aYRPOu HMcp5XNBrTRTvpZxfF+fB8Nfising8N4ET7nLSvylTqqDG/RCdfSxHrEJOczgYd3nY+f dKGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com. [115.124.30.131]) by mx.google.com with ESMTPS id 82si4383673jap.36.2018.12.03.00.01.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 00:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.131 as permitted sender) client-ip=115.124.30.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of xlpang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=xlpang@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01419;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0TEiqOmR_1543824080; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0TEiqOmR_1543824080) by smtp.aliyun-inc.com(127.0.0.1); Mon, 03 Dec 2018 16:01:21 +0800 From: Xunlei Pang To: Michal Hocko , Roman Gushchin , Johannes Weiner Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] mm/memcg: Avoid reclaiming below hard protection Date: Mon, 3 Dec 2018 16:01:19 +0800 Message-Id: <20181203080119.18989-3-xlpang@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 In-Reply-To: <20181203080119.18989-1-xlpang@linux.alibaba.com> References: <20181203080119.18989-1-xlpang@linux.alibaba.com> 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 When memcgs get reclaimed after its usage exceeds min, some usages below the min may also be reclaimed in the current implementation, the amount is considerably large during kswapd reclaim according to my ftrace results. This patch calculates the part over hard protection limit, and allows only this part of usages to be reclaimed. Signed-off-by: Xunlei Pang --- include/linux/memcontrol.h | 7 +++++-- mm/memcontrol.c | 9 +++++++-- mm/vmscan.c | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7ab2120155a4..637ef975792f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -334,7 +334,8 @@ static inline bool mem_cgroup_disabled(void) } enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg); + struct mem_cgroup *memcg, + unsigned long *min_excess); int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, @@ -818,7 +819,9 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm, } static inline enum mem_cgroup_protection mem_cgroup_protected( - struct mem_cgroup *root, struct mem_cgroup *memcg) + struct mem_cgroup *root, + struct mem_cgroup *memcg, + unsigned long *min_excess) { return MEMCG_PROT_NONE; } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6e1469b80cb7..ca96f68e07a0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5694,6 +5694,7 @@ struct cgroup_subsys memory_cgrp_subsys = { * mem_cgroup_protected - check if memory consumption is in the normal range * @root: the top ancestor of the sub-tree being checked * @memcg: the memory cgroup to check + * @min_excess: store the number of pages exceeding hard protection * * WARNING: This function is not stateless! It can only be used as part * of a top-down tree iteration, not for isolated queries. @@ -5761,7 +5762,8 @@ struct cgroup_subsys memory_cgrp_subsys = { * as memory.low is a best-effort mechanism. */ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg) + struct mem_cgroup *memcg, + unsigned long *min_excess) { struct mem_cgroup *parent; unsigned long emin, parent_emin; @@ -5827,8 +5829,11 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, return MEMCG_PROT_MIN; else if (usage <= elow) return MEMCG_PROT_LOW; - else + else { + if (emin) + *min_excess = usage - emin; return MEMCG_PROT_NONE; + } } /** diff --git a/mm/vmscan.c b/mm/vmscan.c index 3d412eb91f73..e4fa7a2a63d0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -66,6 +66,9 @@ struct scan_control { /* How many pages shrink_list() should reclaim */ unsigned long nr_to_reclaim; + /* How many pages hard protection allows */ + unsigned long min_excess; + /* * Nodemask of nodes allowed by the caller. If NULL, all nodes * are scanned. @@ -2503,10 +2506,14 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc unsigned long nr_to_scan; enum lru_list lru; unsigned long nr_reclaimed = 0; - unsigned long nr_to_reclaim = sc->nr_to_reclaim; + unsigned long nr_to_reclaim; struct blk_plug plug; bool scan_adjusted; + nr_to_reclaim = sc->nr_to_reclaim; + if (sc->min_excess) + nr_to_reclaim = min(nr_to_reclaim, sc->min_excess); + get_scan_count(lruvec, memcg, sc, nr, lru_pages); /* Record the original scan target for proportional adjustments later */ @@ -2544,6 +2551,10 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc cond_resched(); + /* Abort proportional reclaim when hard protection applies */ + if (sc->min_excess && nr_reclaimed >= sc->min_excess) + break; + if (nr_reclaimed < nr_to_reclaim || scan_adjusted) continue; @@ -2725,8 +2736,9 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) unsigned long lru_pages; unsigned long reclaimed; unsigned long scanned; + unsigned long excess = 0; - switch (mem_cgroup_protected(root, memcg)) { + switch (mem_cgroup_protected(root, memcg, &excess)) { case MEMCG_PROT_MIN: /* * Hard protection. @@ -2752,6 +2764,7 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) reclaimed = sc->nr_reclaimed; scanned = sc->nr_scanned; + sc->min_excess = excess; shrink_node_memcg(pgdat, memcg, sc, &lru_pages); node_lru_pages += lru_pages;