Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp791366pxt; Thu, 5 Aug 2021 11:45:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTsp5w4bVBOGM6kvpADW9wQBfokQgk3KY6pvlho5JYccYeK57MIGaz088+aGOOG71Xorh6 X-Received: by 2002:a05:6402:2714:: with SMTP id y20mr8493784edd.190.1628189156859; Thu, 05 Aug 2021 11:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628189156; cv=none; d=google.com; s=arc-20160816; b=EwqaBTfS5Klz8CBG9+CGZ+ldpJbenFhijc0iMD/jsj6tJASCYCtkITGJV7lM5BFClZ Khcl/Ap05+QiYM+DKiXbHviVG6vJBYgRUmuSVXSRiEMoAsMt7o5DzXAuamW1U7zN4sLF o+Asw/rcfl7Z+MhadHZA9n+fyetd5XIeUgdJhUgUz8/RBlqGr2+0YWutz32ASyCXC7Fa 3VGIz9QgdHjJ8htaBBPGDkaU2CXAe+WpCiRccIkQVxj2htPZPFRr5BhIp5GlZnbEbY5j sQ8MS3xS+zhW0Soh6DaQs+oxJnv6wnHhhCrgMswK5sbJF81+XrFFjgBw7ytL9nUEGp6s +Maw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=YNGbjRJxzwV2jay0Gz3kjjiqk5HMXz8SmOjh1FDYtWY=; b=ljvKwlNZjIE7PLmrK/3gaTjGze/W1nV7A3Q0gtEWzzjfUtsUlXHfdy1K5ZIOfUd6eV h4fPaGtAxu+3/NP0IjcOnP9fX9CK4nDw3b7IpW76cLXIrQ7z/lbfpkQ49vW+5ZAL6O2Q zFiSHmKR2oCdulNshoZ5CmvIcUwjkuwvcbZPwcKxj1SowHQNq82ZmbjLkpuYKX3JhyWf iZzYRTVGMEsmXqHFshKgRNHhFUhP30SLvq8VvH6Ny+zYIfUZmNQuJdPUmRGUXghdewTx Q6sH2qB5hauRstQr4CP9cse4gNz44ryL1Hsk+/D5n8HpOIBd07mrw0KB1MownJ7EbrK+ 82WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=P6c6omBg; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=4pjRrz0Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si6495950edr.41.2021.08.05.11.45.33; Thu, 05 Aug 2021 11:45:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=P6c6omBg; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=4pjRrz0Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242031AbhHEPUm (ORCPT + 99 others); Thu, 5 Aug 2021 11:20:42 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:33902 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241251AbhHEPUT (ORCPT ); Thu, 5 Aug 2021 11:20:19 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 75838222EE; Thu, 5 Aug 2021 15:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628176804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YNGbjRJxzwV2jay0Gz3kjjiqk5HMXz8SmOjh1FDYtWY=; b=P6c6omBg0tPFChSGkcpbKKeCFT9Gi7pqhPBQz7i1zzJaE5T8Cek3Z5n3Q8MoJT53a1eizY AnWLXYjUAO83AZ50LKnEFA5QtVfJ3ERGeG1JuW0yaO6sPQ+aysYrza8jkiZRnAlolMiN21 hqoKRd5l8ki9aAf5me5cmlViiuekOgg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628176804; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YNGbjRJxzwV2jay0Gz3kjjiqk5HMXz8SmOjh1FDYtWY=; b=4pjRrz0YYFbQ+Xt5vJIHBDk0BfSo4hK5V6RA9qv0PAMvbw43V+pBE7+9BQg0bVa40pYR3w w6oasGxgZx1vyRBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 47CA913DA8; Thu, 5 Aug 2021 15:20:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MIPrEKQBDGFDdQAAMHmgww (envelope-from ); Thu, 05 Aug 2021 15:20:04 +0000 From: Vlastimil Babka To: Andrew Morton , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Jann Horn , Vlastimil Babka Subject: [PATCH v4 02/35] mm, slub: allocate private object map for debugfs listings Date: Thu, 5 Aug 2021 17:19:27 +0200 Message-Id: <20210805152000.12817-3-vbabka@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805152000.12817-1-vbabka@suse.cz> References: <20210805152000.12817-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Slub has a static spinlock protected bitmap for marking which objects are on freelist when it wants to list them, for situations where dynamically allocating such map can lead to recursion or locking issues, and on-stack bitmap would be too large. The handlers of debugfs files alloc_traces and free_traces also currently use this shared bitmap, but their syscall context makes it straightforward to allocate a private map before entering locked sections, so switch these processing paths to use a private bitmap. Signed-off-by: Vlastimil Babka Acked-by: Christoph Lameter Acked-by: Mel Gorman --- mm/slub.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index f5908e6b6fb1..211d380d94d1 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -454,6 +454,18 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page, static unsigned long object_map[BITS_TO_LONGS(MAX_OBJS_PER_PAGE)]; static DEFINE_SPINLOCK(object_map_lock); +static void __fill_map(unsigned long *obj_map, struct kmem_cache *s, + struct page *page) +{ + void *addr = page_address(page); + void *p; + + bitmap_zero(obj_map, page->objects); + + for (p = page->freelist; p; p = get_freepointer(s, p)) + set_bit(__obj_to_index(s, addr, p), obj_map); +} + #if IS_ENABLED(CONFIG_KUNIT) static bool slab_add_kunit_errors(void) { @@ -483,17 +495,11 @@ static inline bool slab_add_kunit_errors(void) { return false; } static unsigned long *get_map(struct kmem_cache *s, struct page *page) __acquires(&object_map_lock) { - void *p; - void *addr = page_address(page); - VM_BUG_ON(!irqs_disabled()); spin_lock(&object_map_lock); - bitmap_zero(object_map, page->objects); - - for (p = page->freelist; p; p = get_freepointer(s, p)) - set_bit(__obj_to_index(s, addr, p), object_map); + __fill_map(object_map, s, page); return object_map; } @@ -4876,17 +4882,17 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, } static void process_slab(struct loc_track *t, struct kmem_cache *s, - struct page *page, enum track_item alloc) + struct page *page, enum track_item alloc, + unsigned long *obj_map) { void *addr = page_address(page); void *p; - unsigned long *map; - map = get_map(s, page); + __fill_map(obj_map, s, page); + for_each_object(p, s, addr, page->objects) - if (!test_bit(__obj_to_index(s, addr, p), map)) + if (!test_bit(__obj_to_index(s, addr, p), obj_map)) add_location(t, s, get_track(s, p, alloc)); - put_map(map); } #endif /* CONFIG_DEBUG_FS */ #endif /* CONFIG_SLUB_DEBUG */ @@ -5813,14 +5819,21 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep) struct loc_track *t = __seq_open_private(filep, &slab_debugfs_sops, sizeof(struct loc_track)); struct kmem_cache *s = file_inode(filep)->i_private; + unsigned long *obj_map; + + obj_map = bitmap_alloc(oo_objects(s->oo), GFP_KERNEL); + if (!obj_map) + return -ENOMEM; if (strcmp(filep->f_path.dentry->d_name.name, "alloc_traces") == 0) alloc = TRACK_ALLOC; else alloc = TRACK_FREE; - if (!alloc_loc_track(t, PAGE_SIZE / sizeof(struct location), GFP_KERNEL)) + if (!alloc_loc_track(t, PAGE_SIZE / sizeof(struct location), GFP_KERNEL)) { + bitmap_free(obj_map); return -ENOMEM; + } for_each_kmem_cache_node(s, node, n) { unsigned long flags; @@ -5831,12 +5844,13 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep) spin_lock_irqsave(&n->list_lock, flags); list_for_each_entry(page, &n->partial, slab_list) - process_slab(t, s, page, alloc); + process_slab(t, s, page, alloc, obj_map); list_for_each_entry(page, &n->full, slab_list) - process_slab(t, s, page, alloc); + process_slab(t, s, page, alloc, obj_map); spin_unlock_irqrestore(&n->list_lock, flags); } + bitmap_free(obj_map); return 0; } -- 2.32.0