From mboxrd@z Thu Jan 1 00:00:00 1970 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 8262EC4828F for ; Fri, 9 Feb 2024 21:51:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13B9F6B0085; Fri, 9 Feb 2024 16:51:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EBA06B0087; Fri, 9 Feb 2024 16:51:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF42D6B0088; Fri, 9 Feb 2024 16:51:46 -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 DD09E6B0085 for ; Fri, 9 Feb 2024 16:51:46 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A6221161022 for ; Fri, 9 Feb 2024 21:51:46 +0000 (UTC) X-FDA: 81773613012.04.EB390E1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf29.hostedemail.com (Postfix) with ESMTP id 6933D12000C for ; Fri, 9 Feb 2024 21:51:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=o3Aqh1my; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IGctspPZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=o3Aqh1my; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IGctspPZ; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1707515504; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DefqWIsK/Bt8MttPzkKY/ykhXHgBYzfo86LWXkmEtbQ=; b=Myops5zTDTAJ2t/vsGaGkoZdm7BgLgV4whbf1/obxjJiW9IOy8wezkrbbydnvEjj80XKJt LCWcVbC/ufc/PmYhk3gl/+r6kL748QgdxoAd1SMODrsYw6UfF/80bgDOlwc7bVLRElsWml 06SXDlSSNxyD27pgt4u6Y/Uydiue9Fc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=o3Aqh1my; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IGctspPZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=o3Aqh1my; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IGctspPZ; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707515504; a=rsa-sha256; cv=none; b=QpoUF14/jUjPeXOm2sVB0obOnuZZgIyLmF6UyzA+RIBLz8CWkU51LEaIZ4dvZ8EZ4MRk1K SbzUpLv8PajvP/+5/YDnTtwn7EzUwf34+LKM121ljslkxg4o5Px7y+xmzmjXyaB4EzJfs8 hT+rtce0dtSSUXN70IwhDc1Krf5WgBk= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6C96D1F834; Fri, 9 Feb 2024 21:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707515502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DefqWIsK/Bt8MttPzkKY/ykhXHgBYzfo86LWXkmEtbQ=; b=o3Aqh1myufMoF8LFhNC8pbhmUZ6BoHteOhIaZvTfnOnDx9Kwc6i59X07xJvJbCpx180mhD jPhlNvAnXzGUB80ZDX1kQpxt8NvORzZxihZPxzpbxaExyJCUELY3aH1dedqOXUsGTqMrNC BZ/WCd4IhmWoP7olQl5TP6Iz7A4SPFE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707515502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DefqWIsK/Bt8MttPzkKY/ykhXHgBYzfo86LWXkmEtbQ=; b=IGctspPZ9dIM6Jy3X942CzbhvGx+EjT+YsV2l4EVuvA5BlcYiuOMGvEKfVItBOJ4TtYRTc +9+hawEQW3nboXBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707515502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DefqWIsK/Bt8MttPzkKY/ykhXHgBYzfo86LWXkmEtbQ=; b=o3Aqh1myufMoF8LFhNC8pbhmUZ6BoHteOhIaZvTfnOnDx9Kwc6i59X07xJvJbCpx180mhD jPhlNvAnXzGUB80ZDX1kQpxt8NvORzZxihZPxzpbxaExyJCUELY3aH1dedqOXUsGTqMrNC BZ/WCd4IhmWoP7olQl5TP6Iz7A4SPFE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707515502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DefqWIsK/Bt8MttPzkKY/ykhXHgBYzfo86LWXkmEtbQ=; b=IGctspPZ9dIM6Jy3X942CzbhvGx+EjT+YsV2l4EVuvA5BlcYiuOMGvEKfVItBOJ4TtYRTc +9+hawEQW3nboXBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E6024139E7; Fri, 9 Feb 2024 21:51:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CfAHNG2exmWybAAAD6G6ig (envelope-from ); Fri, 09 Feb 2024 21:51:41 +0000 Date: Fri, 9 Feb 2024 22:52:48 +0100 From: Oscar Salvador To: Marco Elver Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v7 3/4] mm,page_owner: Display all stacks and their count Message-ID: References: <20240208234539.19113-1-osalvador@suse.de> <20240208234539.19113-4-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6933D12000C X-Stat-Signature: j75oh9383n1og6dyfj3t5xqxnowxxkwr X-HE-Tag: 1707515504-443274 X-HE-Meta: U2FsdGVkX18YAd7hEPovPJzuZdBDDko/9Lzh00+p7ADMb/g/jofqt7ORvXcy6OVgmxnltlfeydZvB6UgmeSQW5OulsTWnmaXWQmuw6qJEjQgwNwWADaQR3gvn8RSpZAm8VUEfCTV9VDZl0N9mAyWLqGhtb7Y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p8gphhrT1ciuf8LQh 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: On Fri, Feb 09, 2024 at 09:00:40AM +0100, Marco Elver wrote: > > +/** > > + * stack_depot_get_next_stack - Returns all stacks, one at a time > > "Returns all stack_records" to be clear that this is returning the struct. Fixed. > > > + * > > + * @table: Current table we are checking > > + * @bucket: Current bucket we are checking > > + * @last_found: Last stack that was found > > + * > > + * This function finds first a non-empty bucket and returns the first stack > > + * stored in it. On consequent calls, it walks the bucket to see whether > > + * it contains more stacks. > > + * Once we have walked all the stacks in a bucket, we check > > + * the next one, and we repeat the same steps until we have checked all of them > > I think for this function it's important to say that no entry returned > from this function can be evicted. > > I.e. the easiest way to ensure this is that the caller makes sure the > entries returned are never passed to stack_depot_put() - which is > certainly the case for your usecase because you do not use > stack_depot_put(). > > > + * Return: A pointer a to stack_record struct, or NULL when we have walked all > > + * buckets. > > + */ > > +struct stack_record *stack_depot_get_next_stack(unsigned long *table, > > To keep consistent, I'd also call this > __stack_depot_get_next_stack_record(), so that we're clear this is > more of an internal function not for general usage. > > > + struct list_head **bucket, > > + struct stack_record **last_found); > > + > > /** > > * stack_depot_fetch - Fetch a stack trace from stack depot > > * > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > > index 197c355601f9..107bd0174cd6 100644 > > --- a/lib/stackdepot.c > > +++ b/lib/stackdepot.c > > @@ -782,6 +782,52 @@ unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) > > } > > EXPORT_SYMBOL(stack_depot_get_extra_bits); > > > > +struct stack_record *stack_depot_get_next_stack(unsigned long *table, > > + struct list_head **curr_bucket, > > + struct stack_record **last_found) > > +{ > > + struct list_head *bucket = *curr_bucket; > > + unsigned long nr_table = *table; > > + struct stack_record *found = NULL; > > + unsigned long stack_table_entries = stack_hash_mask + 1; > > + > > + rcu_read_lock_sched_notrace(); > > We are returning pointers to stack_records out of the RCU-read > critical section, which are then later used to continue the iteration. > list_for_each_entry_continue_rcu() says this is fine if "... you held > some sort of non-RCU reference (such as a reference count) ...". > Updating the function's documentation to say none of these entries can > be evicted via a stack_depot_put() is required. Thinking about it some more, I think I made a mistake: I am walking all buckets, and within those buckets there are not only page_owner stack_records, which means that I could return a stack_record from e.g: KASAN (which I think can evict stack_records) and then everything goes off the rails. Which means I cannot walk the buckets like that. Actually, I think that having something like the following struct list_stack_records { struct stack_record *stack; struct list_stack_records *next; } in page_owner would make sense. Then the only thing I would have to do is to add a new record on every new stack_record, and then I could just walk the list like a linked list. Which means that the function stack_depot_get_next_stack() could be killed because everything would happen in page_owner code. e.g: static void inc_stack_record_count(depot_stack_handle_t handle) { struct stack_record *stack = __stack_depot_get_stack_record(handle); if (stack) { /* * New stack_record's that do not use STACK_DEPOT_FLAG_GET start * with REFCOUNT_SATURATED to catch spurious increments of their * refcount. * Since we do not use STACK_DEPOT_FLAG_{GET,PUT} API, let us * set a refcount of 1 ourselves. */ if (refcount_read(&stack->count) == REFCOUNT_SATURATED) { refcount_set(&stack->count, 1); add_new_stack_record_into_the_list(stack) } refcount_inc(&stack->count); } } and then just walk the list_stack_records list whenever we want to show the stacktraces and their counting. I think that overall this approach is cleaner and safer. -- Oscar Salvador SUSE Labs