From patchwork Wed Mar 29 05:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191898 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 48AD7C6FD18 for ; Wed, 29 Mar 2023 05:32:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16E37900002; Wed, 29 Mar 2023 01:31:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 035796B0080; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D58C1900003; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BA4D56B007E for ; Wed, 29 Mar 2023 01:31:58 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9A0AD1C5D25 for ; Wed, 29 Mar 2023 05:31:58 +0000 (UTC) X-FDA: 80620814316.11.CF133ED Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 1D76C40012 for ; Wed, 29 Mar 2023 05:31:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SKXkmQeC; spf=none (imf17.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=1680067917; a=rsa-sha256; cv=none; b=cW0BmFSgBurwu9RG4hqS2qnE6UzFRBNPOiBNI27EtQQlTKZ4O1ar9vS8tvmAolHEqPBDR+ IVhfbMD1iWBRXz8jXZjnuAcv9sPHE9S1tB+b45SwhqS22qfWTGacjA8lua5dV5YNdqGH6j Tv2y3+oaN9jueFRjcQoS+z5jseJEkdI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SKXkmQeC; spf=none (imf17.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=1680067917; 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=OVBki/su4rPJ0R4MGBd3KBfRD79K0JdU/KMxzb3l9sbaXLLqpRse+VQfWwZ0ynBcJvZ5ST zlF03x5PHLravX0QsUx3oWi0b9yBgG5WlbDwd/UiZxMdAZTfzF9UGlrKyrkZU7/Z2HEh1/ VpeL4y/rAhYFQ/xtWOQGB8A4EXUpPZU= 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=SKXkmQeCEpgQZFnKkN5jdqmQYh 40jq1pxRb3voL7778sBrMGEoSewmZSXoGUfZrB6wUK5nKoXSPw36MkaWBrYWszHlUIQqwXVVCUVCt IyMnqjGzt8GX8Pu2hFTRLiM0viFXqDvIkhHt5owme+jhbjQXGSDIqF7lbmtoaiS4lp5XhenvJfNrW ThblqC87znpBanq7PlA3vgqizKFHQmVFE+ZetKq2g+VimLRHoX9DXwbJdX8iXGmYqq7civwLsSvTc xgRc2rPq21dHnPvqDjXbbuIMsPnhrVCqtKXJOHk8DUupKVu2uwUCWdD8gQdFl8khfl+eycLmOdtcK Kfh2WKIA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRQ-1m; Wed, 29 Mar 2023 05:31:50 +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:31:42 -0700 Message-Id: <20230329053149.3976378-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 1D76C40012 X-Rspamd-Server: rspam01 X-Stat-Signature: r59as6taxd9qzdt8rdyt46575ixx67eb X-HE-Tag: 1680067916-869360 X-HE-Meta: U2FsdGVkX19OKjyGskvOa5c1EbGGJSPTSVplovUxsP/ciHOf1ZKxz1HkL4Gk7GY2GpuN2dysWbOVUMePoMq4FnZvoqAYJxc6AvH82kl7HeVwZW0GTKblvjXpTeQuweFdTE+s9XI4JRQR5KWbUo0C0cjR4+Oa5K89J0v89X4h+hD5hrR1Mo+yTK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f8Y0LqP30OtvvRC+T/vb82JNihsYZvMoGmiPBdKJUL0DZCetxjtIZKkRMGSCVz3shR1lDMvNwJBnW3WkqOKqOvGNP6uQSUDcGDnSP6GYNScVLLhleT8zlPHVQ16ctfSjWQvh1sFoR52qf2bebJLGBLvbCluHK+PWKwJrgBwIBS9Bsjb5YNaP1wzxpJfXqJEfdkM= 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