From patchwork Mon Feb 12 22:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13554127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E29B5C4829D for ; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5736D6B00BC; Mon, 12 Feb 2024 17:29:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4ADB66B00BD; Mon, 12 Feb 2024 17:29:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FF926B00BE; Mon, 12 Feb 2024 17:29:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2040B6B00BC for ; Mon, 12 Feb 2024 17:29:30 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0631140172 for ; Mon, 12 Feb 2024 22:29:29 +0000 (UTC) X-FDA: 81784594458.09.0882304 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf29.hostedemail.com (Postfix) with ESMTP id C87AA120019 for ; Mon, 12 Feb 2024 22:29:27 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=tC+Nwu7M; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=tC+Nwu7M; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707776968; a=rsa-sha256; cv=none; b=NcTcr7MIIWjNsTeA79twd3EYHRBzQWPN3LgPlzkCW7MGYr+8HiHXd1TD7Voy62lo/np9Th x67Q1cVjSF3gMof8Da2h2JKxfr1eUhqagOq2VAexHNOz3BhTYIqa+oKlSzqIMMzPabzT+E kxqn3SjQ9qrlwmJJLYEDbDKy51a+CZo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=tC+Nwu7M; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=tC+Nwu7M; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707776968; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=dGSbprTFHsD7MaU3A4HNDf81IBSHgjPIMzxX+AMtGEumRBnpN60jwLxq0F99/thTYcvgxX 8d9YSd89NG++rjOVkZ6M2wbkuQE7mwsW6/8m+H4TGvADGw8B/dlfcGk1WoM6hccCO9yxTs BIy/WHQPUc4lilb5+VUKA1a5yUvGVbs= 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> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C87AA120019 X-Stat-Signature: 9nwjydu3cbmbnokhisqtj9zhdshubzun X-HE-Tag: 1707776967-690448 X-HE-Meta: U2FsdGVkX18LBva00C/vjv0LeIpYnUO9RFw0h7v/zbDcpQAp/aD8Lmt9TcbWC82oyjqIDg0D6o5yQACroKGfIOfOBLgK75OfRmX7mSmWI5TyV4VenppG6mi538JNDZV+sDCIWAImE/4VlTCis26of45XoxZ8qNz3nNtMUDTIyIELAJIkK8n0FoOgx80/wwXwlP1YhvaiLZ5ELrdDG6tLKP3Dfdscst3W79kiWvs2d2+H+6zAU1xzagpj5Izs5nf2PpjKA6RX05m/GSMyqHlxRCBJmuaQrNSvVBr2lzQ7P7W4WmKFybMQ5w11XQFxMJS2eQzjAeqT9rHuEtTAs6FKGRYtkzPBibDx3noVxdK38OQsPYnw45VDUECVNBqU5DKOx86Kgp7uJW+EVfhVEbmtjUeIy9sV/gWjT7yQ8DInW+IrmNI2HVwDi82nQ0GfmvolxCO/MV9hzzj2NKWAieZRA7fLcRCTg5q+bpcpPkbpNy+XeP7r3i07Ee9DpWkMmpxXz/pN8m85UDg/Vk3HkGBTM9Q3r0gv8Sy/MTJ1hanrDHbmFUSnDk+mL1rU5krxcREOpFCQCfrSY6nfZ/jJtvlbBzQ+wKQinppcMf8oJRYEUcHvqBwKXxDRX6Yn9YJ3viN/JHQlgaDF/yz6kRHDb34Z6ljwnPRul+Rc3F1g7pqIbTgePjFcc589mVPgV0RXRhOUJoBiPwzlr6p6E2gs/FhneAY/fmyDSneRZgolaPOMacScjjOka/mokNsLr2jsxbWpOyTllCmaQszO4reZAtvtU7w4tt0UPPCc7etrLVxqQ4k2iY+TAjUFrp1egEtQJ/4SuFFKbWRmR/nh0MCLDbDMNv56w6sB2OmlBM656Cy3tNqc/OpmiQbjRcDHjTPCJHLwzUpaBDUit8D5lNy3QkI+0ySAMiPMzZOZoDQVr+XDWJl4LhdBIZ0B69OvDNkNE5S4YH/1wsqtncIaKIb7VFl 9brjlgNt sP4MFCXP3hcxgYYJkeC9+9pde0AUH1Le21i7MZJTSuLREvRKm2r0c9aaOY5Q5tyZr1uLfkfAa3WQPEk12SpAjEBC2DRi3A/KpVopZF4MmlHy3LIzxGvSh2Uu3taVoZtI/oYigMX3B8d/isI7RQ08Rnp1Zmd9s/LML759Ji+Ke4SrHpNB/wftDNZdfa/Gdk4ObojqXrtxRvxAW3byeDB3hztQA/utHHg2RZtt6ELStFNCTruOfqvkkDGtq4WkRIajRYGM8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In order to move the heavy lifting into page_owner code, this one needs to have access to the stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Signed-off-by: Oscar Salvador 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 +#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 4a7055a63d9f..6f9095374847 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -36,54 +36,11 @@ #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) #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) -/* 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 = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; From patchwork Mon Feb 12 22:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13554128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07DE8C4829F for ; Mon, 12 Feb 2024 22:29:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12FFD6B00BE; Mon, 12 Feb 2024 17:29:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 08E3B6B00C2; Mon, 12 Feb 2024 17:29:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAE256B00C3; Mon, 12 Feb 2024 17:29:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C7ADB6B00BE for ; Mon, 12 Feb 2024 17:29:32 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9D8641A01C5 for ; Mon, 12 Feb 2024 22:29:32 +0000 (UTC) X-FDA: 81784594584.20.B71AF14 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf08.hostedemail.com (Postfix) with ESMTP id 6897A160005 for ; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fxisH7+Y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jBQ05rww; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fxisH7+Y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jBQ05rww; spf=pass (imf08.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707776970; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=PvQmd8u03P0crGybekqhwD4bBe6rGxsmxc65USJ2EpplIP1xDQHpu2cdyCx4YnbFOBRn0I XDXjMNSGZ4DWqVd6OJkfigSsJIpdd8f2NT7z3/hOqlxI/eWy3MVLCi+mwFkhhMvyEE7Kv8 +6YfYsKQ+rPyZRE9m9HafoG6WFuZ2OY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707776970; a=rsa-sha256; cv=none; b=h6fRkC5AwvGScnEXr3vcFS2HMu+op7nnTQ347XdToCLl1GZmIe/uFscdtb4kVY6uxgjV1Q QvTs/Wc4rK6MsTjaO30HnQLGQDpBGppF4+ykKcJMGMX4SHGR9r08WL+DT0eZTWxjmnkXMP Um+30JSVgVLqU9ekcaO5/lckE3U0ffE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fxisH7+Y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jBQ05rww; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=fxisH7+Y; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=jBQ05rww; spf=pass (imf08.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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> MIME-Version: 1.0 X-Stat-Signature: tbatudbmmnsg64roidx6or93ezucfuwi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6897A160005 X-Rspam-User: X-HE-Tag: 1707776970-421498 X-HE-Meta: U2FsdGVkX19duobSbY7/CUfCXpB4GxIKrvS/gcFz7FOjjqjr8VKoSC9jA/Cc6Tkp64WKjv31YnHl8GR37Ji7v0cFxj/R0PH+wA622sO9TX/7ijfwoujRTg41crUhaQdHKr+rEx6sc5oiRZIRU9m5Z7RrUZ/MPf8+TrqCOxe5JQnL8XpHKNe7jBhuZH4lBwZNoGYqPG8zTP/qTdI9BSqwbWrqwVlY5St3c1n79SA5NzRRjzXkbCl6MYQDssQBm5+2x1jFRgmzIAFvTV8LS9mdo8JnGkWeYQjjP6EDE8pbrJP+vSyMR2QLX3WxNbxOLOAEVTj1c1YdYaI8zwaMoAjw+IS7II6BTXbpXY39s3/OCxI3t+sHTqxqlZEIpvLmMQsZYHB/U0oIYMDMArRoDXPIMzUoqJizlzufX3SbqsMnFo0OPuxUmnKQyJzNGBv/SAbPDJKVowlA6bEVnuZYsCi/MCuR5POzVX6vAsKNl+uEhJYpsCHelNkjqMrCP+HgmhZA2V0ODuOVd2GBw0SBoOR5SrNyZQp9lJ0diyfsWs2T1RcYUXABjlsPYZHvWnVOO+fw9YcFOh2j2yUwb76bpkvZtZ5Y2sx6NjuciTFxy6aeqamhsrfZI4nLS/MYUlHDhARUPTPI7i4T9CfHuZxp7v+HBkOeZIebYjrTvFC93TSthoPosJZh9AbUCLzuYeA8Z4dVr+kjFQsMC0QqDGG8gax/uvXw6za83oC0rcIt/YIeXHmaG3w9cdSsd0s+ZfFAGuovR1X5NylYaeMALiKLjtE+qf1Dmw3cKrxPdhjSq8F408taBuUpWFMU/vVPOnHRnkNqduc7aIOoyA/rt7U5NxQfE5pK/VCiizNa8pN9DjVNEhLMwXj7rukcPPTS9HQ9c/6mMVpDDW0l9ZEjxHpMHZ7NMSLpZer2F7sDrCp91rpygb6KtNd268WctHOcuPQKixlnTTw/BM47qzcIL0uIUbw TQi9Z4NL TNJLr0HdfVArNxj9WlQ98uGmbtjkULRqRSZBQUzqUiXq6wu35FD2V0+58UY0vzx+CajScbsfoBkM+T7INwlxdwc2YyMfCivJ3Xh/FU3SId1YjzTBKwlgFn+BqLpL2aejx8RUHjVeEVG2qLi//OeS7uv1lzhNDNM2Y985bkOFKL1roCHQtZNgvAPpwTESOO+WyGXV1SJocLGIAbJlQwyMoynYB09osbAJ8MgZwyQ2JZYQLlAqzzVZWOPBhkgwocettq1FQ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: page_owner needs to increment a stack_record refcount when a new allocation occurs, and decrement it on a free operation. In order to do that, we need to have a way to get a stack_record from a handle. Implement __stack_depot_get_stack_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 long *entries, depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); +/** + * __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 handle); + /** * 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 *entries, } EXPORT_SYMBOL_GPL(stack_depot_save); +struct stack_record *__stack_depot_get_stack_record(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..7d1b3f75cef3 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -36,6 +36,14 @@ struct page_owner { pid_t free_tgid; }; +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); @@ -61,6 +69,57 @@ static __init bool need_page_owner(void) return page_owner_enabled; } +static void add_stack_record_to_list(struct stack_record *stack_record) +{ + unsigned long flags; + struct stack *stack; + + stack = kmalloc(sizeof(*stack), GFP_KERNEL); + if (stack) { + stack->stack_record = stack_record; + stack->next = NULL; + + spin_lock_irqsave(&stack_list_lock, flags); + if (!stack_list) { + stack_list = stack; + } else { + stack->next = stack_list; + stack_list = stack; + } + spin_unlock_irqrestore(&stack_list_lock, flags); + } +} + +static void inc_stack_record_count(depot_stack_handle_t handle) +{ + struct stack_record *stack_record = __stack_depot_get_stack_record(handle); + + 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) == 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 = __stack_depot_get_stack_record(handle); + + 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 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 +207,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 +221,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 +271,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 Mon Feb 12 22:30:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13554129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97545C4829E for ; Mon, 12 Feb 2024 22:29:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76F676B00C3; Mon, 12 Feb 2024 17:29:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 71E126B00C4; Mon, 12 Feb 2024 17:29:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59AB96B00C5; Mon, 12 Feb 2024 17:29:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4106F6B00C3 for ; Mon, 12 Feb 2024 17:29:34 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 173131C1409 for ; Mon, 12 Feb 2024 22:29:34 +0000 (UTC) X-FDA: 81784594668.10.F5DFEBB Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf10.hostedemail.com (Postfix) with ESMTP id BE2A4C001A for ; Mon, 12 Feb 2024 22:29:31 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aO8sIvNw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IMz7vyf+; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aO8sIvNw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IMz7vyf+; spf=pass (imf10.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707776972; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=hWBFWjpLz19taj8wA5T96HFaBPCXEv+EQO4VABQOe72sHvf68bOYF0C9FkDlqFO0Cx88YR y4T1nQUCa4GN59+Y4DEowC6nLL1lnwvNT+Op/nPJodgLG8Ufds8XXSB3Dq/sdxaNsjwanV yTweFTWfl7k7tdWGv82d+q6sKw9UWYc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707776972; a=rsa-sha256; cv=none; b=ujZKDkQJ09xjeabgKsaa3A8Dn1mBTp8hfVPWfxbYCOkSEnwGYAUN4GSCy8VaZ9av1wm13X ERetBhZ2xRNRWzvCYVmE5ssS4ZVjw8AEYLxrhKxawmZ/TrOUJL5ANNerGVqfF32y/2l08U pCNO/K+iV1OWZ/duIpt5XX9ftReu5Ts= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aO8sIvNw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IMz7vyf+; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aO8sIvNw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=IMz7vyf+; spf=pass (imf10.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: BE2A4C001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zca4udjqz1jauqokd1i9341thmx3u8pd X-HE-Tag: 1707776971-138070 X-HE-Meta: U2FsdGVkX1+YhtW4qMDHe6QUmEfjfKX4yEOI+u6ep4FBomH51uXJnVomXpVckt/GgyRqhMlhiRxkSkY1s/ULmxQswBX0e8G0/x48dcUGcZAYSXXziHDfPlUKPiTA8weZDogyrJ7Lc0cZyVi4dCT9/ThSOl+iJZ/pRaCNkvap0QFKMkphCLINrkQri3djXYGhD6sa/a+HkAEBnj61QVFR44hP8NFchOkb7ScEH1asX7Jg+Ggq0zXhtHw8XVAu9mMC+6I8Qc656VAlR2z++xra+7CIM1+TCZS1Jk7h3zvrsTKDmx33LZwXONSH0fPBeejxI7HO1upSKl4V3hQ/LfN1jDQutG/qcR7Canv3Css+yz8e6h0CFRPXYLdQj8XRR4OI1ysWjmRT73F9HjrLMzKd/MBkHXIg4zhEJib8t7abXw5WND/PRs3rxUbcmzoLGiRV6uqL2cq0Xn/Nm1D/I63Z2nE/l2o/zauWvV07VnpYAnmORngulGQ/EIJ4Hd77MCxIc50PpI6kjr3h5JDoufTk2SoiXpTUhSfeY+fhIZkBMV9zsuwYjF6HuVyC8SsVscUtyaBlut1KB94RMeAkW6tLJ1cN/xEpGuuN8euwyKHcZzek2KIB1XlTv9hWNnkoGOiLEsUXoQnZd/juEc6dyt7tM3Zv+PXm3gvdgGB4d6mrwbvoiJ1Lf51AhUyw5/Ikr+uQqUndm4euIiI1cJmU59GWeEGwCV2dd0RTl7HRBLZea29Z/QdDccQKSgPt5N+fUl4oXmUvCPGrbEt+jO9sLiPiPP+Y22b/9zq9uVzETgvnpZHKZfqI6qnq8PUykBYQAYEp8dDKAaTN0cIGcCne+3CHd6S3a7C3W9pHQyX8m7YPLif3a3MLYfw60Q/IyycEMdWN9b4tTJcT5WzdSzDpaTlk/CYLgEDWGOdVnorWpxha9gy+ZA9uVn5LZx4dRkVuLx0dfBsitOdu1gugusOyfw5 wjGao38L WNk78rUxeb5rwssRIzsajRcn7pQopemBXDCmz5hfau2BeE8oD4xrTRXPcX9QsgmeJWkw4zlZ71gT69BK+VvINAFOrA5cZ9mf/+ts2hi9S0zTK6Bp1SEH8RhfPqd9+xEtoOEsTOcs8G+aXtLPK7+uTOygQGY7arnpanBUzXdVnq5E/wwYk6AmyahFK0g+IK4tiXnn5n4e7+Z8jDKwtCXJz3ILTVACSzBJYK3wAeDuxyaXYlX76UvMe+dULhRPe6dKAQs12 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch adds a new 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 = stack; } else { stack->next = stack_list; - stack_list = 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_operations = { .llseek = lseek_page_owner, }; +static void *stack_start(struct seq_file *m, loff_t *ppos) +{ + struct stack *stack; + + if (*ppos == -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 = smp_load_acquire(&stack_list); + } else { + stack = m->private; + stack = stack->next; + } + + m->private = stack; + + return stack; +} + +static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) +{ + struct stack *stack = v; + + stack = stack->next; + *ppos = stack ? *ppos + 1 : -1UL; + m->private = stack; + + return stack; +} + +static int stack_print(struct seq_file *m, void *v) +{ + char *buf; + int ret = 0; + struct stack *stack = v; + struct stack_record *stack_record = stack->stack_record; + + if (!stack_record->size || stack_record->size < 0 || + refcount_read(&stack_record->count) < 2) + return 0; + + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + + ret += 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 = { + .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, 0); +} + +static 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) { + 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) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + dir = debugfs_create_dir("page_owner_stacks", NULL); + debugfs_create_file("show_stacks", 0400, dir, NULL, + &page_owner_stack_operations); return 0; } From patchwork Mon Feb 12 22:30:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13554130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E576C4829D for ; Mon, 12 Feb 2024 22:29:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 107D36B00C4; Mon, 12 Feb 2024 17:29:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03F0F6B00C5; Mon, 12 Feb 2024 17:29:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D867B6B00C6; Mon, 12 Feb 2024 17:29:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C09B16B00C4 for ; Mon, 12 Feb 2024 17:29:35 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 94235140172 for ; Mon, 12 Feb 2024 22:29:35 +0000 (UTC) X-FDA: 81784594710.01.E8A3A1F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 86C5DC0011 for ; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; 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; 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; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707776973; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=ARJCUmafe0EhLnlqexBZJBnJyIH4Bb0D8DqQ0YMQYIVhFG6mxJoyg9sZKhHY804fhyLCir G+RBI5MerKTeTCCTHn61KRW/zh0pIAmPJG2Q/3VDCyuLK/Wzrwt3BLEyNfHbjePvnv3R/R 9XjTnyFjBRt1DiLhOVLMJptGV3KeZ2A= ARC-Authentication-Results: i=1; imf28.hostedemail.com; 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; 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; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf28.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707776973; a=rsa-sha256; cv=none; b=B+MqfNKaLfZ2TueZDE/YIwpG6oBrA9LeMTht7s4RSzde4/qn+vhzwvg6ECLR58lFfDqcF8 D+2lg9Ys8sAzOOow5GRRMl6kk2vrrg9L6kFRBX5myrXEBa7tC7s0lZXF/nspsUs7uWP7C3 TZDBWit0+hvjwmgPeAoozaVBVgvFFkA= 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> MIME-Version: 1.0 X-Spamd-Bar: ++++ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 86C5DC0011 X-Stat-Signature: j6sugk69u5mnqqpganuet34j1a8qddgx X-HE-Tag: 1707776973-227369 X-HE-Meta: U2FsdGVkX19DxCKCdFKDCYk5JFmISREFIUn6CFaHS7pHgYsFEJs1FNlVCKcDXaOhvhVuFW9DvcfINAZ3BVgcEtQYEhm3ST2sLeR4TW8lm0VllfC99qcTU4f2AHLhV0TyUaPHvMbtjFmh+Hc5uYi0xOidbLgTx6LG0oChRMfHR8VKQXa+QnR+uY09KoU8iqp+dWx9YtybgdQJsBgbVEcUxVBHJDdzG6ArA2HEPCuPuoz7SqHJ6usLJSrhB419g8O4b8wrO9UG7I6RIHQhMBzqGHD2r6D3h4/u+8uDr2ohpr3jflREFWEIDvEflRHysJOz7vUwt/RQ5a/gohAAA31JxauDfH6XUh/cSamcXyA6eKNOyU3XAuQyVKMQSYYS8JVhdvWsvKAI7b9JyiSBbpfF5D9dxxYJ+EkKHSMbnXoQ3WoEGV65L8yJb7AHUFSAc/mlapfeTUoqqEU+X1p6sqEHMFgQqkoikAa8nSbQepuZzqDVEB9aI5AbNEPxn0A4qK4PNVm7xGNHZ+IhU0v/sqYXUx6xEY00BNkptKgWjC/J/SR2Il+Buy4mWKTMbX2W1VQ31TImT292W9vekDBWec5mjIKIQJPyN5oI5iNbJZ1xC+iU0DTGilUMYplqAOmwLCWb2Z4JC/GPkuK8t4gM5pm99eDLGQumS+p0cB2RPaqX013qGzybY6ueUPQx/VkGjuvkGjqmX1vvFzsnpKTqJOqxJTKdfehxLqfor9Ave8vO9BUBin+ythbVpVX1h0bmaMHxOcsa3FWuqiC35ilw1k5jy350v0NvyEDNpo5gUus9m8DJP3/qA+uv/byGWSGrCObFuMnqlQ+CTr77ammyGhv9Jy/sB1vevyMeMBhReVjy9f4fC4fr8fk+qL0TTjYFDfIJwlYsA7ALYx9DhlDqfsgNwkCNtkZvzt8lyOGZwfbbslEitqxtCPvVeUzhV8mK0Gdv6qdtQPql9ir8iMpnq2H YyeEWeYV rIUNx1dkl5B7QzMebhsSxSbCp86haAc1wrv7E X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to be able to filter out the stacks based on a threshold we can 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; } +static unsigned long page_owner_stack_threshold; + static int stack_print(struct seq_file *m, void *v) { char *buf; int ret = 0; struct stack *stack = v; struct stack_record *stack_record = stack->stack_record; + int stack_count = refcount_read(&stack_record->count); 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; buf = kzalloc(PAGE_SIZE, GFP_KERNEL); @@ -851,7 +854,7 @@ static int stack_print(struct seq_file *m, void *v) goto out; scnprintf(buf + ret, PAGE_SIZE - ret, "stack_count: %d\n\n", - refcount_read(&stack_record->count)); + stack_count); seq_printf(m, buf); seq_puts(m, "\n\n"); @@ -884,6 +887,21 @@ static 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) { struct dentry *dir; @@ -898,6 +916,8 @@ static int __init pageowner_init(void) dir = 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); return 0; } From patchwork Mon Feb 12 22:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13554131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1CAFC4829D for ; Mon, 12 Feb 2024 22:29:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F11416B008C; Mon, 12 Feb 2024 17:29:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E97FB6B009A; Mon, 12 Feb 2024 17:29:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCFA86B00C5; Mon, 12 Feb 2024 17:29:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B58A96B008C for ; Mon, 12 Feb 2024 17:29:37 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 86C83120387 for ; Mon, 12 Feb 2024 22:29:37 +0000 (UTC) X-FDA: 81784594794.15.5D7A489 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf03.hostedemail.com (Postfix) with ESMTP id 33CBF20003 for ; Mon, 12 Feb 2024 22:29:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; 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; 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; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707776975; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=8TLWthE1A3NWSYaJKOEdOi+fNfxFGNmFCf2zoWMK16zYxAavG+6T5M6ht1KhRHCrZDOSI7 84CXFeinup4nssZFxOgS/3tWGfhwI+hHJqGyGqi03r3PKBeShu01o4Hb3VF8FRcKCVxcfS maj/edTuBN0QBBXK4y402dRN+nUpWUE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; 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; 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; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707776975; a=rsa-sha256; cv=none; b=xlH1fNQGairNqMazC20wURJA1SNBqOvszc+Da88dPVW9iwpHJGWgmJ414krkZhtyKd1EFE CKRYws3ZJRIhahjGQo3u53C+iYv9Dyo955jL7atvktREi2fMr1QNHrGbL8cMoN26K2pQ+i gzoA4G1RR3bdF6AZ1cSuPQqsWRb50Hc= 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> MIME-Version: 1.0 X-Spamd-Bar: ++++ X-Rspamd-Queue-Id: 33CBF20003 X-Rspam-User: X-Stat-Signature: ht8qndqqrcqbhri3ndagdk4ug4m677nf X-Rspamd-Server: rspam01 X-HE-Tag: 1707776974-360667 X-HE-Meta: U2FsdGVkX1+0QLRBJZlpiH2yl4CH3iMKpIhgRzO6nqzcIJg0Sz2tCcGbgKQMdIvFParmOzFRn69cxQijQN9VyWASYZDrGCTaZp2sKDHo6I4jcUyAk+e9u9MhY79FQ1+0k2UmchjK5Q3zax4KQzIMPTM99uUCpVtzFbEOt33YLW/d/+avJI0qb2FefP2oLFQIh7ZMXeGKQ9S2lhx3ZMA6JkEj+LaBB+RV0PqLu1HlbV3B2yGhgNouJaxrydtdO1sa1x7j4h7GH9e6bcqW4D4zIBxQC4ghrwK4QWt/MRKlh/rCSB44OnNkwRVt7n2/1hQREiVkcYGd584BezpiVD9qHRUeRE8aeSLt1D6NYsvCBpagD9mPOB5QIGbwMBYfpicZ+Ycn1P0SZOoU3nUDTWEydjvpu9O+H5QnSQBx885vHse0OEcX23vvxU9dKLUN9TNZL+WkHSuIpEUatgAQnL9mHBOvkpoqoxoAlRiZUqnq6mZdbqkLYGr6wJRjMTu2t6vyc6avnESs4+vW+0UZi72UJDD8wMPGJtDdcX7JxZDlPm2wBhmUkv+bIjL/Zah+G7yhHYzLB/qgksbo+Oy4OZ0GH1oaxXHOIPOBa5twmMG3FZxDzE3Rt2cZ0H/LNNMjKUa0kejVdak/as9/OAft0uWlympyEGfTI86ml0g+Sn36kMoVEb4xHSVW/l9zpFylTjf5YLuiZc4Ei9HONvZluldaohtkx3wA8bafJx8uS13QndrPEwYRvu4NpStX+w4KGKuRmzg2/xVgi5bRfIkLBPQ5VKGgVZQ7LRtEvMBfEghhkDkYLdq3UdAJwmTJo+KZW39s9M/VyYIiNDdlKOjDhinpllQ+za/CWeilNvrnZGMRMDjTIOb88mIKAHFEm/XPTWBwoNDKrddNjMpVD7NK5NvU6CZQ99mHzbGST95m3fFz3yQJ6rbGjNM9h1AdAdwdMDPG5yt1ANOMvqmTe1A5rer m9ksVhS4 vDzdYPUMHrMF50TtZe1jI/U3lz0w67LoVgQ8dZmexe3fA5FDuMIqFzNJa87l15inVwIRelxBOxxUKN4IFbLssyRM5MGoQnBieIr3mLmQHh5KodDSXmXm1AwuCLy/9MtHGuAX8ygC5y6VR6tBHqmYkhFd1ZKRlZblfY398iJEqyE0N+Po6m1IZNCuaYhVcWaCb9jOdg2vQ9RUhoVo/+Xe6X88TLdA4tRpvAzAOYyWuHYrJofEMNIPb8obNM/lDcy9qyAqB8GKvzhXu9XrPT/tgiXRGRg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 flag information of each page. It is already implemented and activated if page owner is enabled. Other usages are more than welcome. +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=on" 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 4) Analyze information from page owner:: + 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_7000.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