From patchwork Mon Nov 20 08:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 166981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2059996vqn; Mon, 20 Nov 2023 00:44:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFm+pgorwiISxgws+WKXEuxL7UA853SMVwPLxEDV/lKsMoP11QJMGxTjMMFeBmxLrxZs/fD X-Received: by 2002:a17:90a:4b8e:b0:27c:f1f8:261f with SMTP id i14-20020a17090a4b8e00b0027cf1f8261fmr3785071pjh.20.1700469846355; Mon, 20 Nov 2023 00:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700469846; cv=none; d=google.com; s=arc-20160816; b=k/n+UyrvEAcC4CgK7CGpUdYT2kF00YzPzmRb0MohiN/G6AzDFe8NFuzTD9boUKDedw 6Hce9Ks+N+eVXocD/b9OvY6sU8waayB2AYvomFlFKx6U2QrpLW0vdqiwo1Go7drr3ZNc f589gvzeukI/uyMki/KcljsvnJY8TDRjoRkEusR+kvteDgSawi+okj8AzPoNwOtc8Am3 LwSkCUR8EKCvs7C9f7rnCNmy9NrdMe7IjXLTC0Cgli2m2HYiNmh7TeuGe+2NnZGX4Zq2 4DCu+mRGHbqxNyMiWorCYkELPMrLlaKpdDkb3OjGcBwFizEJpDxNuaSYAdK9Csry7K+d IoBw== 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=MGpg1D+QkOzBj9HvH6Pm0yN+PlTUNsrk3hG0zRKlbo0=; fh=Nu0msm8cGz3CvEnu3k13ViJg3Y+V5oHxg1+HtdVamp0=; b=oheo5v5yavJwULk5Lbma+gwzHbWMpjoGRHm1l5VNIulCXtLGdl3n9jmP5vT3EwvRkv LhhE9cnODgJavZiZskHfYHyAfM9/dS/Vafp/c5mKEcCc/EcGgikWCW3vDd/SQPxCIbcC aC906ZkIJkPUpi7KzI1jOFT+31eNFxKLHFo6clRRglSWVk+AgfStybyY5CNx+GwQ16RL jmc3rTuFOM98tG6kor2p9yoHzjJFuZNIS2Ut/Zy7AcNmuW4uAQgch1zKLCWzxdV7eBiR cA67u/y52Qf9ANrqueOUWioP8WH9CG2kaoJlfGf2mn/1NvuS1X3ziTE/bbCAMUDpXjwD vAOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=I2B+KXB0; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ot3-20020a17090b3b4300b002832041e149si10807837pjb.167.2023.11.20.00.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:44:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=I2B+KXB0; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8ACCC804C216; Mon, 20 Nov 2023 00:44:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232306AbjKTInT (ORCPT + 27 others); Mon, 20 Nov 2023 03:43:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232284AbjKTInR (ORCPT ); Mon, 20 Nov 2023 03:43:17 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 123C4A4 for ; Mon, 20 Nov 2023 00:43:13 -0800 (PST) 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 A23E2218EA; Mon, 20 Nov 2023 08:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700469791; 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=MGpg1D+QkOzBj9HvH6Pm0yN+PlTUNsrk3hG0zRKlbo0=; b=I2B+KXB0e9Z8ba/sISmr7L1ZKTOJNxenGu9vqCIQj6M7fRTZftawKFLK4iEL8j5xND0rdf FE99H50tlrN3e4sKT2JKUpEOL9Hk8MzDeOwGBI9689VKXtifZUalbA1rd0lQdVAvZu+9oi lPd0IiBuPwkSK6eJv6UDXx53+W0mUlQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700469791; 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=MGpg1D+QkOzBj9HvH6Pm0yN+PlTUNsrk3hG0zRKlbo0=; b=kFHm8z2IL7kLEdY1UWV1ldcG4z+LFZcCdrWBKgAyr8a324wFwRAr5+772aJ5JFlZVKf0It 09G4NT9vwC+18jDQ== 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 E420F13912; Mon, 20 Nov 2023 08:43:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qFTTNB4cW2U3VgAAMHmgww (envelope-from ); Mon, 20 Nov 2023 08:43:10 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Eric Dumazet , Alexander Potapenko , Oscar Salvador Subject: [PATCH v6 1/4] lib/stackdepot: Add a refcount field in stack_record Date: Mon, 20 Nov 2023 09:42:57 +0100 Message-Id: <20231120084300.4368-2-osalvador@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231120084300.4368-1-osalvador@suse.de> References: <20231120084300.4368-1-osalvador@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 9.30 X-Spamd-Result: default: False [9.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; NEURAL_SPAM_LONG(3.50)[1.000]; RCPT_COUNT_TWELVE(0.00)[12]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,redhat.com,google.com,gmail.com,suse.de]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:44:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783071869686210809 X-GMAIL-MSGID: 1783071869686210809 We want to filter out the page_owner output and print only those stacks for which their counter (number of outstanding allocations) goes beyond a certain threshold. This gives us the chance to get rid of a lot of noise. In order to do that, we need to know how many outstanding allocations with a particular stack (for allocation) do we have, so we add a new refcount_t field in the stack_record struct. Note that this might increase the size of the struct for some architectures. E.g: x86_64 is not affected due to alignment, but x86 32bits might. Besides adding the refcount, this patch also introduces stack_depot_{inc,dec}_count for the allocation/free handle. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 2 ++ lib/stackdepot.c | 53 +++++++++++++++++++++++++++++++------- mm/page_owner.c | 6 +++++ 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index e58306783d8e..6ba4fcdb0c5f 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -94,6 +94,8 @@ static inline int stack_depot_early_init(void) { return 0; } depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags, bool can_alloc); +void stack_depot_inc_count(depot_stack_handle_t handle); +void stack_depot_dec_count(depot_stack_handle_t handle); /** * stack_depot_save - Save a stack trace to stack depot diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 2f5aa851834e..d35edac430c4 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -60,6 +60,7 @@ struct stack_record { u32 hash; /* Hash in the hash table */ u32 size; /* Number of stored frames */ union handle_parts handle; + refcount_t count; /* Number of the same repeated stacks */ unsigned long entries[]; /* Variable-sized array of frames */ }; @@ -305,6 +306,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) stack->handle.offset = pool_offset >> DEPOT_STACK_ALIGN; stack->handle.valid = 1; stack->handle.extra = 0; + refcount_set(&stack->count, 1); memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); pool_offset += required_size; /* @@ -457,8 +459,7 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, } EXPORT_SYMBOL_GPL(stack_depot_save); -unsigned int stack_depot_fetch(depot_stack_handle_t handle, - unsigned long **entries) +static struct stack_record *stack_depot_getstack(depot_stack_handle_t handle) { union handle_parts parts = { .handle = handle }; /* @@ -470,6 +471,26 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; + if (!handle) + return NULL; + + if (parts.pool_index > pool_index_cached) { + WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", + parts.pool_index, pool_index_cached, handle); + return NULL; + } + pool = stack_pools[parts.pool_index]; + if (!pool) + return NULL; + stack = pool + offset; + return stack; +} + +unsigned int stack_depot_fetch(depot_stack_handle_t handle, + unsigned long **entries) +{ + struct stack_record *stack; + *entries = NULL; /* * Let KMSAN know *entries is initialized. This shall prevent false @@ -480,21 +501,33 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle) return 0; - if (parts.pool_index > pool_index_cached) { - WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", - parts.pool_index, pool_index_cached, handle); - return 0; - } - pool = stack_pools[parts.pool_index]; - if (!pool) + stack = stack_depot_getstack(handle); + if (!stack) return 0; - stack = pool + offset; *entries = stack->entries; return stack->size; } EXPORT_SYMBOL_GPL(stack_depot_fetch); +void stack_depot_inc_count(depot_stack_handle_t handle) +{ + struct stack_record *stack = NULL; + + stack = stack_depot_getstack(handle); + if (stack) + refcount_inc(&stack->count); +} + +void stack_depot_dec_count(depot_stack_handle_t handle) +{ + struct stack_record *stack = NULL; + + stack = stack_depot_getstack(handle); + if (stack) + refcount_dec(&stack->count); +} + void stack_depot_print(depot_stack_handle_t stack) { unsigned long *entries; diff --git a/mm/page_owner.c b/mm/page_owner.c index 4f13ce7d2452..d53316d0d9be 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -139,6 +139,7 @@ void __reset_page_owner(struct page *page, unsigned short order) int i; struct page_ext *page_ext; depot_stack_handle_t handle; + depot_stack_handle_t alloc_handle; struct page_owner *page_owner; u64 free_ts_nsec = local_clock(); @@ -146,6 +147,9 @@ void __reset_page_owner(struct page *page, unsigned short order) if (unlikely(!page_ext)) return; + page_owner = get_page_owner(page_ext); + alloc_handle = page_owner->handle; + handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i = 0; i < (1 << order); i++) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); @@ -155,6 +159,7 @@ void __reset_page_owner(struct page *page, unsigned short order) page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); + stack_depot_dec_count(alloc_handle); } static inline void __set_page_owner_handle(struct page_ext *page_ext, @@ -196,6 +201,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order, return; __set_page_owner_handle(page_ext, handle, order, gfp_mask); page_ext_put(page_ext); + stack_depot_inc_count(handle); } void __set_page_owner_migrate_reason(struct page *page, int reason) From patchwork Mon Nov 20 08:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 166978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2059746vqn; Mon, 20 Nov 2023 00:43:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6UmWvu4Q5VwAwAVFZrv99o8qtitmN4g6yoz/GA3HZRs0JUECn5zpR8nBBNI5Yb8T5lATu X-Received: by 2002:a17:90b:4d0d:b0:27d:c36:e12d with SMTP id mw13-20020a17090b4d0d00b0027d0c36e12dmr4448971pjb.6.1700469815596; Mon, 20 Nov 2023 00:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700469815; cv=none; d=google.com; s=arc-20160816; b=LB9b12WtPinny17eZIiV9up4u2evDyl9W21yF/+k03gYtwB/jzRsyNZztnHb6BBROH e+aIYNUfBb/PZdfujqSz1bvC912QHIOt9bplDhsNlXbTuEsgQy3B0lpzVSUrw8H02D2U 2KZxxm89WER2LTeye7S5+XuOWohdOtS1XswGVzJuLtFuW89SgAXApPZKRpSqcq5h/6h6 zVe40b9Dj4dWADhA2lqZ2Nr3fYxVK7MKHzzxBtq1imKI0hW6J9cduIZYiWW2F7Uv8Lwi 4LmPkEYdMRMvEyZ4pQtws12cvKsMOwyv5DVLp2ttGGDampQi1gbhS1oMH6j6jVf5CnQ/ rC7A== 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=9KwZyfV7MQI2yuPA0zEe5ABuumoWkd6UHOrlY+2DXtc=; fh=Nu0msm8cGz3CvEnu3k13ViJg3Y+V5oHxg1+HtdVamp0=; b=wwUdBANSqGqU2EBZSdRFTBQqJ1ezPmqVpW8WicHB4zJ8GcYXrtN59/ASbXj8llJcIx vyJf3kjLA+pL74SUw603U1+FeVI6kglQYJa+vaBAQeM0k91H3xBXzO57CwdAOJN0vFMj j19Gb0rSGTux3s2owXIb4eE2Pl8CFxhPGcVwuF//5ET8UeR8bDSxkCiWx2vMUa2RZUvV AQgfm3ohowPfNC0Kv756MiZCqTCt43xEnKYUCHlrj0EhZVEiIi7H8kkd+YSkoslpQyci GIimI1dZP7PcN/dBa7tyd+A7Dhjas9HPWQmp5QMRT+3mMQxGh30zTLV0/PaJOYT6VrZh NfeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=18reAZ2y; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id nw10-20020a17090b254a00b0027d30e575ccsi8365060pjb.115.2023.11.20.00.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=18reAZ2y; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7630B802A81F; Mon, 20 Nov 2023 00:43:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232276AbjKTIn2 (ORCPT + 27 others); Mon, 20 Nov 2023 03:43:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232290AbjKTInT (ORCPT ); Mon, 20 Nov 2023 03:43:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1C749F for ; Mon, 20 Nov 2023 00:43:14 -0800 (PST) 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 445531F750; Mon, 20 Nov 2023 08:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700469793; 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=9KwZyfV7MQI2yuPA0zEe5ABuumoWkd6UHOrlY+2DXtc=; b=18reAZ2yAcdBFEdQaz+5irPkXXOsJxea/MYnsQ2USIGUzIzALXtdh1iC3nRFOl3Fa83l0D OHUw1+MIjrSfQuR9T8l4yChyFrGeIZjwyqpLPP6qgjQHsoEGBnlbt5vPwMxGsOeXi6z/D3 wABxJWx6Ce7ztWJih95VFqr3pWmgcIY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700469793; 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=9KwZyfV7MQI2yuPA0zEe5ABuumoWkd6UHOrlY+2DXtc=; b=b4bGvsyUeKGgJYWUfFX4xb35t3MGvceX54PAP448j1O6i8ZNYOXZEHgJ7q0xT4BPOq49pN NJmqUYfaGjEVT4AQ== 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 8CA3413912; Mon, 20 Nov 2023 08:43:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IEt/HyAcW2U3VgAAMHmgww (envelope-from ); Mon, 20 Nov 2023 08:43:12 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Eric Dumazet , Alexander Potapenko , Oscar Salvador Subject: [PATCH v6 2/4] lib/stackdepot: Move stack_record struct definition into the header Date: Mon, 20 Nov 2023 09:42:58 +0100 Message-Id: <20231120084300.4368-3-osalvador@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231120084300.4368-1-osalvador@suse.de> References: <20231120084300.4368-1-osalvador@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 9.30 X-Spamd-Result: default: False [9.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; NEURAL_SPAM_LONG(3.50)[1.000]; RCPT_COUNT_TWELVE(0.00)[12]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,redhat.com,google.com,gmail.com,suse.de]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] 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 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:43:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783071837266853842 X-GMAIL-MSGID: 1783071837266853842 In order to move the heavy lifting into page_owner code, this one needs to have access to stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 34 ++++++++++++++++++++++++++++++++++ lib/stackdepot.c | 34 ---------------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 6ba4fcdb0c5f..269a828a5e94 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -32,6 +32,40 @@ typedef u32 depot_stack_handle_t; */ #define STACK_DEPOT_EXTRA_BITS 5 +#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_VALID_BITS 1 +#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ +#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_VALID_BITS - \ + DEPOT_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) +#define DEPOT_POOLS_CAP 8192 +#define DEPOT_MAX_POOLS \ + (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ + (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) + +/* Compact structure that stores a reference to a stack. */ +union handle_parts { + depot_stack_handle_t handle; + struct { + u32 pool_index : DEPOT_POOL_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 valid : DEPOT_VALID_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; + }; +}; + +struct stack_record { + struct stack_record *next; /* Link in the hash table */ + u32 hash; /* Hash in the hash table */ + u32 size; /* Number of stored frames */ + union handle_parts handle; + refcount_t count; /* Number of the same repeated stacks */ + unsigned long entries[]; /* Variable-sized array of frames */ +}; + /* * Using stack depot requires its initialization, which can be done in 3 ways: * diff --git a/lib/stackdepot.c b/lib/stackdepot.c index d35edac430c4..1343d3095bc1 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -30,40 +30,6 @@ #include #include -#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) - -#define DEPOT_VALID_BITS 1 -#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ -#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) -#define DEPOT_STACK_ALIGN 4 -#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) -#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_VALID_BITS - \ - DEPOT_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) -#define DEPOT_POOLS_CAP 8192 -#define DEPOT_MAX_POOLS \ - (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ - (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) - -/* Compact structure that stores a reference to a stack. */ -union handle_parts { - depot_stack_handle_t handle; - struct { - u32 pool_index : DEPOT_POOL_INDEX_BITS; - u32 offset : DEPOT_OFFSET_BITS; - u32 valid : DEPOT_VALID_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; - }; -}; - -struct stack_record { - struct stack_record *next; /* Link in the hash table */ - u32 hash; /* Hash in the hash table */ - u32 size; /* Number of stored frames */ - union handle_parts handle; - refcount_t count; /* Number of the same repeated stacks */ - unsigned long entries[]; /* Variable-sized array of frames */ -}; - static bool stack_depot_disabled; static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; From patchwork Mon Nov 20 08:42:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 166980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2059946vqn; Mon, 20 Nov 2023 00:44:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDz1wVwaClad/vNt6lcWDDMbq/hKV7afiy1ijxODVaVMXGCabNa1dPrXZro5lSJv5QqW1k X-Received: by 2002:a05:6870:460a:b0:1f4:a631:f5fc with SMTP id z10-20020a056870460a00b001f4a631f5fcmr1710109oao.33.1700469841079; Mon, 20 Nov 2023 00:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700469841; cv=none; d=google.com; s=arc-20160816; b=gN49ENh5ZbUljvjQn015bHyRY1Xn+DI/J4i3XYcW8jxC/WTyYgAKXCVIwsKAmI6vj9 kj0zvU3Fhw3fojmOZHNQRgGWFvc0V+93/vAhkUYhZBmrTwC42VFuQqc2zqPRG1o4LFWs YZVltqNWp9KUOwP+47Xzi2gy4UYsKpKEW/9swoO6UQ+X+CyYw9fT13FuBcTN9vwqLnqy syrQCGgvSuXcSciORnlgVKFQQzk+OaFnI9XMzbZldxosIU+SQ84zH3hZuQQeUadBKvXI dZaYvfQZJHwKzybkyKGL3se2wU2ykZfT6vjV4g8VU29urUKm6royrZjRE4weGXo0M/eq 8Whg== 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=7EwAqAp1NFiaOxvyhYru50OYx9A1799Fnc0qEZ742hE=; fh=Nu0msm8cGz3CvEnu3k13ViJg3Y+V5oHxg1+HtdVamp0=; b=tHReR0pJQ1aBQC/12OTELWN+WfnzMp+MEAKshOijyHJl0CaZs4Y51f2XVAGnH1Zy8v pcsemjg8ZrUK8GnYd/8SUw38wj9tjfW9qLZSKOHr+RSJ640A5Ky48lZCqIBHuihqggPq H+SpQrBWl7Zjw0SUPk1YmG4Nr1tDPcoGbK1K19jDbh6XWyM2vznCvKiwLJnM4mKXtojQ eWBbiMRx3S/PFwJzRqhM0zeMGRVTJSDHRv7AHGTirbGYgMjQhCS+NNlLTHztffcs0qVf TWVBKILpOQRe89Qy1GxzKbD7cgGzS0Py9VN756yCNTWEmziF1DqE34FtzbZAGjnUnwVL SDaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=j7OyRP9w; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=RxXVN6L+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 15-20020a63104f000000b005b909e678dfsi7271609pgq.450.2023.11.20.00.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:44:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=j7OyRP9w; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=RxXVN6L+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D0730809C14D; Mon, 20 Nov 2023 00:43:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232343AbjKTInc (ORCPT + 27 others); Mon, 20 Nov 2023 03:43:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232323AbjKTInU (ORCPT ); Mon, 20 Nov 2023 03:43:20 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 837E0E5 for ; Mon, 20 Nov 2023 00:43:16 -0800 (PST) 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 2498E1F7AB; Mon, 20 Nov 2023 08:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700469795; 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=7EwAqAp1NFiaOxvyhYru50OYx9A1799Fnc0qEZ742hE=; b=j7OyRP9wUjBWfFGuqYCOlJ4Uf4LJ0AYn1ES0WLdmpsaoFXdeRHCtefgi+Jb4X80VPBIgHF zNWqHtXrZuVlz+2vtY42snzsEPA5Ws1P9DSV6DEBpFUyH54UGTyWHaKyCo4R2Luwsa80sN JfTIrqzKynVwrl/Tw9F0zaTv54SIRFA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700469795; 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=7EwAqAp1NFiaOxvyhYru50OYx9A1799Fnc0qEZ742hE=; b=RxXVN6L+9WAKE2vHWxLlrQIUbQkcvm0uCy8VrlyaNQ7cR3anpx7Mk09o8jH550OgCTb8O4 czmQIHJXImh1ImAQ== 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 22BA913912; Mon, 20 Nov 2023 08:43:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SFrpACIcW2U3VgAAMHmgww (envelope-from ); Mon, 20 Nov 2023 08:43:14 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Eric Dumazet , Alexander Potapenko , Oscar Salvador Subject: [PATCH v6 3/4] mm,page_owner: Add page_owner_stacks file to print out only stacks and their counter Date: Mon, 20 Nov 2023 09:42:59 +0100 Message-Id: <20231120084300.4368-4-osalvador@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231120084300.4368-1-osalvador@suse.de> References: <20231120084300.4368-1-osalvador@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 9.30 X-Spamd-Result: default: False [9.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; NEURAL_SPAM_LONG(3.50)[1.000]; RCPT_COUNT_TWELVE(0.00)[12]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,redhat.com,google.com,gmail.com,suse.de]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:43:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783071864062918500 X-GMAIL-MSGID: 1783071864062918500 We are not interested in the owner of each individual pfn, but how many outstanding allocations are there for each unique allocating stack trace. Right now, getting that information is quite hard as one needs to fiddle with page_owner output, screen through pfns and make the links. So, instead, let us add a new file called 'page_owner_stacks' that shows just that. Such file will only show the stacktrace once followed by its counter, which represents the number of outstanding allocations. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 2 + lib/stackdepot.c | 29 +++++++++++++ mm/page_owner.c | 87 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 269a828a5e94..09c478b1bf73 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -146,6 +146,8 @@ void stack_depot_dec_count(depot_stack_handle_t handle); depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); +struct stack_record *stack_depot_get_next_stack(unsigned long *table, + struct stack_record *curr_stack); /** * stack_depot_fetch - Fetch a stack trace from stack depot * diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 1343d3095bc1..65708c0c1e50 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -452,6 +452,35 @@ static struct stack_record *stack_depot_getstack(depot_stack_handle_t handle) return stack; } +struct stack_record *stack_depot_get_next_stack(unsigned long *table, + struct stack_record *curr_stack) +{ + unsigned long nr_table = *table; + struct stack_record *next = NULL, **stacks; + unsigned long stack_table_entries = stack_hash_mask + 1; + + if (!curr_stack) { + if (nr_table) { +new_table: + nr_table++; + if (nr_table >= stack_table_entries) + goto out; + } + stacks = &stack_table[nr_table]; + curr_stack = (struct stack_record *)stacks; + next = curr_stack; + } else { + next = curr_stack->next; + } + + if (!next) + goto new_table; + +out: + *table = nr_table; + return next; +} + 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 d53316d0d9be..509c11e506db 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -719,6 +719,91 @@ static const struct file_operations proc_page_owner_operations = { .llseek = lseek_page_owner, }; +static void *stack_start(struct seq_file *m, loff_t *ppos) +{ + unsigned long *nr_table = m->private; + void *stack; + + /* First time */ + if (*ppos == 0) + *nr_table = 0; + + if (*ppos == -1UL) + return NULL; + + stack = stack_depot_get_next_stack(nr_table, NULL); + + return stack; +} + +static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) +{ + unsigned long *nr_table = m->private; + void *next_stack; + + next_stack = stack_depot_get_next_stack(nr_table, v); + *ppos = next_stack ? *ppos + 1 : -1UL; + + return next_stack; +} + +static int stack_depot_get_stack_info(struct stack_record *stack, char *buf) +{ + if (!stack->size || stack->size < 0 || + stack->size > PAGE_SIZE || stack->handle.valid != 1 || + refcount_read(&stack->count) < 1) + return 0; + + return stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, 0); +} + +static int stack_print(struct seq_file *m, void *v) +{ + char *buf; + int ret = 0; + struct stack_record *stack = (struct stack_record *)v; + + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + + ret += stack_depot_get_stack_info(stack, buf); + if (!ret) + goto out; + + scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", + refcount_read(&stack->count)); + + seq_printf(m, buf); + seq_puts(m, "\n\n"); +out: + kfree(buf); + + return 0; +} + +static void stack_stop(struct seq_file *m, void *v) +{ +} + +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 +813,8 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + debugfs_create_file("page_owner_stacks", 0400, NULL, NULL, + &page_owner_stack_operations); return 0; } From patchwork Mon Nov 20 08:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 166979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2059829vqn; Mon, 20 Nov 2023 00:43:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXRSuNO/AgTJvVR4XdYAI/Cvhf6jNIkXzLUsjgZ0S12GsGcy29u+l/XjdHYKaUlAdNhagT X-Received: by 2002:a05:6a20:da90:b0:187:d18a:3164 with SMTP id iy16-20020a056a20da9000b00187d18a3164mr10858300pzb.6.1700469827019; Mon, 20 Nov 2023 00:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700469827; cv=none; d=google.com; s=arc-20160816; b=b9A67CPn6CMkUTUISZE7Na0170de+saOJvujZig0N0090SwldPi9CicHPQGe702sz4 Thx/cwyCmR2KUzgGCgkOK2ZQe8X1m5G+rcUM3rKo37k1Ojs1acCOaDIjfzC7TazwtkzT CSXl0PomQjx4EkIF7fpEq+6jRcdPhBW9VoesUUaS7P1tPeSdeZZA44kRtkGtTCHw1sdj Hy9OUnNeZVxV7hhAUuYUXV0NXfZl4qclCqS8kfXXt7A5P9bVXTCh9GL1dazdDIewZTRq SfTZ2GnOrZICACPZO4mluoHI/3K/e0/u60vpXlY6KrF5c2VWdYy/gRyYV1HzhrDVJ75E baHQ== 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=PDH277g7F2wYgGggepn2hqYKq/ycO2DhoCkVXWauxYM=; fh=Nu0msm8cGz3CvEnu3k13ViJg3Y+V5oHxg1+HtdVamp0=; b=OrSQsfTA5MsJkBR/Lap3JzkqXSNDukPMsRiXJ44M7HedSvat7VnK4Nd9sfzJRg2V8f 22zx2t0+qbDL+4BwHuZeei+Eca45M4vfgYs2sA8PllR2ZYmeaKbhl9OdtXju9M6K2YYy W5wa2DkbS/k9drhSzT0k91Ez6Cg8btWLvd0zaXgR8b6PHKACFvQvNMvO3nMhBrQpfiBs FXcwqiygO3R3qynB1/O2Lyd9NWeHjtfXELm5/unyFGhM/4SpK88CJ5x4NWmT5sx9iqY0 v2CPs1hrLtYePt6vE9Idqo12nW72TcbPOMuBI8a0cgzKb1Nbl2toK0Z/z63u4woTTNKX EWKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=vULYWMFM; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n5-20020a17090a9f0500b002851a01b0absi3239527pjp.151.2023.11.20.00.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:43:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=vULYWMFM; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D29FC802A82F; Mon, 20 Nov 2023 00:43:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbjKTInf (ORCPT + 27 others); Mon, 20 Nov 2023 03:43:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232346AbjKTIn0 (ORCPT ); Mon, 20 Nov 2023 03:43:26 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2FC1AA for ; Mon, 20 Nov 2023 00:43:18 -0800 (PST) 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 58A0D1F855; Mon, 20 Nov 2023 08:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700469796; 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=PDH277g7F2wYgGggepn2hqYKq/ycO2DhoCkVXWauxYM=; b=vULYWMFMmmaG4S6iAkq5rSYmzy20p9tn1S3i6DL/n7pooOCC0Z+gGAbJ3WGHNnAFjw1Oeb OCX2wKXShH5JPzCNgEvnFq1C9WhDIOFSrP9E/HjhIs3ItAn5AwWVeq3djPr7uW40iDdPDj a7gK1tVk27s7VosOL1aTePWRIqQUGJM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700469796; 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=PDH277g7F2wYgGggepn2hqYKq/ycO2DhoCkVXWauxYM=; b=AePaBT45sbywumguZikXpcc3f5I8qh22AOKqNPJdL4aMGBn+rV5hcc7enjPGv4AhKNpohk HO99W3gl6HlKfNCg== 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 A1BEA13912; Mon, 20 Nov 2023 08:43:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uEGWJCMcW2U3VgAAMHmgww (envelope-from ); Mon, 20 Nov 2023 08:43:15 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Eric Dumazet , Alexander Potapenko , Oscar Salvador Subject: [PATCH v6 4/4] mm,page_owner: Filter out stacks by a threshold counter Date: Mon, 20 Nov 2023 09:43:00 +0100 Message-Id: <20231120084300.4368-5-osalvador@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231120084300.4368-1-osalvador@suse.de> References: <20231120084300.4368-1-osalvador@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 4.20 X-Spamd-Result: default: False [4.20 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; R_RATELIMIT(0.00)[to_ip_from(RL5rfg3hcnr63ytnowg6b9545r)]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; NEURAL_SPAM_LONG(3.50)[1.000]; RCPT_COUNT_TWELVE(0.00)[12]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,redhat.com,google.com,gmail.com,suse.de]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:43:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783071849281181718 X-GMAIL-MSGID: 1783071849281181718 We want to be able to filter out the output based on a certain threshold, so we can leave out stacks with a low counter of outstanding allocations. We can control the threshold value by a new file called 'page_owner_threshold', which is 0 by default. Signed-off-by: Oscar Salvador --- mm/page_owner.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index 509c11e506db..6ee345dafd01 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -41,6 +41,8 @@ static depot_stack_handle_t dummy_handle; static depot_stack_handle_t failure_handle; static depot_stack_handle_t early_handle; +static unsigned long page_owner_stack_threshold; + static void init_early_allocated_pages(void); static int __init early_page_owner_param(char *buf) @@ -763,6 +765,9 @@ static int stack_print(struct seq_file *m, void *v) int ret = 0; struct stack_record *stack = (struct stack_record *)v; + if (refcount_read(&stack->count) < page_owner_stack_threshold) + return 0; + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); ret += stack_depot_get_stack_info(stack, buf); @@ -804,6 +809,21 @@ const struct file_operations page_owner_stack_operations = { .release = seq_release, }; +int page_owner_threshold_get(void *data, u64 *val) +{ + *val = page_owner_stack_threshold; + return 0; +} + +int page_owner_threshold_set(void *data, u64 val) +{ + page_owner_stack_threshold = val; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_get, + &page_owner_threshold_set, "%llu"); + static int __init pageowner_init(void) { if (!static_branch_unlikely(&page_owner_inited)) { @@ -815,6 +835,8 @@ static int __init pageowner_init(void) &proc_page_owner_operations); debugfs_create_file("page_owner_stacks", 0400, NULL, NULL, &page_owner_stack_operations); + debugfs_create_file("page_owner_threshold", 0600, NULL, NULL, + &proc_page_owner_threshold); return 0; }