Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2108425rwr; Fri, 21 Apr 2023 04:36:37 -0700 (PDT) X-Google-Smtp-Source: AKy350bxKHAKk9Q9WXSEQM8cxLxJRHpWUWpO0GsDghDNCdc6kj1CzRqgEKpV9kWk1imGwK0RKdQk X-Received: by 2002:a05:6a21:339a:b0:f0:5bb4:9d0e with SMTP id yy26-20020a056a21339a00b000f05bb49d0emr5671715pzb.6.1682076997269; Fri, 21 Apr 2023 04:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682076997; cv=none; d=google.com; s=arc-20160816; b=QxKjbYW0x/qNLWrNkLVWtRhx2u2Xy1vijVfEpE6V1GqqqpUnaQ1Z6VLzmjx8//n77L MSc4zAfBTJre/v0isO6qOxBj7cZXN1fU0KXfZNwJ4jZV3oMT6rxCFvHg9SQnMs7YqiYb QVEo6nFqwm+RRkVy+L2SGD2rmYMhsIFyQ4cG+uJ6EIaGTB8gTm/RfQL0qGMx5dgUeOAF IOE7UQCXecpuLVz8I1m7ItJYk8tRV6iJbUGQZLiClJUipnow5uw2+wKNIL8otcQjfR7j eLN/ntoyvu+aehVwFumXi7Qy+Wo+HaNE0B5uKYwPlGKOtBveK2t+o/LkB26EnXNYe/PV 5hAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=H+bvG24rbj6Mwo1aSiBvly3dKujd5OE0y4T3IN5Gcis=; b=waux7rxpq1S70i9Ee6FJCI3Cgkpru6FrTCWAgzP5x+46XDnf8TSRfYdboUFf9tCVoL DIUYdFzI+NA5fhEqQDV5rq9oV+8LAMyqmD+GN0MdxneFI9j+FP1pX3rUwNSPHQtPU5Yi zQniivWCGT4/PyT9ouUfzpZWtJfQQsmi5Wy+rNW/AWHtXo9X+FDomPl3PxWiOV4ewS64 tSNKgplaqTYgNFxWiC6sFTOe19lm1HlG9yxtR4J5LtAmRrc7Tq2zlG3XGFfUtKx9JG9U 1NaSnWEW8FIU6huvgIfcG7BNwPNTG1NU80+89ikDGRWOT/YQd/yUccWAb7OT71yampWk DEvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZwRBjRJ+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a138-20020a621a90000000b005e06c0a9852si4172204pfa.179.2023.04.21.04.36.02; Fri, 21 Apr 2023 04:36:37 -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=@google.com header.s=20221208 header.b=ZwRBjRJ+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230477AbjDULUX (ORCPT + 99 others); Fri, 21 Apr 2023 07:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbjDULUV (ORCPT ); Fri, 21 Apr 2023 07:20:21 -0400 Received: from mail-ua1-x930.google.com (mail-ua1-x930.google.com [IPv6:2607:f8b0:4864:20::930]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0C4F194 for ; Fri, 21 Apr 2023 04:20:19 -0700 (PDT) Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-771d9ec5aa5so6393909241.0 for ; Fri, 21 Apr 2023 04:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682076019; x=1684668019; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=H+bvG24rbj6Mwo1aSiBvly3dKujd5OE0y4T3IN5Gcis=; b=ZwRBjRJ+anhiesy73RmJ21BZRFAPms930ivmq7t1dyYs9JjJgoqwAWlAU9JJTYTwLN i8CV8K1NV/1NHgAp8qNRPLt2ZYT8yi1+BygITDu/qi/Umh+fRiRCfnaAx496T3pVr2+g E+caliM9mIBhekcjkGaEwdNPVfQr7uMDRzQwz/NPmq+8Xk24oW8SyRgSrdZvMgARgXPL YnLbRcg2DZImn5sX921X/aSrxVYikiUQ8XoBwo3xr3ImaG75JWQ7Y1X0T13R38KjA8Tn sddOZUCP466Ndwu73JRcLHUSS9xDxowUo24EFajBdNjecoRB4ilSF9PIP6G9B/MxAizq 37tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682076019; x=1684668019; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H+bvG24rbj6Mwo1aSiBvly3dKujd5OE0y4T3IN5Gcis=; b=axDWQ3/kYMp3UAzv+yatHu9CoKhISqloCJUlcVh8osbTE8I8j/O66O9JXj7YGDQG6O +UyPqlzoonR61qNlhWgfQsbZlAL0a9fI5VPQrQBcFRs2D10e6Ke7WIfhMCsdJuwx37pD k4Ox1BxB8cUVuzuXKc/nLwPiWIUlX+xPMtD6SWXL2lr/LChtseyL5qx+zDiFL14/SpNf QnHU3sarIOgf7FwXExkYasLeoabrjvTTJNj394vz+79K3lqW4sYId1iJfEFjeldgLIUw J0CT586GAke3w1hR/e+Ai4g1DzZdMkMSErmest0ZA5a2+wd2vIDSUYtPuI9owNFRUBTO rKuQ== X-Gm-Message-State: AAQBX9fYtopdbi/DrysBAk+St7vxMxRuPn9XXZTx+R8YU8NMfI34RW5w 5ECyd3VToSYeO1sRY2mikmum6MjzXzJIk/QgPU8W9g== X-Received: by 2002:a05:6122:d02:b0:440:54e1:5bf7 with SMTP id az2-20020a0561220d0200b0044054e15bf7mr981344vkb.4.1682076018914; Fri, 21 Apr 2023 04:20:18 -0700 (PDT) MIME-Version: 1.0 References: <20230421101415.5734-1-osalvador@suse.de> In-Reply-To: <20230421101415.5734-1-osalvador@suse.de> From: Alexander Potapenko Date: Fri, 21 Apr 2023 13:19:42 +0200 Message-ID: Subject: Re: [PATCH v4 0/3] page_owner: print 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 , Marco Elver , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Apr 21, 2023 at 12:14=E2=80=AFPM Oscar Salvador = wrote: > > Changes v3 -> v4: > - Rebase (long time has passed) > - Use boolean instead of enum for action by Alexander Potapenko > - (I left some feedback untouched because it's been long and > would like to discuss it here now instead of re-vamping > and old thread) > > Changes v2 -> v3: > - Replace interface in favor of seq operations (suggested by Vlastim= il) > - Use debugfs interface to store/read valued (suggested by Ammar) > > Hi, > > page_owner is a great debug functionality tool that gets us to know > about all pages that have been allocated/freed and their stacktrace. > This comes very handy when e.g: debugging leaks, as with some scripting > we might be able to see those stacktraces that are allocating pages > but not freeing theme. > > In my experience, that is one of the most useful cases, but it can get > really tedious to screen through all pages aand try to reconstruct the > stack <-> allocated/freed relationship. There is a lot of noise > to cancel off. > > This patch aims to fix that by adding a new functionality into page_owner= . > What this does is to create a new read-only file "page_owner_stacks", > which prints only the allocating stacktraces and their counting, being th= at > the times the stacktrace has allocated - the times it has freed. > > So we have a clear overview of stacks <-> allocated/freed relationship > without the need to fiddle with pages and trying to match free stacktrace= s > with allocated stacktraces. > > This is achieved by adding a new refcount_t field in the stack_record str= uct, > incrementing that refcount_t everytime the same stacktrace allocates, > and decrementing it when it frees a page. Details can be seen in the > respective patches. I think the implementation of these counters is too specific to page_owner and is hard to use for any other purpose. If we decide to have them, there should be no page_owner-specific logic in the way we initialize/increment/decrement these counters. The thresholds in "mm,page_owner: Filter out stacks by a threshold counter" should also belong elsewhere. Given that no other stackdepot user needs these counters, maybe it should be cleaner to store an opaque struct along with the stack, passing its size to stack_depot_save(), and letting users access it directly using the stackdepot handler. I am also wondering if a separate hashtable mapping handlers to counters would solve the problem for you?