Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp767156rdb; Thu, 8 Feb 2024 23:45:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWe1CXX8h81jw/P72w9ByLaXUMEl8/XuLDlIqpq97w2jvRfFKOcZehS7Cgo8wqsg+ZS59+UfV3ejmocuDG3yAIL8CDprKtl6U9by+5MbQ== X-Google-Smtp-Source: AGHT+IGH5neSsOZ4SJM7oCpKLSRgtN7k6o16CzBmrSX9vhxdgGv6t1YGYTaSxCmyqY5dgAtNycsB X-Received: by 2002:a17:903:41cc:b0:1d9:5ef2:abdd with SMTP id u12-20020a17090341cc00b001d95ef2abddmr1005199ple.0.1707464748256; Thu, 08 Feb 2024 23:45:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707464748; cv=pass; d=google.com; s=arc-20160816; b=Cil/kYaE17SyEaE8+ZE9iGudf7zPHMfl3e1cSOUzPo1Kprd7nsDb+tuYTaF3x1QBoq f5NZxi0lff8Y1XMfmpTnGmfbA89hxh3VV04Otk+23LztUJTUtxJT4u2yHnau+DME3ZRv 4ltJ2vhLOSG3XRwe2Ccre+0Q/OhnQ2LWIMhKY3u0XHW9phynToAHNgUXNBexLrrRkcnS WcZoEnIQhGNzxJ2TY+Zp7sdFykBKrlpWPR5E9SLDlV9NWuSJWuJP39EojPAPcZ422aJ4 6bY7WVikZPYS8RVxh5SBOJEaNt806dC+rPgGaKiXaSLoTdymNEIfLMveYOAFwh4vJBmW d40w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=0ySHx2nX99jANk38wSw2X6YUAqeLte8C5K6rXWwBJss=; fh=cINhyxHk0/jdEOCeg+HCZ4AW3hzhpMCn2KISFzI/FM0=; b=jyks6Zjrj2VMMbx8EUs1FlTFoA1kWjowsxr3QeOcPM/MOyEHt2Lsl/I8C+aXDEH04O cZh4O8rwjNmgjojsKzsQ11UA3ao286wOKhh8ClqZcrXFyL3MxkUC5PyL047NDREP8xzp aSUdfAZDOIdtwoDU+O1nrwrSrl9allDsge0PY0NkMt7nN173H3xsF6tWg+cLCcJ3sjbC KwDSZpe/flFuz+qNdVeXlFS0B56as88pZazeA41LDeqcNgLRW4yi1qP/e2UmnDbnD1oh OtF5JdatM6B/wZpib4W6m6yqsfColyHw5hL5/MIfoOqOCIALCPA7iXej6nA72s8RRlb8 Ntjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=evfNTXsM; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-59083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUWbf/VFjbE1ApEWFzX5EUOW2L48oww2RULA6nxBW+pdW/tck2Unp/LsMBZmZRukIPSufkfRIh3dUqEWkMooXpxfMTIuzGgdolDXsMZcQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lm13-20020a170903298d00b001d90aa800d5si1300536plb.122.2024.02.08.23.45.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 23:45:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=evfNTXsM; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-59083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E1F02282BDB for ; Fri, 9 Feb 2024 07:45:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10C7D65BA6; Fri, 9 Feb 2024 07:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="evfNTXsM" Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BA22657CA for ; Fri, 9 Feb 2024 07:45:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707464739; cv=none; b=UbjHeu6IknntQUuw7lzbjIbFrT8Za2L+HbNDOKzYtFX/oc8NTDGYtQRU+qlMJk5q0CbCiLC92N8FuwDAjlotzP4nQNpxNSSZ6mzepAiteSJ2oP7ooqnTUZYzc4yx5XVcbxkmCYCAwCczipv6PFwZF4cFYK9qoem2AzdkYZ9eKtc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707464739; c=relaxed/simple; bh=LXIhGDJdpN24GA1EQPDtSZXl8Z1b0LQ0pvmd24qKkgI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qiokLKirOe/cVBUefulq9MEx73znlGMTrUL62vvTCGBiZezm1MD8RTcT7jhHD9ek97Wuq54DiDD7o7xbFDnwqHoCc2IeAFJObHw7Z8tKZ0K+R+XO+qg0tzPk4KAz766tT0fOSHJXjAnJKliMmnlzkKUcoTgdL0rT9JuT44QJI00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=evfNTXsM; arc=none smtp.client-ip=209.85.222.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-7d5c40f874aso285775241.1 for ; Thu, 08 Feb 2024 23:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707464736; x=1708069536; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0ySHx2nX99jANk38wSw2X6YUAqeLte8C5K6rXWwBJss=; b=evfNTXsMaMmloCZZMNaac6RVmYkWO9NNB7v3KhQg11COQ0fB3sjLLwpn1tS0a3prS8 AI0IxdNqvUBxzSoVi2KzBXe07+n2mHYPTHDfuR2ligNeaalvSPDqMXn/TfDPJsgLJPos bvwq/cEPyCfV0MUbBsJHM6Vgibtr89hT9iyrDv/FRN7hlR8FF/qvCreIUKnE7sCo0Vdr rFJfdoEyL8VpNaVzyfxemb+gB4lXjF5Ksges4kIZOL6tHKGTFnp33/FpB3pc+c73aUTI fENSZW8owfM/XqEoiPCgml6p3g2I7NJmxCdvGM7k8MYHCrMYDCQV1/Gn26wq/XO5BuqO c67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707464736; x=1708069536; h=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=0ySHx2nX99jANk38wSw2X6YUAqeLte8C5K6rXWwBJss=; b=p3qbSfVEO/aWgvtntXiS7qZIufO/EyvAvIyNPBeCbACcrAJbym9vSErjxLTWVMgnwn +lc56pxGkskL6CEyu1Ss8tpOM1Aiyy42HurWX3Ugelw3K7hESmMIr3r1PFSawTWplMyO P5Yf1RPY5XYMKK2eYdyXheNU9wHjFz4xWmfl64EVFfvRyLUOopJ/kiivQxX9ExjCZX3x UMZ23OzrLv3yMATPXm+QDUdYuxZAc+quEdXauFj9Dn6+qvFcOH4aX6f2PEdqWrgRiZK3 RfbAWwg+PS3xXmEZvuDQXFhZbWEwx3dPe/qzFc76334eXqC6bVKs0Y1CU6XGQOny33Uy Ow3g== X-Forwarded-Encrypted: i=1; AJvYcCW9kqxVdHdXSaw/iIkluWd4ALZu5N79liuphWVxPD9LhKJpcKOQzY/WxTtDoQDcFqe3cbjN6C3V5PH9kQxlEfUA9VqytL2Ve+hsHCUX X-Gm-Message-State: AOJu0YxlXNylHSTFaMnZDe3+QvTOOEg0T2uGK4qF9ndY7JkIgXXzzVE0 2pBlMlTNNopWtGzAgRTs4E2pU6sJsyHGDLeApBSdSexRQyvPkElWEQ1FtDhtqXNIAi3AsrxNcR8 SFy5admxgrEQNkrMc9ocmO5Vv7wIKkxenaRsh X-Received: by 2002:a05:6102:5590:b0:46d:2121:6939 with SMTP id dc16-20020a056102559000b0046d21216939mr780588vsb.23.1707464736329; Thu, 08 Feb 2024 23:45:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240208234539.19113-1-osalvador@suse.de> <20240208234539.19113-3-osalvador@suse.de> In-Reply-To: <20240208234539.19113-3-osalvador@suse.de> From: Marco Elver Date: Fri, 9 Feb 2024 08:45:00 +0100 Message-ID: Subject: Re: [PATCH v7 2/4] mm,page_owner: Implement the tracking of the stacks count To: Oscar Salvador Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Andrey Konovalov , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" On Fri, 9 Feb 2024 at 00:45, Oscar Salvador wrote: > > page_owner needs to increment a stack_record refcount when a new allocation > occurs, and decrement it on a free operation. > In order to do that, we need to have a way to get a stack_record from a > handle. > Implement stack_depot_get_stack() which just does that, and make it public > so page_owner can use it. > > Also implement {inc,dec}_stack_record_count() which increments > or decrements on respective allocation and free operations, via > __reset_page_owner() (free operation) and __set_page_owner() (alloc > operation). > > Signed-off-by: Oscar Salvador > --- > include/linux/stackdepot.h | 8 ++++++++ > lib/stackdepot.c | 8 ++++++++ > mm/page_owner.c | 30 ++++++++++++++++++++++++++++++ > 3 files changed, 46 insertions(+) > > diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h > index d0dcf4aebfb4..ac62de4d4999 100644 > --- a/include/linux/stackdepot.h > +++ b/include/linux/stackdepot.h > @@ -175,6 +175,14 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, > depot_stack_handle_t stack_depot_save(unsigned long *entries, > unsigned int nr_entries, gfp_t gfp_flags); > > +/** > + * stack_depo_get_stack - Get a pointer to a stack struct Typo: "depo" -> depot I would also write "stack_record struct", because "stack struct" does not exist. > + * @handle: Stack depot handle > + * > + * Return: Returns a pointer to a stack struct > + */ > +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle); I don't know what other usecases there are for this, but I'd want to make make sure we give users a big hint to avoid unnecessary uses of this function. Perhaps we also want to mark it as somewhat internal, e.g. by prefixing it with __. So I'd call it __stack_depot_get_stack_record(). > /** > * stack_depot_fetch - Fetch a stack trace from stack depot > * > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 16c8a1bf0008..197c355601f9 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -681,6 +681,14 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, > } > EXPORT_SYMBOL_GPL(stack_depot_save); > > +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle) > +{ > + if (!handle) > + return NULL; > + > + return depot_fetch_stack(handle); > +} > + > unsigned int stack_depot_fetch(depot_stack_handle_t handle, > unsigned long **entries) > { > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 5634e5d890f8..0adf41702b9d 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > @@ -61,6 +61,22 @@ static __init bool need_page_owner(void) > return page_owner_enabled; > } > > +static void inc_stack_record_count(depot_stack_handle_t handle) > +{ > + struct stack_record *stack = stack_depot_get_stack(handle); > + > + if (stack) > + refcount_inc(&stack->count); > +} In the latest stackdepot version in -next, the count is initialized to REFCOUNT_SATURATED to warn if a non-refcounted entry is suddenly used as a refcounted one. In your case this is intentional and there is no risk that the entry will be evicted, so that's ok. But you need to set the refcount to 1 somewhere here on the initial stack_depot_save().