From patchwork Tue Aug 15 12:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjiang Tu X-Patchwork-Id: 13353755 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 95BC3C0015E for ; Tue, 15 Aug 2023 11:58:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E05E08D0006; Tue, 15 Aug 2023 07:57:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFAE68D0008; Tue, 15 Aug 2023 07:57:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C69BD8D0006; Tue, 15 Aug 2023 07:57:59 -0400 (EDT) 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 B7D968D0001 for ; Tue, 15 Aug 2023 07:57:59 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 908881608C1 for ; Tue, 15 Aug 2023 11:57:59 +0000 (UTC) X-FDA: 81126190278.07.887395A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf10.hostedemail.com (Postfix) with ESMTP id 523E8C001D for ; Tue, 15 Aug 2023 11:57:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692100677; a=rsa-sha256; cv=none; b=S7CyHJyHYzOb3cEeDngNDNvZezoqo1jEFaR/Bz08B2XsbNyP13Fy7Is8Ai63ZKS+1TA73e FHt+Fb4qywmbWW0x7cIZCj/1XC0WlEV7lkeP2EaoskeAnJznlPS4Q5xN1EP5lDxee8EUs7 krHxdICQ0ROgCjyygBJJTUdJuok68EY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692100677; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sOJwRWVbCMC8QCq703jqA0C4R5/n4HEDt6cLXNSSTDE=; b=xWESqjOiyFZBVycs/gf1oND8d23i7Kco2dgFm62TOvGqKuvBq67SQsRTM8PpcNhKghC3RY cL5SZKStCMhbjJnGDOAIc9qWayw0BA5lGR4xpN8doVrz4mY/1/xpsY2gAL5hgLepPefPDV sYLDA+YnG4Pw8M50gAocyiJMqLSEOjA= Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RQ8nN5H8CztRw0; Tue, 15 Aug 2023 19:54:16 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 15 Aug 2023 19:57:52 +0800 From: Jinjiang Tu To: , , , , CC: Subject: [PATCH 2/6] mm/page_owner: show modules allocating pages when oom occurred Date: Tue, 15 Aug 2023 20:52:47 +0800 Message-ID: <20230815125251.2865852-3-tujinjiang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230815125251.2865852-1-tujinjiang@huawei.com> References: <20230815125251.2865852-1-tujinjiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500011.china.huawei.com (7.185.36.84) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 523E8C001D X-Stat-Signature: ozeoxc7srot6xc81iri1qk53ow54aekt X-HE-Tag: 1692100675-252701 X-HE-Meta: U2FsdGVkX1/AazssRrwMv4w4aFvME/r+jcEnaeFFsdSWS31gag0la11EUaW+Nx14jT7eds2LspOFFoNvlMxY3VV3QR2J1UPCdVj6qF2wO258ClULFUEgZlUPKqa2R6auWufunPAGBNcPr5IGeYjT3fk+e+PH+s62R+HA4zmBhVnIBMvIxQ00VKwseS2L/DpZP1bhRnfVfMmBZ/K1vuKkBKccmL6DgEp+3AdsnVV0EteT7FUFBYYcs6UGXyIDmiZyo6ms32N5devfZjiddC88V/j9eRPwWg7ldPPdUvqWnB2Wy/IuSKlHVMk4cnqITfpO67UoN9ati6z8i8s9QGNBjqd977J9CMqK3EL9t/+UAFV3zUNSlO5yrZ71Dj04gABLrcxdmL8W/yEDH3dMfpCij6e0xB1rHwxOXwlVreBXEdh8UxClWVAcz+tsxGZ8U5bmdMTabP1bAQKOsFxYxjKzhWDqF6Q2LaEiE2xts82BOIyeDuS0SBWuVRKHKffD3dM/pgSoHZ11bcSrHscYzDMwgpQmnJ8CEPCjOngjKf1XORLPQW14c2dz2dY8a+davnjdmBR/rzxuWB7TfCIe+Ah7F4qRE1EMwCyn7Nc0wAKOs70qUhIBr4Z6QUqbYpkR5SxEF1HNulBsElS1q0pM0vVGogZs2SY3OKF4oiF358wBEQK5j+lYzJ6mGCUbLZf1T6HrM1FJBlZZml9yH+xi6nLFG0mLJWAKMIA9Ii5rxEv5RvhSelTUXlrT6VYND/JQeFXh3hZLad4PItBNTobipV/ML8aA4D8+CJ0n8LCTFRmYbPbwcDpOyR5EWUSvrWWwVMLG5Lr/cM22CJkz/ObZ2Wn5RrLvrkF5lTl6Iu7SFm59FkbQPw5+4SXllHNBsWQMtJltJg3f4vixPmKfEvQl/HEFPsQuamBRxovIIYrgnSoeoD9jXJ5C7ls6GZE3aioIIkCp6NlpwvaUWwiET1HVB49 7PqrK7sy 1+P4/DSaRxAtx2UEOHglFNka8sgMWUh/H6HXquPr29PSdurXHjwdRyc/qKLYT1FxaA7ICzEyJxPqwceaaTxrDEe+I0kNBaGpUyIvUX9mIWuuJkjngGfj5BrPbTxxjBqrbWR2HEeQE7HL+uPpt4g9jhaVs3MjYdxYjKPvOBq36ohuszAtYRBXJ3bNtlSZkxRz+cvXv 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: This patch records the pages allocated by each module and dump the modules when oom occurred. The dump info is as follows: -------------------------------- Modules state: module nr_pages_allocated: ext4 14383 mbcache 9 jbd2 94 -------------------------------- Signed-off-by: Jinjiang Tu --- include/linux/module.h | 4 ++++ kernel/module/Makefile | 1 + kernel/module/main.c | 4 ++++ kernel/module/page_owner.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/page_owner.c | 18 ++++++++++++++---- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 kernel/module/page_owner.c diff --git a/include/linux/module.h b/include/linux/module.h index a98e188cf37b..be374968cbdb 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -583,6 +583,10 @@ struct module { #ifdef CONFIG_DYNAMIC_DEBUG_CORE struct _ddebug_info dyndbg_info; #endif + +#ifdef CONFIG_PAGE_OWNER + atomic_t nr_pages_allocated; +#endif } ____cacheline_aligned __randomize_layout; #ifndef MODULE_ARCH_INIT #define MODULE_ARCH_INIT {} diff --git a/kernel/module/Makefile b/kernel/module/Makefile index a10b2b9a6fdf..b973a3956131 100644 --- a/kernel/module/Makefile +++ b/kernel/module/Makefile @@ -23,3 +23,4 @@ obj-$(CONFIG_KGDB_KDB) += kdb.o obj-$(CONFIG_MODVERSIONS) += version.o obj-$(CONFIG_MODULE_UNLOAD_TAINT_TRACKING) += tracking.o obj-$(CONFIG_MODULE_STATS) += stats.o +obj-$(CONFIG_PAGE_OWNER) += page_owner.o diff --git a/kernel/module/main.c b/kernel/module/main.c index 59b1d067e528..e021c7f6dd24 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2888,6 +2888,10 @@ static int load_module(struct load_info *info, const char __user *uargs, init_param_lock(mod); +#ifdef CONFIG_PAGE_OWNER + atomic_set(&mod->nr_pages_allocated, 0); +#endif + /* * Now we've got everything in the final locations, we can * find optional sections. diff --git a/kernel/module/page_owner.c b/kernel/module/page_owner.c new file mode 100644 index 000000000000..bcf2a15e7ed3 --- /dev/null +++ b/kernel/module/page_owner.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include "internal.h" + +static int po_oom_notify(struct notifier_block *self, + unsigned long val, void *data) +{ + struct module *mod; + int nr; + int ret = notifier_from_errno(0); + + preempt_disable(); + pr_info("Modules state:\n"); + pr_info("module nr_page_allocated\n"); + list_for_each_entry_rcu(mod, &modules, list) { + nr = atomic_read(&mod->nr_pages_allocated); + if (nr <= 0) + continue; + + pr_info("%-20s %d\n", mod->name, nr); + } + preempt_enable(); + + return ret; +} + +static struct notifier_block po_oom_nb = { + .notifier_call = po_oom_notify, + .priority = 0 +}; + +void po_register_oom_notifier(void) +{ + if (register_oom_notifier(&po_oom_nb)) + pr_warn("Failed to register pageowner oom notifier\n"); +} diff --git a/mm/page_owner.c b/mm/page_owner.c index ef8fe1857d42..bbbf5a518a41 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -139,7 +139,7 @@ static noinline depot_stack_handle_t save_stack(gfp_t flags) } #ifdef CONFIG_MODULES -static char *find_module_name(depot_stack_handle_t handle) +static char *find_module_name(depot_stack_handle_t handle, int nr_pages) { int i; struct module *mod = NULL; @@ -158,6 +158,7 @@ static char *find_module_name(depot_stack_handle_t handle) if (!mod) continue; + atomic_add(nr_pages, &mod->nr_pages_allocated); return mod->name; } @@ -187,8 +188,11 @@ static inline void copy_module_name(struct page_owner *old_page_owner, { set_module_name(new_page_owner, old_page_owner->module_name); } + +void po_register_oom_notifier(void); #else -static inline char *find_module_name(depot_stack_handle_t handle) +static inline char *find_module_name(depot_stack_handle_t handle, + int nr_pages) { return NULL; } @@ -208,6 +212,10 @@ static inline void copy_module_name(struct page_owner *old_page_owner, struct page_owner *new_page_owner) { } + +void po_register_oom_notifier(void) +{ +} #endif void __reset_page_owner(struct page *page, unsigned short order) @@ -224,7 +232,7 @@ void __reset_page_owner(struct page *page, unsigned short order) return; handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); - mod_name = find_module_name(handle); + mod_name = find_module_name(handle, -(1 << order)); for (i = 0; i < (1 << order); i++) { __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); page_owner = get_page_owner(page_ext); @@ -245,7 +253,7 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext, u64 ts_nsec = local_clock(); char *mod_name; - mod_name = find_module_name(handle); + mod_name = find_module_name(handle, 1 << order); for (i = 0; i < (1 << order); i++) { page_owner = get_page_owner(page_ext); @@ -809,6 +817,8 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); + po_register_oom_notifier(); + return 0; } late_initcall(pageowner_init)