From patchwork Fri Apr 14 05:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13210931 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 3A53EC77B79 for ; Fri, 14 Apr 2023 05:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB44E6B0072; Fri, 14 Apr 2023 01:08:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B45F0900003; Fri, 14 Apr 2023 01:08:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A04346B0075; Fri, 14 Apr 2023 01:08:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8F72C900003 for ; Fri, 14 Apr 2023 01:08:53 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 52B384011E for ; Fri, 14 Apr 2023 05:08:53 +0000 (UTC) X-FDA: 80678816946.16.89DB27E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id C5EC114000D for ; Fri, 14 Apr 2023 05:08:51 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=HpNHcEsQ; spf=none (imf09.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681448931; h=from:from:sender: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:references:dkim-signature; bh=jhQgpcdU6gyeXMobM0XSItVG4AvZoQZZ5MixvI3m4K8=; b=2yov5CC41dMcTVIEc6k6+lJerk803WQHPpBNy0kYV+cTmOH0IUDmjmgZqTN4AKsvRkzq// Q/FKEnKj+7zeLVWxc4w/kR4h8kRUIFMiE8+n1a/GNQSwjy/ONlj9Zggxlmu1La9dHJjSRt oS9HD6yqIklznpwpqkm3O1jhvtgswi0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=HpNHcEsQ; spf=none (imf09.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681448931; a=rsa-sha256; cv=none; b=phj3dBHZFO1RDBfoEyHDbWTm/6nun4M2+4AuOIYO0ID32Kp2i1yuEPbXiednulyDOu3S+U sYIp4WS4mohRVax0glxqdPu66z1bSlJgI0nP/tI3P2vaDRH0mwN+fF6YjjIswr9OZIP2e8 sCVGjpZi6r3R418BzHFi5BxIJY4itFs= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=jhQgpcdU6gyeXMobM0XSItVG4AvZoQZZ5MixvI3m4K8=; b=HpNHcEsQXfVvSFJkEJm8E3PUH+ kNmfgiNbIGwx5rIrHDAkIKGVBZlEn4AOltbU3ugrKNKKkFjMHm+Z36h56aM84Eqxi/ZOcD6elNgKW MSj8OpTEki2t+XXAGuR0XOtpf7oDXRW3O3nO2zqCFTxasw+9HbF45Wq7kubF+jOmyEvv/rPuelMgg FnHG1jGNse9yhUaRetIbIapaNZQEwlJIfkjXNAhjycsYOMhD19YkxeGd1+ZqmGlVySlFMATDbAn2V XmlAnRZajDT4FPi2fZsJXCoaW7mT6inrtz+CZs5BC0591Z1PBmbuGQuI84SqxJnsPeODsYP7XfslU BTtRi4SQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pnBfp-008KKF-16; Fri, 14 Apr 2023 05:08:37 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, dave@stgolabs.net, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, colin.i.king@gmail.com, jim.cromie@gmail.com, catalin.marinas@arm.com, jbaron@akamai.com, rick.p.edgecombe@intel.com, mcgrof@kernel.org Subject: [PATCH v3 0/4] module: avoid userspace pressure on unwanted allocations Date: Thu, 13 Apr 2023 22:08:32 -0700 Message-Id: <20230414050836.1984746-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Stat-Signature: 6gw4whr13exczgfgfh5i1xn3758zpkgz X-Rspam-User: X-Rspamd-Queue-Id: C5EC114000D X-Rspamd-Server: rspam06 X-HE-Tag: 1681448931-514638 X-HE-Meta: U2FsdGVkX1+mMnb3kmZEzsdPw9RtlNCc49GRIrBry9DiPXCtbJLnc2Cb31gRyoQKtDQRdG/DdR3YmiSG5BpXhqPmEf18BJQTOC06JD9E2A0C8GkRA5B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l4Mlv7eKSvjRasf0uDlAjGoRZElf6Xh6h8H3Dcx25sp5iJ6XS6U3QSfdGDw2C3A1tCq4vH1ssEOtuxRZFi8uPDF5qXMYdMKcMTdSXhosYBL7qLiad2tDdm2LuE+73HDvM4uUQFyW/zcHS6ywlFya7aRigPyerKN6p49MIIS3MY0XpwSJMbcZs4iqdlDZ7IHkWkKFgA+aNvPr1D9SuIQHiCG0tlnyngwQTX42LpgnmpAgtDi1uCaqfRXoFKWwLSuHelBsIl8FPgZy85VfraWeKiOlVnOiggEFhZaBNV2bk= 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 v3 series follows up on the second iteration of these patches [0]. This and other pending changes are avaiable on 20230413-module-alloc-opts branch [1] which is based on modules-next. Changes on this v3: o Catalin Marinas suggested we just use kmemleak_not_leak() for both ELF allocations even if its init stuff. o Considerable amount of effort went into trying to see if there's relationship with CPU count and wasted virtual memory allocations. The new module debugfs counters helped with creating this evaluation. The result of that put me on a path to then add even more debugging facilities to rule out and identify the culprits. In the end I have patches now which can get this down to 0 bytes wasted. The patch in this series which helps reduce the allocations has a graph showing the findings of the relationship between wasted virtual memory allocations and CPU count all during boot. It is insanity that the graph has to go into gigabytes of wasted virtual memory all at boot. o To help folks compare apples to apples I've put the stats debug patch *prior* to the one that helps with allocations. This way folks can see for themselves what the results look like. o Enhanced the statistics a bit more and added an example with 255 CPUs. o Went with atomic_long and casting for the debugs big counters. o Rolled in the patch that moved a helper as David suggested. o Minor fixes reported by 0-day o Added tags for Reviews, etc. [0] https://lkml.kernel.org/r/20230405022702.753323-1-mcgrof@kernel.org [1] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230413-module-alloc-opts Luis Chamberlain (4): module: fix kmemleak annotations for non init ELF sections module: extract patient module check into helper module: add debug stats to help identify memory pressure module: avoid allocation if module is already present and ready Documentation/core-api/kernel-api.rst | 22 +- kernel/module/Kconfig | 37 +++ kernel/module/Makefile | 1 + kernel/module/decompress.c | 4 + kernel/module/internal.h | 74 +++++ kernel/module/main.c | 194 ++++++++---- kernel/module/stats.c | 432 ++++++++++++++++++++++++++ kernel/module/tracking.c | 7 +- 8 files changed, 703 insertions(+), 68 deletions(-) create mode 100644 kernel/module/stats.c