Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5186720rwb; Tue, 6 Sep 2022 21:14:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR4o7jvwjD9t1ULnBolu74FsXRNubJVBGU4vC/JvA18o9Gus7Yp5Zd1GSoNwfwQPutT3jTGe X-Received: by 2002:a65:6216:0:b0:41d:8248:3d05 with SMTP id d22-20020a656216000000b0041d82483d05mr1830377pgv.36.1662524052048; Tue, 06 Sep 2022 21:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662524052; cv=none; d=google.com; s=arc-20160816; b=F08AG78MJzjA7MDlh13zjabtnuslXcnubYblpJ7Hv+TTrNewPX24ByMY//2iyBtJDc 868RD6MOw1VfA4sj6NMiyT5tSnGQrcLg5sJHGzHYiTPWLjiaOf7C7Lg40xE4Qo8gcyLu dh4gb4VRM10/Sk50mUznUm3lQ7f/0KVCjwYMqWdnWitwhch7Wd6m7ForZob8FYt4Vsbt iHNnf2xPJJ/WkbOiodTSXykLh8GspLDGpzmiGvvKRCQXv971MCd4y5BF4TnqlZfuBpkw cQk50dmR1d+cuSFnWvVG0z3t2E8WqAfs+iAWcI82NmYss7damhDsVoTrMpbZ7+lmNwIF eerQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=npuejNubOdyGQXlyaQnjNHAGxJEr1nLk2K2rggJlZR4=; b=jCwxERcGdKjyRw75zGkezV58qwrMZCNcR3BrRT4sCqF1sRAc3vYV4wdG8hwqIRToSS lwy2/ECPh9KaSjk8x1G/t7zLJjZr/Q9ZgQgdjuwL3Fp8+jeDAhYRDObPQil5FiDmrD7p 3hD+UyiCXorTYXjB1YvvFVN+YFAetXSYssmIrbjzXj8gdSfIt9G6N4Gi/KvRSS1zoVQm VKxxx6Vt9XE9J2G0YUUa784dUX1inf5URsT2pZ3cKMWArAlLdWsuJls19Gw4axqXjUUw h9RrcO5pRbTuJFhepzrNz0d7vozTaM8IZjS2SAn2uLH5W/pYzi9p5WAaK/3+n6ce2Wqj cmhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ltPEDAeA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pQIHI3OC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a056a00080500b00537e5d992c2si17464209pfk.56.2022.09.06.21.14.00; Tue, 06 Sep 2022 21:14:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ltPEDAeA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=pQIHI3OC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbiIGEBE (ORCPT + 99 others); Wed, 7 Sep 2022 00:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbiIGEBB (ORCPT ); Wed, 7 Sep 2022 00:01:01 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D46677696F for ; Tue, 6 Sep 2022 21:00:59 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 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: 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 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