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: 200087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp200573dyb; Mon, 12 Feb 2024 14:30:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW3NVguDyAlp8yydTr1hJRyLGBdUaZzgKXzDXs9SH8rSRWrgQ8o9S/13xupSNpRhl6buGXakD3zIHpx+NFrIMfax4Zl7Q== X-Google-Smtp-Source: AGHT+IErTWOw3+bGIRoF3d4KIxJwD9QGFPmgUpSxXuMMxEF8CXPyeJCV0fF59bMAXK0DSTDO/nR7 X-Received: by 2002:a17:902:6b86:b0:1db:3575:b495 with SMTP id p6-20020a1709026b8600b001db3575b495mr59283plk.29.1707777006894; Mon, 12 Feb 2024 14:30:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707777006; cv=pass; d=google.com; s=arc-20160816; b=VkKuQm1wp5u5ud8YZbVByKQTHPVsNADNFKm4v65CIVWaGYxzeMQ6TNGXG5Ux1pZJsW O4SX6rALYzN39Ife0ySCwaN6qrmJSGMkgjIV1722q0BLg0D3wC7YTtLh0p9j7SGYYEMX 2pFeJmmbT1wn16TM5qWA+AxzO/mtco190xgxEjB3wxY007kFmHtJIjeJgkCEvZdZpKKP sIiXLqj9KzH/Scc3LU+gEAps/FBImwuq+hgq6foMPkY4ArMgkb3YKWW1p045q+7JTGuY CjCgisZGQHtw7tC7DVo5OnRV8/q+e12ZyVXotNez+8+BurXQgh/WCUMMInTEetFgwgEu uGUw== 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=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; fh=cy9s2g38W2mpHbUNs1mwbOWzQYZ/I9Fy5nE/K5/ycf0=; b=Pe0TW9Wf4F0Io8JTOA2gaDj/DlJoPUZoCtGdUWaXun+z6c8akT+7oXeGPpHmTbAjFF Pmj3iddCMLY51ywmWUBGaVv73Vw01vxmjUz2fqo92UBFpcA9gUhZ3gfpH+9bz+UJzKt1 QD84qPLKr0F1/QLTYUj+OhUvFzKxz57KokIB5uPSVlP50BpoJ0ERImPYphvRbxzJ5eg7 tKgBXpMGHdL+6XFGIhbrZdoBHmVBBpt3Znr50pIWy8XgHYr933HjV0hVyqJvmoCwyC1e pWydUMu52AFnrpYCBFHZ7xu9SgPUs1yi0UMPoZU6IlRMsdtZ6FRUD6B8PwWc2j4IcC+r lU4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=2EkLibh1; 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-62478-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62478-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCUuBgDzBMgoZ7nSN5imLBY1a+s7tYrZ4oIZwdGzSrfyaAdgvgrbBQoNsqFa8gmb1ZxxrUObGN82yctJkDb1u2ErDawrMw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y5-20020a170902ed4500b001d5e9f77cf3si878712plb.79.2024.02.12.14.30.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:30:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62478-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=2EkLibh1; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=2EkLibh1; 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-62478-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62478-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 EC1A9282324 for ; Mon, 12 Feb 2024 22:30:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7D014F208; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2EkLibh1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tC+Nwu7M"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2EkLibh1"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tC+Nwu7M" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3421E4D595 for ; Mon, 12 Feb 2024 22:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776970; cv=none; b=I0ua04nSzLt4C1OpvEEQFqA7HQb4yIHY1EMg8bpNEFn+qSQrAkvxNy24WSietk2pNyf/cFZ7tOUHsfZ3ov9aet5U7Db7rZ3O+OXRLXw7oXBRgBDqRRrugdQS8GF/hgHFTAaLuhxdhSM1RORzlcvyG63CkgIVqs14RgHQ1w1Myx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776970; c=relaxed/simple; bh=4Q7KJLy2PG12CfEApH1U9an73DqUlm1TwR3tb7XObzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hmBlwiWZAmTvvvbiFFSeh9lJ0gJFpOX4rKAnt3rcgSuUDoj5Qg1+dMsf8NYYWXWs1K3APVLogJrdbMzl17OYSC2gMa473kc99tpSIHwOL4lLTIURpUpU6N3+OtiVvHkWLSsFuWfvSBKZxSBbL2d2tBBpofO2BLhq9GrgqMeonfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2EkLibh1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tC+Nwu7M; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=2EkLibh1; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tC+Nwu7M; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 60F4F1F46E; Mon, 12 Feb 2024 22:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776966; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=2EkLibh1T0Fpvt5mQX5cxgPHMlwcw7SrPLaJ8HP3vpqaLlAPLEjfjZosemRKQVC7usQktP iipLG7yV7zr53ZKaC1QpRqsfGkDShZY3d8MRRXjgN/zj3vssnEC3Kr02aK1diL+lYxp831 EUpqNZHOw0EC9jd3i3AWNhl0i28Zc64= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776966; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=tC+Nwu7MsfACk+TPLrMCNykGk2INKq1bt5vpxNJwB860dZMWrxGpymKG8NT0/qgyClXS23 bRvhU3JQLYp9LpDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776966; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=2EkLibh1T0Fpvt5mQX5cxgPHMlwcw7SrPLaJ8HP3vpqaLlAPLEjfjZosemRKQVC7usQktP iipLG7yV7zr53ZKaC1QpRqsfGkDShZY3d8MRRXjgN/zj3vssnEC3Kr02aK1diL+lYxp831 EUpqNZHOw0EC9jd3i3AWNhl0i28Zc64= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776966; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kxO9mvfKurSdueDhnN3nx9fh6LQJs6PfoMaU2G6mpJQ=; b=tC+Nwu7MsfACk+TPLrMCNykGk2INKq1bt5vpxNJwB860dZMWrxGpymKG8NT0/qgyClXS23 bRvhU3JQLYp9LpDQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 5FF5513212; Mon, 12 Feb 2024 22:29:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id gDGZFMWbymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:25 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v8 1/5] lib/stackdepot: Move stack_record struct definition into the header Date: Mon, 12 Feb 2024 23:30:25 +0100 Message-ID: <20240212223029.30769-2-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790733982922953924 X-GMAIL-MSGID: 1790733982922953924 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: 200088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp200760dyb; Mon, 12 Feb 2024 14:30:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhIZ2Hn7Xc1ZFm9kh53SooxstQb5Ogt1Wb4aQZUr1i6e7Jgaw3mxX4WGzvdcX8c5MDwYo8 X-Received: by 2002:a17:906:68cc:b0:a3c:908b:b95f with SMTP id y12-20020a17090668cc00b00a3c908bb95fmr3611572ejr.14.1707777030674; Mon, 12 Feb 2024 14:30:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707777030; cv=pass; d=google.com; s=arc-20160816; b=Uhp9Pjmqwil4JYl3I8KHUpw+v49mYlieFWddV/IOF3m+eamZ1SyQ2QyXEs9VVNyOw+ cOyUYIKwJwJQtT1qoN1Csu0ATPdIPRMmx1zD/qaHruEV1vfgNGWb5PAWfkm4NEef6GHX ecG8rLaSnx2S9npBwfFE2sPXcx5N0fKHEMyZLgGu2RBp/AjW66ieKyPJA+xIG8xxor50 rC99fpo/wbl+CKz7G4uhfFZpBbm2c1Hkq90qiOKGgmwYZa3iCaBP5bzePw/LpWEgIaoU OeL8SGgxcUkgktldNao41r0dlyEJf9hNEjBccsp+Z6okpjfg2ylX/QZUVMtv85vE3dco 1jSg== 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=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; fh=Mv05bdW1cro5Hnw0QyvzsprETMxw0VwMP4XRNM/by24=; b=z6bUNmkBaZ8SUQX5GjMFfGjqMNrcoaU9oZWWMYN72kGllZ12k4LfWQ7me1kanZvF/R qGhp9i7C85JvKqJw1EFugDg4IZ4Aze3lei5EfAQp5cQP4IHDx00XcoqbCXBB33RDaUNl JAtginCQMJYfC5KBP4fJsogQGA4L1GzPoqB8K3As7Ns9SPgP1MRM9AlxmNVa2iTMk232 MYA/BotqNEug15n9IajWlQMdcY4PSRcdoQKvxn2HihE38opVi3QyTGbUWBGe8tp+PFMJ OnSOZJIbQkF6ip7I3na+e+GDhjloQJbm0GDlmbljTYecs4xioF12T30amf4wynv8GpOU BqQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxisH7+Y; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxisH7+Y; 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-62479-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62479-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCVdsbcxVASE8mxsLX7LEClGcChlE/Z7KrZ1ok1ypEEMocFiRLmu14jjj0mD0Mz8KO24vQ1Dp0AMYjD2FhyKhjJUveMQhg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v14-20020a1709060b4e00b00a3cea6151b4si303134ejg.283.2024.02.12.14.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:30:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62479-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=fxisH7+Y; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fxisH7+Y; 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-62479-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62479-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 1D1E81F229F3 for ; Mon, 12 Feb 2024 22:30:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED72350246; Mon, 12 Feb 2024 22:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxisH7+Y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jBQ05rww"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fxisH7+Y"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jBQ05rww" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC9D74E1D2 for ; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776972; cv=none; b=IiKutnKoa7T+QOeMwbkITAb1u9trejw9FT2Yvd3ySDl6ZWkhRkQqM2uDaSuQ71T8ut47Ztkzl9xGOsTd+OJTyDAGhvi+RN5iZFg6M6QgYZBieeFvn8Poh5FXpnB7TIHCoFvGrB+zv4/oChbiSSAR///crVpFGh3bUKHEu3NgAe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776972; c=relaxed/simple; bh=gNFCECv9ePcmxaUYUJiZyIxZAIAz5HmsoobEzrrMM3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sa1rHXjnS+nRm2p5hsUI9BuznGb3q7ewZi9W3Lt8q3GPQUxjQal8T9lGd40EgZdDWZoNqu0LmunFnDbZEF4mxM/xqKXIIKxeVnwTqaeKgzeB2E7tJGep2hZS5FqOjeSrriht4VGtYbggGBSPBb2IKRuEN8ua2Ti1+EhfGeMgjMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxisH7+Y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jBQ05rww; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fxisH7+Y; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jBQ05rww; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BB3B822177; Mon, 12 Feb 2024 22:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776968; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=fxisH7+Ywg+k3MLHTeypNE73ysJ51gHcpfkHzqy3ymHFJbJX/uV1avZt4d5LfFRP+Gk2R8 UhDuSi+c1JSPl6b0CxwkUuFd+e26s2mCanskxmQbtGBrA8cwXd6Ut0I4Xcx16UlZHtim64 sjp+JOIc0pJnwhoBvrw4KDnjGOCvQVM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776968; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=jBQ05rwwCs72vdAdft1AuBuwuzSrKzDP73TbkM1+0nJRjhxw9YOi7rA+LeU2IMFi7vCkod wqJqqu+Eo9oTaRBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776968; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=fxisH7+Ywg+k3MLHTeypNE73ysJ51gHcpfkHzqy3ymHFJbJX/uV1avZt4d5LfFRP+Gk2R8 UhDuSi+c1JSPl6b0CxwkUuFd+e26s2mCanskxmQbtGBrA8cwXd6Ut0I4Xcx16UlZHtim64 sjp+JOIc0pJnwhoBvrw4KDnjGOCvQVM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776968; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDeumumoHSH5oo9xUAbNOW5Kp3HxNHVXVwRc820AXk=; b=jBQ05rwwCs72vdAdft1AuBuwuzSrKzDP73TbkM1+0nJRjhxw9YOi7rA+LeU2IMFi7vCkod wqJqqu+Eo9oTaRBA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 82E9413212; Mon, 12 Feb 2024 22:29:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id CGxaE8ebymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:27 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v8 2/5] mm,page_owner: Implement the tracking of the stacks count Date: Mon, 12 Feb 2024 23:30:26 +0100 Message-ID: <20240212223029.30769-3-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790734007260813828 X-GMAIL-MSGID: 1790734007260813828 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: 200089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp200817dyb; Mon, 12 Feb 2024 14:30:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtfj3jSRVzC7IWWB+CPzsNLr5cNLkV+l5pKxvT+M4FoP85jpPDqMYobwd3cto5bIsdqVMH5RNmpLqUByM4UW/rW2J42g== X-Google-Smtp-Source: AGHT+IGB2D2uHuWARkiNcYmsjU3dsDqcoiGS7hp9FxY7fi9TQiXthzL6ublSK9mmwuaMa1Xagc6Z X-Received: by 2002:a17:906:da0c:b0:a3c:5e3:df84 with SMTP id fi12-20020a170906da0c00b00a3c05e3df84mr5134540ejb.31.1707777039784; Mon, 12 Feb 2024 14:30:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707777039; cv=pass; d=google.com; s=arc-20160816; b=GNYvsg8aqncuAFzSiOQoT9DO8TIyZU6Z906PzHBiBMazyF0puaeh33YEw2xZtFzKtn XpiucDRnJUWDD1m2KXOOmyrV91WSyaQ87D7gCPOo+emIVcZ3ZY3CWXE6QKHkm8xocTqz ONa3kExHy42mkkdIUThrWGCjWe2yjKz+i4e4n1J5sUXRKOQsHZPRDdVfkjaOYirXeLTS BuNZR2FClzZg2k4EA9hmdqeCEDSu0NdCOHz5NUbvDoMKtE/DK09I/cEv3m3WVv4KEdU4 kcjRMIUuvA5+zXbanvGVGpBxh3DVq6t12pGj0V+mp/+xP3dsVXLNkOcw/MzqKsCZlVcO Lvrw== 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=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; fh=/a2K6YjvOr5qbABnP4J7WLeu68L34XolGfhm2JAouIU=; b=CdvK90Uc+V5xDcBLxOBTyYIKSDunrFwrVBrnNYd8I1RlwU1TU4MHWa4+/SEELCm3f1 j4DNKCgZScK+QTdpDZCxCoXCwiri01HqNZ0BS8+AmF6ryhI3se4S0elO/DndyKAoy8nu f+RsaxZPaGDCZeUYHGoq9Iz5OdnSbUf3W2wk/DB0jXSjhOJOXgrzpiOm4t+Ir0uT7VWl X9qn0T06m71rCT/aUSloRZr+hCfKddCpasHE0YZv9Hs2Qm5bXsUdN6Lfh97QsR/nLQnL MGYq7a8pohzFpzIAORkFYI/1gzuGcHd5AarvlTMB7oJcBwVQutwxBhe9+nMFtvhzsQ3W zVtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aO8sIvNw; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aO8sIvNw; 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-62480-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62480-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCW8PW1Boxwk0W1JbyxvHPjVDSa+vIkv/ht/84fs1ZHeHRerNhKK8Gp9gsAbeuM4X8KWfDftKkV6NUUR9y0VJZrVbfrB/Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j5-20020a170906474500b00a37adf06a45si557561ejs.258.2024.02.12.14.30.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:30:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62480-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=aO8sIvNw; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aO8sIvNw; 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-62480-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62480-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 384601F2285A for ; Mon, 12 Feb 2024 22:30:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B02144D595; Mon, 12 Feb 2024 22:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aO8sIvNw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IMz7vyf+"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="aO8sIvNw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IMz7vyf+" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2CCD4EB34 for ; Mon, 12 Feb 2024 22:29:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776973; cv=none; b=LmqbZtN6ey2xtTH2DND4M8Juhy19aRf9FLZtnDsIJGNfagw3qtFgfA5sKYUgyfSI+iNDAtND8SoMa42ua6pQJiNkn7r9HjtnCKa7CT4b/FLnxW3TGCOuI/B9fUr+llcPrYK8SVZv+FvfcO1dsfO1RaemH9zKoof3ZF+twjFpDEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776973; c=relaxed/simple; bh=PslCDCM3yg1q5QFWu02AeTqtUBHZaW7ctPxFlrHtAsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rauubtk7JUTCwRbPpR4noMBI8JrpzHf+5R81rsJa7Rd0RguenazMHLO3uwXfQ/7PY6OhyStoh1TdBM5boua4X9b6qV6l4w2hPIJiG2aCpmP/II1j0nFMWiiOtQ3iNjxIzbv5SNSi2BYlK8monVaU9sY1PwTHsPnZiuHWx8NvdA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=aO8sIvNw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IMz7vyf+; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=aO8sIvNw; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IMz7vyf+; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4330622160; Mon, 12 Feb 2024 22:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=aO8sIvNwoxgZohBoscNS6wvlgcWjwXje8eEteMwwtBuB/+u2WRUjh8NwW4qXahgHFoOv/3 /2MuhVHGZzW70sU0W/+D51GvcRLU9+pVPIMz7GxwfGGqH/5FTYg667EBvytadc8R/KNzwU i3X2tsgY6Ob+sgqpA4KA0ngkfibk9tQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=IMz7vyf+FqsnnTqxhLZ2ZG4SOkTO2sPVHymdrZdBtZvjkwp8tB+6RN2TSyC8izEmJRrrPE aY8LnAReVrEaukCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=aO8sIvNwoxgZohBoscNS6wvlgcWjwXje8eEteMwwtBuB/+u2WRUjh8NwW4qXahgHFoOv/3 /2MuhVHGZzW70sU0W/+D51GvcRLU9+pVPIMz7GxwfGGqH/5FTYg667EBvytadc8R/KNzwU i3X2tsgY6Ob+sgqpA4KA0ngkfibk9tQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9GgOB2bpckE3olLSUoq4h/Hy5/g1rCORxaucTcFT3o=; b=IMz7vyf+FqsnnTqxhLZ2ZG4SOkTO2sPVHymdrZdBtZvjkwp8tB+6RN2TSyC8izEmJRrrPE aY8LnAReVrEaukCA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 79FDA13212; Mon, 12 Feb 2024 22:29:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id eIdfGcmbymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:29 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v8 3/5] mm,page_owner: Display all stacks and their count Date: Mon, 12 Feb 2024 23:30:27 +0100 Message-ID: <20240212223029.30769-4-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790734017060122311 X-GMAIL-MSGID: 1790734017060122311 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 --- 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: 200090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp200938dyb; Mon, 12 Feb 2024 14:30:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXE5+b9+7rjxtmemU+Rsfgj/X7IUSyhsKy+SJZjAYfo2M3yywoWCS65HnOoHXWamgBdDNcKDB2k7NSmRFrNKgdllGvoZg== X-Google-Smtp-Source: AGHT+IEKO95LubTmKY151U9sL5+0NSdABZKd6YervkpxKOUVCW4F860paMX/BbpnXTM+zTkz37fw X-Received: by 2002:aa7:c3cd:0:b0:55f:f608:9f6a with SMTP id l13-20020aa7c3cd000000b0055ff6089f6amr6885912edr.7.1707777053432; Mon, 12 Feb 2024 14:30:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707777053; cv=pass; d=google.com; s=arc-20160816; b=JP3TPO4JBINhYotu0dIwKkS//7L2sBCHyo7UvsO0voT4OnpVaQas7MmBCknwK7h1q1 MExJQgmuf+8WfwRvHYaZX1oOdPJeifyFyOfZBGRngxMr8NbKNC6/EoGfAei2LqMACW9f JnFFK4kvpqkHb6QOrE+ob8WmWjtHh4quHM6j14yJRpRybKzSDmx3j0mc3HqIPhQZi/ic yfgYeCkNS6LJn/1Rfk/gZrajlFgh3973ObOOcGEKY7/GN+CRALZFl9kC8MnW2AsWRby5 l3HoB4Vh4/l1rImAHtigHruiXrta5L9DbBsgsljtaq24pnRbFG11FvuyogP9TcX0HYBa a1MA== 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=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; fh=WMfSg1rlqJpFzIecZw3CsyL/7HvU4tPOWZN22LIVNck=; b=ONQh2M2v/bI7aWFa7nTOokf7r/TPpD1jO+GH6QIt6CvNwGUUHJhpt11opVSodnsJi+ HjHlQXeOSRoEXqFox8vzOiiIFg34HIcznzo+mZRYgYpso6bc42wVFXFToB0YlcdtP+ot ANv3YsXammU1sr9UWG7M3MrcwCBabfSx/HPLTjEZQidc5Tw6JMc09qKnHyrYzcY73UsY V+dFJdvjiLyPwVt3kns9DoSyOgziSKXfrjOjMiNzzkKt3ge8SjptUwQemOahQ6blRP+X 9JiPFNExEbYQEcnM45/TE83rCmbuDjGA6Q1ECSWRfI3nc/PGioaQ0txSOZ0k5DpFUTWz qf1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=U9jqloks; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=U9jqloks; 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-62481-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62481-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCWqmGid0SlAeIOe7i5ZkAu62PBZRAoYxlIbxM0+N784MWw9bNJSAVUXH/E4QP9+4ssfdSUHK7PtHToeAuIdo3qAKYg72w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c28-20020a50d65c000000b005610fbeab8dsi3025806edj.589.2024.02.12.14.30.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:30:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62481-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=U9jqloks; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=U9jqloks; 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-62481-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62481-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 D98EE1F22AF4 for ; Mon, 12 Feb 2024 22:30:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E04D24E1C5; Mon, 12 Feb 2024 22:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="U9jqloks"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TkinlWVz"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="U9jqloks"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TkinlWVz" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCFF94F20D for ; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776975; cv=none; b=R5IxBPp9MZ5X4j/mPD+baWk2cOl1jUH7zowjPwQ73fTjp4/OOoO1Yycw0BOa1ipPG9Yg7XeESRfplHWQ4CwKd10CrPYURNx+AD/+afJBcW2eKcJZuttdOI/Rz64ZL25kCXeWh48JkNwUacYJmrVdDdINc0dpScGnzpfu3T6Smmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776975; c=relaxed/simple; bh=0UjzajfUgl8WMY9SKpR8JzCcqPQyXSlET4DvDtf+pFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V763CoWRG2jwKANZFZgJ3wESnIZEgS/b1r0zZTKaLR6NUH0n0Iir8AMxXgOILsMsHUqq8Ewqs893qCqfnX7MW7YfWhrbyjroQm6btVexeeTVgDkjXe+mjyAQ2DTnABHbxFVhp6Y3GJPMgj0Q5EXEjLhCEm1YUafRFBtZV/VIqbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=U9jqloks; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TkinlWVz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=U9jqloks; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TkinlWVz; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 11AA7221A6; Mon, 12 Feb 2024 22:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=U9jqloksGUrl/eNBRyCLYgfj6sduFcBCUrcWKDHpeXb24Ugicd6lmLa9UnYqfvX0TuXKS7 9r60PATmtHzXICNvsY/UL9x7L2p6wP0/4TGbvNQuYcsO/8DGCByBw/voo3tYgBZwqrLSt+ VFEJVKqBubRJKJULlxT/ymJWlRYLNiU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=TkinlWVzB7+YhEp3jJr/aZNIP8VQuP4l4pvoZufo1Kr2/64XIZmKINju8djN6EKZQGdFX9 h1A0nNQbWXysyuDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=U9jqloksGUrl/eNBRyCLYgfj6sduFcBCUrcWKDHpeXb24Ugicd6lmLa9UnYqfvX0TuXKS7 9r60PATmtHzXICNvsY/UL9x7L2p6wP0/4TGbvNQuYcsO/8DGCByBw/voo3tYgBZwqrLSt+ VFEJVKqBubRJKJULlxT/ymJWlRYLNiU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776972; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wrmGvHqQzfNaShrvDguSIt1AAdF/oquPyxCU6VC3V/0=; b=TkinlWVzB7+YhEp3jJr/aZNIP8VQuP4l4pvoZufo1Kr2/64XIZmKINju8djN6EKZQGdFX9 h1A0nNQbWXysyuDQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 806AE13212; Mon, 12 Feb 2024 22:29:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 8F2kHMubymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:31 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v8 4/5] mm,page_owner: Filter out stacks by a threshold Date: Mon, 12 Feb 2024 23:30:28 +0100 Message-ID: <20240212223029.30769-5-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=U9jqloks; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=TkinlWVz X-Spamd-Result: default: False [4.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[21.10%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 4.69 X-Rspamd-Queue-Id: 11AA7221A6 X-Spam-Level: **** X-Spam-Flag: NO X-Spamd-Bar: ++++ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790734031463404703 X-GMAIL-MSGID: 1790734031463404703 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: 200091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp200996dyb; Mon, 12 Feb 2024 14:31:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXuy96saindprxlm7lZ6Ooi78zdYOMiAMSWGqDeSUeREAj0kN+MLtFO0pfgp5qVVYCQTC3orORielJJt2cGil1beItKEw== X-Google-Smtp-Source: AGHT+IGOF9XBLdU/funnlPRbMGTFJZTBbGyZacP+fQVW3GhkgKhBo9hkC/rX3ZXch9PPZoRoizz7 X-Received: by 2002:a17:906:1dc7:b0:a38:4f6a:4e7e with SMTP id v7-20020a1709061dc700b00a384f6a4e7emr701104ejh.32.1707777061797; Mon, 12 Feb 2024 14:31:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707777061; cv=pass; d=google.com; s=arc-20160816; b=yEkR8/q5QjsFveaNbtAZkCSBEouDybHxCVBwC9oTdodTc9IhU0DIZWKqz+QsJQZL6C H0F6Sv7kENxd/1lNbl3JjU33u7yb5gaTUllvsZwVocIq3nSU1wBhVdM9B0olOjW7y3m1 Dzkh5+/oJW7OKNgs5EDVnb8kzJAU4LhrX80+DnXmJ86oGr2RcR2+S/Jz74kLOdAD3bXS gpMr2hZr9VYyjwWF9lunRhVnEX71vcvESEE2V/q4TuR8fypKO6qIDD/xYiuu1SJtUTCh CT5AyCzWaB0VRxbLl/X6NLlAJOzJJgqqR6uIWKvtGBKCqDCDlT2lmP7fPFaNRHijSIfh 1ZVw== 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=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; fh=aKM+fxRcXsbtuExarVGqVdXHz4RvYi8MC+Jr6VCMH+w=; b=CP24hVYNTHE9uoV5QdVZoHNTFhHapwdeaX1+zOq4DiLnPdJpLOPzcyDJxP0OClqtNN onYLpxxQ8I2v72z+ZpfLpFPR8rHX9Q1xgmGuvG6XHDEfsQ0Crc9F8oTD/LVGibrGu8W6 pgkoNynVowHBYT1DiN0Y56+Q5cMx9rlhTomIBDK4tF1pSsUThvK7+/2dg9JLQgCVhhp7 gc+lh8BS/oAmd84IZwoqCEiaw/omivvQG5VWuM7Uhyz3sySVgrA/bDAsI3DQOX/LS6Ie 0bITKfAjR90xuCw7vm7x7YqZ5RUhV2EhjMOM/71vknBhQ8WqkViJqIVCfMPXfRGlAeFc BWIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0Hkksmim; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0Hkksmim; 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-62482-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62482-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCXLzVm5O5I+zmC2e1IawLgpSesXarbsUF7XYP/8w2XBGfgLo6QbHo1lgh+xcK8H1gdLwWKN8b7IMRe0YRlW2N0Gg8uM+w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id by16-20020a170906a2d000b00a3c120bb3b4si600287ejb.0.2024.02.12.14.31.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:31:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62482-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=0Hkksmim; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0Hkksmim; 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-62482-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62482-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 3AC821F22AB7 for ; Mon, 12 Feb 2024 22:31:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E7705101E; Mon, 12 Feb 2024 22:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Hkksmim"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZnVGi03v"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0Hkksmim"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZnVGi03v" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 439AB4F613 for ; Mon, 12 Feb 2024 22:29:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776977; cv=none; b=hy8Djrvv5/1Tje0dqjdzeLeDFycOz4smjDbvEXVQVBVSspVg/aw4+e8EA2+2Hz0Jb6iNmp7e7tY2WJf9wjQd29ZO8TGs2/eGZz0LprrfhpXje3bq83++qDslRe3I3EnVNnr5VzwwxgEb+PdmVuzViiE40XgqvMQ7FqCTzDFGXDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707776977; c=relaxed/simple; bh=kovR+ZrYRhElztUO/xzkg9t4G7s0y135A+ZgTQIhorg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oq6jUNACA7JWwrlaZ67wwKIOuichchUapeNXjsi3Byza8Xz+AZJqM87La27UeNAdwezaJzQq4qKvLAt7ZMQEDze+Kh7untAeLoOAdjtsyj/h4uh00QOiWHLhncAk4Ja7OJeK4UD+NQ18ploo8NGe1fIVQsp8TkrWQ80udlM0cGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Hkksmim; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ZnVGi03v; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=0Hkksmim; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=ZnVGi03v; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AD61222177; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776973; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=0HkksmimAKf1X2UchGs1ECrVRZPKtKpJwt693l9NOKJ5pJjpsp/SyDvukNl5wLeGnSUFbx AYwqmHSTXqM/SJpVRjlMOBOxO0rM/s0c6MDVVlIlJYcTLyTM3upL1YC6miq4zlePc2ZO79 zdX7qh0CWgh/3uAXle7lIRUwWwtjOlE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776973; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=ZnVGi03vheW9LR2lPrO/6uN0847XkDBVnIfGMln6MKkPIGMcvcEckEGoHOIS/MPPxXr9Ab pgLcrPPJ9Uwoh3Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707776973; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=0HkksmimAKf1X2UchGs1ECrVRZPKtKpJwt693l9NOKJ5pJjpsp/SyDvukNl5wLeGnSUFbx AYwqmHSTXqM/SJpVRjlMOBOxO0rM/s0c6MDVVlIlJYcTLyTM3upL1YC6miq4zlePc2ZO79 zdX7qh0CWgh/3uAXle7lIRUwWwtjOlE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707776973; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1CzNFL4PMmMQSHbggAgsOI2ejs0tMDCon93dbkR538=; b=ZnVGi03vheW9LR2lPrO/6uN0847XkDBVnIfGMln6MKkPIGMcvcEckEGoHOIS/MPPxXr9Ab pgLcrPPJ9Uwoh3Ag== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2A3A613212; Mon, 12 Feb 2024 22:29:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 6IORB82bymX5JgAAn2gu4w (envelope-from ); Mon, 12 Feb 2024 22:29:33 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador Subject: [PATCH v8 5/5] mm,page_owner: Update Documentation regarding page_owner_stacks Date: Mon, 12 Feb 2024 23:30:29 +0100 Message-ID: <20240212223029.30769-6-osalvador@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212223029.30769-1-osalvador@suse.de> References: <20240212223029.30769-1-osalvador@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=0Hkksmim; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ZnVGi03v X-Spamd-Result: default: False [4.11 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,suse.cz,google.com,gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.58)[81.40%] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 4.11 X-Rspamd-Queue-Id: AD61222177 X-Spam-Level: **** X-Spam-Flag: NO X-Spamd-Bar: ++++ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790734040235308510 X-GMAIL-MSGID: 1790734040235308510 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