From patchwork Thu Feb 8 23:45:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550765 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 C6DD2C4829C for ; Thu, 8 Feb 2024 23:45:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 550EF6B0080; Thu, 8 Feb 2024 18:45:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FFF56B0081; Thu, 8 Feb 2024 18:45:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 352F86B0082; Thu, 8 Feb 2024 18:45:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 232456B0080 for ; Thu, 8 Feb 2024 18:45:16 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E94C1A028F for ; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) X-FDA: 81770270190.12.743DDAD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf05.hostedemail.com (Postfix) with ESMTP id B948A10000F for ; Thu, 8 Feb 2024 23:45:13 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707435914; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=ujZL4mhDr7yzxxbKq57zSReKTiuTU90o2T0OvCcLQ+FcGo93VHlpDNqSXadaDVatU4Zzwc Gt3iFvlQ3Zm4vfoV9oqxXZ1oxAKdjDOWH6AMqW9zIkxxqDv4Z1EL87ORz7T0RDXz3gx5vJ aBfSVu5HwYTbIdMOX5WsD8xpR5sfqRM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=e9Com5bm; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435914; a=rsa-sha256; cv=none; b=5GxE1myccHJt6aiY0Fi6vSaTBGpaZtQgUeGk6+9u+Q0fCdT1AdwR9PgCvCN0EJ5bfgHKaF BZfDXeFwdXPR1hylDzEnHWN2m4oPlaA3YOdpygH9CJTTuFhgUfvrhHAhpcm4roxLGpkdkq g2D1tAXZ7/y9kfJXwlLk8ieX/SxFvIE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 52DCB2231D; Thu, 8 Feb 2024 23:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=FqIo5CvJ6oX+sMFvUZG+ClyHR4cWlBMV/ux5MN/ol+aO92XWT7VftClRCEZdKUIFqzYobq bbLmF2YqyOIw3TkWci/8KIn+799W0jctO1lgK25+uzR7W6eJXMZYrUGg5hIwJk3KyRGa58 BFUulIJUPi65U4NFdLHvmY0UCPSIoDw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=e9Com5bminDIKvAD8i86K8dC9in6zV+PepP4s9oQpN5dbVpe6CHWBBaeUt5KudzVDTMp8y 6L17clAD++kcEtAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=FqIo5CvJ6oX+sMFvUZG+ClyHR4cWlBMV/ux5MN/ol+aO92XWT7VftClRCEZdKUIFqzYobq bbLmF2YqyOIw3TkWci/8KIn+799W0jctO1lgK25+uzR7W6eJXMZYrUGg5hIwJk3KyRGa58 BFUulIJUPi65U4NFdLHvmY0UCPSIoDw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435912; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; b=e9Com5bminDIKvAD8i86K8dC9in6zV+PepP4s9oQpN5dbVpe6CHWBBaeUt5KudzVDTMp8y 6L17clAD++kcEtAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BEBF413984; Thu, 8 Feb 2024 23:45:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uE7SK4dnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:11 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v7 1/4] lib/stackdepot: Move stack_record struct definition into the header Date: Fri, 9 Feb 2024 00:45:36 +0100 Message-ID: <20240208234539.19113-2-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: B948A10000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: in9c7hsugkufch15wyrnbfzizqxc3ghz X-HE-Tag: 1707435913-61344 X-HE-Meta: U2FsdGVkX1+h0Z94bJJwhj6hy+Z23kkULyGg6Fl3iQmd/77gIjBqKWKGvwlHwaHldw7lrGRDMhX1QMiqCFmiykUYX5J6lIc0sc1bY5542bew2yumoYBZCbu7KxNKDImFSbItvp8Y7EovqArTwNoiaEFHlMK2ApnKs+Jj+OkSsqbboiAoDqDzPV0BbnfGUKhg6oVLn9VQ0kMV7VHp7UtsyIKmv1HApODuDcClEnjH9IgIh7N/H8QovkXgOdujMnHrUC+coeL12gAsIiahfi4fKTRyGxLosWyMkzT61frx5yu1hBmCX21p7awyLB8LhSU71hJUr3DB34AVuRnttFiKKuzLfP7hxMeViU8020B0GUEHRjbR4lBtrLsOxwCBs77oXE+PUdMRzkw239RdIY7yY7767zdmmLHKS4dbvM79VT8Stl2xSyQd9TKRIIHNYgX96dJ4rdJfFpgMl2UASt5pE7mfAxCPzVFd8psS0Vnc6b0TvCu2MsCeZ3qFiW/IOA9mb/BdA+y5Nzre52/4pJG6lGuei9h+s4hkibBooG3FvJzulzk+69P6CpapEJviwdPvYFCgEtcrGphe1fQKthQtv3W8JzpdVrniNrGJ3rZ09NWI7CoXzDqKPeygo/p7PY4pUgE45JQxnjUpd2Yo0gblCQ9rjhz19ZAmcsQybYYeJGGlJjiBo9f8lHj4vYogDRtqTaEAyQHPiRmExO8l+mJi8Ku4oCimNVOGOQ+knI8T1mFkWn/DWF4hthqYP9Mq984vzk4q3ggTeJAju7CUN3oeMO5llTd8rNyx+Tx2CGXT/gYW1OoUiTQdHiy2fkPwjZF3j4scSeoSmxTk+alSorZ/Kf80kYY+WK2fbK6tH5GMgcFM5g731ylUMOwPauamg7yAYpKUZH6PpwYgLgEmoCSceO6LzA9po4rYocKavZmr5PN2gcqpwNwfyfBtEw5T9z4VTBudTnNR1GzQzD+PfTA AfEIHJDk bcnQaaJXbOuA/kdSE4jUtv1fb/Kp5siJ4o2Yi0pUIYddVKtKG5tmMhpTtDX9CuEQzAystVDa3lumHE+QgOXv5ltuN8yIEQCYBuYpvVjHdKyyqP6xnLAbs3dfElenygC5zZaObz0RQtmyake0Q51i0QI2yNSYwQcS5F9VRdj6+1USJyePaKmI5s2QyNWDrleR49YcdPdRLXWvwN9Wu7fp5uFozowumVGYhM6LMAMo7ZgPXyU+wrZyDBd2XblACafBFxogFIMryGeUp7qOnjjjNeJ+UEg== 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: List-Subscribe: List-Unsubscribe: In order to move the heavy lifting into page_owner code, this one needs to have access to the stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 44 ++++++++++++++++++++++++++++++++++++++ lib/stackdepot.c | 43 ------------------------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index adcbb8f23600..d0dcf4aebfb4 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -30,6 +30,50 @@ typedef u32 depot_stack_handle_t; */ #define STACK_DEPOT_EXTRA_BITS 5 +#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ +#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ + STACK_DEPOT_EXTRA_BITS) + +/* Compact structure that stores a reference to a stack. */ +union handle_parts { + depot_stack_handle_t handle; + struct { + u32 pool_index : DEPOT_POOL_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; + }; +}; + +struct stack_record { + struct list_head hash_list; /* Links in the hash table */ + u32 hash; /* Hash in hash table */ + u32 size; /* Number of stored frames */ + union handle_parts handle; /* Constant after initialization */ + refcount_t count; + union { + unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ + struct { + /* + * An important invariant of the implementation is to + * only place a stack record onto the freelist iff its + * refcount is zero. Because stack records with a zero + * refcount are never considered as valid, it is safe to + * union @entries and freelist management state below. + * Conversely, as soon as an entry is off the freelist + * and its refcount becomes non-zero, the below must not + * be accessed until being placed back on the freelist. + */ + struct list_head free_list; /* Links in the freelist */ + unsigned long rcu_state; /* RCU cookie */ + }; + }; +}; + typedef u32 depot_flags_t; /* diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 5caa1f566553..16c8a1bf0008 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -35,14 +35,6 @@ #include #include -#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) - -#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ -#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) -#define DEPOT_STACK_ALIGN 4 -#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) -#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ - STACK_DEPOT_EXTRA_BITS) #if IS_ENABLED(CONFIG_KMSAN) && CONFIG_STACKDEPOT_MAX_FRAMES >= 32 /* * KMSAN is frequently used in fuzzing scenarios and thus saves a lot of stack @@ -58,41 +50,6 @@ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) -/* Compact structure that stores a reference to a stack. */ -union handle_parts { - depot_stack_handle_t handle; - struct { - u32 pool_index : DEPOT_POOL_INDEX_BITS; - u32 offset : DEPOT_OFFSET_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; - }; -}; - -struct stack_record { - struct list_head hash_list; /* Links in the hash table */ - u32 hash; /* Hash in hash table */ - u32 size; /* Number of stored frames */ - union handle_parts handle; /* Constant after initialization */ - refcount_t count; - union { - unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ - struct { - /* - * An important invariant of the implementation is to - * only place a stack record onto the freelist iff its - * refcount is zero. Because stack records with a zero - * refcount are never considered as valid, it is safe to - * union @entries and freelist management state below. - * Conversely, as soon as an entry is off the freelist - * and its refcount becomes non-zero, the below must not - * be accessed until being placed back on the freelist. - */ - struct list_head free_list; /* Links in the freelist */ - unsigned long rcu_state; /* RCU cookie */ - }; - }; -}; - #define DEPOT_STACK_RECORD_SIZE \ ALIGN(sizeof(struct stack_record), 1 << DEPOT_STACK_ALIGN) From patchwork Thu Feb 8 23:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550766 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 EE3B9C4828F for ; Thu, 8 Feb 2024 23:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EC606B0081; Thu, 8 Feb 2024 18:45:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C8E6B0082; Thu, 8 Feb 2024 18:45:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A2606B0083; Thu, 8 Feb 2024 18:45:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 226BA6B0081 for ; Thu, 8 Feb 2024 18:45:18 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EED2540F53 for ; Thu, 8 Feb 2024 23:45:17 +0000 (UTC) X-FDA: 81770270274.29.3931B77 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf01.hostedemail.com (Postfix) with ESMTP id ABC2E40011 for ; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707435916; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=gpvYIXJwFzm3WaBhMZ9qxGm9mEIXmZDKw6oE7wEufJ1fJbMis/dJK2o9/aPZrOVnZGHJnv B3+yzqtCPYVaBLrvD+26jKw7+NOjIek4B55LnvNu4q5glpFfFiOkaWgoxR9QwUDLbW6aCK XYh7RnficxZ2Ocx0GMerOa9RhN6s8AI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=P94itunw; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf01.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435916; a=rsa-sha256; cv=none; b=xRVbotqlBpLm+M5cOoz9Tupqbq4Z1cyzkEv93og1t7YbcFL4jt1Hvf44qC9ocr3AKn3M/z 0RBxdFIjF99H9iWbkJ/24KDV+jBCQujVpNNv7Tps6ZjeMaIURQcDsoY7wXGkf46RD0GwoW QSMlFIIAW2svgw3TkTkOt3R8Nzhs68Q= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0223922315; Thu, 8 Feb 2024 23:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=ZwBUTcSH+yLhiMahPKyOuS6osd4fSVbDvSv0ya9UGW8LetG88/d1KWoq3atCJvOX06Hwzy xBwNVvWy/AX19x6X2g6vJmpbvfXHPxyd/hbLKimF1aN1lbKPslwvtSlUR1c71B5sF9gdOZ 4zAFuPrZgEa8zf1XjkjfiZ8IofdJMc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=P94itunwwRNbkd3dZY3MmvmKcwBH9vGwln8BkDZ7EFifY/wZ5ri9E0MFoYpFJKTDwXvZyN KTNeSOR1XY3gdoCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=ZwBUTcSH+yLhiMahPKyOuS6osd4fSVbDvSv0ya9UGW8LetG88/d1KWoq3atCJvOX06Hwzy xBwNVvWy/AX19x6X2g6vJmpbvfXHPxyd/hbLKimF1aN1lbKPslwvtSlUR1c71B5sF9gdOZ 4zAFuPrZgEa8zf1XjkjfiZ8IofdJMc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435914; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; b=P94itunwwRNbkd3dZY3MmvmKcwBH9vGwln8BkDZ7EFifY/wZ5ri9E0MFoYpFJKTDwXvZyN KTNeSOR1XY3gdoCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6076D13984; Thu, 8 Feb 2024 23:45:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ODavFIlnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:13 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v7 2/4] mm,page_owner: Implement the tracking of the stacks count Date: Fri, 9 Feb 2024 00:45:37 +0100 Message-ID: <20240208234539.19113-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Spamd-Bar: + X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: ABC2E40011 X-Stat-Signature: gt83irzx8m5gppfrkaxzqemrf7i68k15 X-Rspam-User: X-HE-Tag: 1707435915-544957 X-HE-Meta: U2FsdGVkX1+8Hle0sBtvYXskHvx3OYXfbHHwDzuDZ9XXxUNwd4nrJ2+qoDQE5yWedT04B26uDYkby+T+PWZBqNhaRuRstH9h+AWjftYp4zWGxgxmnBuWW8lFCwU2j3lcbv1T0pwIRAZIWHvc4FMxDEbDCqoOwgN4DvHLeT+dKJYxZIcK/8s45X9XSm1LuiEEiJ7WgwXZhvzgXjuY5q/duE0URfaKvxOjddvELw4bnAB1Bp7rwIuwkj78mdOqOhkOjfyXTZ3KCQPyFAwviqcbJYK9YmLSZyxQ23y0koIkgMnyKKaRf8dLDlL4ix1mo5IeLQwKR3ftUz9lsUjC9NNv9CWzXxgy0axJrothRsWL5ezFXoMoiDTgd+9STlbr3MiXMEwocynqro9H+AzoYrVzsX5yGZwhoz+yyv6B72prxtgoyHgp/VbO2SLJzzQ5WLe5MVbHGEAq8oA5EPnb6QPh4ckhU2NP4xa8Vw8HKaxdr9hOYZcixr4QII/KCt5iAieb+/JEZQ0uXgo9MoX8bHZbcQf5xm8htRzPgUteuDJNOPEw1IkJKB2zfiRdHgzGWTyNmOx7h+sgwu5xAvEVPULWVuzgWZcxUoVbuGhEW57wrnQ1y/dWtQhl7vpCN79a1BpK0m9y6MUYB1MIzxkDxj2IMflQDtvSKWx5jr/NWQkSsDoa/rJzEPWxT0iFS7YJyicb4zwCvzNXafMiAr4O4qOW03marOE3RpvGAwRKuho3h80mDhwO+jJ6qweWkuS0gLqYelsm7e65cxjTOA/+e0PkRte4bjs721hbD5PHQaGsLwo1hhyaF7/dbPDVUp7WAT8dXRSly3NlajqdTauSoXhX+T3fkWfbDV21J4cTVH98TthDBJbQlj9CyQIAw/v0yGWjTFxm7XavmSnc82UaefmRF6+10J7JVx6NbhormHXkLJ/iNPr9IZE+fJDtTL3KXN6j0Y5uJJYOWAseCvgxBHU Wy1ly55z 9UhFxWhDEi3RPx7S62PW1wLSz8T1j/6BZf6++KCoLSQ1p4in9BWVe4KZXBsXWtnIoCdhOEndcGiIZs//0UlHljnFmf/utZoJzv7afvV7DbsjdFIMzshD7tl17D9coNJ2w55xNQbtxthUFWsICgjorMbtn3NJRH1rKBCIpQQ6eNIrVfmJoaUQHoC9c5MYZr0LQIGG8YhDrRvNd+/brOhx/LPWrF7abiTsflQ+bQRXmn5dMb2ukcu4uLt0y2xuF4lhbN3CBNIP7C+smT08xxugg3rygaw== 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: List-Subscribe: List-Unsubscribe: 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 + * @handle: Stack depot handle + * + * Return: Returns a pointer to a stack struct + */ +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle); + /** * 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); +} + +static void dec_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack = stack_depot_get_stack(handle); + + if (stack) + refcount_dec(&stack->count); +} + static __always_inline depot_stack_handle_t create_dummy_stack(void) { unsigned long entries[4]; @@ -140,6 +156,7 @@ void __reset_page_owner(struct page *page, unsigned short order) int i; struct page_ext *page_ext; depot_stack_handle_t handle; + depot_stack_handle_t alloc_handle; struct page_owner *page_owner; u64 free_ts_nsec = local_clock(); @@ -147,6 +164,9 @@ void __reset_page_owner(struct page *page, unsigned short order) if (unlikely(!page_ext)) return; + page_owner = get_page_owner(page_ext); + alloc_handle = page_owner->handle; + handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i = 0; i < (1 << order); i++) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); @@ -158,6 +178,15 @@ void __reset_page_owner(struct page *page, unsigned short order) page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); + if (alloc_handle != early_handle) + /* + * early_handle is being set as a handle for all those + * early allocated pages. See init_pages_in_zone(). + * Since their refcount is not being incremented because + * the machinery is not ready yet, we cannot decrement + * their refcount either. + */ + dec_stack_record_count(alloc_handle); } static inline void __set_page_owner_handle(struct page_ext *page_ext, @@ -199,6 +228,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order, return; __set_page_owner_handle(page_ext, handle, order, gfp_mask); page_ext_put(page_ext); + inc_stack_record_count(handle); } void __set_page_owner_migrate_reason(struct page *page, int reason) From patchwork Thu Feb 8 23:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550767 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 29F58C48260 for ; Thu, 8 Feb 2024 23:45:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15ABE6B0083; Thu, 8 Feb 2024 18:45:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10BEC6B0085; Thu, 8 Feb 2024 18:45:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2AA26B0087; Thu, 8 Feb 2024 18:45:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C9F4C6B0083 for ; Thu, 8 Feb 2024 18:45:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6F8821A06DD for ; Thu, 8 Feb 2024 23:45:19 +0000 (UTC) X-FDA: 81770270358.20.8CD4259 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf19.hostedemail.com (Postfix) with ESMTP id 44AF81A0003 for ; Thu, 8 Feb 2024 23:45:17 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=p5HZ5uBZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=p5HZ5uBZ; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435917; a=rsa-sha256; cv=none; b=pW7JF42jORvhkc5v8BjVgulLjSSMOvJoEmwYvvE7axH0V3Ta9UcbYK6ZBPliQ19kS9bBNn zR7hiNR5/dsdjOgLDXdm+rUkBTzK71Iccf3mM7BQ/dmaoCN7ZClShkva9YcMm+W746QC1i WME58Mx2v7sH00bNPJA9iuNcAEBG8U8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=p5HZ5uBZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=p5HZ5uBZ; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707435917; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; b=BxR/hgf2IxLJL5dY5Hcjj77MGvqcqx1cuKd+mwvuQv1gHKfhvru9wrZtOG/HF80BCLE3gO XgypXpoyDKsBAnTPmFJCZD5MORwVq9mlRPHl15TMzXSZoTl2T5L/XTvWsH8CsB92RmsbvI vURHWrIYnoOlzNq7MIMtxhD+nTUO5N8= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A783422317; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435915; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; b=hY9JCYvAncAGepUu81hefJSrPIqWxz/6UK81x78gggd7DefAzQkSaFtX/UeMHzsUrsprWg UnkgoUNyQrDRszamEUWOuLhaRRJBjVfAf5YiWMHqvwRf62A7ru9jv/bv/vvDNy+oUMNH+u QAu0UK+6FYmPjn6QLgfthVizcCiWcww= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435915; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; b=p5HZ5uBZO2fi/Vl014Q4Qrb0lax8dsjC8lQ2L5wn/MAUf37MHid3+N7LFaSZ6Sd95BS7TW b1gGtfcxLmlURUDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435915; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; b=hY9JCYvAncAGepUu81hefJSrPIqWxz/6UK81x78gggd7DefAzQkSaFtX/UeMHzsUrsprWg UnkgoUNyQrDRszamEUWOuLhaRRJBjVfAf5YiWMHqvwRf62A7ru9jv/bv/vvDNy+oUMNH+u QAu0UK+6FYmPjn6QLgfthVizcCiWcww= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435915; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; b=p5HZ5uBZO2fi/Vl014Q4Qrb0lax8dsjC8lQ2L5wn/MAUf37MHid3+N7LFaSZ6Sd95BS7TW b1gGtfcxLmlURUDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1BB6413984; Thu, 8 Feb 2024 23:45:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WI3VA4tnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:15 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v7 3/4] mm,page_owner: Display all stacks and their count Date: Fri, 9 Feb 2024 00:45:38 +0100 Message-ID: <20240208234539.19113-4-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 44AF81A0003 X-Stat-Signature: unc78gkm686ei88uffskmpaa33hrxgt5 X-Rspam-User: X-HE-Tag: 1707435917-725421 X-HE-Meta: U2FsdGVkX1+uE7r5GERT43u1ALdwmzaB3PgoA3cHU7XjQI0FoYUcx5yXPP23yyuTlm0n3FAkNqf39mZbfatwRa8yq6wZobRRA64LgUuyVBwuwTz2v+rQ8uaHp0OhqVd51n7UK9QtWCQqxV+nGenJKko2VvrlxtbG2yXNCaTw+M40k+FvGPaQypa29dK0sZciby8B+tUsHTVesNcaomVNlA475O/qnM7CI3dXj5Ub+4HQrLk0pgpmFirGJqds8ygfoQ7qlKf6OsyF76E/pQvy42sVn85PvWvktfFqrIQk6KcXQ/pSS9sJ8S893oaEXfu52ThAvXz9RBqZMTFAf4Fm6xleesOYUSUAKGUioN2Iz8ggIcaSeF8H8IihNQLXu9Hazfn4F1olSYrOhDSdmkpN8h3jsHYMFo6ewk7Tb+DUUE11FAJ9vnxzdHj8kVitm3L1mgMJ7c+OAgXqxVl2stOqW5HqYDaoHIGe2uaDXwCj+QAirykkUO182ZTYsp9EGCNalTVED4BI3SwpiHcOyG9sZO+JoXyWsjsm/6QZBp2EhwzXxWhOXds4FAYplsUjPysrJBC/r/cZXdL53EXpx3CN5WkXFr5qGpZwaUYEvqgkTOhDY/x3bgcNIzu30DGNplBSwkn2l+Dhy2/a56XRfwPb8GFeNQZ4Ph4CP9DI3HwKJUM8sM/RVojcrh6mDWC5mg/cvFqCfK45pO+ZDCIXjVOCK/Q+dxvkaJv64Z5/IizivSSC76log7oNcV2z/s4BaKrssGRS3zXE8sawmWRBHIfoMcKtBxIQ+/mL6RRh/4Tfnv6mXgMo+svsvvVr8BVZMDknb3MuTGrG0uPBS0wVw4+zciVWVWaKzftPUSNWxkhDJ858WWryOTvX4cXHJIEGjJRVYvxfOUK5cDSM4lM/d5chYaw8cVD2s1pwCbztrjBnMm7+5HKh/4Un+3yqoUeh/vbfOQyrKkE7Q9vDgkiJhn4 1Y4EB4GG k2uf/vDSJjrEfvIqHBP1rlTPseEuOKA+Fpgzz0hIwuNqVj4Rn7PmhFbLX9T8BwLdtHotkUwh24ioInCdJ0feh+SrpJjr2qY+JhwD3ijo3ch1HOx0FUk8FEQAu5burBSBDdIUmMtbJrx+/jxch97LYNcNwZquAc+OquZQCFT3U9fYy98FKSdHtdhxRSJ8hAPMfPKohGZtM0ha99rJ6wfrKssga1Ti6MWmBCmL1zVsrLifgzitMqnyGptnnGo1GdSF5Zsigh+D/qHkRppgrtKZ63Xlc40SD9hlPA98M 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: List-Subscribe: List-Unsubscribe: This patch adds a new file called 'page_owner_stacks', which will show all stacks that were added by page_owner followed by their counting, giving us a clear overview of stack <-> count relationship. E.g: prep_new_page+0xa9/0x120 get_page_from_freelist+0x801/0x2210 __alloc_pages+0x18b/0x350 alloc_pages_mpol+0x91/0x1f0 folio_alloc+0x14/0x50 filemap_alloc_folio+0xb2/0x100 __filemap_get_folio+0x14a/0x490 ext4_write_begin+0xbd/0x4b0 [ext4] generic_perform_write+0xc1/0x1e0 ext4_buffered_write_iter+0x68/0xe0 [ext4] ext4_file_write_iter+0x70/0x740 [ext4] vfs_write+0x33d/0x420 ksys_write+0xa5/0xe0 do_syscall_64+0x80/0x160 entry_SYSCALL_64_after_hwframe+0x6e/0x76 stack_count: 4578 In order to show all the stacks, we implement stack_depot_get_next_stack(), which walks all buckets while retrieving the stacks stored in them. stack_depot_get_next_stack() will return all stacks, one at a time, by first finding a non-empty bucket, and then retrieving all the stacks stored in that bucket. Once we have completely gone through it, we get the next non-empty bucket and repeat the same steps, and so on until we have completely checked all buckets. Signed-off-by: Oscar Salvador --- include/linux/stackdepot.h | 20 +++++++++ lib/stackdepot.c | 46 +++++++++++++++++++++ mm/page_owner.c | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index ac62de4d4999..d851ec821e6f 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -183,6 +183,26 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, */ struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle); +/** + * stack_depot_get_next_stack - Returns all stacks, one at a time + * + * @table: Current table we are checking + * @bucket: Current bucket we are checking + * @last_found: Last stack that was found + * + * This function finds first a non-empty bucket and returns the first stack + * stored in it. On consequent calls, it walks the bucket to see whether + * it contains more stacks. + * Once we have walked all the stacks in a bucket, we check + * the next one, and we repeat the same steps until we have checked all of them + * + * Return: A pointer a to stack_record struct, or NULL when we have walked all + * buckets. + */ +struct stack_record *stack_depot_get_next_stack(unsigned long *table, + struct list_head **bucket, + struct stack_record **last_found); + /** * stack_depot_fetch - Fetch a stack trace from stack depot * diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 197c355601f9..107bd0174cd6 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -782,6 +782,52 @@ unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) } EXPORT_SYMBOL(stack_depot_get_extra_bits); +struct stack_record *stack_depot_get_next_stack(unsigned long *table, + struct list_head **curr_bucket, + struct stack_record **last_found) +{ + struct list_head *bucket = *curr_bucket; + unsigned long nr_table = *table; + struct stack_record *found = NULL; + unsigned long stack_table_entries = stack_hash_mask + 1; + + rcu_read_lock_sched_notrace(); + if (!bucket) { + /* + * Find a non-empty bucket. Once we have found it, + * we will use list_for_each_entry_continue_rcu() on the next + * call to keep walking the bucket. + */ +new_table: + bucket = &stack_table[nr_table]; + list_for_each_entry_rcu(found, bucket, hash_list) { + goto out; + } + } else { + /* Check whether we have more stacks in this bucket */ + found = *last_found; + list_for_each_entry_continue_rcu(found, bucket, hash_list) { + goto out; + } + } + + /* No more stacks in this bucket, check the next one */ + nr_table++; + if (nr_table < stack_table_entries) + goto new_table; + + /* We are done walking all buckets */ + found = NULL; + +out: + *table = nr_table; + *curr_bucket = bucket; + *last_found = found; + rcu_read_unlock_sched_notrace(); + + return found; +} + static int stats_show(struct seq_file *seq, void *v) { /* diff --git a/mm/page_owner.c b/mm/page_owner.c index 0adf41702b9d..aea212734557 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -749,6 +749,89 @@ static const struct file_operations proc_page_owner_operations = { .llseek = lseek_page_owner, }; +struct stack_iterator { + unsigned long nr_table; + struct list_head *bucket; + struct stack_record *last_stack; +}; + +static void *stack_start(struct seq_file *m, loff_t *ppos) +{ + struct stack_iterator *iter = m->private; + + if (*ppos == -1UL) + return NULL; + + return stack_depot_get_next_stack(&iter->nr_table, + &iter->bucket, + &iter->last_stack); +} + +static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) +{ + struct stack_iterator *iter = m->private; + struct stack_record *stack; + + stack = stack_depot_get_next_stack(&iter->nr_table, + &iter->bucket, + &iter->last_stack); + *ppos = stack ? *ppos + 1 : -1UL; + + return stack; +} + +static int stack_print(struct seq_file *m, void *v) +{ + char *buf; + int ret = 0; + struct stack_iterator *iter = m->private; + struct stack_record *stack = iter->last_stack; + + if (!stack->size || stack->size < 0 || refcount_read(&stack->count) < 2) + return 0; + + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + + ret += stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, + 0); + if (!ret) + goto out; + + scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", + refcount_read(&stack->count)); + + seq_printf(m, buf); + seq_puts(m, "\n\n"); +out: + kfree(buf); + + return 0; +} + +static void stack_stop(struct seq_file *m, void *v) +{ +} + +static const struct seq_operations page_owner_stack_op = { + .start = stack_start, + .next = stack_next, + .stop = stack_stop, + .show = stack_print +}; + +static int page_owner_stack_open(struct inode *inode, struct file *file) +{ + return seq_open_private(file, &page_owner_stack_op, + sizeof(struct stack_iterator)); +} + +const struct file_operations page_owner_stack_operations = { + .open = page_owner_stack_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + static int __init pageowner_init(void) { if (!static_branch_unlikely(&page_owner_inited)) { @@ -758,6 +841,8 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + debugfs_create_file("page_owner_stacks", 0400, NULL, NULL, + &page_owner_stack_operations); return 0; } From patchwork Thu Feb 8 23:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13550768 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 9D9D4C4829C for ; Thu, 8 Feb 2024 23:45:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 560586B0087; Thu, 8 Feb 2024 18:45:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C1726B0088; Thu, 8 Feb 2024 18:45:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 293526B0089; Thu, 8 Feb 2024 18:45:22 -0500 (EST) 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 11F3C6B0087 for ; Thu, 8 Feb 2024 18:45:22 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C768680456 for ; Thu, 8 Feb 2024 23:45:21 +0000 (UTC) X-FDA: 81770270442.24.8AAED91 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf27.hostedemail.com (Postfix) with ESMTP id 610A740004 for ; Thu, 8 Feb 2024 23:45:19 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QnlWa4ie; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QnlWa4ie; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707435919; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; b=AlGSH4xMu+Or921SJi7JUOd4g/V+ykdLYpvaBwxIp5hdhkPVhUsJTHkLRMR6Cly/hFV/gE NSyT+OunsNlBdVNqo2S6w6D6e6vCWpltoDGZQOs1Iau7q8vzVRO1+KHChf4NZvhvxLvymn K0ib1x+TF5mK1ifW8Ge1lu185WW0SsQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QnlWa4ie; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QnlWa4ie; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf27.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707435919; a=rsa-sha256; cv=none; b=QEmFtakNBX4KSpB8yre6Wb6CVP6lHOtiw8b87V7eRaroWYY2A1LeIIoXb2yUc7Ay5HlpCj B4Cr4LvWcK/OUqAI32rAL9gxRXXeiWKZN5ch60rcxMCpe9lFx8VEfe5S1ecP2c5ORAgwod C/YNVDyQQxLCXHV9Fer6cBxAA/4EMds= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 56E6F1F7AB; Thu, 8 Feb 2024 23:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435917; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; b=ICG5MFU6nDqsx4akax9QFJCZ0gtmoOaumfOV5ciFWe3dszk6jCbvNQweZcREVQQQQtV1CE +EFKutBxG92XfUBOsAlfYK87ItwpTFKkaSkxdax8JJkZYqj3wQry0zfFawbVfIhdFBFGQe 3OvPAm+/b+WN2TdWWdBp/ppLPLkEm7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435917; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; b=QnlWa4ieMNxaHh1lPaByAiwWzG4twvBtatrUDg7Kfyqlf/+raHbjXP5l93h60PpXsRrbOg PCDMFPgk9mg4gTCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707435917; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; b=ICG5MFU6nDqsx4akax9QFJCZ0gtmoOaumfOV5ciFWe3dszk6jCbvNQweZcREVQQQQtV1CE +EFKutBxG92XfUBOsAlfYK87ItwpTFKkaSkxdax8JJkZYqj3wQry0zfFawbVfIhdFBFGQe 3OvPAm+/b+WN2TdWWdBp/ppLPLkEm7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707435917; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; b=QnlWa4ieMNxaHh1lPaByAiwWzG4twvBtatrUDg7Kfyqlf/+raHbjXP5l93h60PpXsRrbOg PCDMFPgk9mg4gTCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C9CAA13984; Thu, 8 Feb 2024 23:45:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id KDmJLoxnxWWUfAAAD6G6ig (envelope-from ); Thu, 08 Feb 2024 23:45:16 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v7 4/4] mm,page_owner: Filter out stacks by a threshold Date: Fri, 9 Feb 2024 00:45:39 +0100 Message-ID: <20240208234539.19113-5-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> MIME-Version: 1.0 X-Spamd-Bar: +++ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 610A740004 X-Stat-Signature: 8anhx5mmwtp557teeab77otkd9fd966m X-HE-Tag: 1707435919-478105 X-HE-Meta: U2FsdGVkX1+3TeRnZlERTpS6UbH8SczrRRWhRZ8cTxtzSSAnuxdtPD2jFoEdttvnKcJXTojkhW0pava4wdrjCrYfU8QeFGZSvCA9fHuWJb9COuFEMjWAvcDjBx0+4uOXcZL1osYa2r9oAZGWASCE2YaxiocNVZ1SrDwV+VPCWSwteuIQldKyiPdHmG9PdjqLI9/oeuEIz6rsLbr6hziUIsT0jyO+k8HdZgFUlV22F00cmhZmmVwAIwqV/sPqHD7C7FwVvs+fumYXx2W93k80XpleWrxyaPUgunt+WNJCr0sRi6Yta5qytpbo3Hg4Fh/PNLc9En57NZ8cAbYNAnRPfHMKNs5VXq1OJzs/dv4sDj9YZ2Pxm2gMxanWeAtPwURFj2tLq9DvfTJHHNwgnNCUizYiJxVsVkdwDm1DWLSVVKuGSVNyMc8wn3KV8gtrc7s1XL9DB+drEQftJcdZBDRdEneLMK6C8T4SGxmRraWnsKiRLrYPldjCyThqaiXSv8izmQ4o2of10g22Ses4FYm0it0qW4f4WuRro3Y2sSqlIwH+hFvii5WEAWX3O16ZfN4vhwuB6F7YVikr48PI+rIUBNYDcMIQCnsjlTXdFlD+5tWpDMTMdszP9pBJ4wUkBlRlSgJnzbcnS58onofC0M75uLSzsgy+Y5D1BMBeNyJqj+zEz5bjeAfZVcCqRcXGzTGa4oG0hR2uNvKOdhY31Ltrr2DhMA9SeVgfb3GMO7tVwWogVZ0u7wjyUkAP0W7xEQ69dmm4V2H2yhEhxB6+QcxLCR5W9euVgKAvPQnoq4CADwpdBbjM3+66QwKHD5fD2w7Ijz4AirmK9TJKhL+A669kbMiKRrgTJXVMGzjwCEwW8/SO3bOm30+KOXcbRoXLrFHys2g0mJ2BY7iGKwRmI5EKQpjnSh1gIBaEb3YNIkVAhISLpk2o1PUfUCU8iNm/fb5cbK+yEfh/jE41EYrNhOo fT42u27A M0q3Y7Az2oWNCKnZiUi0SpoSKNx3H5HdpqHDHAE5JuP2HNHXShyW8rPndnEjiwUTdgc2v2DWiLeYVRk7An3ggai66jxiHkYca4N+A/HUbBK3hkV6P9mmxhTeW6t+foTCK1CufeqtWIWWh8MBWCkzpKsIW5LzFUl7V3MCH/NdHs4oGn/lZSl6hvryrYcKoaFieMpOSYf5sosxWNQPWkhHW3Id1JBfLpbJ06mz6rLAHgYjLFhY9WjfGLWIEm2stJR/NcpGLPJ89nFu5mHS8pebQPrORcBj6PNq7lhnBRw/SlFaaUGkrBZt4TlfCbQ== 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: List-Subscribe: List-Unsubscribe: We want to be able to filter out the stacks based on a threshold we can tune. By writing to 'page_owner_threshold' file, we can adjust the threshold value. Signed-off-by: Oscar Salvador --- mm/page_owner.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index aea212734557..d95a73cf2581 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -780,14 +780,18 @@ static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) return stack; } +static unsigned long page_owner_stack_threshold; + static int stack_print(struct seq_file *m, void *v) { char *buf; int ret = 0; struct stack_iterator *iter = m->private; struct stack_record *stack = iter->last_stack; + int stack_count = refcount_read(&stack->count); - if (!stack->size || stack->size < 0 || refcount_read(&stack->count) < 2) + if (!stack->size || stack->size < 0 || stack_count < 2 || + stack_count < page_owner_stack_threshold) return 0; buf = kzalloc(PAGE_SIZE, GFP_KERNEL); @@ -832,6 +836,21 @@ const struct file_operations page_owner_stack_operations = { .release = seq_release, }; +static int page_owner_threshold_get(void *data, u64 *val) +{ + *val = page_owner_stack_threshold; + return 0; +} + +static int page_owner_threshold_set(void *data, u64 val) +{ + page_owner_stack_threshold = val; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_get, + &page_owner_threshold_set, "%llu"); + static int __init pageowner_init(void) { if (!static_branch_unlikely(&page_owner_inited)) { @@ -843,6 +862,8 @@ static int __init pageowner_init(void) &proc_page_owner_operations); debugfs_create_file("page_owner_stacks", 0400, NULL, NULL, &page_owner_stack_operations); + debugfs_create_file("page_owner_threshold", 0600, NULL, NULL, + &proc_page_owner_threshold); return 0; }