From patchwork Tue Dec 17 11:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11297347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84B4B6C1 for ; Tue, 17 Dec 2019 11:31:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 47FFC207FF for ; Tue, 17 Dec 2019 11:31:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o4+ceH3W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47FFC207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6F8C58E0056; Tue, 17 Dec 2019 06:31:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A8CE8E0040; Tue, 17 Dec 2019 06:31:22 -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 571BC8E0056; Tue, 17 Dec 2019 06:31:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 41CF48E0040 for ; Tue, 17 Dec 2019 06:31:22 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id C54738249980 for ; Tue, 17 Dec 2019 11:31:21 +0000 (UTC) X-FDA: 76274417562.05.body37_28f580a773a2e X-Spam-Summary: 2,0,0,72b2201a450269d1,d41d8cd98f00b204,laoar.shao@gmail.com,:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org:viro@zeniv.linux.org.uk::linux-fsdevel@vger.kernel.org:laoar.shao@gmail.com:aaron.lu@intel.com,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1431:1437:1534:1541:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:4250:4321:4605:5007:6119:6261:6653:7514:7901:7903:8603:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12517:12519:12555:12895:12986:13069:13138:13161:13229:13231:13311:13357:14096:14181:14384:14394:14687:14721:21080:21444:21450:21451:21627:21666:21972:30034:30054:30056:30064:30090,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: body37_28f580a773a2e X-Filterd-Recvd-Size: 4790 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 11:31:21 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id o11so4443916pjp.9 for ; Tue, 17 Dec 2019 03:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BpFS4ToaQ+oe6Ip5CmXL+qTNhJ6T5OxwPQOYZvo7h1c=; b=o4+ceH3WOEc9xJ6ASmn6cuSNePCY7AIbZkbZjByDUFDLr1Nv28bSA3NdI8FXR9xoxi 3qgxs0f1HIhpHGG3qotyZRBJdqShtNasVuiSubIk8lJY5L474yxYltqHQnRnYQc9UYbY cQVppl4qcmCarMf6Zg0P3J5WqXrUBh5K0NMb2UK8mfNyCQcBtJH6Ha+ZOEpvPV1na6EZ Clpr5BZpG8Ihzca+Je2gB3IdTyU/qXkjDMQ5ETI0jaGOyPPvM6lzic/WueiBKB6bR0ka 5szd6vJA3mt+AuWm4TQf4JAMggWIzTe4bGejVn7JJ5t7EcsBlvKIZxP0S5TXL/1PBceq RSJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BpFS4ToaQ+oe6Ip5CmXL+qTNhJ6T5OxwPQOYZvo7h1c=; b=m1U+zBbNi99/LUmms29Mgg4jWkKRaojlm6mr/xld9auKxc5AdZxSD3qt2ug1HZtdUo 10FI3yAE9f4ulcD3YNYcIF5BJIjiAmdOuru4pSawp0yr30tYfe+maL3/Q5LDkTbY3gXt ma8ix+szy9BW/trru45S1mgZFB203S7BAK+rOCiyM9kUn++XkrQTvdAIV513IKtl3vc7 IBG93swJMNrOYH6M1h0hJAk0+5qKo0FDaU2Pmp0FriYThdcUbY6ueqcsqyzdCHIwuIl/ ErFof/JJUbDGS9/iQ5z2RdDBjCKgrHjxRFoVXIEnX4NtDkyYmc5SwKYgbdaiZFHTeHsM aOjg== X-Gm-Message-State: APjAAAWD0jRV2QU9s0P/00PuDC/Q4J8+kjV7SpOYS9LfS9kbHUByjlxN j30mBTonM8/lOe6MjwZQw/c= X-Google-Smtp-Source: APXvYqwmJ9uXmmvZ0m9A7jESIE+N5e4Bnr6zUDk3KHJOdY7miJJNO8rV7iJrrkPEZCWUKLNEAhQ5mw== X-Received: by 2002:a17:90a:eb06:: with SMTP id j6mr5320406pjz.81.1576582280315; Tue, 17 Dec 2019 03:31:20 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id q21sm26246460pff.105.2019.12.17.03.31.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 03:31:19 -0800 (PST) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Yafang Shao , Aaron Lu Subject: [PATCH 1/4] mm, memcg: reduce size of struct mem_cgroup by using bit field Date: Tue, 17 Dec 2019 06:29:16 -0500 Message-Id: <1576582159-5198-2-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> References: <1576582159-5198-1-git-send-email-laoar.shao@gmail.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: There are some members in struct mem_group can be either 0(false) or 1(true), so we can define them using bit field to reduce size. With this patch, the size of struct mem_cgroup can be reduced by 64 bytes in theory, but as there're some MEMCG_PADDING()s, the real number may be different, which is relate with the cacheline size. Anyway, this patch could reduce the size of struct mem_cgroup more or less. Cc: Aaron Lu Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index a7a0a1a5..612a457 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -229,20 +229,26 @@ struct mem_cgroup { /* * Should the accounting and control be hierarchical, per subtree? */ - bool use_hierarchy; + unsigned int use_hierarchy : 1; /* * Should the OOM killer kill all belonging tasks, had it kill one? */ - bool oom_group; + unsigned int oom_group : 1; /* protected by memcg_oom_lock */ - bool oom_lock; - int under_oom; + unsigned int oom_lock : 1; - int swappiness; /* OOM-Killer disable */ - int oom_kill_disable; + unsigned int oom_kill_disable : 1; + + /* Legacy tcp memory accounting */ + unsigned int tcpmem_active : 1; + unsigned int tcpmem_pressure : 1; + + int under_oom; + + int swappiness; /* memory.events and memory.events.local */ struct cgroup_file events_file; @@ -297,9 +303,6 @@ struct mem_cgroup { unsigned long socket_pressure; - /* Legacy tcp memory accounting */ - bool tcpmem_active; - int tcpmem_pressure; #ifdef CONFIG_MEMCG_KMEM /* Index in the kmem_cache->memcg_params.memcg_caches array */ From patchwork Tue Dec 17 11:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11297351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C334414E3 for ; Tue, 17 Dec 2019 11:31:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8FC5B207FF for ; Tue, 17 Dec 2019 11:31:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ay5w39y6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FC5B207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A7C778E0057; Tue, 17 Dec 2019 06:31:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A53A28E0040; Tue, 17 Dec 2019 06:31: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 968418E0057; Tue, 17 Dec 2019 06:31:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 8317C8E0040 for ; Tue, 17 Dec 2019 06:31:25 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4636E8249980 for ; Tue, 17 Dec 2019 11:31:25 +0000 (UTC) X-FDA: 76274417730.01.seed05_2971351b76f02 X-Spam-Summary: 2,0,0,5cb5c331b8241ec4,d41d8cd98f00b204,laoar.shao@gmail.com,:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org:viro@zeniv.linux.org.uk::linux-fsdevel@vger.kernel.org:laoar.shao@gmail.com:guro@fb.com,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3352:3865:3866:3867:3871:3872:3874:4321:4605:5007:6261:6653:7514:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:13069:13311:13357:14096:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21740:21990:30054:30064:30070,0,RBL:209.85.214.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: seed05_2971351b76f02 X-Filterd-Recvd-Size: 4522 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 11:31:24 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id p9so1730665plk.9 for ; Tue, 17 Dec 2019 03:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fFfoleXjv3JSEmvkK0O9oMZGbyG7YMfuDochkkrQvOQ=; b=Ay5w39y6OP8b3+PSyWbNiB80MxHJVJSkjW+k+erc0+AmU1eBRpUnMfmFdSpTt3lBiL WXKb1e+X82cm+QC6jSydUQ6aqBNsbSp40uxC77iTvEE/hBw1nGeZiGyQrZek3edQH7Gl ifi8kZqgJUVhbSMYNppmKS5VPIFpQoxn8FW8OZfVzMArfXENhsNhFjv7OoOs906svNnk UyazUX4Lne2F3b0VB4++90jelJF4NorPxOROqwdwtNfnKoAq9gzFSoiF/IYMstPeSHeg 3O7TOCPm2IasOAdlxc7HFvCLj70+9f37uu7qlYmhyeS8aHA9bjFxLAUttL9nUe8+YMnG okPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fFfoleXjv3JSEmvkK0O9oMZGbyG7YMfuDochkkrQvOQ=; b=KZqLC7P/3gT62vdijrMNlyi/bodSjSdA05rLMnWnmHdYwni/v0o76wVFJUy1xEXBH/ Si1/pDM0yFtIYMnrfO+mEiyHYTxlXYellC9HlBqqC3tp45CzUAYVv7u1w/CYfWaZAgiz Jda6IPPZiCEfOlSipZho4kfbge5EjE9WYRgZ5Bb2N9z1mkugODQp8PbRNO3Sm/c2k8V4 kDyI1xqGz1x7MwyEsSUoJYkj6CxZ6jfMhuALBUVbfmAWxbtDkqVr3M27N6qNGTdrdWF2 pvbResltxghXJFOM1t7XG9OVSZMzG8eOvPRo7rdmneTUobwHhbJXeQPbs4FFA7uteREK AyXg== X-Gm-Message-State: APjAAAU0Qf5VlHeqNNtrGkgVIYuyaPsQlN0Vy0m+wf/quSskWg2pAkWY Wl2/jSia0CRVCuExLrWKrOo= X-Google-Smtp-Source: APXvYqwgOIO9DkR9d5dmrB5DvMfBD6fXB5FS6maFa7bVNVo9BDd0ix+SDlXBo+0I1chqAKdB25eFeg== X-Received: by 2002:a17:902:9b86:: with SMTP id y6mr20608166plp.253.1576582283572; Tue, 17 Dec 2019 03:31:23 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id q21sm26246460pff.105.2019.12.17.03.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 03:31:23 -0800 (PST) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Yafang Shao , Roman Gushchin Subject: [PATCH 2/4] mm, memcg: introduce MEMCG_PROT_SKIP for memcg zero usage case Date: Tue, 17 Dec 2019 06:29:17 -0500 Message-Id: <1576582159-5198-3-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> References: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the usage of a memcg is zero, we don't need to do useless work to scan it. That is a minor optimization. Cc: Roman Gushchin Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 2 +- mm/vmscan.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 612a457..1a315c7 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -54,6 +54,7 @@ enum mem_cgroup_protection { MEMCG_PROT_NONE, MEMCG_PROT_LOW, MEMCG_PROT_MIN, + MEMCG_PROT_SKIP, /* For zero usage case */ }; struct mem_cgroup_reclaim_cookie { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c5b5f74..f35fcca 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6292,7 +6292,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, usage = page_counter_read(&memcg->memory); if (!usage) - return MEMCG_PROT_NONE; + return MEMCG_PROT_SKIP; emin = memcg->memory.min; elow = memcg->memory.low; diff --git a/mm/vmscan.c b/mm/vmscan.c index 5a6445e..3c4c2da 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2677,6 +2677,12 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) * thresholds (see get_scan_count). */ break; + case MEMCG_PROT_SKIP: + /* + * Skip scanning this memcg if the usage of it is + * zero. + */ + continue; } reclaimed = sc->nr_reclaimed; From patchwork Tue Dec 17 11:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11297355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E947D6C1 for ; Tue, 17 Dec 2019 11:31:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B5F75207FF for ; Tue, 17 Dec 2019 11:31:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rFBgOLw5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5F75207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AA3468E0058; Tue, 17 Dec 2019 06:31:28 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A78DF8E0040; Tue, 17 Dec 2019 06:31:28 -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 9B6FF8E0058; Tue, 17 Dec 2019 06:31:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 8730F8E0040 for ; Tue, 17 Dec 2019 06:31:28 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 40D60180AD807 for ; Tue, 17 Dec 2019 11:31:28 +0000 (UTC) X-FDA: 76274417856.01.knot12_29e499528860c X-Spam-Summary: 2,0,0,ca26ec6a9f0125c2,d41d8cd98f00b204,laoar.shao@gmail.com,:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org:viro@zeniv.linux.org.uk::linux-fsdevel@vger.kernel.org:laoar.shao@gmail.com:chris@chrisdown.name,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3874:5007:6261:6653:7514:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:13069:13161:13229:13311:13357:14096:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054:30070:30090,0,RBL:209.85.215.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: knot12_29e499528860c X-Filterd-Recvd-Size: 4241 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 11:31:27 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id k197so5504542pga.10 for ; Tue, 17 Dec 2019 03:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PfAZz+7YFL5P4jlslEzjz2qfIRhr8Qk9D33rUR/m3Pc=; b=rFBgOLw5GBbA5M6JYtyuopWqCS7rTgK8GrRgyaJZh1EwcwoZ4adsA7i45dxIH3ks1E cA2ShGT5a87N90+9y/AWBHgw7Lf9duh3wh6k7jK23S5xE38qGx7w/tTaPsAgKYDeCbgR qXasE3JU3WZBesFJ+CLsGJzaVeKYysjUCV32mI8wvz0bafDNCtRXZgdXXvXc/huTpRk5 VF+QSU/YyBf3afiP4m8kPjHDwt+ETnPXi9fap5jkKdx6Nw+j2uHfk6PZ+Cheyd2oXDEN 2/wLFGhXHmWHa1niJ7qkuiAbDyQr1Gc4aj+s0FOfPe95qklSqw9a/gvAPNINJ6cLkkoS atDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PfAZz+7YFL5P4jlslEzjz2qfIRhr8Qk9D33rUR/m3Pc=; b=RiJrx+QmfJdP6c18ze9H45FPZIy8xUS82O94qvSDnJ0ldfza+vJYf6vQpo1BFdUWH+ T+bM31e72szQqGTGiQm0TirYqa3GSG3GJf/H4yfySkWa7igPAYVA73MkrUptvqpbxZ68 DufVxL3FQvxYE/9vcL9CcJhNuQGOn0VDCNz4dwL8CDNvt/h1Bh3ZwiT20TyWu+BN+8Xg JzP9s8lIklI64CrxOQB+XuuPNsOTvtBS7y6CaNppHJLvfSryZQH00DyIxzCBfKw7zFLH eu8cPKmZo0U/FdVJxwc7kUlcDqQYGAtPVtzdyXnZmbBHm8T32WjpixrR+ZmnfFaIOIU6 JvZg== X-Gm-Message-State: APjAAAX3pI/IUYj21S69fKbLVxK0z6zymg6NQq0wbzJOdBOZm4MsO0/g e3UqCht7e3IAfYY8H1JbBo4/HwcAB4U= X-Google-Smtp-Source: APXvYqxKC4uL4weF1OEd7OR+j+1clxzVjXRygLvMNhVRBcvixxJuond5I2PkqDo/eiZsiVduAVa7ZA== X-Received: by 2002:a65:56c6:: with SMTP id w6mr25047436pgs.167.1576582286912; Tue, 17 Dec 2019 03:31:26 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id q21sm26246460pff.105.2019.12.17.03.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 03:31:26 -0800 (PST) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Yafang Shao , Chris Down Subject: [PATCH 3/4] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself Date: Tue, 17 Dec 2019 06:29:18 -0500 Message-Id: <1576582159-5198-4-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> References: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.005788, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: memory.{emin, elow} are set in mem_cgroup_protected(), and the values of them won't be changed until next recalculation in this function. After either or both of them are set, the next reclaimer to relcaim this memcg may be a different reclaimer, e.g. this memcg is also the root memcg of the new reclaimer, and then in mem_cgroup_protection() in get_scan_count() the old values of them will be used to calculate scan count, that is not proper. We should reset them to zero in this case. Cc: Chris Down Signed-off-by: Yafang Shao --- mm/memcontrol.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f35fcca..234370c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6287,8 +6287,17 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (!root) root = root_mem_cgroup; - if (memcg == root) + if (memcg == root) { + /* + * Reset memory.(emin, elow) for reclaiming the memcg + * itself. + */ + if (memcg != root_mem_cgroup) { + memcg->memory.emin = 0; + memcg->memory.emin = 0; + } return MEMCG_PROT_NONE; + } usage = page_counter_read(&memcg->memory); if (!usage) From patchwork Tue Dec 17 11:29:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11297359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C25914E3 for ; Tue, 17 Dec 2019 11:31:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C42A207FF for ; Tue, 17 Dec 2019 11:31:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZyV99MTr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C42A207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1C9688E0059; Tue, 17 Dec 2019 06:31:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 154968E0040; Tue, 17 Dec 2019 06:31:33 -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 041C68E0059; Tue, 17 Dec 2019 06:31:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id E3CD68E0040 for ; Tue, 17 Dec 2019 06:31:32 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 50F55181AEF0B for ; Tue, 17 Dec 2019 11:31:32 +0000 (UTC) X-FDA: 76274418024.21.oil79_2a765054eb432 X-Spam-Summary: 2,0,0,82847a1f4af18f49,d41d8cd98f00b204,laoar.shao@gmail.com,:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org:viro@zeniv.linux.org.uk::linux-fsdevel@vger.kernel.org:laoar.shao@gmail.com:guro@fb.com:chris@chrisdown.name:dchinner@redhat.com,RULES_HIT:2:41:355:379:541:800:960:965:966:973:988:989:1260:1345:1359:1437:1535:1605:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2693:2897:2898:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4049:4120:4250:4321:4385:4390:4395:4470:4605:5007:6119:6261:6653:7514:7875:7903:9413:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13161:13229:14096:14394:14687:21080:21433:21444:21450:21451:21627:21666:21740:21796:21990:30036:30054:30064:30070:30090,0,RBL:209.85.214.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:n one,Cust X-HE-Tag: oil79_2a765054eb432 X-Filterd-Recvd-Size: 9170 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Dec 2019 11:31:31 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id f20so4203453plj.5 for ; Tue, 17 Dec 2019 03:31:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mUxzvwjgO2ZHffdQyZgrVhwhMVrr5KtTx2eyM983GSE=; b=ZyV99MTr7TRmBgXevNorWGAiLdpHGh5vhPG68r3LAmi3qW5mszrDUnC/nemNzdlGba 9gziqICgCOonEX3+3FqBCM/7nGUqtkOluvGIH08bkbH1VtljgDj6aGPb8QwkvdPWuU3Z 9sRTh3xgtAAq1SD1qQ/RVPtDPmjAHnhMjUM+nChqOQ4jz6qLeqpYdvyq1d86gr+eQLi4 JOj3m983q9z1A0D+hUJ3E9fxVpat52/bcanlQMQo6N/Lw3jcKIcS2Dxghd/8TKp8iNr4 Zoa094mEFPJqHxh+p2FfxPVu/+lWkWfaCxgXzDGGPnHnYMUHopz21/RBJ6f7Qhg/czUd XcwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mUxzvwjgO2ZHffdQyZgrVhwhMVrr5KtTx2eyM983GSE=; b=Uist7G1mlp3M2Sf6t9vJT3TfXCrVtmsRJk8jLL6tvdzPUzlUK2+OQN2U1+BCZ+/Ic8 GyPC7iAMNINxaAs2ihZraJ9qCSjQKf3BSTGoMztu3RNAufPE9IPVUjkW7IEvzMNT3l1Q asfOErj4kSKvQqW2ujhx9AHSKAdQAtk+Brcm3BfzikTtTTkcomnjaHR3T9mRqwwuIbh6 QaqGcNP3WgBTw5NnNK8K23NJh2wJDODi2f6vvTOx3dQpjAOg+GlWg2UDeC4LowqCPYVD i6f7suzz3R5Pt0BjNC8MnFmK0MnVoRQx7lkHr0If95BbEskUr2L0qsmWwyGVkAi47RHu eTkA== X-Gm-Message-State: APjAAAWJ9bRF2uiR/j5ghki9/E7oYeZpChzvr0aHnl5fRmKikXPJbA8m 7HMsp1KqIdLNWJFWMKTcZ3M= X-Google-Smtp-Source: APXvYqxenXdKMwF1wXuyr9N43cbveSFn99SPjKOUFQEVuvOKGVqYmKHFw15XIdQBlplXGhUHN/nbSw== X-Received: by 2002:a17:902:9a8f:: with SMTP id w15mr7059647plp.149.1576582290689; Tue, 17 Dec 2019 03:31:30 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id q21sm26246460pff.105.2019.12.17.03.31.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 03:31:30 -0800 (PST) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Yafang Shao , Roman Gushchin , Chris Down , Dave Chinner Subject: [PATCH 4/4] memcg, inode: protect page cache from freeing inode Date: Tue, 17 Dec 2019 06:29:19 -0500 Message-Id: <1576582159-5198-5-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576582159-5198-1-git-send-email-laoar.shao@gmail.com> References: <1576582159-5198-1-git-send-email-laoar.shao@gmail.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: On my server there're some running MEMCGs protected by memory.{min, low}, but I found the usage of these MEMCGs abruptly became very small, which were far less than the protect limit. It confused me and finally I found that was because of inode stealing. Once an inode is freed, all its belonging page caches will be dropped as well, no matter how may page caches it has. So if we intend to protect the page caches in a memcg, we must protect their host (the inode) first. Otherwise the memcg protection can be easily bypassed with freeing inode, especially if there're big files in this memcg. The inherent mismatch between memcg and inode is a trouble. One inode can be shared by different MEMCGs, but it is a very rare case. If an inode is shared, its belonging page caches may be charged to different MEMCGs. Currently there's no perfect solution to fix this kind of issue, but the inode majority-writer ownership switching can help it more or less. Cc: Roman Gushchin Cc: Chris Down Cc: Dave Chinner Signed-off-by: Yafang Shao --- fs/inode.c | 9 +++++++++ include/linux/memcontrol.h | 15 +++++++++++++++ mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 4 ++++ 4 files changed, 74 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index fef457a..b022447 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -734,6 +734,15 @@ static enum lru_status inode_lru_isolate(struct list_head *item, if (!spin_trylock(&inode->i_lock)) return LRU_SKIP; + + /* Page protection only works in reclaimer */ + if (inode->i_data.nrpages && current->reclaim_state) { + if (mem_cgroup_inode_protected(inode)) { + spin_unlock(&inode->i_lock); + return LRU_ROTATE; + } + } + /* * Referenced or dirty inodes are still in use. Give them another pass * through the LRU as we canot reclaim them now. diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 1a315c7..21338f0 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -247,6 +247,9 @@ struct mem_cgroup { unsigned int tcpmem_active : 1; unsigned int tcpmem_pressure : 1; + /* Soft protection will be ignored if it's true */ + unsigned int in_low_reclaim : 1; + int under_oom; int swappiness; @@ -363,6 +366,7 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg, enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, struct mem_cgroup *memcg); +unsigned long mem_cgroup_inode_protected(struct inode *inode); int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, @@ -850,6 +854,11 @@ static inline enum mem_cgroup_protection mem_cgroup_protected( return MEMCG_PROT_NONE; } +static inline unsigned long mem_cgroup_inode_protected(struct inode *inode) +{ + return 0; +} + static inline int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, @@ -926,6 +935,12 @@ static inline struct mem_cgroup *get_mem_cgroup_from_page(struct page *page) return NULL; } +static inline struct mem_cgroup * +mem_cgroup_from_css(struct cgroup_subsys_state *css) +{ + return NULL; +} + static inline void mem_cgroup_put(struct mem_cgroup *memcg) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 234370c..efb53f3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6355,6 +6355,52 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, } /** + * Once an inode is freed, all its belonging page caches will be dropped as + * well, even if there're lots of page caches. So if we intend to protect + * page caches in a memcg, we must protect their host first. Otherwise the + * memory usage can be dropped abruptly if there're big files in this + * memcg. IOW the memcy protection can be easily bypassed with freeing + * inode. We should prevent it. + * The inherent mismatch between memcg and inode is a trouble. One inode + * can be shared by different MEMCGs, but it is a very rare case. If + * an inode is shared, its belonging page caches may be charged to + * different MEMCGs. Currently there's no perfect solution to fix this + * kind of issue, but the inode majority-writer ownership switching can + * help it more or less. + */ +unsigned long mem_cgroup_inode_protected(struct inode *inode) +{ + unsigned long cgroup_size; + unsigned long protect = 0; + struct bdi_writeback *wb; + struct mem_cgroup *memcg; + + wb = inode_to_wb(inode); + if (!wb) + goto out; + + memcg = mem_cgroup_from_css(wb->memcg_css); + if (!memcg || memcg == root_mem_cgroup) + goto out; + + protect = mem_cgroup_protection(memcg, memcg->in_low_reclaim); + if (!protect) + goto out; + + cgroup_size = mem_cgroup_size(memcg); + /* + * Don't need to protect this inode, if the usage is still above + * the limit after reclaiming this inode and its belonging page + * caches. + */ + if (inode->i_data.nrpages + protect < cgroup_size) + protect = 0; + +out: + return protect; +} + +/** * mem_cgroup_try_charge - try charging a page * @page: page to charge * @mm: mm context of the victim diff --git a/mm/vmscan.c b/mm/vmscan.c index 3c4c2da..1cc7fc2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2666,6 +2666,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) sc->memcg_low_skipped = 1; continue; } + memcg->in_low_reclaim = 1; memcg_memory_event(memcg, MEMCG_LOW); break; case MEMCG_PROT_NONE: @@ -2693,6 +2694,9 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) shrink_slab(sc->gfp_mask, pgdat->node_id, memcg, sc->priority); + if (memcg->in_low_reclaim) + memcg->in_low_reclaim = 0; + /* Record the group's reclaim efficiency */ vmpressure(sc->gfp_mask, memcg, false, sc->nr_scanned - scanned,