From patchwork Wed May 24 21:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13254549 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 EF469C7EE31 for ; Wed, 24 May 2023 21:36:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 168F0900002; Wed, 24 May 2023 17:36:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07D3A900006; Wed, 24 May 2023 17:36:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0370900002; Wed, 24 May 2023 17:36:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B52F0900003 for ; Wed, 24 May 2023 17:36:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2D2CC1C7799 for ; Wed, 24 May 2023 21:36:39 +0000 (UTC) X-FDA: 80826458118.16.B97A69D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id D4956140007 for ; Wed, 24 May 2023 21:36:36 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=zZvtruf5; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684964197; 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=WAKoqUN95n3fVgR2gHhetTOzf1TmlU2sJtM2C/TK2Mc=; b=36WnGnrN/B1vrE/fBTfgLp1r6IhvdEe1yFyqxcppuTyBNY1PZYXPhycN3GegDdO0n2t8hW +4XyMe2/fDHx+R8s/k3ju36Sd9z1Bxcxg4QbrGV9LA72JfOSakgVCUz2Iq/xTrYxTGM+cM TK8EsJdocHCcXdAN0rMHxerq2GE+OX0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=zZvtruf5; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684964197; a=rsa-sha256; cv=none; b=vFsY9oE8PSJAzXK9jOqhEEQD7sjWiUA+FjZpMKRgfFfG9NWPly1wcv9TuauqUGREqgY9Nt tTzprKb/SpPRDY0pNIchPraAlkqZUu71cJXeO4ZgTCWi1pldjN/BMnWO6e8MSW73p1EVzg XbOkw6TU2JTIptF9ki1esIqVTqfYWj0= 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=WAKoqUN95n3fVgR2gHhetTOzf1TmlU2sJtM2C/TK2Mc=; b=zZvtruf52Q7ffeHQ5bphR02la/ Fn8L4xH0iakr0/r8/YHx/Ep+FALG1qw7qd1rxcWBgVbm4dOIeSSgRBBIUdIjz6vs41eNWIIrErLb4 ZCnmzF7lzqL/9kw71rXSrgim2ExYTBDqUqgnxCXwviRyZ+z8w/9ok2+xIi9w6DEV2ahxS6NKUPvVG PHfmLgw0iKB1YoF7VJwKcu2+0TcP605ieh40OgUtVQ9WFSXXFnFwY68mrQw6iC1wv0vGQXFWHabNq 3EHp1IRfqwvGBePzAAQ4+hTRD9S3CuT6g4lfyFDFzIZiEzF2MLOiYCj9TfoTjpP67+gQAweqIVpA8 OhqWrOjg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q1w9d-00EitF-0h; Wed, 24 May 2023 21:36:21 +0000 From: Luis Chamberlain To: david@redhat.com, tglx@linutronix.de, hch@lst.de, 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, lennart@poettering.net Cc: gregkh@linuxfoundation.org, rafael@kernel.org, song@kernel.org, lucas.de.marchi@gmail.com, lucas.demarchi@intel.com, christophe.leroy@csgroup.eu, peterz@infradead.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, yujie.liu@intel.com, mcgrof@kernel.org Subject: [PATCH 0/2] module: avoid all memory pressure due to duplicates Date: Wed, 24 May 2023 14:36:18 -0700 Message-Id: <20230524213620.3509138-1-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D4956140007 X-Stat-Signature: imtnwwqobnyioafn5puyq63jk9uupgs8 X-Rspam-User: X-HE-Tag: 1684964196-415853 X-HE-Meta: U2FsdGVkX1+Xikcr37lyVDRHVt6fMpKYpebHucv/axeu6CbfnzF1cFHPC09xFCXsCzXky5F3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1TgNkQCRNtOwO+aT1VzvRJw7IqQ3qMmLemRsNa5AzFpA9FHv9qQJW9H7sJSNKZDUmniKUjsidKfQCPt9z5dwR327gbQpuUj95+tw2lWUnNvfpml6pR29sQB1S9A0rFWdCZj8qaKHfkoaMiRR0Dvo1gry+BSO7WcjXtynM8cAp/uu2g3J7Uqe5R0niOyAnV//WsB5MhJ08/tCIShChNSGX2sQHeIdXjS92hsB0YRemjQUNZOwxQ== 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: We now know that duplicate kernel module loading can incur considerable vmalloc memory pressure on boot. Module loading uses vmalloc space 3 times in the worst case. Detecting duplicates early before processing the module name was the last mile we had to go and we recently were debating if userspace should fix this or the kernel should fix this. We decided to punt the problem to userspace. At LSFMM 2023 in Vancouver this year I talked to Lennart Poettering about this and described the issue with udev. Fixing this in userspace would be complex, and it was preferable if we could resolve this in-kernel. And indeed it is possible to resolve it relatively easily in-kernel with just the inode. So let's do that and be done with the issue. Patch #2 has the details on the savings on a 255 CPU system. With this we get 0 bytes wasted incurred due to duplicates. Luis Chamberlain (2): fs/kernel_read_file: add support for duplicate detection module: add support to avoid duplicates early on load fs/Kconfig | 3 + fs/kernel_read_file.c | 124 +++++++++++++++++++++++++++++++ include/linux/kernel_read_file.h | 14 ++++ include/linux/module.h | 1 + kernel/module/Kconfig | 20 +++++ kernel/module/internal.h | 1 + kernel/module/main.c | 19 +++-- 7 files changed, 175 insertions(+), 7 deletions(-)