Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932435AbVLUPes (ORCPT ); Wed, 21 Dec 2005 10:34:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932419AbVLUPes (ORCPT ); Wed, 21 Dec 2005 10:34:48 -0500 Received: from ms-smtp-04.nyroc.rr.com ([24.24.2.58]:64501 "EHLO ms-smtp-04.nyroc.rr.com") by vger.kernel.org with ESMTP id S932435AbVLUPes (ORCPT ); Wed, 21 Dec 2005 10:34:48 -0500 Subject: [PATCH] SLAB - have index_of bug at compile time. From: Steven Rostedt To: LKML Cc: Pekka J Enberg , Andrew Morton , Gunter Ohrner , john stultz , Andrew Morton , Matt Mackall , Shai Fultheim , Shobhit Dayal , Alok N Kataria , Christoph Lameter , Ingo Molnar In-Reply-To: References: <1134860251.13138.193.camel@localhost.localdomain> <20051220133230.GC24408@elte.hu> <20051220135725.GA29392@elte.hu> <1135093460.13138.302.camel@localhost.localdomain> <20051220181921.GF3356@waste.org> <1135106124.13138.339.camel@localhost.localdomain> <84144f020512201215j5767aab2nc0a4115c4501e066@mail.gmail.com> <1135114971.13138.396.camel@localhost.localdomain> <20051221065619.GC766@elte.hu> Content-Type: text/plain Date: Wed, 21 Dec 2005 10:34:07 -0500 Message-Id: <1135179247.14810.26.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1838 Lines: 57 Hi, after all the talk over SLAB and SLOBs I decided to make myself useful, and I'm trying very hard to understand the Linux implementation of SLAB. So I'm going through ever line of code and examining it thoroughly, when I find something that could be improved, either performance wise (highly doubtful), clean up wise, documentation wise, enhancement wise, or just have a question, I'll make myself known. This email is enhancement wise. ;) I noticed the code for index_of is a creative way of finding the cache index using the compiler to optimize to a single hard coded number. But I couldn't help noticing that it uses two methods to let you know that someone used it wrong. One is at compile time (the correct way), and the other is at run time (not good). OK, this isn't really an enhancement since the code already works. But this change can help those later who do real enhancements to SLAB. -- Steve Signed-off-by: Steven Rostedt Index: linux-2.6.15-rc6/mm/slab.c =================================================================== --- linux-2.6.15-rc6.orig/mm/slab.c 2005-12-20 16:47:05.000000000 -0500 +++ linux-2.6.15-rc6/mm/slab.c 2005-12-21 10:20:03.000000000 -0500 @@ -315,6 +315,8 @@ */ static __always_inline int index_of(const size_t size) { + extern void __bad_size(void); + if (__builtin_constant_p(size)) { int i = 0; @@ -325,12 +327,9 @@ i++; #include "linux/kmalloc_sizes.h" #undef CACHE - { - extern void __bad_size(void); - __bad_size(); - } + __bad_size(); } else - BUG(); + __bad_size(); return 0; } - 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/