Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1221379pxb; Sat, 4 Sep 2021 03:52:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxDQyq4J4M8yFXp59xSqJKOezwafNtuVpNHKhrCsJXLMGIg+hQYKnDeRFnoOJcx0Ak+VW4 X-Received: by 2002:a92:bf0b:: with SMTP id z11mr1219058ilh.117.1630752779022; Sat, 04 Sep 2021 03:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630752779; cv=none; d=google.com; s=arc-20160816; b=YGE6FC3FJ/9iKq/tF/XQK7Ksz7SRT+/Ea7eQwVZmdAVJc7yvXuYduEsxw32nkk+w4M yKAAzg7JgDqU0C00pIM2oZco0IzDB7rFVDT2pTpPsUQrxstG31WlVjwrcTJ+fuOmxVAX 9G2wGOf3DtHWNMsYkHkMi3OzMcmZ5eBxuNHAYkqFHNmM/IHL2WNT+m38j9Y0z9patFM9 HObW/SLNC8b0jINdai9OvsnapjxFwsy9tgz5bHOp/KPi53SDSblOx6Dt0eleRd56A7LZ hGapX0XnExSpbTIQQwKV/gXx0D5qySBvGImfQSNvIjikaKPsPUX29YPboiS4mQPkCrHk DTFw== 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=ITxCAAL4SXwuHPYQguc6W8x3Sm4Ihsgn/MUBOil9JUc=; b=Cawcq9O6Tohc6cpwAMlKckB1cPz/9zoVwRoLBxqMRjb3h2EclxtkpUhjDGo6udQUIO eG8yQQF3bVhK+9vmpfQdkBfs+xmKxUdcUwAK92XmFNlZc/3Z3icgzQGtG/FbnyYNYT+6 3CLWtP+46Hc/Ttt+fAyZFynqXZBsGw8YyDnNwrPwwKLjnGOKDa2O2OkmhMmXIZLIoLhY n+/gR7Rzv1re9M1wo4XzDVxM9SqtEmtMu1bHoClBNLfKEXtWn1a4MAcICT1iNYZY5BoY 8vXmzISuDel994I3i0XuURs3K+X16mOsuAZLw1lnqmCsQGSDjOPspTqeP3TFJIOJz1y8 nijg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=xxVrGwjw; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 16si1665825ily.161.2021.09.04.03.52.47; Sat, 04 Sep 2021 03:52:59 -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=xxVrGwjw; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 S1351166AbhIDKvX (ORCPT + 99 others); Sat, 4 Sep 2021 06:51:23 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59624 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236298AbhIDKvM (ORCPT ); Sat, 4 Sep 2021 06:51:12 -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 9F44722684; Sat, 4 Sep 2021 10:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630752609; 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=ITxCAAL4SXwuHPYQguc6W8x3Sm4Ihsgn/MUBOil9JUc=; b=xxVrGwjwpQgeGE0RrLoE0kWeplXyQYTNYZAuYAepJptkDcKKrA+16QotFC+ZvNY9m3QGd6 1hQsMOJ7aAgRWLWU4jTbreaH/PRD+RGdr0PF/u92xlfWtbY+VqFyiLBWhMEMvRPkGqccMp nB/XEJq39hFlt2CkTxY1L633cLdgFF0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630752609; 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=ITxCAAL4SXwuHPYQguc6W8x3Sm4Ihsgn/MUBOil9JUc=; b=vJ80wD0u1f+FlRMXfbpusQcvj/t9PJ0ScpC8MbX+09jlmveV1ptbQZXLx3XIERyIxUS6pg 6iwiMohWpa5pw3DA== 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 773DA1348A; Sat, 4 Sep 2021 10:50:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KCyPHGFPM2HoUQAAMHmgww (envelope-from ); Sat, 04 Sep 2021 10:50:09 +0000 From: Vlastimil Babka To: linux-mm@kvack.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, Mike Galbraith , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Vlastimil Babka Subject: [PATCH v6 02/33] mm, slub: allocate private object map for debugfs listings Date: Sat, 4 Sep 2021 12:49:32 +0200 Message-Id: <20210904105003.11688-3-vbabka@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210904105003.11688-1-vbabka@suse.cz> References: <20210904105003.11688-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4107; h=from:subject; bh=yDD5rL6ZzdDujCTvdtzx623dCcV9M2Dg37A4C5ro2cw=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhM08CJB/81PGbk+hGGYj+nhySDq1zZ6FFCkLO/27G MTCJdtqJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYTNPAgAKCRDgIcpz8YmpEDJRCA Cb35w6QHtuv5coDbTIlt8n3NSVE7DLZgtxBww+Q9RswH+xxyCaaAm4I+eND4O2bEWq8Jr9fOps9SjD WqABY5qnXdrXqXjiX8wemK7WrbmdOVaZJR+O4ugwtxIsj/NgOPz+Bn6Xu8m6oeE+Vf31L22AXwrv6e N84/5/Zv/HH4HYWZh5KGrHggk/gcHmFP2pP1shG4aGMIGtliIrnakMYPEjk5OPYxmPPf4ID0iYQj20 BARAjo5MWoEunH4OL0WzivGyozDqIgC0jAfPaASjUQU+i/1ETo8PEuohGLGhQZIcjVyKxDIbUPc+oF gqrQuY+bijtflod54JfZdQGCPEkhq4 X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 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 f6063ec97a55..fb603fdf58cb 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; } @@ -4879,17 +4885,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 */ @@ -5816,14 +5822,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; @@ -5834,12 +5847,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.33.0