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: 13460930 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 4E7B0C54E76 for ; Mon, 20 Nov 2023 08:43:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDB876B0405; Mon, 20 Nov 2023 03:43:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8C526B0406; Mon, 20 Nov 2023 03:43:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C54D96B0407; Mon, 20 Nov 2023 03:43:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B61CB6B0405 for ; Mon, 20 Nov 2023 03:43:15 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 81EAB1407E2 for ; Mon, 20 Nov 2023 08:43:15 +0000 (UTC) X-FDA: 81477693150.03.7BBE59C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf13.hostedemail.com (Postfix) with ESMTP id 6AD6A20023 for ; Mon, 20 Nov 2023 08:43:13 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=I2B+KXB0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=kFHm8z2I; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf13.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.28 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700469793; 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=MGpg1D+QkOzBj9HvH6Pm0yN+PlTUNsrk3hG0zRKlbo0=; b=3k/v23tZUkBIYeqp+iy9TiEWpWyUC0VhrAUrADvuj5k7RtOiHQPxbGqMpCauOMoeBkbsLM R++Z8X3JLBiHnp5Hs+z0S+ASEpoyGhwpY6FVnUIFcYtd2NjzbcCW1s0DN9/rmomM/8kPkE haeVOTCdpzhqIsOMSNgmpE7ZgeML2ck= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=I2B+KXB0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=kFHm8z2I; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf13.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.28 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700469793; a=rsa-sha256; cv=none; b=WD3tCPBE6EKKTCi4UZlpZTylUjQGaxNlhL/4CP7XPRgAQ3XmwqhftlkAP190FMhV1/Q8Qo E/SX5gfPD9IevJ+aimdcEkyscZvDcefQiP1+aqot1Kn0pOFbHcbtmB81B5doKg8sy2hY9f LVU1IVrwNqqcxykpzGg/FLsWeYdTIac= 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 X-Rspamd-Queue-Id: 6AD6A20023 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: w91tdyg7e7me6zygsu91qckybe94upqd X-HE-Tag: 1700469793-311261 X-HE-Meta: U2FsdGVkX18LAiIZYYTns9qBTmEdEOULHIhzLNsWl3GnJZgwmnIYvSpZAY7De3k/mJCqq9aEDmCOkpS209elAotLbumbnADhUwxwbUeYNYpVhmSVHuJMekqKKxW0/ROJZvIL6RV8Rpu2CLy8qbJmdKKEkSUxWjmr5fE5c0P0KGVvfROgWhpCJub2sDv2s6Zdp1UyHwquYJjZhKAKnJp8uiZr6zjqTqQ1ZOMogqs+s7TsLfznqmKwj7ZG97YXZbxl57CY9pNGp51q3iSkQDiLeADnsKmobfZQ9iHJpKbW372WVjeYjIQDZv+6K89lRmdXz4o+rloL/QpFkuLrcQ1mmIN9NrL8Y8j6szn1Kjmj8JoKHiMf2Iqx3/X+PWecgU/msB+xjEXmzRFatQKJpwcuy6wi3THOeUW9IqcIFvDeL98G7I1nic83O05HQQOZb6LG2S3gZGmM4yK1JUrKMHk9s0567c+Hc6p7d+etKesyhODeKphZtHKI7hMieuJfmqVJfPxhzphDPslC/or28IQdPlppJIsaG5SWr97Z2x+LhbLooKfBgDQ79a/pIJAnz974sV49/SUZsUCibkSKcF83SLTR+vH7dPHD2vsqNg7aORpwxdXH0ujnq0oN5akkom5JpSeZQmxyTfynDpeNoFPY1ULiEOUo0lihfopnqcb9wUisfVg/XmXhNZGqAlfGm/89Wm9SLChC/SqRUSyv59HZzLghFOAgB7/1g0lZ/OnnaIDuhtuAMzwLv88TFT7SZCGgUULgjzOz5EWgDiI6h4FpXO0GlYyDnH7QTkUJvZeXmHyxRAI7aRO5JM/Z9+9mkouUBpOs+xhFZqhrMG285geg0NCMULcxX9kx9yI3OnC1Vi8+N9LZ+w2/HUIwQkyFE6FJnwtiiwLF054QhUynxtyYPQzh0AKdq1kmalrFa3yZ4IAYTB72JOYN9bZsaLNYpG+PhJzb0MZa+BAzhdfGJcP bJVoe59a LT/JpiiAYDmY8YOw4EebIY8qEotX5HeeREWEQQZ58WBACnBPX4fSM1v3B/miWcvodUPRJI9A5HNsz9w+/Eo0wWiapHfppnMtEd9R4EqpAxDcCtnpmS3SgoOsGoC6m9YWEBWrm19AbalDg/oBqas2BTu+VZ6d2nRJYSWGsttB6OJuX8Ep609LExxGwcoZsQtRhFNaFGk+V06ceiZ9sklnOGzPCkhZbYK7PJhxQg63WIyNyHwCO4iQv6Ss5cEDP32w7fzpx 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: List-Subscribe: List-Unsubscribe: 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: 13460931 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 A3AC5C5AD4C for ; Mon, 20 Nov 2023 08:43:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32F0F6B0409; Mon, 20 Nov 2023 03:43:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 307906B0408; Mon, 20 Nov 2023 03:43:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 159916B0409; Mon, 20 Nov 2023 03:43:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 037056B0406 for ; Mon, 20 Nov 2023 03:43:17 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A2F7AB5863 for ; Mon, 20 Nov 2023 08:43:16 +0000 (UTC) X-FDA: 81477693192.21.47ECDCC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf19.hostedemail.com (Postfix) with ESMTP id 911791A0003 for ; Mon, 20 Nov 2023 08:43:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=18reAZ2y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=b4bGvsyU; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700469794; 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=9KwZyfV7MQI2yuPA0zEe5ABuumoWkd6UHOrlY+2DXtc=; b=Y0cGXhwHcBz7OrYb5Yd8DunSC4ANSM0bmjY75T4wRxffKmLEsqMgjsGc6qU7ITPasqS/YZ SCsyamP5I2gAD5dSR3b4lsW4FwMh/tzPvelZgJrnAUrZjzdz3D7OPX7lQ2tPRSmS6hPpSr laa606WKS8FM1V9Bf+VTXCZ1+M5g8LA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=18reAZ2y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=b4bGvsyU; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf19.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=1700469794; a=rsa-sha256; cv=none; b=OjuhHCTvy5jh6n2NLhbo0YC6o9vFY5obFGsxNIuDLfEP/OYgeDyCCpLCXaR9ELLUepe1FA F6FZtEiqEhV4a6CndhxwAroTvgzfg/X92uq7xkVBaaharhvqbfhD/rJ5AOdd702BEZnZNI c3GMrpGcDJu1114mdxLgBo8ldXOmUJU= 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 911791A0003 X-Stat-Signature: o6sesuw5z78g7bwek8zcysp1ftsfm83a X-Rspam-User: X-HE-Tag: 1700469794-932269 X-HE-Meta: U2FsdGVkX18nqyi38sWG1ZI5V/iyAZNBsylhcLEkYbGPEopdhLNuCDCJMVzyQ3CRcUnM13OFGKvrrKzLJdPSSOWNr+YA/q7FGt0FmJKHPir1xgisEPzw5RBkmr2lg4prh305NcfPMOYYzKf8EdJVII4UoR0YxbKDgZgmz4B0GlqGXGBRvZjhULbJBIxVQNFSiR4sk85BHSsJL6/1OLocwWNHqwGf+yhjPbo0IkENcF+uQZv3oyHg4ydCWEZ+kbIY3hqONxzdpvACfRDfAH74TxVquqCgrhHAwAnl0RbR/uGgiJaOGXORs9WkNB7+X63NkZwzVSiL7jDstdrDuvR7r67C+uA5jKKuUY7rHsXblO/UrHtBWFByrytWq/LFj2SEIn03yzyYy4bqIEVpgSC/XnTZ1zojQ9SlZFxQkaDHFFUaJ9lUxZME4U+O2+BtfzZSCiIGOWbIqRTyJLATl3EN263rwQjQ6wMnwY8YCBUY7dHTXKoL3E4JItRFD/eZ0NnGt8UcQEkAHy9/dacYNgwY+fVsDeVHA8bYHY7TpuMv4eJynwdSPTbqaw2CjcjgQ69v3AXFLr0SxvQXEmZFLaVljuUFIe3Axk+IdJmngWfmIpJgE/jxk4w7Wm5vRJrjHkdyd6gJvI38jmWT/VN1Bh+/bWT4abTE20tfYbl8FgSlCRCbduW4pi0vl+a1wy3qUBMKLA5NA4bdm0Wbsm4lcVMZkZE3yRJr2IUtr/SBLW26H+udj074y5ZPnUm/TGagvdbpMbzEtGfMY55yT4/utB/pfVM+pTwouRvPKA1z5L7O1SKbrhbgoignjRTKIMY2i9LtqN6z5BcHLpSsIHbrFciRJuCmTEaZmA/AReFZk6pojNRtNFrJxhQzwXo6l74UNr4kb17jrHcZG1eiKGJBE6fvoj4880qiXa8GYgHH144MmUvzwd6xonn/tj1dx2mvnb8AzoHF0T/3vJRd3nszGwo sMtK6EKy k/cG+ni3WXV96KgAmqjKUcof2b8wrs2eQUMYnJALQHmXM05PaAJ62r5qwP0wWDBnZMO71KOmvZIe/cAI4ix2AZ5nlbOfnbVV5Fby6bhCBshNcJULnygwxWlFQrn2kLIPx0hEckjHT9zCk0r5doQGnfISSUGpT52SWdMHkKnwAjtOoS2JQ2f7DAd6caz2kg6KPD4NnqKXfmv/7AnCxfwK+CG7mGNAeTnSN+4ke83eHcTd26kgypYdnn2jHbw9/XfxCS7BP 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: List-Subscribe: List-Unsubscribe: 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: 13460932 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 C8B5CC54E76 for ; Mon, 20 Nov 2023 08:43:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D14B6B0408; Mon, 20 Nov 2023 03:43:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1585F6B040A; Mon, 20 Nov 2023 03:43:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEE3D6B040B; Mon, 20 Nov 2023 03:43:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DAEC76B0408 for ; Mon, 20 Nov 2023 03:43:18 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BCCD31A07FA for ; Mon, 20 Nov 2023 08:43:18 +0000 (UTC) X-FDA: 81477693276.09.112A22B Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf25.hostedemail.com (Postfix) with ESMTP id AFD9FA0019 for ; Mon, 20 Nov 2023 08:43:16 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=j7OyRP9w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RxXVN6L+; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700469797; 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=7EwAqAp1NFiaOxvyhYru50OYx9A1799Fnc0qEZ742hE=; b=PKax6otujTllDKHBDcvlH1+vwW7wOaVR5De+OGCUlOHtE/QgjFJ6Y+iDT3fqrjUDkbgEL3 HaFNW9+tOn7AiHtnC+6Y+ir0HG2I//ISNv1L4/iq8wtsJW0zpLeuvCYXp35J7maqmvRBlB hzfsy5ErUaj8MfeC3gx7mXjBnT5mAgQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=j7OyRP9w; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=RxXVN6L+; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.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=1700469797; a=rsa-sha256; cv=none; b=CAaCaue21LnnrD1VIXsDaCVf03gY4sMFnUdpJTZ+LtGOT7qSziha4eEVoqlLCHuNhwPSwG t5hOR6BQFa5HJ4om9f9DybfhWk+n0P0gXO6xqhpJ84gJk99k99pPsqpz84BVOsD1ELK+G9 Y6SjHynDei4iXoKFBdZ0LeeDWSxZJtA= 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 X-Rspamd-Queue-Id: AFD9FA0019 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: nes7zui4u4wfxsf59a6873baiupe4w3u X-HE-Tag: 1700469796-770509 X-HE-Meta: U2FsdGVkX19Ho4uDy8fPzOJIiYHysm6AOs0YGSqMM+noA2EMTk8nqgRD9CeZqazHHBZmTRIo3eoCzG7R1P71Z2fXDbxfBtDfAPs77WYj/80qyOMVcJPsNOs/Cb2mBarNomCWkRU5PfLow9r1P+ivvnzpS8JFoFa7GTsl7SozJ2131HS1DO0GJmHylTpsmCrZjFDKcML/hUqA2hK+mopIg+tMG5qdsgGOwTewx4uulG4cs+by1+Mt1/8RPHPFcGuqdj2ghqNhd3T6m4WV/Mor2+J8uMauZbE6lmZCMNvLNyHIaJpL8JdlW1cH3Phe8io+mkh/GTf+EvCAgGCGPCdXrDSmysY5deZIbZ3YX1gO6lkog8Daqd6q407AvTce3hXvf5upYsmf+LlB7VMRI/YpuscwLDIo5Q2CES0yZb2sdG7ks/4/aK6ZGAHtBxrzY0Zr4CVH/UEGhXCVkisBqFVt0Oe4x4l9Nj5VOZ49FP9+yd171v11Ilwgsqxl4N8ZkHFtzLc33F1FRm3wPQEsqobkphhOUg+moNxf9uOGKJ49lHaZjN5DD/V3EbH7WhOk9d9J7KRalMGpHiGYi5+XtEOx8WO9KWjI4vKJDbla3GX1hsBpNJLNXp/dESMoK4R0FMN9QHcwZhN+/2mKlLcHzcW7syPAHn1foyQHmVicwaYnrwrYK7JHpTxTV6Nb2FsR3cAJpLuY6jW4+RjlxdZ+LeAmWk/AodqHalVflUb2GgNVzi0ghjCNti49KlT7uQ7WYMp2Sn7mBgSx/d/vYedzXsalkqxjHTQ6PFM85mUAz3eaUe7B9a0ptk+aDsgZLpOiyvYzZtAQCLTL/RUnYX1axcJXgWxhcfeGUhmdRZQMqa7V747nLd4v8Pb0dBBw8JISrB6AHiY+8GB9LSq7Re4udTESMmAAk9sGKO8hzdy5guEIRmNN2E5UViybmvLCAQHKPysV4ChbjYX9v7dsQj5/LI3 jpvENqd9 ASjyYNh2EY1XCMpTG7Va7jr9r0wHoGRJ+EczcbO106oy2i22yMtAfYEQNw1CpJVM7KllYYZnZ1hgvuGA0imV+BJO1SD4hFsBE/brfloMPTPiWSTcHPP93qpUeIzx6Dtty12/m8zIkf7ATGCEGwQQBgG+XZyhMPv1yeLcILpOoCcuztgT/0dHqrfpK1G2AZ/JxqE8Xpfs6f5YDvvyydBAfAXc+stSIFNPy6TaKMdi0PELk3wz5wufbTO+omNNB/Y8FUmpk 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: List-Subscribe: List-Unsubscribe: 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: 13460933 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 46B3FC197A0 for ; Mon, 20 Nov 2023 08:43:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D7906B040A; Mon, 20 Nov 2023 03:43:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8850C6B040B; Mon, 20 Nov 2023 03:43:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68D766B040E; Mon, 20 Nov 2023 03:43:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 533976B040A for ; Mon, 20 Nov 2023 03:43:20 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 31112A063B for ; Mon, 20 Nov 2023 08:43:20 +0000 (UTC) X-FDA: 81477693360.28.D36E4A3 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id 2153CC0012 for ; Mon, 20 Nov 2023 08:43:17 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vULYWMFM; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=AePaBT45; spf=pass (imf10.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700469798; 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=PDH277g7F2wYgGggepn2hqYKq/ycO2DhoCkVXWauxYM=; b=iIKHeyIP8sgiGUL/cT9q6Q1HA4XHSS7Xax70W80g3DIX701fnepwaXILS3cQi9mYPM4Ejr CB513wOVvPwwH+7w0WTQGzlgaEOf2qDvQwBIze4YRDVS1lQH5XnhKbyADxldZeAyh4vdir No8N1WaQypAtYdPCdSjHbROnG5STmgA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700469798; a=rsa-sha256; cv=none; b=YNqOJPdfQgj7686uHlMxbrLMrn8dFgIkgvKGLohLfRymHexPcWYvv2VE0Mn0A8KkOLXLPu iAFLWdsDvDoRwEOU2fRJayg7jwL4C/MU76SsmO/5HOCH3hgkk7/QOwjkHC0M8vT40I3kMz IZ4Diu4D2Y92BlR6nrDqhnburUD5X5s= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=vULYWMFM; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=AePaBT45; spf=pass (imf10.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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 X-Rspamd-Queue-Id: 2153CC0012 X-Rspam-User: X-Stat-Signature: 4uxnne3si4chnsn3bzsc7ay4itd8xwik X-Rspamd-Server: rspam03 X-HE-Tag: 1700469797-212056 X-HE-Meta: U2FsdGVkX19EFDbtCupkuhj5zEsgH0iA/nVqMd7STl4gK2Y51c0yXk2bvtJtKTuWkYAtO+hbST2/keS69/O3J+dYwr0eorp3kVOXoAt1P75pZgATtEJtoBiKOzbtT3d1ASabVeTBoaMQADalSiuobdkJ6c+38Ii0WPLo21hLh5T4AocfD1aP+fY8msQ3QFG+hhxUJiZWbwOx0lMbFjxwPvf0YinlHQ2/xaLUjEIKyq5zUMrDuSi3BXpCEjrNGP4papP7zq/oBEbUIFQrh/2CNTUKh7qB9Dqxzxleo5OtHLSwtiLRrPhH6lEq8KwTkpwyDLkt1Fdn+jJh+kDrfR/wY7rNpgCcx6SgamFxH2cIF91m5bkA+8qMCjqmqG+UHn0z68KS6VPz8GDuPtdvYj+cZWygRkfTSY+3IM2u/hgOzV9bdABnUsI6wNyN4ykJ0x97/0cUUk4tZWGFG8LAbfzfzv9r677cRdbf/J0iGZNAVjbWooveFg8sUdmGfd68MZO6vYUFlVt9CH+gU/wnd7EWZmP3nyya8CODvgIMpyqfYSMC7CL8MqtLPrHjJvGcLyKZuIabeAp17/fid6u/+AKbv/c3gIckQOUCV4o+m2CS5rJ+RRxIT46lBAAZc3ke0D5rr1G57cb+67gHSDyXaX90Q6jB3Ni/IXJabHUpThj2CVbVQ4zptptWE6bsGMpxldt6mpnlmMxQqwT+md2o4yVXjwusTwlazW2L88Tw/8e4p7niW/zp/myf1jg8zE1uWp0P5dnf4ecaR9HxF5WUIYjviK2mMPNlp5k98pY/TAIm1muqMu+CNDkVEfTdWVsom/J19xgKL2+sq3wCHzDXotJTB3KcPGTnUclGHq+ekdErQo1KjcZHbJh2AH8vzUhwmhHimh0qW/vASCC5MwjiclAA0bG6msn0lvUPmGDXUdy9XzP4ANQrumVJK+FAmdd1SsspBrIZyLF3TZwT/B1v8jk dPtlPHOt 9VLDyGE/QeTb0THzvFR/ZRDL9v8BwIrwj1m3NsziPiDVb4/ZIZyPuWGNIRnuyfB06820Xb7EFt3rynhYcNwZVoDNETalQvmB52aQkB8upni9K7gzNo2HQlLClIUv9i1eb80t+j7Dvvi60jXYyGqmC5XLmYIwsCHcdw5PSmtmnAVVpYOPQXhpI4H2jUYLQf1BvVPIz82q6Z2EpxYYmrJYihRbX7Oi9PcPS+IqxrEVs7aihmD9enHq8dZw2Nhx5NmxvOfsF 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: List-Subscribe: List-Unsubscribe: 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; }