From patchwork Fri Apr 21 10:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 86227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp959816vqo; Fri, 21 Apr 2023 03:19:33 -0700 (PDT) X-Google-Smtp-Source: AKy350a3pdDpPsq92Uc3qkiOFiGhWTc0CE+03WfFQnqN73354BQ3toOlaC2lFy1GiOjPnrdKbr9a X-Received: by 2002:a17:902:9688:b0:1a6:b98b:eea9 with SMTP id n8-20020a170902968800b001a6b98beea9mr4093400plp.20.1682072372931; Fri, 21 Apr 2023 03:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682072372; cv=none; d=google.com; s=arc-20160816; b=gQtaR+lfoYX9PDDRNldOH25qF4aJdr7+sUg3vzvhnLPwv2ovDiXfPhy9yJCj3xrqlG k4StGVT2EVmQTEnyXf8/Ukjac/37Pf0FlWdquNhGoOl2yFLxO4AJfuNmsJhscliaNvoP Z5/G2BNiRJzU8hoaQ7KdjUPdJDgFPfx/H1l0QRGp/GJoXYBCSU1ueQCiByLlLzBrfYIy aqnmYB2ri8oHEY51iVzIZkKGIHX4iJbEyzfNLGIJhqyZpbWvU60eh3hUcdm8Hxloq1Gt x3KHkfzYv02vlndmHDiN1CE5Oko8kOAcsOmHkOw8d6VxNawUWayUyqAPNLtMMf51U4RS w8ig== 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=zE4KUQItN/3/UV4PaOZpW67hAUQM7k7JGXQXpSUX7jM=; b=bAbobomEqZZiI+UcQeKmReGjbbcwgZGALE5+sBSb6MIocA1hECj+bYapU1ZSF/XOhN 6Jb5OFVXDXVki7v2BDukX1GWyeQNXJoLNokiDVoZB+8SVsqaQ/5neBMi4wFDTyYpAyIB GAoWF0J5niOjGZK7LygtO2Q3CSGitgc7tOyHCFhFozFFxDPkkRPId6iGCYZI4TpL31Jw Slmd9EFaSKI+CD/exM5DfQ7mL9UUsmxqV/Z0a3G0lbug7k29uxjWd7XsrLu1jyWVOT9m kqHgUc1didVqQWKKcHFqpjuXHGlngW8TLYT2jOD0SNVNfOEC4fdyu4W78OuRqnPhNlmd d5qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LxPC06Rf; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=TfOtgFn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u13-20020a170902e80d00b0019ca7d69673si4975028plg.196.2023.04.21.03.19.20; Fri, 21 Apr 2023 03:19:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LxPC06Rf; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=TfOtgFn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbjDUKPC (ORCPT + 99 others); Fri, 21 Apr 2023 06:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbjDUKOk (ORCPT ); Fri, 21 Apr 2023 06:14:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 706FCC16B for ; Fri, 21 Apr 2023 03:14:39 -0700 (PDT) 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 236311FDDE; Fri, 21 Apr 2023 10:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1682072078; 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=zE4KUQItN/3/UV4PaOZpW67hAUQM7k7JGXQXpSUX7jM=; b=LxPC06RfpZaf/PV59ic/kcvwI8MQ/gLjs6JkYCNJ/RNb4xRaG70GAN+PGm+8H+ryznSgpc YrF8dckTbYzILZ5H8nPsp0rNBoS1mIsN58UGleQbLSkmKQt45pkJxWA4xeNLFKhm3E6CSB bgDU8rZ29b2J1dRT10rROtiAB8ISjTE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1682072078; 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=zE4KUQItN/3/UV4PaOZpW67hAUQM7k7JGXQXpSUX7jM=; b=TfOtgFn8V7n2eVcwCSKoDkdsIoC3KMz6ZTBfi4H+A0+FegXVYPQtLSIWwe1Nz6zW8lDvXx 1QolS+TvzBBDJnBQ== 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 542F01390E; Fri, 21 Apr 2023 10:14:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GNpvEQ1iQmRNaAAAMHmgww (envelope-from ); Fri, 21 Apr 2023 10:14:37 +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 v4 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte Date: Fri, 21 Apr 2023 12:14:14 +0200 Message-Id: <20230421101415.5734-3-osalvador@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230421101415.5734-1-osalvador@suse.de> References: <20230421101415.5734-1-osalvador@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763780720327486728?= X-GMAIL-MSGID: =?utf-8?q?1763780720327486728?= 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_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) @@ -499,6 +501,77 @@ static struct stack_record *stack_depot_getstack(depot_stack_handle_t handle) return stack; } +#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 + unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { diff --git a/mm/page_owner.c b/mm/page_owner.c index b6637524e442..b191ad1d41f9 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -718,6 +718,31 @@ static const struct file_operations proc_page_owner_operations = { .llseek = lseek_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)) { @@ -728,6 +753,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)