Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753272Ab2HIRBj (ORCPT ); Thu, 9 Aug 2012 13:01:39 -0400 Received: from g1t0029.austin.hp.com ([15.216.28.36]:28329 "EHLO g1t0029.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751396Ab2HIRBi (ORCPT ); Thu, 9 Aug 2012 13:01:38 -0400 Message-ID: <1344531695.2393.27.camel@lorien2> Subject: Re: [PATCH v2] mm: Restructure kmem_cache_create() to move debug cache integrity checks into a new function From: Shuah Khan Reply-To: shuah.khan@hp.com To: "Christoph Lameter (Open Source)" Cc: penberg@kernel.org, glommer@parallels.com, js1304@gmail.com, David Rientjes , linux-mm@kvack.org, LKML , Andrew Morton , Linus Torvalds , shuahkhan@gmail.com Date: Thu, 09 Aug 2012 11:01:35 -0600 In-Reply-To: References: <1342221125.17464.8.camel@lorien2> <1344224494.3053.5.camel@lorien2> <1344266096.2486.17.camel@lorien2> <1344272614.2486.40.camel@lorien2> <1344287631.2486.57.camel@lorien2> Organization: ISS-Linux Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2359 Lines: 65 On Thu, 2012-08-09 at 09:13 -0500, Christoph Lameter (Open Source) wrote: > On Mon, 6 Aug 2012, Shuah Khan wrote: > > > +#ifdef CONFIG_DEBUG_VM > > +static int kmem_cache_sanity_check(const char *name, size_t size) > > Why do we pass "size" in? AFAICT there is no need to. It is an oversight on my part. Will re-work the patch as needed. Please see more on your second comment below. > > > @@ -53,48 +93,17 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align > > { > > struct kmem_cache *s = NULL; > > > > -#ifdef CONFIG_DEBUG_VM > > if (!name || in_interrupt() || size < sizeof(void *) || > > size > KMALLOC_MAX_SIZE) { > > - printk(KERN_ERR "kmem_cache_create(%s) integrity check" > > - " failed\n", name); > > + pr_err("kmem_cache_create(%s) integrity check failed\n", name); > > goto out; > > } > > -#endif > > > > If you move the above code into the sanity check function then you will be > using the size as well. These are also sanity checks after all. Yes these are also sanity checks, however these checks are common to debug and non-debug paths, hence the reasoning to leave them in kmem_cache_create(). You are right, if these checks get moved into the debug section in kmem_cache_sanity_check, size will be used. Moving these checks into kmem_cache_sanity_check() would mean return path handling will change. The first block of sanity checks for name, and size etc. are done before holding the slab_mutex and the second block that checks the slab lists is done after holding the mutex. Depending on which one fails, return handling is going to be different in that if second block fails, mutex needs to be unlocked and when the first block fails, there is no need to do that. Nothing that is too complex to solve, just something that needs to be handled. Comments, thoughts on 1. just remove size from kmem_cache_sanity_check() parameters or 2. move first block sanity checks into kmem_cache_sanity_check() Personally I prefer the first option to avoid complexity in return path handling. Would like to hear what others think. -- Shuah -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/