Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4247175imm; Fri, 18 May 2018 01:44:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3ZUjm4T16wsD2yLGNJcWNNj+w1dgc71nR6pHSN9tk0hzHBRZ3eLt+E+ECXSnzvh5EkIZE X-Received: by 2002:a63:6fcd:: with SMTP id k196-v6mr6706364pgc.376.1526633069375; Fri, 18 May 2018 01:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526633069; cv=none; d=google.com; s=arc-20160816; b=N2a8Euyt/RdSD1TtK/ltbxpl1qakQie9Dm3XjriI7/6piaHlcU5nz0/Ir0xFWzdoVX u0O5IlKi44pl8FKCvpUHLk3D9rd5EW/Z3ECws3NGVPl+zOg2X5dXnM0rcI6ZMyQQKrBO +/YYQ28s5K+zqxAzF6VXwRWGxanM3Rxj4RIQLOFIjy3EJgd2VdK3bjwll3LANNItLqC8 nBCZc9C+xKEuqW3S057oR3XPo9yZ5eYivsL748k93+d6cfdoNEVqwIJySvbXDP+i7jDu gGa8aNqFLFpsYb4EzDuopbmoap2AehD6T85nvwdbaNIpcZw3hSBfUTgZ3hjUxsj/+Z8T a0qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject :dkim-signature:arc-authentication-results; bh=HMwdRD3+7OdPBg0FuiXPYL/OV9rHb3ut7yPZXNSPW2s=; b=ndAx/hFRitMEqEUWFDV/gpScqXx1yqXF+HinPmGhqSyJLqhK/c+FEDQz+/4a1A5O+D v2tO+UcPJ42CJwYFSvta/IJJnUnd7ua890cs01Cqxr4vcgaBmIbTb/1WeEtvJW20LRaY XyyVZONMZSmwKX2bZPnppqRF8MC58B0S6H3mjwqneTDXApn1DmSHxYIp5I7qW8EN2O0b Iv5j8hHHs0kpYu2wJUyK8nIJRfpxtiCPs2wvRWDsRYX+kc4BV0J9YqHyOWa/kN/N2Kka rjUWn7BuwcArgHGbazEhXYNngY3kKCAuHgQETV9r693QuFWJIJKyAXeSS41af7o1bD14 ejSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=UpPy2lsY; 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=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24-v6si6691264pfm.257.2018.05.18.01.44.15; Fri, 18 May 2018 01:44:29 -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=@virtuozzo.com header.s=selector1 header.b=UpPy2lsY; 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=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753922AbeERIn7 (ORCPT + 99 others); Fri, 18 May 2018 04:43:59 -0400 Received: from mail-ve1eur01on0115.outbound.protection.outlook.com ([104.47.1.115]:47200 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753535AbeERInx (ORCPT ); Fri, 18 May 2018 04:43:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HMwdRD3+7OdPBg0FuiXPYL/OV9rHb3ut7yPZXNSPW2s=; b=UpPy2lsYeJAWddQDRMtwRnDWqzl/W1swvUJfXZspfC72YAKFwA5BpBdg46XWMyalATUR+9Vkq/h3lma5A7xnsvKT+t6nuexbWBOG7YBfyMY3uUpxQ3hOFLJbT37SEL8paSkA2PPzEhw8+4J49veo8BUhYU7TAFd8BECi0LKAZtU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by VI1PR0801MB1341.eurprd08.prod.outlook.com (2603:10a6:800:3a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Fri, 18 May 2018 08:43:45 +0000 Subject: [PATCH v6 12/17] mm: Set bit in memcg shrinker bitmap on first list_lru item apearance From: Kirill Tkhai To: akpm@linux-foundation.org, vdavydov.dev@gmail.com, shakeelb@google.com, viro@zeniv.linux.org.uk, hannes@cmpxchg.org, mhocko@kernel.org, ktkhai@virtuozzo.com, tglx@linutronix.de, pombredanne@nexb.com, stummala@codeaurora.org, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, guro@fb.com, mka@chromium.org, penguin-kernel@I-love.SAKURA.ne.jp, chris@chris-wilson.co.uk, longman@redhat.com, minchan@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, jbacik@fb.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, lirongqing@baidu.com, aryabinin@virtuozzo.com Date: Fri, 18 May 2018 11:43:42 +0300 Message-ID: <152663302275.5308.7476660277265020067.stgit@localhost.localdomain> In-Reply-To: <152663268383.5308.8660992135988724014.stgit@localhost.localdomain> References: <152663268383.5308.8660992135988724014.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0902CA0016.eurprd09.prod.outlook.com (2603:10a6:3:e5::26) To VI1PR0801MB1341.eurprd08.prod.outlook.com (2603:10a6:800:3a::27) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:VI1PR0801MB1341; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1341;3:5cG6Cn6gfAi1xXL8PE3pa9s6Tkuv5GGOjsyUSYURydGUqUpeo9kHZd1ZMwtDdbU8PhTVt0AySKyJWq3u9lfoqfhHGXdPGgYEDl89WlJDMOdh2pvLlrUjDI1QnKvmbqqTzenYXEF4mYVHts8MpNSn7O+H9NL13QMvr+sBti8Trr0PfCSzLdi/cweIjfLi7HBV13xgMMm2kbsI73eVcV8OljnBM8HxxtpzpTMRjoMqbuf/hy0Cbbz9YkGctg9yKDCC;25:SX189sW+HraFvBY2oVCyemmUdaj5VD9T0PM5luKv1f9mLzbFF2XLs6miZrbU/dZ6oweehHBwxYW8UGIDozUUvaVAXVX+mSFNwhYwnHWCEffS3PCcP/zQVd2jMrrm7fIGaZk+GqKIhuqlkNYorHa1nm2GMaJW5xXW/iezPPARTRP4Kir2KQiuz61nkk0BTqNnZYf7ROIY5xPVYBvNvFS6e7ACuj7UOhekRfzi7y8YKcp/sACBXcDRKPtiULRY+I1AjlOCdrjgHe133BQsg3N3U3+xHMt4yfJy0z0yKwndobrdlEiHyPpiXs3QatkOIGT5ecJJx1JR4MoL+UOtEgkIgw==;31:pU9EbRg0B/35Wspax0s06UNGJEaGDnDlrbBFoAO+nyvYZKdcwkea99xtstHE6O/XC6w0ETY+pi+yyr9vs4ltDr7YCYR2/ewt4V/Tly9UBMpXobptPhFsXfQ8Yg9HSTM+mGijjiPESdkuyLy1LOogDjQPKcDGg9zJUgQHXfiviCfYy18cYf95Df/hevnJfRpeL13W8vThp3gztCGBkF9zaZEVKDNX8xeBcyc17nF8W9Q= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1341: X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1341;20:VNx0mxPOIb1VYPd2rvEQDVtusfvXs/MzOM4jBbnSQylQDvw+X5f9QL7OMZf3YZ5FKuUqP0eR9TJtidiDWvC++v+mughCAqNkbTltt9qeKgCMKSLHYoxFo0iQFExhGTiwvPHlGJFnNS1xFmFOKfDolSVNRqPKOsnhuPH5ami9ntMVBvnnytHRqw3NGVwua6A6XGVn5D+pY58N1GDpecgXA2e8gUJBh+olgCNAjOPqksdLCmOClocfZWrHrpy51d2m37iZvMQQGe75+3Y3Oq49Xnesdu3cF10Y/e6Dwmv1kLTZ+vGoBwSJhN78/4KmY1X46IEWAqaWlQOdg7f8Cw/tlsElqgvKwiRE3100GtabgGsiYTCJPqur5Lldk3lUtPY6wPccSHwyt9jm830cUN238ggvv6yG4V2iYbwoQj4Fc5et+KOiU1iNSDjYCBfUtLDMoBXCt3WMH/ejG/SKGiULP6d5RnZR0O4NDDRniKnxQrw7q9lESzUsAe8GcCHYYvv8;4:1R952GqsdgL0HKZt2UV4dGPATUGkQRaK1zn0sQVKZiK6cfd//+0f2OWbf3lu4Xl0xRcpPY7bShgtOovjR2c2hRahHQ6GDGNK6BXu8q3Q0KTlUcHGCetO0PsUQi9BDZqnUT9Sx7IvMnHlID8uVlU899HRoIrRqKkvlyAeqpX56rsH9KPU8tWBrDHppmX55BL7PkEZDKvA8CzujPGP64CtmiSqc3CwfeanB/zHWukuA7E4Y9gZ670+RNEQ5E3PWg4VWijot2MN1FqhdEC6a4xROQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(149027)(150027)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:VI1PR0801MB1341;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1341; X-Forefront-PRVS: 0676F530A9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(376002)(39850400004)(39380400002)(396003)(366004)(346002)(189003)(199004)(6116002)(25786009)(39060400002)(81166006)(81156014)(106356001)(8676002)(68736007)(486006)(55016002)(8936002)(66066001)(47776003)(11346002)(3846002)(446003)(476003)(478600001)(956004)(105586002)(16526019)(103116003)(186003)(59450400001)(58126008)(9686003)(26005)(50466002)(53936002)(2906002)(230700001)(7736002)(5660300001)(33896004)(316002)(7416002)(97736004)(55236004)(6666003)(6636002)(61506002)(86362001)(7696005)(575784001)(386003)(6506007)(2486003)(23676004)(76176011)(52116002)(305945005)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1341;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA4MDFNQjEzNDE7MjM6bEFnVldjL0JhRnorNnBndnAyblF5Z2Rq?= =?utf-8?B?QXB1eEYrWWY3MEwxdTh4bE4wQ1NUa3NyMnd5VVdZMTJ6S1hIVStob0ozalhR?= =?utf-8?B?b0JrYkpwWjc1aWhNQ2ExMWpvR0RTUndtVFZOdWt1UkJpQnFYODZ5aDNtbHJZ?= =?utf-8?B?YmQ3L2FzekxCTXE5Q2NIYXAyRzg3SnpLS09GQWFkZlNnZlN4NXhQckd5cXNx?= =?utf-8?B?RFZELzlZWXYva1VNbUpBOFFCNTVFZ1RXSmRkMVpjVEpZdlJIUGcwV2RSWG5m?= =?utf-8?B?R0cxZm1xRVE1Vkg5QWRVek5ScnJnK3pkV01GV0h3NXdDa25LNmJkT0N0VitW?= =?utf-8?B?Wk1GYTZZSUpLS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RA6kyWZ0o2sWzVFxOohZpPi0hFGxKOmGjv6/1xsWDHNTtsB9wevCBq9pLnPXrksbyptPyn0jaB3CFgDdgSYfvNPR8Huc4oLKc8n8DkQj641n0zt+1KkSLgydy3EBHoB7Mfs= X-MS-Office365-Filtering-Correlation-Id: f8fed029-6638-46ab-fe8c-08d5bc9b78ea X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2018 08:43:45.5067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8fed029-6638-46ab-fe8c-08d5bc9b78ea X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1341 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce set_shrinker_bit() function to set shrinker-related bit in memcg shrinker bitmap, and set the bit after the first item is added and in case of reparenting destroyed memcg's items. This will allow next patch to make shrinkers be called only, in case of they have charged objects at the moment, and to improve shrink_slab() performance. Signed-off-by: Kirill Tkhai --- include/linux/memcontrol.h | 14 ++++++++++++++ mm/list_lru.c | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e51c6e953d7a..7ae1b94becf3 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1275,6 +1275,18 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg) extern int memcg_expand_shrinker_maps(int new_id); +static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, + int nid, int shrinker_id) +{ + if (shrinker_id >= 0 && memcg && memcg != root_mem_cgroup) { + struct memcg_shrinker_map *map; + + rcu_read_lock(); + map = rcu_dereference(memcg->nodeinfo[nid]->shrinker_map); + set_bit(shrinker_id, map->map); + rcu_read_unlock(); + } +} #else #define for_each_memcg_cache_index(_idx) \ for (; NULL; ) @@ -1297,6 +1309,8 @@ static inline void memcg_put_cache_ids(void) { } +static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, + int nid, int shrinker_id) { } #endif /* CONFIG_MEMCG_KMEM */ #endif /* _LINUX_MEMCONTROL_H */ diff --git a/mm/list_lru.c b/mm/list_lru.c index cab8fad7f7e2..7df71ab0de1c 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -31,6 +31,11 @@ static void list_lru_unregister(struct list_lru *lru) mutex_unlock(&list_lrus_mutex); } +static int lru_shrinker_id(struct list_lru *lru) +{ + return lru->shrinker_id; +} + static inline bool list_lru_memcg_aware(struct list_lru *lru) { /* @@ -94,6 +99,11 @@ static void list_lru_unregister(struct list_lru *lru) { } +static int lru_shrinker_id(struct list_lru *lru) +{ + return -1; +} + static inline bool list_lru_memcg_aware(struct list_lru *lru) { return false; @@ -119,13 +129,17 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item) { int nid = page_to_nid(virt_to_page(item)); struct list_lru_node *nlru = &lru->node[nid]; + struct mem_cgroup *memcg; struct list_lru_one *l; spin_lock(&nlru->lock); if (list_empty(item)) { - l = list_lru_from_kmem(nlru, item, NULL); + l = list_lru_from_kmem(nlru, item, &memcg); list_add_tail(item, &l->list); - l->nr_items++; + /* Set shrinker bit if the first element was added */ + if (!l->nr_items++) + memcg_set_shrinker_bit(memcg, nid, + lru_shrinker_id(lru)); nlru->nr_items++; spin_unlock(&nlru->lock); return true; @@ -520,6 +534,7 @@ static void memcg_drain_list_lru_node(struct list_lru *lru, int nid, struct list_lru_node *nlru = &lru->node[nid]; int dst_idx = dst_memcg->kmemcg_id; struct list_lru_one *src, *dst; + bool set; /* * Since list_lru_{add,del} may be called under an IRQ-safe lock, @@ -531,7 +546,10 @@ static void memcg_drain_list_lru_node(struct list_lru *lru, int nid, dst = list_lru_from_memcg_idx(nlru, dst_idx); list_splice_init(&src->list, &dst->list); + set = (!dst->nr_items && src->nr_items); dst->nr_items += src->nr_items; + if (set) + memcg_set_shrinker_bit(dst_memcg, nid, lru_shrinker_id(lru)); src->nr_items = 0; spin_unlock_irq(&nlru->lock);