From patchwork Fri Nov 4 09:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13031545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBD96C43217 for ; Fri, 4 Nov 2022 09:34:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21A918E0003; Fri, 4 Nov 2022 05:34:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A4C08E0002; Fri, 4 Nov 2022 05:34:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9BCD8E0003; Fri, 4 Nov 2022 05:34:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C3A178E0002 for ; Fri, 4 Nov 2022 05:34:14 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8C5C01C7010 for ; Fri, 4 Nov 2022 09:34:14 +0000 (UTC) X-FDA: 80095248828.01.87905DF Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf17.hostedemail.com (Postfix) with ESMTP id E427E40003 for ; Fri, 4 Nov 2022 09:34:13 +0000 (UTC) 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-out2.suse.de (Postfix) with ESMTPS id C2FE51F8B6; Fri, 4 Nov 2022 09:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667554452; 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=06k17Kzb8I50UujN65615D+OfTo3VSRSefXLgWtXH4s=; b=REMbrl1azfOylp4pAnJt1FL6ZrrasKRv5lozVitWbG2UHqREoEBIF9GKRdfjQsD57D2svL 91z2mW8bta4V4blD0Kipp2nS2ajmH+IaDYaGy5Ww/NqmRa8DKIQ3USjuAZ7krdSYoH42MB l5/FyUmXRDlT5BZlv2SCY2rZVipQhkg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667554452; 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=06k17Kzb8I50UujN65615D+OfTo3VSRSefXLgWtXH4s=; b=vLH12hbo4td915aOcm9kAB3t3BajZdE4D3pmeF2CdDKx7OiOv3kzGVpUpIkwW1rjLXYFYt 19mmpa0C1bJlKpBw== 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 535FB1346F; Fri, 4 Nov 2022 09:34:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0LWDD5LcZGP3BQAAMHmgww (envelope-from ); Fri, 04 Nov 2022 09:34:10 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v3 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte Date: Fri, 4 Nov 2022 10:33:53 +0100 Message-Id: <20221104093354.6218-3-osalvador@suse.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221104093354.6218-1-osalvador@suse.de> References: <20221104093354.6218-1-osalvador@suse.de> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667554454; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=06k17Kzb8I50UujN65615D+OfTo3VSRSefXLgWtXH4s=; b=dBGUNdii2EqQgU7tD2ewWFTeZ167QLyyPBqBjSKauS02ewOxXTHj7mXuOqRX66DnDICCar XQgHH37RVOQ2ro7OwTfA6J/WP+EcFGkqSXd7Uq86L34RaJv7faKu08Mn0yexI1zxm870K3 TFgFqHDGfBNaysG01IcSLwM6+Zy1W9o= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=REMbrl1a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=vLH12hbo; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf17.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667554454; a=rsa-sha256; cv=none; b=i8rC06jJWNQmln7tPMuFYb+zwhjW9yWQYQQQ8IFM1WScbPqYKmy+PgHhzpUe2s9htkmZcn a9P8JUj0BitSk35/MSE0mAyqa1yXudpRSjbewJYv76SXjnL1dAUOWC6fwH2Z2nyqMYiuwN smQeh5L9CV7jAyJ8RzOXRC/I1V/JAX8= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=REMbrl1a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=vLH12hbo; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf17.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E427E40003 X-Stat-Signature: 35ddyjnq3gjt6czitdu3ec11j9kqmswr X-HE-Tag: 1667554453-662788 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: We might be only interested in knowing about stacks <-> count relationship, so instead of having to fiddle with page_owner output and screen through pfns, let us add a new file called 'page_owner_stacks' that does just that. By cating such file, we will get all the stacktraces followed by its counter, so we can have a more global view. Signed-off-by: Oscar Salvador #include #include +#include +#include #define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) @@ -565,3 +567,74 @@ depot_stack_handle_t stack_depot_save_action(unsigned long *entries, return __stack_depot_save(entries, nr_entries, alloc_flags, true, action); } EXPORT_SYMBOL_GPL(stack_depot_save_action); + +#ifdef CONFIG_PAGE_OWNER +void *stack_start(struct seq_file *m, loff_t *ppos) +{ + unsigned long *table = m->private; + struct stack_record **stacks, *stack; + + /* First time */ + if (*ppos == 0) + *table = 0; + + if (*ppos == -1UL) + return NULL; + + stacks = &stack_table[*table]; + stack = (struct stack_record *)stacks; + + return stack; +} + +void *stack_next(struct seq_file *m, void *v, loff_t *ppos) +{ + unsigned long *table = m->private; + unsigned long nr_table = *table; + struct stack_record *next = NULL, *stack = v, **stacks; + unsigned long stack_table_entries = stack_hash_mask + 1; + + if (!stack) { +new_table: + /* New table */ + nr_table++; + if (nr_table >= stack_table_entries) + goto out; + stacks = &stack_table[nr_table]; + stack = (struct stack_record *)stacks; + next = stack; + } else { + next = stack->next; + } + + if (!next) + goto new_table; + +out: + *table = nr_table; + *ppos = (nr_table >= stack_table_entries) ? -1UL : *ppos + 1; + return next; +} + +int stack_print(struct seq_file *m, void *v) +{ + char *buf; + int ret = 0; + struct stack_record *stack =v; + + if (!stack->size || stack->size < 0 || + stack->size > PAGE_SIZE || stack->handle.valid != 1 || + refcount_read(&stack->count) < 1) + return 0; + + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + ret += stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, 0); + scnprintf(buf + ret, PAGE_SIZE - ret, "stack count: %d\n\n", + refcount_read(&stack->count)); + seq_printf(m, buf); + seq_puts(m, "\n\n"); + kfree(buf); + + return 0; +} +#endif diff --git a/mm/page_owner.c b/mm/page_owner.c index 8730f377fa91..3808c0985060 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -668,6 +668,32 @@ static const struct file_operations proc_page_owner_operations = { .read = read_page_owner, }; +static void stack_stop(struct seq_file *m, void *v) +{ + return; +} + +static const struct seq_operations page_owner_stack_op = { + .start = stack_start, + .next = stack_next, + .stop = stack_stop, + .show = stack_print +}; + +static int page_owner_stack_open(struct inode *inode, struct file *file) +{ + return seq_open_private(file, &page_owner_stack_op, + sizeof(unsigned long)); +} + + +const struct file_operations page_owner_stack_operations = { + .open = page_owner_stack_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + static int __init pageowner_init(void) { if (!static_branch_unlikely(&page_owner_inited)) { @@ -678,6 +704,9 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + debugfs_create_file("page_owner_stacks", S_IRUSR, NULL, NULL, + &page_owner_stack_operations); + return 0; } late_initcall(pageowner_init)