From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751361AbdAQWys (ORCPT ); Tue, 17 Jan 2017 17:54:48 -0500 Received: from mail-pg0-f46.google.com ([74.125.83.46]:33343 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbdAQWyr (ORCPT ); Tue, 17 Jan 2017 17:54:47 -0500 Date: Tue, 17 Jan 2017 14:54:42 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: kwon cc: Joonsoo Kim , Christoph Lameter , Pekka Enberg , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] slab: add a check for the first kmem_cache not to be destroyed In-Reply-To: <764E463A-F743-4BE6-8BFC-07D50FF57DDA@toanyone.net> Message-ID: References: <20170116070459.43540-1-kwon@toanyone.net> <20170117013300.GA25940@js1304-P5Q-DELUXE> <764E463A-F743-4BE6-8BFC-07D50FF57DDA@toanyone.net> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 17 Jan 2017, kwon wrote: > >> diff --git a/mm/slab_common.c b/mm/slab_common.c > >> index 1dfc209..2d30ace 100644 > >> --- a/mm/slab_common.c > >> +++ b/mm/slab_common.c > >> @@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s) > >> bool need_rcu_barrier = false; > >> int err; > >> > >> - if (unlikely(!s)) > >> + if (unlikely(!s) || s->refcount == -1) > >> return; > > > > Hello, Kyunghwan. > > > > Few lines below, s->refcount is checked. > > > > if (s->refcount) > > goto unlock; > > > > Am I missing something? > > > > Thanks. > > Hello, Joonsoo. > > In case it is called the number of int size times. refcount would finally reach > to 0 since decreased every time the function called. > The only thing using create_boot_cache() should be the slab implementation itself, so I don't think we need to protect ourselves from doing something like kmem_cache_destroy(kmem_cache) or kmem_cache_destroy(kmem_cache_node) even a single time.