From mboxrd@z Thu Jan 1 00:00:00 1970 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 06D0BC433FE for ; Fri, 4 Nov 2022 00:19:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25C586B0073; Thu, 3 Nov 2022 20:19:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20B548E0001; Thu, 3 Nov 2022 20:19:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D3086B0075; Thu, 3 Nov 2022 20:19:05 -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 F1F006B0073 for ; Thu, 3 Nov 2022 20:19:04 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C15031C6EED for ; Fri, 4 Nov 2022 00:19:04 +0000 (UTC) X-FDA: 80093849808.01.113A238 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 683B680002 for ; Fri, 4 Nov 2022 00:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/2Q/ImbZMskPL9hsW9RTI0f/QW9ny2RC9HqNP2cEM00=; b=oeLxwE1iHDWw8asW4K8yOPUuQw ChjlHQ+fpJB3SnXtAAPyLHpMIF+GVjEoLd9xspwpb3WJ6SrQMJdZooYA40/eaJGYL6r6319zkQ2GV WPxEHesYWBvONkQidohP+KTmEC88Mf/YxTb4IDDunzA3GasxPmFuWZ2nQtCB292do7iZsOQrikjJn m7nHdTd23YbKmeUqgD5Q99MIHYkm43Gb/YRi4D9soveiIEXIkSnnedyhNDTbUAka0b+Uc6tsy+94s QZvhXjp07hdtDFbP57IgO2tPt/qI+E2RqFkI+avegYaV1mdKu9PCDIYtFpoFnug8vYwLuTTpkkI/d Qh6FsspA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqkQ7-0021Ql-Ln; Fri, 04 Nov 2022 00:18:51 +0000 Date: Thu, 3 Nov 2022 17:18:51 -0700 From: Luis Chamberlain To: "Edgecombe, Rick P" Cc: "rppt@kernel.org" , "p.raghav@samsung.com" , "peterz@infradead.org" , "bpf@vger.kernel.org" , "dave@stgolabs.net" , "willy@infradead.org" , "linux-mm@kvack.org" , "song@kernel.org" , "hch@lst.de" , "vbabka@suse.cz" , "zhengjun.xing@linux.intel.com" , "x86@kernel.org" , "akpm@linux-foundation.org" , "Torvalds, Linus" , "Hansen, Dave" , "kbusch@kernel.org" , "mgorman@suse.de" , "a.manzanares@samsung.com" Subject: Re: [PATCH bpf-next v1 RESEND 1/5] vmalloc: introduce vmalloc_exec, vfree_exec, and vcopy_exec Message-ID: References: <20221031222541.1773452-1-song@kernel.org> <20221031222541.1773452-2-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667521143; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/2Q/ImbZMskPL9hsW9RTI0f/QW9ny2RC9HqNP2cEM00=; b=MqT0SxT4TsJ1+r9ecnyvUZHUKZsJjjRVNd30KnhietZb75SWOotvC1h6HygsB7z0qDpVlb nJUR7RPqXAJrfYR2Z0vUxtTWpPqKv87Uv9WlFzKUT74Fl0dhjwgIaCTnfms1YuyPZw3j0G 2rtuETlNdtKaXPqlkgAZRXwiDPpp4s8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oeLxwE1i; spf=none (imf30.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=1667521143; a=rsa-sha256; cv=none; b=2dpBEOKfrI/GO0cAebhqAqXkLZhICaGleerGgrn6h4UADAEDlvccRUJ6MrrAKcaCpmGvVc +2xO5MsswKolFzKZRq3wrtdYsz/fa/nBrX4bwWcH5ylFkmuOCZnHTVUwFPyyNda+Xi5kES QsDEEwFDSdwDxI0jYjpjUTyl29SqFA8= X-Stat-Signature: cx6y5z848e3ucsp7xtt4nczcb4hmw7pt X-Rspamd-Queue-Id: 683B680002 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oeLxwE1i; spf=none (imf30.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) X-HE-Tag: 1667521143-899557 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: On Thu, Nov 03, 2022 at 09:19:25PM +0000, Edgecombe, Rick P wrote: > On Thu, 2022-11-03 at 11:59 -0700, Luis Chamberlain wrote: > > > > Mike Rapoport had presented about the Direct map fragmentation > > > > problem > > > > at Plumbers 2021 [0], and clearly mentioned modules / BPF / > > > > ftrace / > > > > kprobes as possible sources for this. Then Xing Zhengjun's 2021 > > > > performance > > > > evaluation on whether using 2M/1G pages aggressively for the > > > > kernel direct map > > > > help performance [1] ends up generally recommending huge pages. > > > > The work by Xing > > > > though was about using huge pages *alone*, not using a strategy > > > > such as in the > > > > "bpf prog pack" to share one 2 MiB huge page for *all* small eBPF > > > > programs, > > > > and that I think is the real golden nugget here. > > > > > > > > I contend therefore that the theoretical reduction of iTLB misses > > > > by using > > > > huge pages for "bpf prog pack" is not what gets your systems to > > > > perform > > > > somehow better. It should be simply that it reduces fragmentation > > > > and > > > > *this* generally can help with performance long term. If this is > > > > accurate > > > > then let's please separate the two aspects to this. > > > > > > The direct map fragmentation is the reason for higher TLB miss > > > rate, both > > > for iTLB and dTLB. > > > > OK so then whatever benchmark is running in tandem as eBPF JIT is > > hammered > > should *also* be measured with perf for iTLB and dTLB. ie, the patch > > can > > provide such results as a justifications. > > Song had done some tests on the old prog pack version that to me seemed > to indicate most (or possibly all) of the benefit was direct map > fragmentation reduction. Matches my observations but I also provided quite a bit of hints as to *why* I think that is. I suggested lib/test_kmod.c as an example beefy multithreaded selftests which really kicks the hell out of the kernel with whatever crap you want to run. That is precicely how I uncovered some odd kmod bug lingering for years. > This was surprised me, since 2MB kernel text > has shown to be beneficial. > > Otherwise +1 to all these comments. This should be clear about what the > benefits are. I would add, that this is also much nicer about TLB > shootdowns than the existing way of loading text and saves some memory. > > So I think there are sort of four areas of improvements: > 1. Direct map fragmentation reduction (dTLB miss improvements). The dTLB gains should be on the benchmark which runs in tandem to the ebpf-JIT-monster-selftest, not on the ebpf-JIT-monster-selftest, right? > This > sort of does it as a side effect in this series, and the solution Mike > is talking about is a more general, probably better one. > 2. 2MB mapped JITs. This is the iTLB side. I think this is a decent > solution for this, but surprisingly it doesn't seem to be useful for > JITs. (modules testing TBD) Yes I'm super eager to get this tested. In fact I wonder if one can boot Linux with less memory too... > 3. Loading text to reused allocation with per-cpu mappings. This > reduces TLB shootdowns, which are a short term load and teardown time > performance drag. My understanding is this is more of a problem on > bigger systems with many CPUs. This series does a decent job at this, > but the solution is not compatible with modules. Maybe ok since modules > don't load as often as JITs. There are some tests like fstests which make heavy use of module removal. But as a side effect, indeed I like to reboot to have a fresh system before running fstests. I guess fstests should run with a heavily fragmented memory too as a side corner case thing. > 4. Having BPF progs share pages. This saves memory. This series could > probably easily get a number for how much. Once that does hit modules / kprobes / ftrace, the impact is much much greater obviously. Luis