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 C4790C38145 for ; Wed, 7 Sep 2022 07:15:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ADAF6B0072; Wed, 7 Sep 2022 03:15:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 536026B0073; Wed, 7 Sep 2022 03:15:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D7108D0002; Wed, 7 Sep 2022 03:15:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 27CF46B0072 for ; Wed, 7 Sep 2022 03:15:13 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EE6FEAB87B for ; Wed, 7 Sep 2022 07:15:12 +0000 (UTC) X-FDA: 79884428064.02.7A8A097 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf16.hostedemail.com (Postfix) with ESMTP id A6C65180074 for ; Wed, 7 Sep 2022 07:15:12 +0000 (UTC) Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-346cd4c3d7aso27463227b3.8 for ; Wed, 07 Sep 2022 00:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=OmUSwa/mYLk9frSI3Ci/hO94fZOgJznoYBMXxqpBXFg=; b=WfmaH9qowdYFia3pdj+mLnLLgbNONrD37xKKUHjBYpLQFKSBGCbfBpnYcNcCaKXGn6 HZKPfXdqkGsxb9qiTuQll8nsk3chATfr5IAUHPQD8Tbv39VEvRrKGgFmhfFMIzYItkaF M7OCtsxaTpIrpzPtd60pDPgSawXHEHuGpNoYXbKCR/5vJju28fPxa/0dVdqx/GhBw6ok baSAbCKWLbrodu6EvYah+2+mu/AvzY+6rrDTkGIH6eeTTHpMmnbK8brbqfVj7vYQ82c3 r/t3Re1kxq2R7+oYslQ6iYw001SuiX7n0vkH8rHZ7XfwBAXoxql9kI6b3xtkZSFzpfeV zPaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=OmUSwa/mYLk9frSI3Ci/hO94fZOgJznoYBMXxqpBXFg=; b=WJcIZ2EizL+5eZSPRx1LKHLXuyjIv6EklUJZ8o3qAwSl8c0eh4IuImSVS8z9tX4gZx hQDjvHciDyUgIu3qZ+DviOZJ4W0yL2nntc71gI7BOWqxZ8zoNJluVlyIRAAOoizhxsbw VNLNiwVAoedyNho1nRaTDlbGU4DL24EyYbevF3uzBnW2+/hKc3H+9ga10Gt9hES0Ttha mBBRijyiQb3Npuv3m5WYMDrncOjguy8rB+2Dv0XI5jyv4/4VgT8/bQkoSsIJMgKIfTnz Hn/J+oix9jwEVChxnHN8WRSeaTHjVrenuarvRMxsCnfQHboyKkaF4g5SaqUVSbucPPO8 Y/jA== X-Gm-Message-State: ACgBeo0ZdpjVHQt+byUHn7Ub19nLwizqm4+bvLzuxkmdqrQ+pt3ytWMf F56yt1LSR4fhmscFTQnbsjq/5iiwa6vTXugwQoAZ9Q== X-Google-Smtp-Source: AA6agR7Br17REgcXmW+wFleLtGpNAN6RYdhFOGLv/Eyg+5io2AhocmRFtyvXUP4hKAtUWwF99s8mcgifCYWUtJbMLS8= X-Received: by 2002:a81:a16:0:b0:345:afa:5961 with SMTP id 22-20020a810a16000000b003450afa5961mr1898089ywk.11.1662534911778; Wed, 07 Sep 2022 00:15:11 -0700 (PDT) MIME-Version: 1.0 References: <20220905031012.4450-1-osalvador@suse.de> <20220905031012.4450-3-osalvador@suse.de> In-Reply-To: From: Marco Elver Date: Wed, 7 Sep 2022 09:14:35 +0200 Message-ID: Subject: Re: [PATCH v2 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counter To: Oscar Salvador 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 Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662534912; a=rsa-sha256; cv=none; b=v4zvehQXbr4z0s9J+dS5IH8hecZikW1U6EvChjmo9PVJgVqEa+VPRIR7T6q8l6G2NGNDB4 T/MkqBvGnsb311vTV+BCvl6XFx0pVfVJRZ5GxcVQWvkYQ5e4J3TS9h49dxi7rmsl+EYev5 43ly4xrI4Fo3WAPV5JN5azAU2NcVI74= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WfmaH9qo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of elver@google.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=elver@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662534912; 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=OmUSwa/mYLk9frSI3Ci/hO94fZOgJznoYBMXxqpBXFg=; b=m47AsEJE7wyKKP7MMpXbHdgJcoMYjaxtjklAAdHbFCuoB6vvukZzOkqRow6VG18UfKQZjb wLr+XC84alhYbXyXFeXZvq9qlpi4D254GBZge71B9tQ2W3VOQeYCv2vE6LqP4u2FniJBdL OmQlNvvNDAf7zFc5prDBTkSJRNA6Gjw= X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: a7tawyd3amm7abjs4fd9cp6typ9yxn48 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WfmaH9qo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of elver@google.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=elver@google.com X-Rspamd-Queue-Id: A6C65180074 X-HE-Tag: 1662534912-245555 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 Wed, 7 Sept 2022 at 06:00, Oscar Salvador wrote: > > 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; Why are you casting a stack_record** to a stack_record*? stack_table is already appropriately typed, and there should be no need to cast things around. 'stacks' is supposed to be the bucket? In which case you need to dereference it to get the first entry in the bucket: bucket = stack_table[table_i]; stack_i cannot be used to index into the bucket, because the elements in it are a linked list and not necessarily adjacent in memory. You have to traverse the linked list stack_i elements to get to the start: for (int i = 0; stack && i < stack_i; stack = stack->next, ++i); then you can proceed with the below code. > 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; While you're at it, could you try to come up with a version that avoids the goto? > return 0; > } > ----> > > I will give it a go. > > Thanks Marco! > > > -- > Oscar Salvador > SUSE Labs