Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757490AbXKETP7 (ORCPT ); Mon, 5 Nov 2007 14:15:59 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755054AbXKETPq (ORCPT ); Mon, 5 Nov 2007 14:15:46 -0500 Received: from netops-testserver-3-out.sgi.com ([192.48.171.28]:60659 "EHLO relay.sgi.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757363AbXKETPo (ORCPT ); Mon, 5 Nov 2007 14:15:44 -0500 Date: Mon, 5 Nov 2007 11:15:43 -0800 (PST) From: Christoph Lameter X-X-Sender: clameter@schroedinger.engr.sgi.com To: stable@kernel.org cc: Hugh Dickins , =?iso-8859-1?Q?Oliv=E9r_Pint=E9r?= , Linus Torvalds , Andrew Morton , Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] slub: fix leakage In-Reply-To: Message-ID: References: <6101e8c40711031027x3f946b28p324dadeab7c1b2c3@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2317 Lines: 65 On Mon, 5 Nov 2007, Hugh Dickins wrote: > Okay, I wanted to make the point, but I've no wish to hold up your fix > (and removing code, particularly code that has given trouble, is always > welcome). Please go ahead - thanks. Here is the fix against 2.6.23: SLUB: Fix memory leak by not reusing cpu_slab Fix the memory leak that may occur when we attempt to reuse a cpu_slab that was allocated while we reenabled interrupts in order to be able to grow a slab cache. The per cpu freelist may contain objects and in that situation we may overwrite the per cpu freelist pointer loosing objects. This only occurs if we find that the concurrently allocated slab fits our allocation needs. If we simply always deactivate the slab then the freelist will be properly reintegrated and the memory leak will go away. Signed-off-by: Christoph Lameter --- mm/slub.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) Index: linux-2.6.23/mm/slub.c =================================================================== --- linux-2.6.23.orig/mm/slub.c 2007-10-09 13:31:38.000000000 -0700 +++ linux-2.6.23/mm/slub.c 2007-11-05 11:09:49.000000000 -0800 @@ -1501,28 +1501,8 @@ new_slab: page = new_slab(s, gfpflags, node); if (page) { cpu = smp_processor_id(); - if (s->cpu_slab[cpu]) { - /* - * Someone else populated the cpu_slab while we - * enabled interrupts, or we have gotten scheduled - * on another cpu. The page may not be on the - * requested node even if __GFP_THISNODE was - * specified. So we need to recheck. - */ - if (node == -1 || - page_to_nid(s->cpu_slab[cpu]) == node) { - /* - * Current cpuslab is acceptable and we - * want the current one since its cache hot - */ - discard_slab(s, page); - page = s->cpu_slab[cpu]; - slab_lock(page); - goto load_freelist; - } - /* New slab does not fit our expectations */ + if (s->cpu_slab[cpu]) flush_slab(s, s->cpu_slab[cpu], cpu); - } slab_lock(page); SetSlabFrozen(page); s->cpu_slab[cpu] = page; - 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/