Received: by 10.213.65.68 with SMTP id h4csp181369imn; Wed, 21 Mar 2018 15:44:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELsOZgkt8PvsQqzaXCKyVuchiVer0nOO3QuSdvh4Pf4GUQ6HBDrY2TQlzuQAsnCGpuS5Xry6 X-Received: by 2002:a17:902:780d:: with SMTP id p13-v6mr21218022pll.281.1521672280243; Wed, 21 Mar 2018 15:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521672280; cv=none; d=google.com; s=arc-20160816; b=HnbVIYb6OVDKP6pLRCv0hbeL/mOG+hU7Ez2c4xI+b17ZVeusB34iOLQqX4UGKUjaz3 tMM2oxVdPt4r+nXejRw/g4GNI1WcSWrVHIH7gPvYIFxPI3E7eUXQkDSGfLWjgi9X/0gH stQ4yjuVczmgERJWd9JEAkGeDqbKxaQ5O+NHoccgfPAYgm//ALKHB7+bGMCvA11FmiP7 HqNu6VAz8lJFFSI+u/42CL7ZRE7KwRvJ64V3zUW1dnY3hMhn8syQcavu/wiQjiTn2rEB SAu9R1APhvlwOhBxT86aeCJf6p91aPGFjcZSpuuqIuH/G9KMOrAGYEwFOVNf1MKaUmvK OxJA== 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:cc:to:from :dkim-signature:arc-authentication-results; bh=UNK/Hbj/i8PACwQEkV8JI9asoU0eQTCBewrWA9e3tO8=; b=ujEMalmrHo+4GN/GN/8WbuVHNHmst6tp2mTs6gFAecVUvaV65Ska8YvvWuw+5HtotR UOstuX4CG2CWz+2pHMjS92ebIIzx2UffV6JOZYBq11XT6bXmiEf3UpeRz3nI2GYm6Sdx diIqgXAb4XvzrTSeobJmzKPy06SLHzKVD7asdk0qGlWVZcf2At/sv22HdS9AU14y3AhM 6EILPcxMaLYrndrE4Kc9HXuJDy9AJFpG9jDWvN8w9TPbruwQFJeTAmqz1XB1A015PHY6 bxmekve5ipxWAmm0mWMRhok7xU1Iyc/Kx8E1GZChaEeqoODYyPtka28BG9hd6wtcx5r3 9SgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Omw4j9HL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o189si1769504pfo.319.2018.03.21.15.44.25; Wed, 21 Mar 2018 15:44:40 -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=@google.com header.s=20161025 header.b=Omw4j9HL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753927AbeCUWna (ORCPT + 99 others); Wed, 21 Mar 2018 18:43:30 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:41635 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753479AbeCUWn2 (ORCPT ); Wed, 21 Mar 2018 18:43:28 -0400 Received: by mail-pl0-f66.google.com with SMTP id b7-v6so4051823plr.8 for ; Wed, 21 Mar 2018 15:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UNK/Hbj/i8PACwQEkV8JI9asoU0eQTCBewrWA9e3tO8=; b=Omw4j9HLsRUb0MkTcrbQPqd8bEUloA4zxSLI3qj90eOmhYtMASru+I/0KIeaFo5Mws sBWBtHOhIMOe6TOakLCFf9VhiV9vlzRpiIyEpt5oPHFL0HesBD+PCwK/GvHFXsSthRMC yiRTUjJQyUvBv6oK/K+qXYR/Xk7Ib7A0n70Ezx+XP6Tb5ChZRnIEsI8DLC+5ZLWFMD9g OIdhJralPEy0k7ESs9o/NA+DdA+oA4cBtqdyFfpP/aMqPYJnKS9uZDP6WXLlIW1x0MVz YUn2UmG6q1V7r/NEhuLmS2HBY8cjr9aCrHMnp9T1TDiKaWh8XTHmWSpec60Q4uoWefli 4few== 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; bh=UNK/Hbj/i8PACwQEkV8JI9asoU0eQTCBewrWA9e3tO8=; b=KXJLqjclL/nxriYo1KZo/GK/6H1+0fzvC/FU6RmkzXCEu5b5OXhtzxHtP4itSNsCPA 0EZQ1PkaldO+SgHPQFE4P2yOV2RYBazlMkfVwpR7103FeeJnyd4C/oL7cB9Ez3CO+/Xc QaDBon/UmbfgaBSkHu4TIvB0XyTGRJ2HZPojeQZonLjreUOILfZwLq+NcIEjNH+72A5V B8YRHili2hLViKZHe7KA4ITj7o9sdvh+b6vfuysBVYa7W532oV78OiKz7VTIQ1owVpmR HmuznaqvpxqpRZy1q5Ytth4Cv3An/xt2E9LQ80xG+KciSnkdvDqxHbCGroUJZ9bkbanB Ykyw== X-Gm-Message-State: AElRT7FzLe5TIWHyXSPteI1tnEg6SMrqLvvPhchtZMksZumQuA0nkF7R uesVsQ5YDgeAvCOlu2TI9KUKXg== X-Received: by 2002:a17:902:28c4:: with SMTP id f62-v6mr1955580plb.19.1521672207804; Wed, 21 Mar 2018 15:43:27 -0700 (PDT) Received: from shakeelb.mtv.corp.google.com ([2620:15c:2cb:201:3a5f:3a4f:fa44:6b63]) by smtp.gmail.com with ESMTPSA id j23sm9362800pfi.78.2018.03.21.15.43.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 15:43:26 -0700 (PDT) From: Shakeel Butt To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Greg Thelen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt Subject: [PATCH] mm, slab: eagerly delete inactive offlined SLABs Date: Wed, 21 Mar 2018 15:43:01 -0700 Message-Id: <20180321224301.142879-1-shakeelb@google.com> X-Mailer: git-send-email 2.17.0.rc0.231.g781580f067-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With kmem cgroup support, high memcgs churn can leave behind a lot of empty kmem_caches. Usually such kmem_caches will be destroyed when the corresponding memcg gets released but the memcg release can be arbitrarily delayed. These empty kmem_caches wastes cache_reaper's time. So, the reaper should destroy such empty offlined kmem_caches. Signed-off-by: Shakeel Butt --- mm/slab.c | 18 ++++++++++++++++-- mm/slab.h | 15 +++++++++++++++ mm/slab_common.c | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 66f2db98f026..9c174a799ffb 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -4004,6 +4004,16 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n, slabs_destroy(cachep, &list); } +static bool is_slab_active(struct kmem_cache *cachep) +{ + int node; + struct kmem_cache_node *n; + + for_each_kmem_cache_node(cachep, node, n) + if (READ_ONCE(n->total_slabs) - n->free_slabs) + return true; + return false; +} /** * cache_reap - Reclaim memory from caches. * @w: work descriptor @@ -4018,7 +4028,7 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n, */ static void cache_reap(struct work_struct *w) { - struct kmem_cache *searchp; + struct kmem_cache *searchp, *tmp; struct kmem_cache_node *n; int node = numa_mem_id(); struct delayed_work *work = to_delayed_work(w); @@ -4027,7 +4037,7 @@ static void cache_reap(struct work_struct *w) /* Give up. Setup the next iteration. */ goto out; - list_for_each_entry(searchp, &slab_caches, list) { + list_for_each_entry_safe(searchp, tmp, &slab_caches, list) { check_irq_on(); /* @@ -4061,6 +4071,10 @@ static void cache_reap(struct work_struct *w) 5 * searchp->num - 1) / (5 * searchp->num)); STATS_ADD_REAPED(searchp, freed); } + + /* Eagerly delete inactive kmem_cache of an offlined memcg. */ + if (!is_memcg_online(searchp) && !is_slab_active(searchp)) + shutdown_cache(searchp); next: cond_resched(); } diff --git a/mm/slab.h b/mm/slab.h index e8981e811c45..e911b10efae7 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -166,6 +166,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, SLAB_TEMPORARY | \ SLAB_ACCOUNT) +int shutdown_cache(struct kmem_cache *s); int __kmem_cache_shutdown(struct kmem_cache *); void __kmem_cache_release(struct kmem_cache *); int __kmem_cache_shrink(struct kmem_cache *); @@ -290,6 +291,15 @@ static __always_inline void memcg_uncharge_slab(struct page *page, int order, memcg_kmem_uncharge(page, order); } +static __always_inline bool is_memcg_online(struct kmem_cache *s) +{ + if (!memcg_kmem_enabled()) + return true; + if (is_root_cache(s)) + return true; + return mem_cgroup_online(s->memcg_params.memcg); +} + extern void slab_init_memcg_params(struct kmem_cache *); extern void memcg_link_cache(struct kmem_cache *s); extern void slab_deactivate_memcg_cache_rcu_sched(struct kmem_cache *s, @@ -342,6 +352,11 @@ static inline void memcg_uncharge_slab(struct page *page, int order, { } +static inline bool is_memcg_online(struct kmem_cache *s) +{ + return true; +} + static inline void slab_init_memcg_params(struct kmem_cache *s) { } diff --git a/mm/slab_common.c b/mm/slab_common.c index 61ab2ca8bea7..d197e878636b 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -573,7 +573,7 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) } } -static int shutdown_cache(struct kmem_cache *s) +int shutdown_cache(struct kmem_cache *s) { /* free asan quarantined objects */ kasan_cache_shutdown(s); -- 2.17.0.rc0.231.g781580f067-goog