From nobody Sat Sep 7 23:50:16 2024 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 3421E4D595 for ; Mon, 12 Feb 2024 22:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776970; cv=none; b=I0ua04nSzLt4C1OpvEEQFqA7HQb4yIHY1EMg8bpNEFn+qSQrAkvxNy24WSietk2pNyf/cFZ7tOUHsfZ3ov9aet5U7Db7rZ3O+OXRLXw7oXBRgBDqRRrugdQS8GF/hgHFTAaLuhxdhSM1RORzlcvyG63CkgIVqs14RgHQ1w1Myx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776970; c=relaxed/simple; bh=4Q7KJLy2PG12CfEApH1U9an73DqUlm1TwR3tb7XObzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hmBlwiWZAmTvvvbiFFSeh9lJ0gJFpOX4rKAnt3rcgSuUDoj5Qg1+dMsf8NYYWXWs1K3APVLogJrdbMzl17OYSC2gMa473kc99tpSIHwOL4lLTIURpUpU6N3+OtiVvHkWLSsFuWfvSBKZxSBbL2d2tBBpofO2BLhq9GrgqMeonfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2EkLibh1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tC+Nwu7M; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2EkLibh1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tC+Nwu7M; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2EkLibh1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tC+Nwu7M"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2EkLibh1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tC+Nwu7M" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 60F4F1F46E; Mon, 12 Feb 2024 22:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776966; 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=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=2EkLibh1T0Fpvt5mQX5cxgPHMlwcw7SrPLaJ8HP3vpqaLlAPLEjfjZosemRKQVC7usQktP iipLG7yV7zr53ZKaC1QpRqsfGkDShZY3d8MRRXjgN/zj3vssnEC3Kr02aK1diL+lYxp831 EUpqNZHOw0EC9jd3i3AWNhl0i28Zc64= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776966; 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=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=tC+Nwu7MsfACk+TPLrMCNykGk2INKq1bt5vpxNJwB860dZMWrxGpymKG8NT0/qgyClXS23 bRvhU3JQLYp9LpDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776966; 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=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=2EkLibh1T0Fpvt5mQX5cxgPHMlwcw7SrPLaJ8HP3vpqaLlAPLEjfjZosemRKQVC7usQktP iipLG7yV7zr53ZKaC1QpRqsfGkDShZY3d8MRRXjgN/zj3vssnEC3Kr02aK1diL+lYxp831 EUpqNZHOw0EC9jd3i3AWNhl0i28Zc64= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776966; 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=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=tC+Nwu7MsfACk+TPLrMCNykGk2INKq1bt5vpxNJwB860dZMWrxGpymKG8NT0/qgyClXS23 bRvhU3JQLYp9LpDQ== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 5FF5513212; Mon, 12 Feb 2024 22:29:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id gDGZFMWbymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:25 +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 v8 1/5] lib/stackdepot: Move stack_record struct definition into the header Date: Mon, 12 Feb 2024 23:30:25 +0100 Message-ID: <20240212223029.30769-2-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Marco Elver Reviewed-by: Vlastimil Babka --- 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..90274860fd8e 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 =20 +#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_ALI= GN) +#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; =20 /* diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 4a7055a63d9f..6f9095374847 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -36,54 +36,11 @@ #include #include =20 -#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_ALI= GN) -#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ - STACK_DEPOT_EXTRA_BITS) #define DEPOT_POOLS_CAP 8192 #define DEPOT_MAX_POOLS \ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) =20 -/* 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 */ - }; - }; -}; - static bool stack_depot_disabled; static bool __stack_depot_early_init_requested __initdata =3D IS_ENABLED(C= ONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; --=20 2.43.0 From nobody Sat Sep 7 23:50:16 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 AC9D74E1D2 for ; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776972; cv=none; b=IiKutnKoa7T+QOeMwbkITAb1u9trejw9FT2Yvd3ySDl6ZWkhRkQqM2uDaSuQ71T8ut47Ztkzl9xGOsTd+OJTyDAGhvi+RN5iZFg6M6QgYZBieeFvn8Poh5FXpnB7TIHCoFvGrB+zv4/oChbiSSAR///crVpFGh3bUKHEu3NgAe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776972; c=relaxed/simple; bh=gNFCECv9ePcmxaUYUJiZyIxZAIAz5HmsoobEzrrMM3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sa1rHXjnS+nRm2p5hsUI9BuznGb3q7ewZi9W3Lt8q3GPQUxjQal8T9lGd40EgZdDWZoNqu0LmunFnDbZEF4mxM/xqKXIIKxeVnwTqaeKgzeB2E7tJGep2hZS5FqOjeSrriht4VGtYbggGBSPBb2IKRuEN8ua2Ti1+EhfGeMgjMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxisH7+Y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jBQ05rww; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxisH7+Y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jBQ05rww; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxisH7+Y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jBQ05rww"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxisH7+Y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jBQ05rww" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 BB3B822177; Mon, 12 Feb 2024 22:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776968; 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=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=fxisH7+Ywg+k3MLHTeypNE73ysJ51gHcpfkHzqy3ymHFJbJX/uV1avZt4d5LfFRP+Gk2R8 UhDuSi+c1JSPl6b0CxwkUuFd+e26s2mCanskxmQbtGBrA8cwXd6Ut0I4Xcx16UlZHtim64 sjp+JOIc0pJnwhoBvrw4KDnjGOCvQVM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776968; 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=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=jBQ05rwwCs72vdAdft1AuBuwuzSrKzDP73TbkM1+0nJRjhxw9YOi7rA+LeU2IMFi7vCkod wqJqqu+Eo9oTaRBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776968; 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=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=fxisH7+Ywg+k3MLHTeypNE73ysJ51gHcpfkHzqy3ymHFJbJX/uV1avZt4d5LfFRP+Gk2R8 UhDuSi+c1JSPl6b0CxwkUuFd+e26s2mCanskxmQbtGBrA8cwXd6Ut0I4Xcx16UlZHtim64 sjp+JOIc0pJnwhoBvrw4KDnjGOCvQVM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776968; 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=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=jBQ05rwwCs72vdAdft1AuBuwuzSrKzDP73TbkM1+0nJRjhxw9YOi7rA+LeU2IMFi7vCkod wqJqqu+Eo9oTaRBA== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 82E9413212; Mon, 12 Feb 2024 22:29:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id CGxaE8ebymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:27 +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 v8 2/5] mm,page_owner: Implement the tracking of the stacks count Date: Mon, 12 Feb 2024 23:30:26 +0100 Message-ID: <20240212223029.30769-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" 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_record() 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). Traversing all stackdepot buckets comes with its own complexity, plus we would have to implement a way to mark only those stack_records that were originated from page_owner, as those are the ones we are interested in. For that reason, page_owner maintains its own list of stack_records, because traversing that list is faster than traversing all buckets while keeping at the same time a low complexity. inc_stack_record_count() is responsible of adding new stack_records into the list stack_list. Modifications on the list are protected via a spinlock with irqs disabled, since this code can also be reached from IRQ context. Signed-off-by: Oscar Salvador Reviewed-by: Marco Elver --- include/linux/stackdepot.h | 9 +++++ lib/stackdepot.c | 8 +++++ mm/page_owner.c | 73 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 90274860fd8e..f3c2162bf615 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -175,6 +175,15 @@ depot_stack_handle_t stack_depot_save_flags(unsigned l= ong *entries, depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); =20 +/** + * __stack_depot_get_stack_record - Get a pointer to a stack_record struct + * This function is only for internal purposes. + * @handle: Stack depot handle + * + * Return: Returns a pointer to a stack_record struct + */ +struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t h= andle); + /** * stack_depot_fetch - Fetch a stack trace from stack depot * diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 6f9095374847..fdb09450a538 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -685,6 +685,14 @@ depot_stack_handle_t stack_depot_save(unsigned long *e= ntries, } EXPORT_SYMBOL_GPL(stack_depot_save); =20 +struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t h= andle) +{ + 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..7d1b3f75cef3 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -36,6 +36,14 @@ struct page_owner { pid_t free_tgid; }; =20 +struct stack { + struct stack_record *stack_record; + struct stack *next; +}; + +static struct stack *stack_list; +static DEFINE_SPINLOCK(stack_list_lock); + static bool page_owner_enabled __initdata; DEFINE_STATIC_KEY_FALSE(page_owner_inited); =20 @@ -61,6 +69,57 @@ static __init bool need_page_owner(void) return page_owner_enabled; } =20 +static void add_stack_record_to_list(struct stack_record *stack_record) +{ + unsigned long flags; + struct stack *stack; + + stack =3D kmalloc(sizeof(*stack), GFP_KERNEL); + if (stack) { + stack->stack_record =3D stack_record; + stack->next =3D NULL; + + spin_lock_irqsave(&stack_list_lock, flags); + if (!stack_list) { + stack_list =3D stack; + } else { + stack->next =3D stack_list; + stack_list =3D stack; + } + spin_unlock_irqrestore(&stack_list_lock, flags); + } +} + +static void inc_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack_record =3D __stack_depot_get_stack_record(hand= le); + + if (stack_record) { + /* + * New stack_record's that do not use STACK_DEPOT_FLAG_GET start + * with REFCOUNT_SATURATED to catch spurious increments of their + * refcount. + * Since we do not use STACK_DEPOT_FLAG_{GET,PUT} API, let us + * set a refcount of 1 ourselves. + */ + if (refcount_read(&stack_record->count) =3D=3D REFCOUNT_SATURATED) { + refcount_set(&stack_record->count, 1); + + /* Add the new stack_record to our list */ + add_stack_record_to_list(stack_record); + } + refcount_inc(&stack_record->count); + } +} + +static void dec_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack_record =3D __stack_depot_get_stack_record(hand= le); + + if (stack_record) + refcount_dec(&stack_record->count); +} + static __always_inline depot_stack_handle_t create_dummy_stack(void) { unsigned long entries[4]; @@ -140,6 +199,7 @@ void __reset_page_owner(struct page *page, unsigned sho= rt 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 =3D local_clock(); =20 @@ -147,6 +207,9 @@ void __reset_page_owner(struct page *page, unsigned sho= rt order) if (unlikely(!page_ext)) return; =20 + page_owner =3D get_page_owner(page_ext); + alloc_handle =3D page_owner->handle; + handle =3D save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i =3D 0; i < (1 << order); i++) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); @@ -158,6 +221,15 @@ void __reset_page_owner(struct page *page, unsigned sh= ort order) page_ext =3D page_ext_next(page_ext); } page_ext_put(page_ext); + if (alloc_handle !=3D 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); } =20 static inline void __set_page_owner_handle(struct page_ext *page_ext, @@ -199,6 +271,7 @@ noinline void __set_page_owner(struct page *page, unsig= ned short order, return; __set_page_owner_handle(page_ext, handle, order, gfp_mask); page_ext_put(page_ext); + inc_stack_record_count(handle); } =20 void __set_page_owner_migrate_reason(struct page *page, int reason) --=20 2.43.0 From nobody Sat Sep 7 23:50:16 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 F2CCD4EB34 for ; Mon, 12 Feb 2024 22:29:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776973; cv=none; b=LmqbZtN6ey2xtTH2DND4M8Juhy19aRf9FLZtnDsIJGNfagw3qtFgfA5sKYUgyfSI+iNDAtND8SoMa42ua6pQJiNkn7r9HjtnCKa7CT4b/FLnxW3TGCOuI/B9fUr+llcPrYK8SVZv+FvfcO1dsfO1RaemH9zKoof3ZF+twjFpDEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776973; c=relaxed/simple; bh=PslCDCM3yg1q5QFWu02AeTqtUBHZaW7ctPxFlrHtAsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rauubtk7JUTCwRbPpR4noMBI8JrpzHf+5R81rsJa7Rd0RguenazMHLO3uwXfQ/7PY6OhyStoh1TdBM5boua4X9b6qV6l4w2hPIJiG2aCpmP/II1j0nFMWiiOtQ3iNjxIzbv5SNSi2BYlK8monVaU9sY1PwTHsPnZiuHWx8NvdA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=aO8sIvNw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IMz7vyf+; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=aO8sIvNw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IMz7vyf+; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aO8sIvNw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IMz7vyf+"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aO8sIvNw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IMz7vyf+" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 4330622160; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776970; 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=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=aO8sIvNwoxgZohBoscNS6wvlgcWjwXje8eEteMwwtBuB/+u2WRUjh8NwW4qXahgHFoOv/3 /2MuhVHGZzW70sU0W/+D51GvcRLU9+pVPIMz7GxwfGGqH/5FTYg667EBvytadc8R/KNzwU i3X2tsgY6Ob+sgqpA4KA0ngkfibk9tQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776970; 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=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=IMz7vyf+FqsnnTqxhLZ2ZG4SOkTO2sPVHymdrZdBtZvjkwp8tB+6RN2TSyC8izEmJRrrPE aY8LnAReVrEaukCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776970; 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=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=aO8sIvNwoxgZohBoscNS6wvlgcWjwXje8eEteMwwtBuB/+u2WRUjh8NwW4qXahgHFoOv/3 /2MuhVHGZzW70sU0W/+D51GvcRLU9+pVPIMz7GxwfGGqH/5FTYg667EBvytadc8R/KNzwU i3X2tsgY6Ob+sgqpA4KA0ngkfibk9tQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776970; 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=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=IMz7vyf+FqsnnTqxhLZ2ZG4SOkTO2sPVHymdrZdBtZvjkwp8tB+6RN2TSyC8izEmJRrrPE aY8LnAReVrEaukCA== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 79FDA13212; Mon, 12 Feb 2024 22:29:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id eIdfGcmbymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:29 +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 v8 3/5] mm,page_owner: Display all stacks and their count Date: Mon, 12 Feb 2024 23:30:27 +0100 Message-ID: <20240212223029.30769-4-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO Content-Type: text/plain; charset="utf-8" This patch adds a new directory called 'page_owner_stacks' under /sys/kernel/debug/, with a file called 'show_stacks' in it. Reading from that file 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 The seq stack_{start,next} functions will iterate through the list stack_list in order to print all stacks. Signed-off-by: Oscar Salvador Acked-by: Marco Elver --- mm/page_owner.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 7d1b3f75cef3..3e4b7cd7c8f8 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -84,7 +84,12 @@ static void add_stack_record_to_list(struct stack_record= *stack_record) stack_list =3D stack; } else { stack->next =3D stack_list; - stack_list =3D stack; + /* This pairs with smp_load_acquire() from function + * stack_start(). This guarantees that stack_start() + * will see an updated stack_list before starting to + * traverse the list. + */ + smp_store_release(&stack_list, stack); } spin_unlock_irqrestore(&stack_list_lock, flags); } @@ -792,8 +797,97 @@ static const struct file_operations proc_page_owner_op= erations =3D { .llseek =3D lseek_page_owner, }; =20 +static void *stack_start(struct seq_file *m, loff_t *ppos) +{ + struct stack *stack; + + if (*ppos =3D=3D -1UL) + return NULL; + + if (!*ppos) { + /* + * This pairs with smp_store_release() from function + * add_stack_record_to_list(), so we get a consistent + * value of stack_list. + */ + stack =3D smp_load_acquire(&stack_list); + } else { + stack =3D m->private; + stack =3D stack->next; + } + + m->private =3D stack; + + return stack; +} + +static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) +{ + struct stack *stack =3D v; + + stack =3D stack->next; + *ppos =3D stack ? *ppos + 1 : -1UL; + m->private =3D stack; + + return stack; +} + +static int stack_print(struct seq_file *m, void *v) +{ + char *buf; + int ret =3D 0; + struct stack *stack =3D v; + struct stack_record *stack_record =3D stack->stack_record; + + if (!stack_record->size || stack_record->size < 0 || + refcount_read(&stack_record->count) < 2) + return 0; + + buf =3D kzalloc(PAGE_SIZE, GFP_KERNEL); + + ret +=3D stack_trace_snprint(buf, PAGE_SIZE, stack_record->entries, + stack_record->size, 0); + if (!ret) + goto out; + + scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", + refcount_read(&stack_record->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 =3D { + .start =3D stack_start, + .next =3D stack_next, + .stop =3D stack_stop, + .show =3D stack_print +}; + +static int page_owner_stack_open(struct inode *inode, struct file *file) +{ + return seq_open_private(file, &page_owner_stack_op, 0); +} + +static const struct file_operations page_owner_stack_operations =3D { + .open =3D page_owner_stack_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D seq_release, +}; + static int __init pageowner_init(void) { + struct dentry *dir; + if (!static_branch_unlikely(&page_owner_inited)) { pr_info("page_owner is disabled\n"); return 0; @@ -801,6 +895,9 @@ static int __init pageowner_init(void) =20 debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + dir =3D debugfs_create_dir("page_owner_stacks", NULL); + debugfs_create_file("show_stacks", 0400, dir, NULL, + &page_owner_stack_operations); =20 return 0; } --=20 2.43.0 From nobody Sat Sep 7 23:50:16 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 DCFF94F20D for ; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776975; cv=none; b=R5IxBPp9MZ5X4j/mPD+baWk2cOl1jUH7zowjPwQ73fTjp4/OOoO1Yycw0BOa1ipPG9Yg7XeESRfplHWQ4CwKd10CrPYURNx+AD/+afJBcW2eKcJZuttdOI/Rz64ZL25kCXeWh48JkNwUacYJmrVdDdINc0dpScGnzpfu3T6Smmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776975; c=relaxed/simple; bh=0UjzajfUgl8WMY9SKpR8JzCcqPQyXSlET4DvDtf+pFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V763CoWRG2jwKANZFZgJ3wESnIZEgS/b1r0zZTKaLR6NUH0n0Iir8AMxXgOILsMsHUqq8Ewqs893qCqfnX7MW7YfWhrbyjroQm6btVexeeTVgDkjXe+mjyAQ2DTnABHbxFVhp6Y3GJPMgj0Q5EXEjLhCEm1YUafRFBtZV/VIqbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=U9jqloks; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TkinlWVz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=U9jqloks; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TkinlWVz; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="U9jqloks"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TkinlWVz"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="U9jqloks"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TkinlWVz" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 11AA7221A6; Mon, 12 Feb 2024 22:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776972; 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=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=U9jqloksGUrl/eNBRyCLYgfj6sduFcBCUrcWKDHpeXb24Ugicd6lmLa9UnYqfvX0TuXKS7 9r60PATmtHzXICNvsY/UL9x7L2p6wP0/4TGbvNQuYcsO/8DGCByBw/voo3tYgBZwqrLSt+ VFEJVKqBubRJKJULlxT/ymJWlRYLNiU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776972; 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=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=TkinlWVzB7+YhEp3jJr/aZNIP8VQuP4l4pvoZufo1Kr2/64XIZmKINju8djN6EKZQGdFX9 h1A0nNQbWXysyuDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776972; 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=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=U9jqloksGUrl/eNBRyCLYgfj6sduFcBCUrcWKDHpeXb24Ugicd6lmLa9UnYqfvX0TuXKS7 9r60PATmtHzXICNvsY/UL9x7L2p6wP0/4TGbvNQuYcsO/8DGCByBw/voo3tYgBZwqrLSt+ VFEJVKqBubRJKJULlxT/ymJWlRYLNiU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776972; 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=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=TkinlWVzB7+YhEp3jJr/aZNIP8VQuP4l4pvoZufo1Kr2/64XIZmKINju8djN6EKZQGdFX9 h1A0nNQbWXysyuDQ== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 806AE13212; Mon, 12 Feb 2024 22:29:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 8F2kHMubymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:31 +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 v8 4/5] mm,page_owner: Filter out stacks by a threshold Date: Mon, 12 Feb 2024 23:30:28 +0100 Message-ID: <20240212223029.30769-5-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=U9jqloks; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=TkinlWVz X-Spamd-Result: default: False [4.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[21.10%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 4.69 X-Rspamd-Queue-Id: 11AA7221A6 X-Spam-Level: **** X-Spam-Flag: NO X-Spamd-Bar: ++++ Content-Type: text/plain; charset="utf-8" We want to be able to filter out the stacks based on a threshold we can can tune. By writing to 'set_threshold' file, we can adjust the threshold value. Signed-off-by: Oscar Salvador --- mm/page_owner.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 3e4b7cd7c8f8..c4f9e5506e93 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -832,15 +832,18 @@ static void *stack_next(struct seq_file *m, void *v, = loff_t *ppos) return stack; } =20 +static unsigned long page_owner_stack_threshold; + static int stack_print(struct seq_file *m, void *v) { char *buf; int ret =3D 0; struct stack *stack =3D v; struct stack_record *stack_record =3D stack->stack_record; + int stack_count =3D refcount_read(&stack_record->count); =20 if (!stack_record->size || stack_record->size < 0 || - refcount_read(&stack_record->count) < 2) + stack_count < 2 || stack_count < page_owner_stack_threshold) return 0; =20 buf =3D kzalloc(PAGE_SIZE, GFP_KERNEL); @@ -851,7 +854,7 @@ static int stack_print(struct seq_file *m, void *v) goto out; =20 scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", - refcount_read(&stack_record->count)); + stack_count); =20 seq_printf(m, buf); seq_puts(m, "\n\n"); @@ -884,6 +887,21 @@ static const struct file_operations page_owner_stack_o= perations =3D { .release =3D seq_release, }; =20 +static int page_owner_threshold_get(void *data, u64 *val) +{ + *val =3D page_owner_stack_threshold; + return 0; +} + +static int page_owner_threshold_set(void *data, u64 val) +{ + page_owner_stack_threshold =3D val; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(proc_page_owner_threshold, &page_owner_threshold_g= et, + &page_owner_threshold_set, "%llu"); + static int __init pageowner_init(void) { struct dentry *dir; @@ -898,6 +916,8 @@ static int __init pageowner_init(void) dir =3D debugfs_create_dir("page_owner_stacks", NULL); debugfs_create_file("show_stacks", 0400, dir, NULL, &page_owner_stack_operations); + debugfs_create_file("set_threshold", 0600, dir, NULL, + &proc_page_owner_threshold); =20 return 0; } --=20 2.43.0 From nobody Sat Sep 7 23:50:16 2024 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 439AB4F613 for ; Mon, 12 Feb 2024 22:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776977; cv=none; b=hy8Djrvv5/1Tje0dqjdzeLeDFycOz4smjDbvEXVQVBVSspVg/aw4+e8EA2+2Hz0Jb6iNmp7e7tY2WJf9wjQd29ZO8TGs2/eGZz0LprrfhpXje3bq83++qDslRe3I3EnVNnr5VzwwxgEb+PdmVuzViiE40XgqvMQ7FqCTzDFGXDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776977; c=relaxed/simple; bh=kovR+ZrYRhElztUO/xzkg9t4G7s0y135A+ZgTQIhorg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oq6jUNACA7JWwrlaZ67wwKIOuichchUapeNXjsi3Byza8Xz+AZJqM87La27UeNAdwezaJzQq4qKvLAt7ZMQEDze+Kh7untAeLoOAdjtsyj/h4uh00QOiWHLhncAk4Ja7OJeK4UD+NQ18ploo8NGe1fIVQsp8TkrWQ80udlM0cGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Hkksmim; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ZnVGi03v; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Hkksmim; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ZnVGi03v; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Hkksmim"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZnVGi03v"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Hkksmim"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZnVGi03v" Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 AD61222177; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776973; 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=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=0HkksmimAKf1X2UchGs1ECrVRZPKtKpJwt693l9NOKJ5pJjpsp/SyDvukNl5wLeGnSUFbx AYwqmHSTXqM/SJpVRjlMOBOxO0rM/s0c6MDVVlIlJYcTLyTM3upL1YC6miq4zlePc2ZO79 zdX7qh0CWgh/3uAXle7lIRUwWwtjOlE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776973; 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=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=ZnVGi03vheW9LR2lPrO/6uN0847XkDBVnIfGMln6MKkPIGMcvcEckEGoHOIS/MPPxXr9Ab pgLcrPPJ9Uwoh3Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776973; 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=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=0HkksmimAKf1X2UchGs1ECrVRZPKtKpJwt693l9NOKJ5pJjpsp/SyDvukNl5wLeGnSUFbx AYwqmHSTXqM/SJpVRjlMOBOxO0rM/s0c6MDVVlIlJYcTLyTM3upL1YC6miq4zlePc2ZO79 zdX7qh0CWgh/3uAXle7lIRUwWwtjOlE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776973; 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=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=ZnVGi03vheW9LR2lPrO/6uN0847XkDBVnIfGMln6MKkPIGMcvcEckEGoHOIS/MPPxXr9Ab pgLcrPPJ9Uwoh3Ag== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2A3A613212; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 6IORB82bymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:33 +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 v8 5/5] mm,page_owner: Update Documentation regarding page_owner_stacks Date: Mon, 12 Feb 2024 23:30:29 +0100 Message-ID: <20240212223029.30769-6-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0Hkksmim; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZnVGi03v X-Spamd-Result: default: False [4.11 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.58)[81.40%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 4.11 X-Rspamd-Queue-Id: AD61222177 X-Spam-Level: **** X-Spam-Flag: NO X-Spamd-Bar: ++++ Content-Type: text/plain; charset="utf-8" Update page_owner documentation including the new page_owner_stacks feature to show how it can be used. Signed-off-by: Oscar Salvador --- Documentation/mm/page_owner.rst | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Documentation/mm/page_owner.rst b/Documentation/mm/page_owner.= rst index 62e3f7ab23cc..bcde81bf0902 100644 --- a/Documentation/mm/page_owner.rst +++ b/Documentation/mm/page_owner.rst @@ -24,6 +24,11 @@ fragmentation statistics can be obtained through gfp fla= g information of each page. It is already implemented and activated if page owner is enabled. Other usages are more than welcome. =20 +It can also be used to show all the stacks and their outstanding +allocations, which gives us a quick overview of where the memory is going +without the need to screen through all the pages and match the allocation +and free operation. + page owner is disabled by default. So, if you'd like to use it, you need to add "page_owner=3Don" to your boot cmdline. If the kernel is built with page owner and page owner is disabled in runtime due to not enabling @@ -68,6 +73,45 @@ Usage =20 4) Analyze information from page owner:: =20 + cat /sys/kernel/debug/page_owner_stacks/show_stacks > stacks.txt + cat stacks.txt + prep_new_page+0xa9/0x120 + get_page_from_freelist+0x7e6/0x2140 + __alloc_pages+0x18a/0x370 + new_slab+0xc8/0x580 + ___slab_alloc+0x1f2/0xaf0 + __slab_alloc.isra.86+0x22/0x40 + kmem_cache_alloc+0x31b/0x350 + __khugepaged_enter+0x39/0x100 + dup_mmap+0x1c7/0x5ce + copy_process+0x1afe/0x1c90 + kernel_clone+0x9a/0x3c0 + __do_sys_clone+0x66/0x90 + do_syscall_64+0x7f/0x160 + entry_SYSCALL_64_after_hwframe+0x6c/0x74 + stack_count: 234 + ... + ... + echo 7000 > /sys/kernel/debug/page_owner_stacks/set_threshold > stacks_70= 00.txt + cat stacks_7000.txt + prep_new_page+0xa9/0x120 + get_page_from_freelist+0x7e6/0x2140 + __alloc_pages+0x18a/0x370 + alloc_pages_mpol+0xdf/0x1e0 + folio_alloc+0x14/0x50 + filemap_alloc_folio+0xb0/0x100 + page_cache_ra_unbounded+0x97/0x180 + filemap_fault+0x4b4/0x1200 + __do_fault+0x2d/0x110 + do_pte_missing+0x4b0/0xa30 + __handle_mm_fault+0x7fa/0xb70 + handle_mm_fault+0x125/0x300 + do_user_addr_fault+0x3c9/0x840 + exc_page_fault+0x68/0x150 + asm_exc_page_fault+0x22/0x30 + stack_count: 8248 + ... + cat /sys/kernel/debug/page_owner > page_owner_full.txt ./page_owner_sort page_owner_full.txt sorted_page_owner.txt =20 --=20 2.43.0