From patchwork Wed Mar 29 05:29:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191893 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 2F776C77B61 for ; Wed, 29 Mar 2023 05:30:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 259B56B0072; Wed, 29 Mar 2023 01:30:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E4E96B0074; Wed, 29 Mar 2023 01:30:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 084E26B0075; Wed, 29 Mar 2023 01:30:06 -0400 (EDT) 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 E9F746B0072 for ; Wed, 29 Mar 2023 01:30:05 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ACE1B140B82 for ; Wed, 29 Mar 2023 05:30:05 +0000 (UTC) X-FDA: 80620809570.15.42CB01B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 514C6C000D for ; Wed, 29 Mar 2023 05:30:02 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ROoiZKye; spf=none (imf28.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=1680067803; 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=KLOfytIcH4rEmrgbqWZrqXW6JlCkVbvgRIm3hytVuTY=; b=ivbdN3fU5GpkoY3Q0m1ymxHUdmj+1vbZG7lZkLFF09ZLhsMJy3lp/GW6pES1L2BTIREf+m fM/b6B8km8129in2Q6JEbCXVtCPKcIVPvmvK/u+PVinGGD2HC/v9SMvULv27jEUkEkJ9+p eXYWq6mxMSPJ3XdquAPtz5SXIOuOClo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ROoiZKye; spf=none (imf28.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=1680067803; a=rsa-sha256; cv=none; b=QHXwrZkO0Dm6pG3nMKcjx/eoZBP36Ihb0WwBDdcEiGVcOhexhLS+sHkNjzsUI/LLWM97Mm 11RNMDZT/DAS2Ic35XvPeufyiD5U29BOkYV7RLEpMs+ZdP/ttMJD6PVeXzVEvVsSkIhCZi HjkI3GdtmXIDtKUwEHKzqn5ua9Ma+vw= 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=KLOfytIcH4rEmrgbqWZrqXW6JlCkVbvgRIm3hytVuTY=; b=ROoiZKyehNzSjwkNI60IK7yKO7 fOShguZIG/ospXSSDk5eEl2XgDhWH+t3YLln9yz3Eu+U+U0PnmCImMTsaMdd2gqKmkEW97UnW2LzB bXtZoyCMVOZFDnQVwJW/nNFXK31HjX08x/i16yhJH/PNXN4v8qlY5kNCny/oS4h4XLM4PplwVPd9S wsOdcAB0JV/FWLrUYOn5xtbiBHV1n77NaYnB9+Mi/J+ypZMgFY3GQ9pa9c1Jm3VppJYgx2HIlxJic kUXFPGW30t+0wt5vVEepKimb/zrDGgRwkJTUauNwO1EARsVUF20ln+ylwOC35REIYqDbAnk4toKD8 kNlGQwnA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phONf-00Gfy0-2S; Wed, 29 Mar 2023 05:29:55 +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, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 0/7] module: avoid userspace pressure on unwanted allocations Date: Tue, 28 Mar 2023 22:29:54 -0700 Message-Id: <20230329052954.3974542-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 514C6C000D X-Rspam-User: X-Stat-Signature: 3nxxfq54hkpd9u7npwt9eme8rcmiyxa5 X-HE-Tag: 1680067802-913945 X-HE-Meta: U2FsdGVkX1+eUEJ6ipWho+iqEs1iAKH+r0R1ssK7mfJULH83xeEZCquQLsO/oN8IcIq2HZuZo90G/4Vhdf0baV/+jEAOf23ATQ3iM7SyVLD4nS/DBZ1/rklgfYC/lgmHMlNbCpW8a+Sz2EzYL3JmVEy9CnePogvJIQjeZy0yACXjiZxsnkz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stq9Wa6fbOtk3WaUSR6ncDVgFMakSvWLoKqGLsLusgUi7vyEPxqvZjmALLIydBOssMCeVxiBvnMNFWSsaGPMn8100s3ay68eihXJsnk4sQb1yrbLPZZ+Pl3ocCD3t5/mcWXzBQPDqhOtHaoiOLJU/D/jg8JULcyqhipVtKNYD2q6UEfuiAS82UJg= 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 set addresses a fix to the vmap allocation presure issues which David Hildenbrand had reported last year in October. While at it, I've simplified the kmod concurrency delimiter using Linus' suggestion, and added debugfs stats to help us keep sane in doing analysis for memory pressure issues on the finit_module() side of things. That should *also* help do an empirical evaluation of module .text sizes *actually* present on systems, given userspace makes it a bit tricky to get that right. All this would not have been possible without stress-ng and Colin Ian King's help to getting a modules ops in shape so to reproduce a situation only reported so far on a system with over 400 CPUs. I *think* the degugfs stats *should* probably be used to help identify areas where we perhaps need *more work* to try to mitigate vmalloc() space, as in the worst case we can end up using vmap space 3 times for a single module, two just as big as the module, and if you are enabling compression one with the compressed module size. That's significant memory pressure on vmalloc() / vmap() space. If you'd like to give this a spin this is available on my branch based on modules-next 20230328-module-alloc-opts [2]. [0] https://lkml.kernel.org/r/20221013180518.217405-1-david@redhat.com [1] https://github.com/ColinIanKing/stress-ng [2] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=20230328-module-alloc-opts Luis Chamberlain (7): module: move finished_loading() module: extract patient module check into helper module: avoid allocation if module is already present and ready sempahore: add a helper for a concurrency limiter modules/kmod: replace implementation with a sempahore debugfs: add debugfs_create_atomic64_t for atomic64_t module: add debug stats to help identify memory pressure fs/debugfs/file.c | 36 +++++++ include/linux/debugfs.h | 2 + include/linux/semaphore.h | 3 + kernel/module/Kconfig | 32 ++++++ kernel/module/Makefile | 4 + kernel/module/debug.c | 16 +++ kernel/module/internal.h | 35 +++++++ kernel/module/kmod.c | 26 ++--- kernel/module/main.c | 164 ++++++++++++++++++++----------- kernel/module/stats.c | 200 ++++++++++++++++++++++++++++++++++++++ kernel/module/tracking.c | 7 +- 11 files changed, 445 insertions(+), 80 deletions(-) create mode 100644 kernel/module/debug.c create mode 100644 kernel/module/stats.c