Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752194AbXKSSW1 (ORCPT ); Mon, 19 Nov 2007 13:22:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751427AbXKSSVg (ORCPT ); Mon, 19 Nov 2007 13:21:36 -0500 Received: from pentafluge.infradead.org ([213.146.154.40]:41887 "EHLO pentafluge.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbXKSSVd (ORCPT ); Mon, 19 Nov 2007 13:21:33 -0500 Date: Mon, 19 Nov 2007 10:18:01 -0800 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@kernel.org Cc: Justin Forbes , Zwane Mwaikambo , "Theodore Ts'o" , Randy Dunlap , Dave Jones , Chuck Wolber , Chris Wedgwood , Michael Krufky , Chuck Ebbert , Domenico Andreoli , torvalds@linux-foundation.org, akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk, Oliv?r Pint?r , Hugh Dickins , Willy Tarreau , Christoph Lameter Subject: [patch 01/26] SLUB: Fix memory leak by not reusing cpu_slab Message-ID: <20071119181801.GB15425@kroah.com> References: <20071119181438.617190424@mini.kroah.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="slub-fix-memory-leak-by-not-reusing-cpu_slab.patch" In-Reply-To: <20071119181746.GA15425@kroah.com> User-Agent: Mutt/1.5.16 (2007-06-09) X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2170 Lines: 67 2.6.22-stable review patch. If anyone has any objections, please let us know. ------------------ From: Christoph Lameter backport of 05aa345034de6ae9c77fb93f6a796013641d57d5 from Linus's tree. 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 Cc: Hugh Dickins Signed-off-by: Greg Kroah-Hartman --- mm/slub.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) --- a/mm/slub.c +++ b/mm/slub.c @@ -1431,28 +1431,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/