Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3845762pxj; Mon, 24 May 2021 16:42:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1cH8jP7WYZk76HmlyXyKEotdjXrRxjIGjqzvRxOYKIxayYYZInZPKyhyih+8TKPzr+R2t X-Received: by 2002:a17:906:3f86:: with SMTP id b6mr25980761ejj.530.1621899760916; Mon, 24 May 2021 16:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899760; cv=none; d=google.com; s=arc-20160816; b=Rfq4e0c7i90kF9LdLKGGo6g8Iq9SF2XkcucBW17NV5nEzol/p6hVORbKqYE3jkz7Tz DWS48yYtZcJbBtzemr1i6M8KJuCD6+W0KNChocPef6ILp8xaBTXjkt+rCTEdgOefIat6 JVjFi7SoeY9D6FfsXlR2m+d3U2ibTSkWK8yg/Q8a+CwCpvYyKi2D1FIhTUatORRwupQS wVOZYbt/qdh3lE+slrytp5NBNCGH/UetBq2P14Kk0yltCEDCy3riX95KcQHA71xaZPaZ vjdxZf85yASq3XX9ZDLxQqG6L+hFOT4YbofSaC8x+sGtRsE865STz1zCfbLkPr2S165M K98Q== 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=QAc7SlXYGxt2yuMRE5XHgxbmgFR+ii55sq8tCy9hQcc=; b=Aa4/HWClxasMDpijCb1OIhEvIL4++O7nw1rj2vHS9lUmyOcynrWsUyjAWGt3Sun4/N fPGCr5olRjdeGd8oJpz4A9cnTW2n2IHlohvSgK6WHSa8EMhVUcla1wSFj13r7+YrQyJR geyfod2lKz1H+SS0iTvWf16bFa725hKgdRPowHmlGHqwmd5nf1UmRe0hzF1e8dn7fPJ5 gzIHAwRQVjaG5BVABXZDzJKeMtGNYdgsQRahp8i+sXz+enCDV0+Z/QSkvwXMu2ccOHjJ otvEOcEcIR8/pr9wBHS7T9TFiJrwO440oEdrrJj0jY68rQ1GYdZ5MzOXatL+hL517NIX za9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=OX7OPqIo; 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 jw7si3666617ejc.204.2021.05.24.16.42.17; Mon, 24 May 2021 16:42:40 -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=OX7OPqIo; 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 S230034AbhEXXm3 (ORCPT + 99 others); Mon, 24 May 2021 19:42:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:50510 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbhEXXmT (ORCPT ); Mon, 24 May 2021 19:42:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621899648; 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=QAc7SlXYGxt2yuMRE5XHgxbmgFR+ii55sq8tCy9hQcc=; b=OX7OPqIoBu3mU8tTU8iucEudGCJLSAPXm9wKohyhEcrd9YnAXAfyczVFjiQ08hIf6tCjH/ ZwBFkKQx9q1HrzMp1VxGFEF86wP5Ug1+Sn/CvtM1OV4PZrt42dFlm7dZVPOQdhCY8R4vhT o85Y40TG7RGgXZBl7jPbcgzkNTNF6P8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621899648; 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=QAc7SlXYGxt2yuMRE5XHgxbmgFR+ii55sq8tCy9hQcc=; b=9Wtrrbdf8ROT0GDVejk3inSy+nSfQtLKinR6vFqxAOZz6+oR6PKp+MlaJ3Iu1N/1SetK8T KdstWqO4650PJTDQ== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EAC66AF1F; Mon, 24 May 2021 23:40:47 +0000 (UTC) From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra , Jann Horn , Vlastimil Babka Subject: [RFC 01/26] mm, slub: allocate private object map for sysfs listings Date: Tue, 25 May 2021 01:39:21 +0200 Message-Id: <20210524233946.20352-2-vbabka@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524233946.20352-1-vbabka@suse.cz> References: <20210524233946.20352-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 sysfs files alloc_calls and free_calls 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 --- mm/slub.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 3f96e099817a..4c876749f322 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -448,6 +448,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); +} + /* * Determine a map of object in use on a page. * @@ -457,17 +469,11 @@ static DEFINE_SPINLOCK(object_map_lock); 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; } @@ -4813,17 +4819,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); } static int list_locations(struct kmem_cache *s, char *buf, @@ -4834,11 +4840,18 @@ static int list_locations(struct kmem_cache *s, char *buf, struct loc_track t = { 0, 0, NULL }; int node; struct kmem_cache_node *n; + unsigned long *obj_map; + + obj_map = bitmap_alloc(oo_objects(s->oo), GFP_KERNEL); + if (!obj_map) + return sysfs_emit(buf, "Out of memory\n"); if (!alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location), GFP_KERNEL)) { + bitmap_free(obj_map); return sysfs_emit(buf, "Out of memory\n"); } + /* Push back cpu slabs */ flush_all(s); @@ -4851,12 +4864,14 @@ static int list_locations(struct kmem_cache *s, char *buf, 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); + for (i = 0; i < t.count; i++) { struct location *l = &t.loc[i]; -- 2.31.1