Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp3604657rwn; Sat, 10 Sep 2022 16:01:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6DOyI52EIeMn/pFORvMraIBjhjSX+2X/snUJksZ9Mp6BXtAOaTFJcWSqqwf7sGW3xP41eF X-Received: by 2002:a17:906:30c8:b0:73c:81a9:f8e1 with SMTP id b8-20020a17090630c800b0073c81a9f8e1mr14134362ejb.649.1662850880831; Sat, 10 Sep 2022 16:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662850880; cv=none; d=google.com; s=arc-20160816; b=e3S20CsuRogxb4Qdh6Gb6QcuI+tGA9jGp0bebIboJFGBUoUX+b7jQ62GF9twdW63Gi juVepFZInXctVskqfr8KW0+JYhUcUrnfxkR+ZoZ7tK28kPVhmg2KCgM7s/DX2TL+nU77 gjnJStIjJofdnviddtrl21S15QqqYBaJdt3CIfViBQ6ajG/ZYZTsBZ4EDJ9rLfDyHIgw GXTtT2QLVfWKqgNCnQZ9d6T4ehxHzfOX9bZNbvTdvKr3mXW6UR1hSbfQ4m5LpkhVZxMO vaJ1lmTnzsJldISE36YBOC2x0keeqCH5VoEqrpgT4VsNx/UudAeqIloQosAP23MZVVtd Y8CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rkBnb2K/p/J8hLmaT99r7CzCPZNFhjTvaKUvRHmeOhU=; b=RjNk3ieC3le8UJ2HvUVLxkldpuOcYH4Y0k0B6Cbn1fOJPFRwCH1vlqOI3FtrmYOqj4 T2PZ6WruORuSGIXDuekZx7msEL+hENguEcwpHYNZQAv7QMs6fgjuGsbvD+VsHMXzooC9 H9OadlqBWrEmM/f2ExpqtMakm4/2YgdzkhW1j+1WrtTsxs0c9u87Gym2iqOHQnt0NERB zJWAVeXwo8vYJNz+psgmiyTgVFBpFvfxGbKKpNwbAIFd4u7Xg36nNwxcCIjalGLtgQZN 4ekVdSUtQxs6SSsRxEz0XBQs9ukrcNjvhmAgUi3eDSoXrvZlabn8UlWCWTdZ/oFjEOtr i99Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=i5yv2hh6; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs37-20020a1709072d2500b0073beb58e98dsi4870096ejc.276.2022.09.10.16.00.54; Sat, 10 Sep 2022 16:01:20 -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=@gmail.com header.s=20210112 header.b=i5yv2hh6; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiIJWf2 (ORCPT + 99 others); Sat, 10 Sep 2022 18:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbiIJWfG (ORCPT ); Sat, 10 Sep 2022 18:35:06 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89C474507B for ; Sat, 10 Sep 2022 15:33:15 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id h21so3826225qta.3 for ; Sat, 10 Sep 2022 15:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=rkBnb2K/p/J8hLmaT99r7CzCPZNFhjTvaKUvRHmeOhU=; b=i5yv2hh6Fa+6IoYmAkb8iQ4y7spBmLCby+cfpYHSZ95RM0n25zR3hbcu1XNCFCHKGs voOQS5W4q25ZULvtDeBuxOdfKA3YFo5iQPQPMP25D+/qDhrh/UxGeVUfKxuOgzZ5WtYb BI1qjjzMe5/y6pV8/2QvKSe0E6fqQfLNK1RzE9AJWxUsnIesSnmh5NrH6sJQpIXzlY/R gMVTIVpOCRhnI8sSGaN0C1WilTWpacfeGXxIPUhbxUDqJzKqWPlPUSfUoqxc/cxpyIDF tbHsWL1g6BuuETXBOo68pEXGwlWLr0s0k/VGgZybINwMWpcVa4+nTEhs/m9b0CBh2ZSP p9Vg== 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=rkBnb2K/p/J8hLmaT99r7CzCPZNFhjTvaKUvRHmeOhU=; b=0FUJTb3MevEv9YhgmH8cu2hnP4Z1xOr28RIcDXfk9ZRzkllosbGsoISlfNdtN7ft1u WNbqu3NPQpsh+bbxmH5cMoMqtXukvQHhZyRfxXClDcG/jeY2GLDUj+qskhMrFKxP9Q3N k/eJn9czE5rNYRhSg1MGHBlDxyWUw2OPm+DFiUGiM91NgFGzyHxze50qkNtR/6WGOTXY zvYn9hszPEYfjafrMeE1MBfZg2PFdYKVsWnpRzqLFzxb8iBibNrfmpXuh4/pYoIUQ7LA e3Uf94zd+KHcpVAV9XRQ2QaR0I2XSNj/0W6MmQjIzRZZiz6R6dB/R5opw+c96XzkZwls zFCQ== X-Gm-Message-State: ACgBeo2XZyYBcHyTQoodFez56theGgQ5KCzq2nh5CsyBEzzv84QvKoaE Ch82ZJyACveb3U6A/cI4/j2PH7BJ6E00o8S7GVM= X-Received: by 2002:a05:622a:11cf:b0:35b:a369:cc3 with SMTP id n15-20020a05622a11cf00b0035ba3690cc3mr7027882qtk.11.1662849194344; Sat, 10 Sep 2022 15:33:14 -0700 (PDT) MIME-Version: 1.0 References: <20220905031012.4450-1-osalvador@suse.de> <20220905031012.4450-2-osalvador@suse.de> In-Reply-To: From: Andrey Konovalov Date: Sun, 11 Sep 2022 00:33:03 +0200 Message-ID: Subject: Re: [PATCH v2 1/3] lib/stackdepot: Add a refcount field in stack_record To: Oscar Salvador Cc: Andrew Morton , LKML , Linux Memory Management List , Michal Hocko , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan , Marco Elver , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 6, 2022 at 5:54 AM Oscar Salvador wrote: > > On Mon, Sep 05, 2022 at 10:57:20PM +0200, Andrey Konovalov wrote: > > On Mon, Sep 5, 2022 at 5:10 AM Oscar Salvador wrote: > > > +enum stack_depot_action { > > > + STACK_DEPOT_ACTION_NONE, > > > + STACK_DEPOT_ACTION_COUNT, > > > +}; > > > > Hi Oscar, > > Hi Andrey > > > Why do we need these actions? Why not just increment the refcount on > > each stack trace save? > > Let me try to explain it. > > Back in RFC, there were no actions and the refcount > was incremented/decremented in __set_page_ownwer() > and __reset_page_owner() functions. > > This lead to a performance "problem", where you would > look for the stack twice, one when save it > and one when increment it. I don't get this. If you increment the refcount at the same moment when you save a stack trace, why do you need to do the lookup twice? > We figured we could do better and, at least, for the __set_page_owner() > we could look just once for the stacktrace when calling __stack_depot_save, > and increment it directly there. Exactly. > We cannot do that for __reset_page_owner(), because the stack we are > saving is the freeing stacktrace, and we are not interested in that. > That is why __reset_page_owner() does: > > <--- > depot_stack_handle_t alloc_handle; > > ... > alloc_handle = page_owner->handle; > handle = save_stack(GFP_NOWAIT | __GFP_NOWARN, STACK_DEPOT_ACTION_NONE); > page_owner->free_handle = handle > stack_depot_dec_count(alloc_handle); > ---> > > alloc_handle contains the handle for the allocation stacktrace, which was set > in __set_page_owner(), and page_owner->free handle contains the handle for the > freeing stacktrace. > But we are only interested in the allocation stack and we only want to increment/decrement > that on allocation/free. But what is the problem with incrementing the refcount for free stacktrace in __reset_page_owner? You save the stack there anyway. Or is this because you don't want to see free stack traces when filtering for bigger refcounts? I would argue that this is not a thing stack depot should care about. If there's a refcount, it should reflect the true number of references. Perhaps, what you need is some kind of per-stack trace user metadata. And the details of what format this metadata takes shouldn't be present in the stack depot code. > > Could you split out the stack depot and the page_owner changes into > > separate patches? > > I could, I am not sure if it would make the review any easier though, > as you could not match stackdepot <-> page_owner changes. > > And we should be adding a bunch of code that would not be used till later on. > But I can try it out if there is a strong opinion. Yes, splitting would be quite useful. It allows backporting stack depot changes without having to backport any page_owner code. As long as there are not breaking interface changes, of course. Thanks!