Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp9815314ybc; Sat, 30 Nov 2019 15:10:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyaOZL4DjJ3z0CbADI0OQnAk7/iJV4qgvrn+mA/eSSwjSeCcccCYoUYMwmFP01my5f6gSPf X-Received: by 2002:aa7:df8f:: with SMTP id b15mr25127815edy.214.1575155454328; Sat, 30 Nov 2019 15:10:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575155454; cv=none; d=google.com; s=arc-20160816; b=BwyyQfVbZBlUf5mukgC67v+VFqH9NADY4V0dmwSnyIFccN5fYArvfjXVGPZxrwAzNJ gIvRNMr1sfcHS5pZAeE+naTgo5oyEWZHHtT+xLwEBXruiGKsLNXmuU1/eaWgbDvzYywn jkmx994q4J4d8VkHsmB0C/1JdrxUWi3XuzBAC4nEw2cIAoTuX8Rd2bMzxr6EeFPyxKce rnBpzUMSxum4o3TzjvtRKQLj9lH+HrLGJNtfEPkWzr4bRn0v03Hl+BC6/cpCA2HSDvdi J9vi6Lt9jX3rg3F0nDl9KvKzo97j3ti4w8HBO0EX5SZtC1hO3Lg2KLdtHpWka/RQOav2 5XFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=GBw4fWrewXXn6HYdQZbkQABy1vb9YqS+VXKlOxovua8=; b=Mu+qcEBWE+jp6Ed8pgcz1QntXrSa+hjPrxvuN3tiwWeUPn0Mso3Aiv0ZTOWqUtz9cM 3xshnoCGL7JaKlYrsC51UAvAj0d6SxjYzRvHK8HsIaPozN1f7fdUaOl0Oz4mGRDX1Gxc mSUucGtbBIAkCmIl56zhLJL4MohNB02CKp3ZSqr6WjfgRqFvBqDxQJsVFw6aIwT9/e4z 7cvsw+S7HM2baKY3+OpVA1HSR5s6eR6h3Z4V2SvqEd0bfYmAoC0VHKa9mYiGCX3z95CA 1tyR6IhrVg/DstA3uc4IjWBDLLD5qO2DMIcsolLyA0n8b9Ttj7VcQicWCzypF3ht7Vak BzCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1ZdZyFhw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si17064223ejj.374.2019.11.30.15.10.30; Sat, 30 Nov 2019 15:10:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1ZdZyFhw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727438AbfK3XJK (ORCPT + 99 others); Sat, 30 Nov 2019 18:09:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:50854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbfK3XJK (ORCPT ); Sat, 30 Nov 2019 18:09:10 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4245C2072C; Sat, 30 Nov 2019 23:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575155349; bh=+rUlFwPAJgYEfS8TYww8cNCIY3tqU3ON5emEPe+Dxfg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=1ZdZyFhwrZJBqdGQXkp6Hoijogl30uQ+ZRQwlJf19mnxuMjE5ivT9r0jE3o+EiZp0 BT4uDPgEM32KfQwXAFwS1mhENhRHgOiIMtV/bNx7AVvIAS7OZwYtI+3R6NYm5QxwIQ M0q50569YvYKbV7UK+jtko15zqW0G9piez2yGHOU= Date: Sat, 30 Nov 2019 15:09:08 -0800 From: Andrew Morton To: Christopher Lameter Cc: Yu Zhao , Pekka Enberg , David Rientjes , Joonsoo Kim , "Kirill A . Shutemov" , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: Re: [FIX] slub: Remove kmalloc under list_lock from list_slab_objects() V2 Message-Id: <20191130150908.06b2646edfa7bdc12a943c25@linux-foundation.org> In-Reply-To: References: <20190914000743.182739-1-yuzhao@google.com> <20191108193958.205102-1-yuzhao@google.com> <20191108193958.205102-2-yuzhao@google.com> <20191109230147.GA75074@google.com> <20191110184721.GA171640@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 Nov 2019 15:55:05 +0000 (UTC) Christopher Lameter wrote: > Regardless of the issue with memcgs allowing allocations from its > kmalloc array during shutdown: This patch cleans things up and properly > allocates the bitmap outside of the list_lock. > > > [FIX] slub: Remove kmalloc under list_lock from list_slab_objects() V2 > > V1->V2 : Properly handle CONFIG_SLUB_DEBUG. Handle bitmap free correctly. > > list_slab_objects() is called when a slab is destroyed and there are objects still left > to list the objects in the syslog. This is a pretty rare event. > > And there it seems we take the list_lock and call kmalloc while holding that lock. > > Perform the allocation in free_partial() before the list_lock is taken. No response here? It looks a lot simpler than the originally proposed patch? > --- linux.orig/mm/slub.c 2019-10-15 13:54:57.032655296 +0000 > +++ linux/mm/slub.c 2019-11-11 15:52:11.616397853 +0000 > @@ -3690,14 +3690,15 @@ error: > } > > static void list_slab_objects(struct kmem_cache *s, struct page *page, > - const char *text) > + const char *text, unsigned long *map) > { > #ifdef CONFIG_SLUB_DEBUG > void *addr = page_address(page); > void *p; > - unsigned long *map = bitmap_zalloc(page->objects, GFP_ATOMIC); > + > if (!map) > return; > + > slab_err(s, page, text, s->name); > slab_lock(page); > > @@ -3710,7 +3711,6 @@ static void list_slab_objects(struct kme > } > } > slab_unlock(page); > - bitmap_free(map); > #endif > } > > @@ -3723,6 +3723,11 @@ static void free_partial(struct kmem_cac > { > LIST_HEAD(discard); > struct page *page, *h; > + unsigned long *map = NULL; > + > +#ifdef CONFIG_SLUB_DEBUG > + map = bitmap_alloc(oo_objects(s->max), GFP_KERNEL); > +#endif > > BUG_ON(irqs_disabled()); > spin_lock_irq(&n->list_lock); > @@ -3732,11 +3737,16 @@ static void free_partial(struct kmem_cac > list_add(&page->slab_list, &discard); > } else { > list_slab_objects(s, page, > - "Objects remaining in %s on __kmem_cache_shutdown()"); > + "Objects remaining in %s on __kmem_cache_shutdown()", > + map); > } > } > spin_unlock_irq(&n->list_lock); > > +#ifdef CONFIG_SLUB_DEBUG > + bitmap_free(map); > +#endif > + > list_for_each_entry_safe(page, h, &discard, slab_list) > discard_slab(s, page); > }