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 090ACC433FE for ; Tue, 8 Nov 2022 21:41:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 204826B0072; Tue, 8 Nov 2022 16:41:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B5056B0073; Tue, 8 Nov 2022 16:41:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07D878E0001; Tue, 8 Nov 2022 16:41:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EAE616B0072 for ; Tue, 8 Nov 2022 16:41:35 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A6459141254 for ; Tue, 8 Nov 2022 21:41:35 +0000 (UTC) X-FDA: 80111596950.28.B409BD7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 3A4C31C000A for ; Tue, 8 Nov 2022 21:41:27 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3B645617A5 for ; Tue, 8 Nov 2022 21:40:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F523C43150 for ; Tue, 8 Nov 2022 21:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667943618; bh=DG52Qt0X9uCRX4ZMFnlRQ+I0s2VdUOhaMVzB3OcS3is=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IwpsXa1m++OKWum/FHqab2HECstRVHJ3d9f/WLq38YZQhhgNNwXzKYiHucx4RkxvU ufNxCSjolRd1BPya53EdgWhXN7ReJJg9BGttma9Yy8Ad51gHn9Gy+Nan6YrhNyA/ge 7wUFoqE0T4ZzQnQrC0iHZt9ffeBii7LB0gFGZCprbJ/nMdCbsJjniwsQue6RifyHL0 ECLp3zrEHuuHG+PSuqdlGfsTVUlY2+OX1lmSvWl9hn9Tybb5eQymxk+zoVuKi2Xlum LeTKgnL7WhIarVdgyTITHfOywdpG54itAmsqjtws6aMPn2+rlWk+5K+1qf5ripDmKs Zom6QKPY20PGw== Received: by mail-ej1-f46.google.com with SMTP id t25so41961055ejb.8 for ; Tue, 08 Nov 2022 13:40:18 -0800 (PST) X-Gm-Message-State: ANoB5pnif0lo7szzBQ8Fj9YUKWB3PUSZg59DbsnH1GG3dzT8w06Wp73W 6ABqyum7WdhsSrBpOUAQARTZD/JPJQPMASYROJE= X-Google-Smtp-Source: AA0mqf7vWZd1US4JgjryCPXuH+3J1irvG1VGRjt97h/YYupJixqA3kqC6TR1QrcBsLJ//jQPsAGt9UGEfXvqoCgyTew= X-Received: by 2002:a17:907:2995:b0:7ae:8956:ab56 with SMTP id eu21-20020a170907299500b007ae8956ab56mr995385ejc.719.1667943616639; Tue, 08 Nov 2022 13:40:16 -0800 (PST) MIME-Version: 1.0 References: <20221107223921.3451913-1-song@kernel.org> In-Reply-To: From: Song Liu Date: Tue, 8 Nov 2022 13:40:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 0/5] execmem_alloc for BPF programs To: Christophe Leroy Cc: Mike Rapoport , "bpf@vger.kernel.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "x86@kernel.org" , "peterz@infradead.org" , "hch@lst.de" , "rick.p.edgecombe@intel.com" , "aaron.lu@intel.com" , "mcgrof@kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 3A4C31C000A X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IwpsXa1m; spf=pass (imf21.hostedemail.com: domain of song@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=song@kernel.org; dmarc=temperror reason="query timed out" header.from=kernel.org (policy=temperror) X-Stat-Signature: ab4sdozefzynca3yo7yt5b8gu3rftp81 X-HE-Tag: 1667943687-242005 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 Tue, Nov 8, 2022 at 11:43 AM Christophe Leroy wrote: > > > > Le 08/11/2022 =C3=A0 19:41, Song Liu a =C3=A9crit : > > On Tue, Nov 8, 2022 at 3:27 AM Mike Rapoport wrote: > >> > >> Hi Song, > >> > >> On Mon, Nov 07, 2022 at 02:39:16PM -0800, Song Liu wrote: > >>> This patchset tries to address the following issues: > >>> > >>> 1. Direct map fragmentation > >>> > >>> On x86, STRICT_*_RWX requires the direct map of any RO+X memory to be= also > >>> RO+X. These set_memory_* calls cause 1GB page table entries to be spl= it > >>> into 2MB and 4kB ones. This fragmentation in direct map results in bi= gger > >>> and slower page table, and pressure for both instruction and data TLB= . > >>> > >>> Our previous work in bpf_prog_pack tries to address this issue from B= PF > >>> program side. Based on the experiments by Aaron Lu [4], bpf_prog_pack= has > >>> greatly reduced direct map fragmentation from BPF programs. > >> > >> Usage of set_memory_* APIs with memory allocated from vmalloc/modules > >> virtual range does not change the direct map, but only updates the > >> permissions in vmalloc range. The direct map splits occur in > >> vm_remove_mappings() when the memory is *freed*. > >> > >> That said, both bpf_prog_pack and these patches do reduce the > >> fragmentation, but this happens because the memory is freed to the sys= tem > >> in 2M chunks and there are no splits of 2M pages. Besides, since the s= ame > >> 2M page used for many BPF programs there should be way less vfree() ca= lls. > >> > >>> 2. iTLB pressure from BPF program > >>> > >>> Dynamic kernel text such as modules and BPF programs (even with curre= nt > >>> bpf_prog_pack) use 4kB pages on x86, when the total size of modules a= nd > >>> BPF program is big, we can see visible performance drop caused by hig= h > >>> iTLB miss rate. > >> > >> Like Luis mentioned several times already, it would be nice to see num= bers. > >> > >>> 3. TLB shootdown for short-living BPF programs > >>> > >>> Before bpf_prog_pack loading and unloading BPF programs requires glob= al > >>> TLB shootdown. This patchset (and bpf_prog_pack) replaces it with a l= ocal > >>> TLB flush. > >>> > >>> 4. Reduce memory usage by BPF programs (in some cases) > >>> > >>> Most BPF programs and various trampolines are small, and they often > >>> occupies a whole page. From a random server in our fleet, 50% of the > >>> loaded BPF programs are less than 500 byte in size, and 75% of them a= re > >>> less than 2kB in size. Allowing these BPF programs to share 2MB pages > >>> would yield some memory saving for systems with many BPF programs. Fo= r > >>> systems with only small number of BPF programs, this patch may waste = a > >>> little memory by allocating one 2MB page, but using only part of it. > >> > >> I'm not convinced there are memory savings here. Unless you have hundr= eds > >> of BPF programs, most of 2M page will be wasted, won't it? > >> So for systems that have moderate use of BPF most of the 2M page will = be > >> unused, right? > > > > There will be some memory waste in such cases. But it will get better w= ith: > > 1) With 4/5 and 5/5, BPF programs will share this 2MB page with kernel = .text > > section (_stext to _etext); > > 2) modules, ftrace, kprobe will also share this 2MB page; > > 3) There are bigger BPF programs in many use cases. > > And what I love with this series (for powerpc/32) is that we will likely > now be able to have bpf, ftrace, kprobe without the performance cost of > CONFIG_MODULES. Yeah, I remember reading emails about using tracing tools without CONFIG_MODULES. We still need more work (beyond this set) to make it happen for powerpc/32. For example, current powerpc bpf_jit doesn't support jitting into ROX memory. Song > > Today, CONFIG_MODULES means page mapping, which means handling of kernel > page in ITLB miss handlers. > > By using some of the space between end of rodata and start of inittext, > we are able to use ROX linear memory which is mapped by blocks. It means > there is no need to handle kernel text in ITLB handler (You can look at > https://elixir.bootlin.com/linux/v6.1-rc3/source/arch/powerpc/kernel/head= _8xx.S#L191 > to better understand what I'm talking about). > > Thanks > Christophe