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: 198694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp522367dyd; Thu, 8 Feb 2024 15:45:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoP/bYS2xXgqktdSQnqITYdHxE+Dz2T5ZqkTk0LO/us5zOVSO3PypajWT28AvC8ZEHrfRP X-Received: by 2002:a05:6a20:6f91:b0:19e:b920:89d3 with SMTP id gv17-20020a056a206f9100b0019eb92089d3mr129763pzb.14.1707435949687; Thu, 08 Feb 2024 15:45:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435949; cv=pass; d=google.com; s=arc-20160816; b=PRulXh1V6HH17egBT+eBbDCyPSfNu/oDBWIBZOCeVKeJkTtd9oX7fhWsed/sx10EqN xNFg7tOM/lKY0TBEgrhax5dYKl47lROU85AecNcadsfF4CiVP2mHWzkO6fhnoPJSAhKH sYvxJvytkGjQofBM/XoiqQoBnZLRtqY0fv+f61hVIPxFXJmuUsJA9pXFpHHsoCxEOr6q 6+RweO+0fM5hQDxq9QVu4nDJ33r52acaupjJ0fpMwmR19aSDhLmT/d5BwIvHRV+8lFFX 7hbk3DT/Vrk5TlSAdQUVlWrG/9uEYaTSjSyCHlMEQT/ctt3l07BezGD94+Lx2UbNrtDz TNnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=txtCde6C1McUcle00OaiAlK/R7byCyLGw0BeYvVKqOg=; fh=mVeUunaerEMUBIjeZnDTAXXaeSu91TfU4vhKvopCXs0=; b=S9R5DUnAR57PCmJVQpzgiTe+1pEvjY2YXJwM4/iacwZPhIBA2FFKoXYt3mXgbmWC3P f43beapfCu//9/VX6GUw8MlJ0yeyTwn+aIFhIUMlIabbFLmgLYMLsLrWArmDhzjGCcRp c5+zI2ra3Fe0JnLWY1vRrTRHSPXkQ2lrW98pbxx/hUC+GqbxgyboDkCl+sk+Qr1ywQkC 7bgSCYkHUE/5GcV/Nb/NIIGEDX2gZscViAjRuAXWaX5MZuQfzfFKfnjMz5s811mW59Gt GuX+iJuLwdAqa2sUhg6q+UpG5ck/0uigDCkuZAqSbm7z1vRNJLVILfQq0mgl5xY2lscH OS2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=e9Com5bm; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCUtisK7Kl5pInbixWnuab8t78VTdYBboanlyltYFmjQXEBRXlFeEyndu8bOrvLyL63i4MpL/b5NZeywVod/NvY9NjXaDQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nh24-20020a17090b365800b002961cc0cda1si528849pjb.83.2024.02.08.15.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:45:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FqIo5CvJ; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=e9Com5bm; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58878-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 706E0287029 for ; Thu, 8 Feb 2024 23:45:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02DA151C4E; Thu, 8 Feb 2024 23:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FqIo5CvJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="e9Com5bm"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FqIo5CvJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="e9Com5bm" 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 1AB9B50267 for ; Thu, 8 Feb 2024 23:45:13 +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=1707435916; cv=none; b=Q/GuHL9+oywkO2z3VJ4tTb49be1x0UOJiVaEgEddeqlDXviEoQQgqRIGcr0qgzNCEeOxYulrwnE67IJ8Jtem9rQB0xCc5I8Hh+Pp5FfKCGYThYDNfLYMzVpSN+yJQbOvXjxsBWnu8Ngchk8E1XhQCEZJ+vPGshTDMtVGCRuTLFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435916; c=relaxed/simple; bh=wdjyH8x1YZucLguMDb3KPjDfIknPxybLEtYyM3a0pcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IsJurOFWSh6MzLgeEEkVehitK0/yXz6LeX7/xSXScxsWbPv5zZ/XHDM2zsvY97cZ7Bx8Q4hiwRJePqIttsBuGmRR6F0psYSUdRZ4hTwUY0MjVXh+Me/z3aVuJ6VOrBFcfNeQ4Oqx4vddiVqFe2cf44UveBBUnsgxLhnaV7jKiuM= 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=FqIo5CvJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=e9Com5bm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=FqIo5CvJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=e9Com5bm; 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.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)[] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376358405231329 X-GMAIL-MSGID: 1790376358405231329 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: 198695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp522481dyd; Thu, 8 Feb 2024 15:46:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeJw9jivNjQK9XkHiwbnadmvSm2rpKtMSEVyWjJx4s2ZI6oxNp+2USwOI4FkUWfRJ1wAqz X-Received: by 2002:a17:906:a850:b0:a3b:bed0:e488 with SMTP id dx16-20020a170906a85000b00a3bbed0e488mr556322ejb.51.1707435968780; Thu, 08 Feb 2024 15:46:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435968; cv=pass; d=google.com; s=arc-20160816; b=fLXGbQrrpoOKif5MldVqd1sPkDNbPLfNcqCmBxIA5ttVsLcpyi9L+v/GPzObdDmjZH uXWQ/+RIjGpgv4ISNHQafH+lIkXDjxVxLSpThWEmc6ipqa69brIMfJGTxVJmPZacm4TB gfFuJ6k7j/6d/9LzubvmeoutL7NNw82UbC6UhXJNIWjVwYHFKj4qINwHWGFh5ryUOHIL 5L3bFqdxUHKeV/XJ+JWapbRUzVjHJ3VPMtTCZQaBJFXTryX7QySKvZOGX/WKoYRN1QvM q3626nUorV464Ahdu5DFjBb2ETTcek5KlmEB9DagNOK59D49vB4yo3ZIdQo9tnemnt9G C0dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=SOtnmJyjTMio6JnPiONHFMtYXU8AmDD2FzaIP6UxlE0=; fh=by1YHhA399D1zzE8toF9mKpYppUgSlH6BQvHdRNdAAI=; b=gKxx6F/VqXKTM9m3lGPvHpjq9tTt/QDVaoPVOD4DzCxFFtZaXZmL0EyIos87ZViYEy YfASS/qKIJmnoNMXjBCEaU1junRzKSop20u7f+4X4bWxBWgo5pus9seIpYrfMlavLanI fBNBfUi2+DVsNBk7BZ1QuBizwExN5PtxoeFUmhUPCmzdjcpG2cvE9gjpzE0vOGJgtwjn u0Ypg+uEAI7IS18uJOgRcKYP+EdbjFSv/mXNMf8k7B03TMAdPkznGr7Hdh6i95dlXeYj lNr6qwZt8aZY3GH7Ldn7O3EbOTsEKxSVh46XtraQfBmVj+QdBUq2xcUtQXYZMMM4g2NK ArQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58879-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58879-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCX8FvWhYzOQlzGtnzcw0wtlAzooBlT6OsTKfUGC0Hfox7jVGVMIu21y4fCC0Te0UPo7r1VJiClP/FfH4ru0H99S149ZsA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id k11-20020a170906578b00b00a382c80d2f1si183224ejq.23.2024.02.08.15.46.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:46:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58879-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ZwBUTcSH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58879-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58879-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3CC861F24B96 for ; Thu, 8 Feb 2024 23:46:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA11B524C1; Thu, 8 Feb 2024 23:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZwBUTcSH"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="P94itunw"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ZwBUTcSH"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="P94itunw" 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 1980750A6D for ; Thu, 8 Feb 2024 23:45:15 +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=1707435918; cv=none; b=S6MVCsvxanm5VPbdWYQD8ViuxcSlNmpuQrLZQSxOeIBpU7tiYMNcQaERy7VEodSrPtJTrHjmceKOn16+Hu+MW35Px6Oj5f5zFj/YXkMjb7/7cub+5FS0b0irrVV+W4VncTGQUSdSCc4+vLXZv0tL0fd76e2TNwGkJ5d5feHU0bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435918; c=relaxed/simple; bh=SZfyzV7sF3kLKFjE9KI/KE075YQWak/Z7IHyRZhnK50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qYk7u5NECDMcAzJDhyzZvSyC6p67BSHvmO6/SgIbEuJ12TIZqMe65NnsHRwAWlBltDRiMu6Qir44bc7rgwMZC0THrnZN7r8MpOJU3jYY3PpWhhzzbI5QpIz0A65BZJHWdmCdRtVqB3fFVR80OrCqULQ6lirG2rlah2CnwL0ZkhI= 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=ZwBUTcSH; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=P94itunw; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ZwBUTcSH; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=P94itunw; 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; 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 X-Spamd-Result: default: False [1.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]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; 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(-3.00)[100.00%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 1.69 X-Rspamd-Queue-Id: 0223922315 X-Spam-Level: * X-Spam-Flag: NO X-Spamd-Bar: + X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790376378418189859 X-GMAIL-MSGID: 1790376378418189859 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: 198707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp533137dyd; Thu, 8 Feb 2024 16:10:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7nmESTjfMJX+TC5WFWVASxut92/iVGSon3fl9hdy9rX5vOUFY4xTCi9OAuY29aAb43HOm X-Received: by 2002:a05:6a20:e608:b0:19e:3659:c23a with SMTP id my8-20020a056a20e60800b0019e3659c23amr194310pzb.43.1707437424664; Thu, 08 Feb 2024 16:10:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707437424; cv=pass; d=google.com; s=arc-20160816; b=eO1ZsTx1l8PX+i8JZ1C1h1+A4Xpww5G5LapHg4bl8hq4aI3J4WvBUGj3M9zreHUdgv o2/NnY28HP3Au+0kiE1K0ZA/a3WOn0UfzidS+AJGxbS8qlmJTF2KpPaDadXYUtuk2CRr 0OTP6dKxWHgTrE80T0G/u7ouofllfnMQowIXnzLPFi7REhrzYHjBnweomJh6ut3ILs02 Kgcx9mqZcbXcQ38hf1vPHOQhX5Bn+FiAn9RF4uvUyjfA5J9usyZZn1KQAJYS2WmogQ2y FF00FRLDv43zCWwELfCWWQYA53vdoia5tYdkJ2b8OwbI1931ffQPS6hrlm8spx5S3RgN x9lA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=1RIuerYMWRH7Xo5xR9Dr7KugCllJ88k2PizonkIPXIU=; fh=AECHGR58kb7Z2UqvdgXv9rX9cOrtxXsYpAlsTh7RP1s=; b=KlQKuE+6bCGrs/J5KmWE/8U1rCpEnj9euJcL8hoCjTSRBh9j7s2phwFwafD0wGpCfE cXjXSoq/CnV036TiBwJnSsdzm1qJovSMVvvRhzWRwd0Ek6Xmx9P57UwTTO2S8qfnR6v7 h9V36omXJmbDTnQsnI6mOP/3S7lWjpjWbynWThHKtruJ9uKkZRjxYtKDCOSZuEDuM761 0iN/UKpKiK4O5dyWWZY4HYjyvr/OmWaxT1mktZ4J7CpFhqxBqm+9Hv7hAk8vAdjsoB6u 1xdk3R5+xXpgqRIF3pafyyiACFGk5WMxq2W23t4WSiHeREVobAkugkh+0QWazF8OgW45 qlkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58880-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCU/hDL/11TLU+rGs9cgFSg9xTgrKrUEEBmB4b7WNh8kh96NkA+wwRQvN5IK9JjaGYUhg2Iv4dcQU+CnHMkS0OI9jRixTA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e11-20020a65688b000000b005dbd0facb50si665287pgt.384.2024.02.08.16.10.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:10:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hY9JCYvA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58880-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E0CFBB2933B for ; Thu, 8 Feb 2024 23:46:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4764B52F6B; Thu, 8 Feb 2024 23:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hY9JCYvA"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="p5HZ5uBZ"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hY9JCYvA"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="p5HZ5uBZ" 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 683EB5101E for ; Thu, 8 Feb 2024 23:45:17 +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=1707435919; cv=none; b=TK5JoUjnSZ1zjdxo+HIfyQl3wkDCcUB5NJWXi8a8mpBCiBR8XTbXwT31HUt9GwsZFORFlvrvXb0x3HeuJH5HiCq4IeXM1mtAJABFZzuN1fLjVyT2rg0yUvI1/hL0M7oOZkYLYIBucBhaxHSSp/BvO82V/lofJ8OWRXMOREMnS0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435919; c=relaxed/simple; bh=vD+uDbcZd1nUQSYd7TnT05L2X2yMg5F/ZdZDImKbnS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h7NUL4oEwN7ssndHREhCFuQnUcryDuWIPfmn+HlG83NBo62fiSQ/1bvG6bMMnT+0rtuxpbryrP26ayg56o9laPEMeZ2j0qU1NQwL3DN6wqUE7qnfXYDShqqXzuWqQdSk7CcwYuZCocn3BwpsMPQ5oxFbGDixI9UNXWYtwy+MJ6I= 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=hY9JCYvA; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=p5HZ5uBZ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=hY9JCYvA; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=p5HZ5uBZ; 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; 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]; 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-Level: * X-Spam-Score: 1.90 X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377905213618678 X-GMAIL-MSGID: 1790377905213618678 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: 198706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp533104dyd; Thu, 8 Feb 2024 16:10:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXD3nMaMbNlVhTQYShNmaPcaagOd2W544lzHg8tqBziAExSVusdGbE93jO8udDJPgN691XuCFP34Q72DwO5+33VwjAGMQ== X-Google-Smtp-Source: AGHT+IGeLOv6ZEexKwMgnlT25Enc5lukXm0xHynyZ5Yl2g25uWYt78F2fxqWQHWx1mLd1BVH67H6 X-Received: by 2002:a17:902:e98a:b0:1d4:e0e6:693 with SMTP id f10-20020a170902e98a00b001d4e0e60693mr799543plb.35.1707437417245; Thu, 08 Feb 2024 16:10:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707437417; cv=pass; d=google.com; s=arc-20160816; b=aLdEHd4DcxvHCpp7pThvJRoMTRrn5dQum6T/fwxCk6lUKmXyrENe5fCzjaepNvkVrs m+UTkcfl8UeGiRlt3Ljf3gKLJyen2YMySSJddX/6i1HO3U8e2IWN7Osp1/Nh+x3IS2J7 5PVkqSiiQ4WeSJ8HclMJnNqTvkvOUj/BPQd5Cu5s2PeChxP8AGyS6UEfBi830InZiONg 9zghrbZBQJtGEAI2MrlMCX4Sm6YdczhWtTLAzYg8Yq780evLRDliBrvgxbWqJIttRyHX OXCBY1GxE/lrOEAZPJzSxp3bC8Zel49dH0Qhrrg4kMk4AxUMMVTvM7v+NYIjgr9FhC/s CYng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=5Ny8/gais+bfRbc1kxGSF6BydkfkKmZPjGNqn+J3Zwo=; fh=vhUeXuzrdD++fUY1Lgrd0NWrs7AAts8frFzwR+8E4/Y=; b=hsNMAGJNrU3vjdC0/WtiYyql3qWNuD9YjcJMk3Re4yIh7KnBbV+ft4DaAyjeKH6Bxs 2OdDeNWybj25+CkqVqLBlvg/BkL1qQmsERpxgCKw6Namw32zUY59cdzJ30uFGmvWCHTN AFmq00UHSgNUba9Rho1OCtmCTxV+/yoxjmmJbd9q+mkeKJRuimO/L07QjJeOV5qCRz2s RP8P588KzADWyHvMQKispSvxwqWrR+TvLa0QtcYQsVkcmgjKB/v5L9R9KUfjKlXwghB+ u7G+np6hDuIhaqxILZTyUv012GcX9dLbtYsErZyYGO2pgXRGGufM69QaRKRVjONZo+CD CDpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58881-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58881-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCXNIZIKUEZ9EkiEkZDgJgockMEplig9atZvS7uvk0XSgHxMt/v2KdRRr+VZnhe8IdQlHH7l8pBVDOFV4hwqC9mDw6vPXA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z4-20020a170903018400b001d9a4ecc5besi556942plg.555.2024.02.08.16.10.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 16:10:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58881-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ICG5MFU6; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-58881-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58881-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 699FAB29975 for ; Thu, 8 Feb 2024 23:46:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AECA52F7C; Thu, 8 Feb 2024 23:45:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ICG5MFU6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QnlWa4ie"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ICG5MFU6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QnlWa4ie" 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 1988051C3D for ; Thu, 8 Feb 2024 23:45:18 +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=1707435920; cv=none; b=I+l3TRIc0QnlGEvnXdbvXKE0FVxWdJalBBy0H7lqJcMr/l3rjf3eEJN9xPv2FIcibHVQD7CzWv9JChsAZ6vzyv7ewP8WY4nv+SwSaxmqMENBm19Pq4q/hqVbNj7y5g1FubijTPjsunVGA69e5+inoi3WTgejwDXrT1Ef8QzcnKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707435920; c=relaxed/simple; bh=iZR/cSUAPw61zT2l0lvV0xr2ZHSjmz6eg0cTSrld+h0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/tL3W5qxwWyPseg+Xu9aXMuZ7dTLN7MDlNsqJHnmTyhNq3UoPwF/RA1Kdb8VzIZmJkTC7XtrN/dHArovi3z2d5+iFDxWwA6MYeKGZd6f7wcmtL9I8hu59PUVbArqJvB8pUdyyZyd508/SG5RjynRXB4OzTpZ7EfRsMo1gtnQZo= 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=ICG5MFU6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=QnlWa4ie; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ICG5MFU6; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=QnlWa4ie; 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: *** X-Spamd-Bar: +++ Authentication-Results: smtp-out2.suse.de; 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 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [3.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[17.25%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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:dkim,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-Score: 3.49 X-Rspamd-Queue-Id: 56E6F1F7AB X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790377897318330915 X-GMAIL-MSGID: 1790377897318330915 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; }