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 8A24CC38145 for ; Wed, 7 Sep 2022 04:01:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A456D6B0072; Wed, 7 Sep 2022 00:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F5C46B0073; Wed, 7 Sep 2022 00:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BD598D0001; Wed, 7 Sep 2022 00:01:01 -0400 (EDT) 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 792E96B0072 for ; Wed, 7 Sep 2022 00:01:01 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4737AA0FBC for ; Wed, 7 Sep 2022 04:01:01 +0000 (UTC) X-FDA: 79883938722.17.7BB262E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf09.hostedemail.com (Postfix) with ESMTP id ABEB914007C for ; Wed, 7 Sep 2022 04:00:59 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2CD3B1FE78; Wed, 7 Sep 2022 04:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1662523258; 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=npuejNubOdyGQXlyaQnjNHAGxJEr1nLk2K2rggJlZR4=; b=ltPEDAeAJDZd3nBa8es43GTlO0wXsuHSOxcGJOzHlNGi3XvHv1ZXCEkSpA8/iknka32Dr5 p7Q6g7I7Qn30Rtx/b6UsyjQWIUPcHL7YUS6TiN5tN5fyF3qg/wQNkmNr9QFW8KlbPy8r1z 2eK0PbuSZ6TCszdQA/NrHK0nAC0P2Uc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1662523258; 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=npuejNubOdyGQXlyaQnjNHAGxJEr1nLk2K2rggJlZR4=; b=pQIHI3OCLZbMyrnl1GDcSg6pbXOkICpng01ByWrGUluvMAMN8RkBCiyLmHA0FRLz/uA8lI xUr/QvxgcUuJpiAA== 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 8A81913486; Wed, 7 Sep 2022 04:00:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id u+0aH3kXGGMPMAAAMHmgww (envelope-from ); Wed, 07 Sep 2022 04:00:57 +0000 Date: Wed, 7 Sep 2022 06:00:55 +0200 From: Oscar Salvador To: Marco Elver Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v2 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counter Message-ID: References: <20220905031012.4450-1-osalvador@suse.de> <20220905031012.4450-3-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662523259; 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=npuejNubOdyGQXlyaQnjNHAGxJEr1nLk2K2rggJlZR4=; b=KLQuS5ctHFPOZAhG/Qt5+EV+4YysX0Mer4vhr7IagI4djjfkNaIOIRpFBlWXu1gTNWrA06 1hsG29JOUcJ78saUKaWdNnXPHrjpF2JfuF4yO1TC5wbKy1MnWtNvdIdjc0/GFWC8h1Jop7 fTbLAV+xKyc+QaxYlLhn38g6wAisQUM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ltPEDAeA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=pQIHI3OC; spf=pass (imf09.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662523259; a=rsa-sha256; cv=none; b=ayXiy2Et1wHLi7XYv2vgEDukWKqmK+W/grqc3JLRfAZINN3qB5vbAAkhGuZQ/8SaVIaZH8 4bbEeduUO2UNSq+VIsn5Rdt7ZJ5cjD+Oqcdq/pjG250wkZA9PdyGWLsGEjUKVO/mjBsyu1 F5GlC/9KLCsQL7CtPXmi3PskkvdsH28= X-Stat-Signature: fh17qsamhq587fw4x49kzt4k9c5rd76m X-Rspamd-Queue-Id: ABEB914007C X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ltPEDAeA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=pQIHI3OC; spf=pass (imf09.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 X-Rspamd-Server: rspam03 X-HE-Tag: 1662523259-93519 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: On Tue, Sep 06, 2022 at 10:35:00AM +0200, Marco Elver wrote: > I think it's clear from the fact we're using the stack depot that any > printing will print stacks. To mirror the existing > 'stack_depot_print()', I'd go with 'stack_depot_print_all_count()'. Fair enough, I will rename it then. > Moderately better, but still not great. Essentially you need 2 > cursors, but with loff_t you only get 1. > > I think the loff_t parameter can be used to encode both cursors. In > the kernel, loff_t is always 'long long', so it'll always be 64-bit. > > Let's assume that collisions in the hash table are rare, so the number > of stacks per bucket are typically small. Then you can encode the > index into the bucket in bits 0-31 and the bucket index in bits 32-63. > STACK_HASH_ORDER_MAX is 20, so 32 bits is plenty to encode the index. I see, I didn't think of it to be honest. Then, the below (completely untested) should the trick: <---- int stack_depot_print_all_count(char *buf, size_t size, loff_t *pos) { int ret = 0, stack_i, table_i; struct stack_record **stacks, *stack; unsigned long stack_table_entries = stack_hash_mask + 1; stack_i = (*pos & 31); table_i = (*pos >> 32); new_table: stacks = &stack_table[table_i]; stack = ((struct stack_record *)stacks) + stack_i; for (; stack; stack = stack->next, stack_i++) { if (!stack->size || stack->size < 0 || stack->size > size || stack->handle.valid != 1 || refcount_read(&stack->count) < 1) continue; ret += stack_trace_snprint(buf, size, stack->entries, stack->size, 0); ret += scnprintf(buf + ret, size - ret, "stack count: %d\n\n", refcount_read(&stack->count)); *pos |= stack_i; *pos |= ((long long)table_i << 32); return ret; } table_i++; /* Keep looking all tables for valid stacks */ if (table_i < stack_table_entries) goto new_table; return 0; } ----> I will give it a go. Thanks Marco! -- Oscar Salvador SUSE Labs