From patchwork Fri May 21 12:11:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Glitta X-Patchwork-Id: 12273001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D46BC433B4 for ; Fri, 21 May 2021 12:11:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D391F61073 for ; Fri, 21 May 2021 12:11:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D391F61073 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3C1528E0037; Fri, 21 May 2021 08:11:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36FB98E0022; Fri, 21 May 2021 08:11:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EA898E0037; Fri, 21 May 2021 08:11:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id E3E3F8E0022 for ; Fri, 21 May 2021 08:11:31 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7B8E9DB39 for ; Fri, 21 May 2021 12:11:31 +0000 (UTC) X-FDA: 78165123582.30.FADD260 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 2E33840B8CF0 for ; Fri, 21 May 2021 12:11:30 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id j14so19108841wrq.5 for ; Fri, 21 May 2021 05:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ml9aXgYWsxmLMe303aemuEkZuwFy+qH+s0r1NMT4fd0=; b=G/y47iLV9zx1VyEIaxEgrqDGsn62RsNLQqEpjLroeGdYnN6Qtn3rQH+gX5cZBdaEpv wPar/LUQLrM+8TGApiAaIbFAPgBWFuggukQMtECP5+bahU5Di8h4R+lSr5Tiko2/rpuR GcvuDNhfGEmZeY/JzKn8m+flnUdGinGHX3ihLFXqpPArO74ezylDdv3b1vrs4M4gl63S RynlKm2daNsDvVtfX0ln0DkYJXI/cx/SHvZVJnTOUUhvYs5HK5yUBZyCwHxQKnV0URxL 7cx15SnBT3Oog83WwenE29Z4icoTrgklovwy91BbMslPQH27KfpWnAZwlzNsydJXa9zs aAyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ml9aXgYWsxmLMe303aemuEkZuwFy+qH+s0r1NMT4fd0=; b=Z8vHfaBb+OMgEyM7oMNuVw8pPyb1OjBCvcdalF4nV8fzfKhsNeecDGnVH1Wf60WXPd dSV0ItZ8K1ep54R0uywOhLqfNMA4u/T7XS2FsVNMBWQL806wxmEXQl1LOezHbMQp5A+r CUv88sIO1IFI3bpoyoBAfF71sXFIfKWpYaLiU4vyHe799ncvZb3TX6cTb76XSDU2XY4n btNaH8vK4VDUyYD1oykzrtcjk7vB++XMcKYZ224dc8kDGC/j3EQoUhb5mpShHoUDd+B5 simEmZFqP7IjPTzgG/gJJ15pI+xEdmp1JYFdMnpJyHAgV3y0TFDTDAT3aed0/dR5ytFg IsUw== X-Gm-Message-State: AOAM532Vmc6FefRm8JwUyPRKGSWo3YxVYxqqf3G6hq633vPXPgA51jtj xnmJ5PYS3gYiHHx13lVMiAE= X-Google-Smtp-Source: ABdhPJyARzQ5c2zgj9Ij37sb3vRqmocu60KNmQ5m0huB27J8Uo/pGQO62NjtYRLFuHqtdGD698zp8Q== X-Received: by 2002:a5d:648e:: with SMTP id o14mr9037494wri.27.1621599089846; Fri, 21 May 2021 05:11:29 -0700 (PDT) Received: from oliver-Z170M-D3H.cuni.cz ([2001:718:1e03:5128:e010:8b67:85b8:dc89]) by smtp.gmail.com with ESMTPSA id c64sm3339401wma.15.2021.05.21.05.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 05:11:29 -0700 (PDT) From: glittao@gmail.com To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, faiyazm@codeaurora.org, Oliver Glitta Subject: [RFC 1/3] mm/slub: aggregate objects in cache by stack trace Date: Fri, 21 May 2021 14:11:25 +0200 Message-Id: <20210521121127.24653-1-glittao@gmail.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E33840B8CF0 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b="G/y47iLV"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of glittao@gmail.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=glittao@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: pczcronbbir3bcqwiqt3xfomggd7y7gx X-HE-Tag: 1621599090-359277 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oliver Glitta Aggregate objects in slub cache by stack trace in addition to caller address during alloc_calls and free_calls implementation in debugfs. Add stack trace to output. Add all_objects implementation to debugfs to print information about all objects. Signed-off-by: Oliver Glitta Reviewed-by: Vlastimil Babka --- Based on next-20210518 and https://lore.kernel.org/r/1621341949-26762-1-git-send-email-faiyazm@codeaurora.org/ mm/slub.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) -- 2.31.1.272.g89b43f80a5 diff --git a/mm/slub.c b/mm/slub.c index e9b84eddc50d..d5ed6ed7d68b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4770,6 +4770,7 @@ EXPORT_SYMBOL(validate_slab_cache); */ struct location { + depot_stack_handle_t handle; unsigned long count; unsigned long addr; long long sum_time; @@ -4822,9 +4823,15 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, { long start, end, pos; struct location *l; - unsigned long caddr; + unsigned long caddr, chandle; unsigned long age = jiffies - track->when; + depot_stack_handle_t handle; +#ifdef CONFIG_STACKDEPOT + handle = READ_ONCE(track->handle); +#else + handle = 0; +#endif start = -1; end = t->count; @@ -4839,7 +4846,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, break; caddr = t->loc[pos].addr; - if (track->addr == caddr) { + chandle = t->loc[pos].handle; + if ((track->addr == caddr) && (handle == chandle)) { l = &t->loc[pos]; l->count++; @@ -4864,6 +4872,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, if (track->addr < caddr) end = pos; + else if (track->addr == caddr && handle < chandle) + end = pos; else start = pos; } @@ -4886,6 +4896,7 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, l->max_time = age; l->min_pid = track->pid; l->max_pid = track->pid; + l->handle = handle; cpumask_clear(to_cpumask(l->cpus)); cpumask_set_cpu(track->cpu, to_cpumask(l->cpus)); nodes_clear(l->nodes); @@ -5837,6 +5848,21 @@ static int slab_debugfs_show(struct seq_file *seq, void *v) seq_printf(seq, " nodes=%*pbl", nodemask_pr_args(&l->nodes)); +#ifdef CONFIG_STACKDEPOT + { + depot_stack_handle_t handle; + unsigned long *entries; + unsigned int nr_entries, j; + + handle = READ_ONCE(l->handle); + if (handle) { + nr_entries = stack_depot_fetch(handle, &entries); + seq_puts(seq, "\n"); + for (j = 0; j < nr_entries; j++) + seq_printf(seq, "\t%pS\n", (void *)entries[j]); + } + } +#endif seq_puts(seq, "\n"); } From patchwork Fri May 21 12:11:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Glitta X-Patchwork-Id: 12273003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71002C43460 for ; Fri, 21 May 2021 12:11:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 099BA613D6 for ; Fri, 21 May 2021 12:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 099BA613D6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B88D38E0038; Fri, 21 May 2021 08:11:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B60428E0022; Fri, 21 May 2021 08:11:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A00358E0038; Fri, 21 May 2021 08:11:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 7246E8E0022 for ; Fri, 21 May 2021 08:11:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1CE091814ACBF for ; Fri, 21 May 2021 12:11:32 +0000 (UTC) X-FDA: 78165123624.07.578F9FD Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf19.hostedemail.com (Postfix) with ESMTP id 217F990009EF for ; Fri, 21 May 2021 12:11:29 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id r12so20856926wrp.1 for ; Fri, 21 May 2021 05:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i3PtvIn3e83BJKazxoRmqSdndVRiSDgFlBve83mzSb0=; b=lWo0CnDeza1lg1y/wl0wstJvMhHfAumf114y9xzRjwZTnbUeMXVE0HNqg24Uerkn/j jG2Cx8StiDpVjcp2++hDyzfPQ9XoAGSPQP1npC720ODVBqWDMR9FxsRc1vI1PbBC5p9i CIYLPCk1UZ3oGnnLmUSVAdWoUA1Xui6x/MY/Rd1HZzrH/F3RSoAGAIif4tNRyXDzRXv7 cOjqCOum6LSTCJ4y0GDGCv97FqImIFPn1taGtcelrXNxuojOn2JTWXrh07dDN1xADLGq VqC5EQYKkSqWeJ0VC6LG6j0NuYeIYYpET3cXlffeE5D7wVLHs0aazL4EdrKfzAI6LdyS V+Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i3PtvIn3e83BJKazxoRmqSdndVRiSDgFlBve83mzSb0=; b=mTz8vA5mONro2vLuPRGXja+tV0jnocjy7yfJI0BXjt4ElFuZ5qJzI8CjuD7Is6nO33 rlk91P0M7pmDaY1lNrvQy0XFF7aud4nWviujgdpx1+qPjbmxIjXztj4o+IBJlyD06gfu 7ZNdpt3Ez4ZwYBqX4SPMsFuYar7v0M12grlXZeXH6iKvzFrouz4C4GGqc73ZR3nmj6s2 IpsR24GhHvSokH2pDdETt3o3Z5xjE6yu6/TuwslhzVua2cRJtImph9659tpHywOw2QSY YYPh5kX173lGQdLGfUQVSMJNBRK3odpDmelY6CUn54omt1eVKbdwdO3oSBI7u9n412BH BrwQ== X-Gm-Message-State: AOAM530pbH6MtUxHjoMtBpg9hmGEVwz2NfAmm4ltZZIJZ2BpxkVv35lQ NfRzEoncc0ZwBrPH0uKGkzUEEW0u0XCco/mO X-Google-Smtp-Source: ABdhPJwrgnwHqggWQ/pppvxseMU9ZskSzS2UEsOWZW6JmOTj/pMlpOtg3UuT78DMFju3VNdIhAveMA== X-Received: by 2002:adf:f10c:: with SMTP id r12mr9416310wro.26.1621599090895; Fri, 21 May 2021 05:11:30 -0700 (PDT) Received: from oliver-Z170M-D3H.cuni.cz ([2001:718:1e03:5128:e010:8b67:85b8:dc89]) by smtp.gmail.com with ESMTPSA id c64sm3339401wma.15.2021.05.21.05.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 05:11:30 -0700 (PDT) From: glittao@gmail.com To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, faiyazm@codeaurora.org, Oliver Glitta Subject: [RFC 2/3] mm/slub: sort objects in cache by frequency of stack trace Date: Fri, 21 May 2021 14:11:26 +0200 Message-Id: <20210521121127.24653-2-glittao@gmail.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 In-Reply-To: <20210521121127.24653-1-glittao@gmail.com> References: <20210521121127.24653-1-glittao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 217F990009EF Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=lWo0CnDe; spf=pass (imf19.hostedemail.com: domain of glittao@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=glittao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam04 X-Stat-Signature: 9skiafcdxzmdpcdaij1cer4rcbfitzah X-HE-Tag: 1621599089-154817 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oliver Glitta Sort objects in slub cache by the frequency of stack trace used in object location in alloc_calls and free_calls implementation in debugfs. Most frequently used stack traces will be the first. Signed-off-by: Oliver Glitta Reviewed-by: Vlastimil Babka --- mm/slub.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index d5ed6ed7d68b..247983d647cd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -5893,6 +5894,17 @@ static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos) return NULL; } +static int cmp_loc_by_count(const void *a, const void *b, const void *data) +{ + struct location *loc1 = (struct location *)a; + struct location *loc2 = (struct location *)b; + + if (loc1->count > loc2->count) + return -1; + else + return 1; +} + static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) { struct kmem_cache_node *n; @@ -5944,6 +5956,11 @@ static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) process_slab(&t, s, page, alloc); spin_unlock_irqrestore(&n->list_lock, flags); } + + /* Sort locations by count */ + sort_r(t.loc, t.count, sizeof(struct location), + cmp_loc_by_count, NULL, NULL); + } if (*ppos < t.count) { From patchwork Fri May 21 12:11:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Glitta X-Patchwork-Id: 12273005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E5D6C433ED for ; Fri, 21 May 2021 12:11:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D230661073 for ; Fri, 21 May 2021 12:11:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D230661073 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D369D8E0039; Fri, 21 May 2021 08:11:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D10118E0022; Fri, 21 May 2021 08:11:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3B098E0039; Fri, 21 May 2021 08:11:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id 8112F8E0022 for ; Fri, 21 May 2021 08:11:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1CA02D201 for ; Fri, 21 May 2021 12:11:33 +0000 (UTC) X-FDA: 78165123666.17.1873F12 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf27.hostedemail.com (Postfix) with ESMTP id 1D3F680192EE for ; Fri, 21 May 2021 12:11:29 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id r12so20856975wrp.1 for ; Fri, 21 May 2021 05:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lbm/0t9Bcu3Cc8VRMspsd0pyAsMK2XlLm2WMFLI7zWA=; b=hlnntsX9ad1YyLSBCI1T17JeaeDbO2WE6dtl4tSyo6dhGchUBQVGcm84pk/uQf/p09 iNoaJrNgyn8sCOF1NaKspMgkoY8BVZmwR4BJHPB5/IKvQVor2trKnN21fnkJntsOuOX5 euy/S0w8NylWqWHMXOa9am4zAdXPcHE/ockzPhkztubNKwtqv/7UN9v5TNzP1Ey2xwsM +uoNzKdBlZkG/Xc3HdcAjCIRKVrjDAQ1SnaYg3aHg5pu7WkObeeBPlEXE+aabFvXaaWG tXtrTKBRff8rdfP25lzAL21sJ4ApzTE/aj4r3Yhcqf4SejJqxvSYOm+EcpiZ/jOleA/b VZ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lbm/0t9Bcu3Cc8VRMspsd0pyAsMK2XlLm2WMFLI7zWA=; b=IW68ZQn5EmjRrD6SpVPZfIED1dkYidT0lwC/IKxLU8V/nNeQt+aJbdzzoooMP9XPMv WQWVE7Rhd0yB//g9n7QQBEw7QIib8rNCLgQyuC+vKN2+sdeZWDO+COap1pOqxs9oEDr2 2UQiqjc+vij+FxngbIh7YvNOm0Vp4J3ombkjyRsh3t4xpUtZ9j2QqvC+LQAnaNnfY5IL EzAj2QstOv3eOB4k5k/xFa2lFmZ84MWmFlnX1cg+RClUI0qnCG3z9I0JyL4Ta1vtz4zZ I/kzXKSfLWVkt9xM6m2UWGHP5+X01yC6iuqkEuNt+yycGEKCEB2wfRr5iKjiRgGSPGNV AgDQ== X-Gm-Message-State: AOAM532NxlFxCrifOmy95b+L7UUDKL4Dsfe9OtdxMATz0q7XcHXiN20I qFwSqag4NXwlECq1JTt0zaQ= X-Google-Smtp-Source: ABdhPJx3mGLz96WGyH/ZEKPgbc9Yi3dVaGFE671uNkJOblMcn4pHukqz79gEYYJOBMYbDsWGyjwj/w== X-Received: by 2002:adf:e58d:: with SMTP id l13mr9111832wrm.369.1621599091815; Fri, 21 May 2021 05:11:31 -0700 (PDT) Received: from oliver-Z170M-D3H.cuni.cz ([2001:718:1e03:5128:e010:8b67:85b8:dc89]) by smtp.gmail.com with ESMTPSA id c64sm3339401wma.15.2021.05.21.05.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 05:11:31 -0700 (PDT) From: glittao@gmail.com To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, faiyazm@codeaurora.org, Oliver Glitta Subject: [RFC 3/3] mm/slub: add all_objects implementation in debugfs Date: Fri, 21 May 2021 14:11:27 +0200 Message-Id: <20210521121127.24653-3-glittao@gmail.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 In-Reply-To: <20210521121127.24653-1-glittao@gmail.com> References: <20210521121127.24653-1-glittao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=hlnntsX9; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of glittao@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=glittao@gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1D3F680192EE X-Stat-Signature: 599yups4tgu13tdom9szo8iw1fp35tcg X-HE-Tag: 1621599089-687097 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oliver Glitta Add all_objects implementation to debugfs to print information about all objects in slub cache. Signed-off-by: Oliver Glitta --- mm/slub.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 247983d647cd..885d0b074e31 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4789,6 +4789,17 @@ struct loc_track { struct location *loc; }; +enum slub_list_field { PARTIAL_LIST, FULL_LIST }; + +struct slab_debug_private { + struct inode *inode; + struct kmem_cache_node *node; + unsigned long nid; + long slabs_remaining; + enum slub_list_field field; + unsigned long *map; +}; + static struct dentry *slab_debugfs_root; struct loc_track t = { 0, 0, NULL }; @@ -5809,6 +5820,216 @@ static int debugfs_slab_alias(struct kmem_cache *s, const char *name) return 0; } +static struct kmem_cache_node *find_node(struct kmem_cache *s, unsigned long *nid) +{ + struct kmem_cache_node *node = NULL; + + while (*nid < nr_node_ids) { + node = s->node[*nid]; + ++*nid; + if (!node || !atomic_long_read(&node->nr_slabs)) + node = NULL; + else + break; + } + return node; +} + +static bool next_page_new_node(struct slab_debug_private *priv) +{ + struct kmem_cache_node *node; + struct kmem_cache *s = priv->inode->i_private; + + node = find_node(s, &priv->nid); + + if (!node) + return false; + + priv->node = node; + + if (node->nr_partial > 0) { + priv->field = PARTIAL_LIST; + priv->slabs_remaining = node->nr_partial; + } else if (atomic_long_read(&node->nr_slabs) > 0) { + priv->field = FULL_LIST; + priv->slabs_remaining = atomic_long_read(&node->nr_slabs); + } + + return priv->slabs_remaining; +} + +static struct page *next_page(struct slab_debug_private *priv) +{ + struct page *page = NULL; + struct kmem_cache *s = priv->inode->i_private; + struct kmem_cache_node *node; + unsigned long flags; + +redo: + node = priv->node; + if (priv->slabs_remaining > 0) { + struct list_head *head; + void *p, *addr; + + --priv->slabs_remaining; + + if (priv->field == PARTIAL_LIST) + head = &node->partial; + else + head = &node->full; + + spin_lock_irqsave(&node->list_lock, flags); + page = list_first_entry(head, struct page, slab_list); + if (page) { + get_page(page); + slab_lock(page); + addr = page_address(page); + bitmap_zero(priv->map, page->objects); + + for (p = page->freelist; p; p = get_freepointer(s, p)) + set_bit(__obj_to_index(s, addr, p), priv->map); + slab_unlock(page); + } + list_rotate_left(head); + spin_unlock_irqrestore(&node->list_lock, flags); + + } else if ((priv->field == PARTIAL_LIST) + && (atomic_long_read(&node->nr_slabs) != node->nr_partial)) { + + priv->field = FULL_LIST; + priv->slabs_remaining = atomic_long_read(&node->nr_slabs) - node->nr_partial; + + goto redo; + } else { + if (next_page_new_node(priv)) + goto redo; + } + + return page; +} + +static int debugfs_all_objects_show(struct seq_file *seq, void *v) +{ + struct slab_debug_private *priv = seq->private; + struct kmem_cache *s = priv->inode->i_private; + struct page *page = v; + void *addr = page_address(page); + void *p; + unsigned long *map = priv->map; + struct track *track; + depot_stack_handle_t handle; + unsigned long *entries; + unsigned int nr_entries, j; + + for_each_object(p, s, addr, page->objects) { + seq_printf(seq, "Object: %pK ", p); + if (!test_bit(__obj_to_index(s, addr, p), map)) + seq_puts(seq, "allocated\n"); + else + seq_puts(seq, "free\n"); + + track = get_track(s, p, TRACK_ALLOC); + seq_printf(seq, "Last allocated: %pS age=%ld pid=%d cpu=%u\n", + (void *)track->addr, jiffies - track->when, track->pid, track->cpu); + +#ifdef CONFIG_STACKDEPOT + handle = READ_ONCE(track->handle); + if (handle) { + nr_entries = stack_depot_fetch(handle, &entries); + for (j = 0; j < nr_entries; j++) + seq_printf(seq, "\t%pS\n", (void *)entries[j]); + } +#endif + + track = get_track(s, p, TRACK_FREE); + seq_printf(seq, "Last free: %pS age=%ld pid=%d cpu=%u\n", + (void *)track->addr, jiffies - track->when, track->pid, track->cpu); + +#ifdef CONFIG_STACKDEPOT + handle = READ_ONCE(track->handle); + if (handle) { + nr_entries = stack_depot_fetch(handle, &entries); + for (j = 0; j < nr_entries; j++) + seq_printf(seq, "\t%pS\n", (void *)entries[j]); + } +#endif + seq_puts(seq, "\n"); + } + return 0; +} + +static void *debugfs_all_objects_start(struct seq_file *m, loff_t *ppos) +{ + struct slab_debug_private *priv = m->private; + struct kmem_cache *s = priv->inode->i_private; + struct page *page; + + priv->map = kmalloc(BITS_TO_LONGS(MAX_OBJS_PER_PAGE), GFP_KERNEL); + + if (!priv->map) + return NULL; + + if (!(s->flags & SLAB_STORE_USER)) + return ERR_PTR(-EOPNOTSUPP); + + page = next_page(priv); + return page; +} + +static void *debugfs_all_objects_next(struct seq_file *m, void *v, loff_t *ppos) +{ + struct slab_debug_private *priv = m->private; + struct page *page; + + if (v) + put_page(v); + + ++*ppos; + page = next_page(priv); + + return page; +} + +static void debugfs_all_objects_stop(struct seq_file *m, void *v) +{ + struct slab_debug_private *priv = m->private; + struct kmem_cache *s = priv->inode->i_private; + + kfree(priv->map); + + if (v && (s->flags & SLAB_STORE_USER)) + put_page(v); +} + +static const struct seq_operations debugfs_all_objects_ops = { + .start = debugfs_all_objects_start, + .next = debugfs_all_objects_next, + .stop = debugfs_all_objects_stop, + .show = debugfs_all_objects_show +}; + +static int debugfs_all_objects_open(struct inode *inode, struct file *file) +{ + struct slab_debug_private *priv = __seq_open_private(file, + &debugfs_all_objects_ops, sizeof(struct slab_debug_private)); + + if (!priv) + return -ENOMEM; + + priv->inode = inode; + priv->nid = 0; + priv->field = FULL_LIST; + + return 0; +} + +static const struct file_operations debugfs_all_objects_fops = { + .open = debugfs_all_objects_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release_private, +}; + static int slab_debugfs_show(struct seq_file *seq, void *v) { struct location *l; @@ -6018,6 +6239,10 @@ static void debugfs_slab_add(struct kmem_cache *s) debugfs_create_file("free_traces", 0400, slab_cache_dir, s, &slab_debugfs_fops); + debugfs_create_file("all_objects", 0400, + slab_cache_dir, s, &debugfs_all_objects_fops); + + if (!unmergeable) /* Setup first alias */ debugfs_slab_alias(s, s->name); From patchwork Tue Jun 8 08:45:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Glitta X-Patchwork-Id: 12305891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0D95C47082 for ; Tue, 8 Jun 2021 08:45:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8520661287 for ; Tue, 8 Jun 2021 08:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8520661287 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F03736B0070; Tue, 8 Jun 2021 04:45:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB32B6B0071; Tue, 8 Jun 2021 04:45:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D04E66B0072; Tue, 8 Jun 2021 04:45:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id 95D246B0070 for ; Tue, 8 Jun 2021 04:45:21 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3BD1552CC for ; Tue, 8 Jun 2021 08:45:21 +0000 (UTC) X-FDA: 78229922442.40.B0FC24B Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf18.hostedemail.com (Postfix) with ESMTP id 78711200109D for ; Tue, 8 Jun 2021 08:45:18 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id g8so31350160ejx.1 for ; Tue, 08 Jun 2021 01:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fR3ab/zjle1Nt5uNzFnvgGqgsj2Kj0CI4fURhn3/mgg=; b=NDGy3qSGukY0MuCs9OFy7RAF3W3bLsQSZ25MzP+N8xFY2Jl+u1YT9C08Gdb1QlFVGr OE3R1gyCwf6EHTdXtEKMTS0jV5A2qQPNTJPwv3DyuA7fNpPmnAZDdVuXt0CJ1Bpx33V1 Wj7d+us7cCYIuq/SO41nQL+1QJHY5hPxLugL/iRHMweIiRjPgVZ5JEYtxVxJZKJBVl7w IgD0IKvjJiNgWEAmJthlvxrjmRJlFmvvdmLNqkvE3E+traDk6sFLoZd1P8unFM3jt7pY IJNgqyQ7XDF9gteqszgms8WFEpEXr/iZ+rVzv56jl+/OZGVqr88zmFLhL0b9vKNVgMEm bOOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fR3ab/zjle1Nt5uNzFnvgGqgsj2Kj0CI4fURhn3/mgg=; b=lazao3HVUcug14ksYpNk6Csnpgb9Rmbmd6AMskqA/F5CcW/Xc6wc8w9oi4cFo1aaqg 3MLt+aj7RKSKElBweAFnez1/p/o+7DPWDGOln3uXzfFYP5A/eBf6smaJP1DrCTR7Cdvj 4SV8vZh9aHSCE3uYhT/4/AaFyJFH6V8wpOmNJX4J2rJS0f6vC1fwJgviraOzHC1MJyi5 YfxFcRn2DQp7FfSwwnP4g1WagEAY71Z6l9IxfyItD6BusO6nXjcKzdzaZCqeCYsPOHSx OvmKPJ7u9NAKjHbo6TqAfsfebmuGzJSEHXhiOYMsyzBvQFGAkoNC9UwXQoQIbb3S4PaT Pecw== X-Gm-Message-State: AOAM533u6YG5advkFnDQBGDrczfaSHdBau0noBTUtw5kMRgbDE3oZlUG +LX0WMixMO6sGfhBw2Q+/VE= X-Google-Smtp-Source: ABdhPJzcPlCByzHE+0eTX3kyRDawZVkCCk1Q5edkuoHkkm9Qe22jfhGQl7cWRkva+y8IT7FyLd7MGA== X-Received: by 2002:a17:907:2bf9:: with SMTP id gv57mr22369726ejc.189.1623141919565; Tue, 08 Jun 2021 01:45:19 -0700 (PDT) Received: from localhost.localdomain (ispc-static-34.84-47-111.telekom.sk. [84.47.111.34]) by smtp.gmail.com with ESMTPSA id m4sm7353184eje.8.2021.06.08.01.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 01:45:19 -0700 (PDT) From: glittao@gmail.com To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, faiyazm@codeaurora.org, corbet@lwn.net, linux-doc@vger.kernel.org, Oliver Glitta Subject: [RFC 4/4] docs: add description of debugfs files for SLUB cache Date: Tue, 8 Jun 2021 10:45:17 +0200 Message-Id: <20210608084517.6119-1-glittao@gmail.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 In-Reply-To: <20210521121127.24653-1-glittao@gmail.com> References: <20210521121127.24653-1-glittao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=NDGy3qSG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of glittao@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=glittao@gmail.com X-Stat-Signature: yjpmszrh78arcypqfq5f3mfwwiow9uyn X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 78711200109D X-HE-Tag: 1623141918-838741 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oliver Glitta Add description of debugfs files alloc_traces, free_traces and all_objects to SLUB cache documentation. Signed-off-by: Oliver Glitta Acked-by: David Rientjes --- Documentation/vm/slub.rst | 109 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) -- 2.31.1.272.g89b43f80a5 diff --git a/Documentation/vm/slub.rst b/Documentation/vm/slub.rst index 03f294a638bd..2280d74d395c 100644 --- a/Documentation/vm/slub.rst +++ b/Documentation/vm/slub.rst @@ -384,5 +384,114 @@ c) Execute ``slabinfo-gnuplot.sh`` in '-t' mode, passing all of the 40,60`` range will plot only samples collected between 40th and 60th seconds). + +DebugFS files for SLUB +====================== + +For more debug information about current state of SLUB caches +with the user tracking debug option enabled, debugfs files +are available. There are 3 types of these files +with different debug information: + +1. alloc_traces:: + + Prints information about unique allocation traces of + the currently allocated objects together with their frequency. + Output sorted by frequency of use. + + Information on output: + Number of uses, allocating function, minimal/average/maximal jiffies since alloc, + pid of the process, allocated by cpu and stack trace. + + Example::: + + 1085 populate_error_injection_list+0x97/0x110 age=166678/166680/166682 pid=1 cpus=1:: + __slab_alloc+0x6d/0x90 + kmem_cache_alloc_trace+0x2eb/0x300 + populate_error_injection_list+0x97/0x110 + init_error_injection+0x1b/0x71 + do_one_initcall+0x5f/0x2d0 + kernel_init_freeable+0x26f/0x2d7 + kernel_init+0xe/0x118 + ret_from_fork+0x22/0x30 + + +2. free_traces:: + + Prints information about unique free traces of + the currently free objects together with their frequency. + Output sorted by frequency of use. + + Information on output: + Number of uses, freeing function, minimal/average/maximal jiffies since free, + pid of the process, freed by cpu and stack trace. + + Example::: + + 51 acpi_ut_update_ref_count+0x6a6/0x782 age=236886/237027/237772 pid=1 cpus=1 + kfree+0x2db/0x420 + acpi_ut_update_ref_count+0x6a6/0x782 + acpi_ut_update_object_reference+0x1ad/0x234 + acpi_ut_remove_reference+0x7d/0x84 + acpi_rs_get_prt_method_data+0x97/0xd6 + acpi_get_irq_routing_table+0x82/0xc4 + acpi_pci_irq_find_prt_entry+0x8e/0x2e0 + acpi_pci_irq_lookup+0x3a/0x1e0 + acpi_pci_irq_enable+0x77/0x240 + pcibios_enable_device+0x39/0x40 + do_pci_enable_device.part.0+0x5d/0xe0 + pci_enable_device_flags+0xfc/0x120 + pci_enable_device+0x13/0x20 + virtio_pci_probe+0x9e/0x170 + local_pci_probe+0x48/0x80 + pci_device_probe+0x105/0x1c0 + + +3. all_objects:: + + Prints information about all object (both allocated and free) + in given SLUB cache. + + Example::: + + Object: 0000000042ee8b00 free + Last allocated: ima_queue_key+0x2f/0x1b0 age=247112 pid=1 cpu=1 + __slab_alloc+0x6d/0x90 + kmem_cache_alloc_trace+0x2eb/0x300 + ima_queue_key+0x2f/0x1b0 + ima_post_key_create_or_update+0x46/0x80 + key_create_or_update+0x383/0x5b0 + load_certificate_list+0x75/0xa0 + load_system_certificate_list+0x2f/0x31 + do_one_initcall+0x5f/0x2d0 + kernel_init_freeable+0x26f/0x2d7 + kernel_init+0xe/0x118 + ret_from_fork+0x22/0x30 + Last free: ima_process_queued_keys.part.0+0x84/0xf0 age=170962 pid=137 cpu=1 + kfree+0x2db/0x420 + ima_process_queued_keys.part.0+0x84/0xf0 + ima_keys_handler+0x57/0x60 + process_one_work+0x2a5/0x590 + worker_thread+0x52/0x3f0 + kthread+0x140/0x160 + ret_from_fork+0x22/0x30 + + Information on output: + + a) Object:
allocated/free + There is address of object and information whether object is + allocated or free. + + b) Last allocated:
age= pid= cpu= + + c) Alloc stacktrace + + d) Last free:
age= pid= cpu= + + e) Free stacktrace + + Christoph Lameter, May 30, 2007 Sergey Senozhatsky, October 23, 2015