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 07CFEC43217 for ; Mon, 14 Nov 2022 20:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CC7A6B0071; Mon, 14 Nov 2022 15:45:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67D5E6B0072; Mon, 14 Nov 2022 15:45:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 544DE8E0001; Mon, 14 Nov 2022 15:45:34 -0500 (EST) 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 40E3B6B0071 for ; Mon, 14 Nov 2022 15:45:34 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 07C8B1A0593 for ; Mon, 14 Nov 2022 20:45:34 +0000 (UTC) X-FDA: 80133228588.28.4DE3DBE Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf12.hostedemail.com (Postfix) with ESMTP id 6BFD740006 for ; Mon, 14 Nov 2022 20:45:33 +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 ams.source.kernel.org (Postfix) with ESMTPS id C33AEB81262 for ; Mon, 14 Nov 2022 20:45:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72C64C433D7 for ; Mon, 14 Nov 2022 20:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668458730; bh=/eoltmfxhsBQW5kbqj1zICYdalEqwl1ONE/tve5V7AE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IQCgWBHlftUOEBFnnrG/zBegCsdaFFUHrFU4LcjgMbRNhQhwia+oSFePr3A8Jmlv5 XIlOjrKtLHvNOVxHLQ0s9iYU8OdV/2z+Nj1qbj4kSU75jdQGF9AHe56N/7nk7ijwQt LStNFzhA6zuR208290meBL49XG2JI10ALR0nW3OBwrDcDNR50zwkCQVrLs6xmJLbhf YswuXiWK25+spdG0cTd+3vlcMn23oTWbpTmyKYb9q8s9p8mh8Tl8N7CZYF1Q49h0iJ LPS+jYwixSpYop/fYjky6Vvt6LnVZWSzV2xnONPWW3oUYxMIqcEZjV1oEXZ7v16B+Y dyA8QFXKg4LZw== Received: by mail-ej1-f44.google.com with SMTP id ft34so31204535ejc.12 for ; Mon, 14 Nov 2022 12:45:30 -0800 (PST) X-Gm-Message-State: ANoB5pmFCa8DoAAWhFi57rz8bxULZy/6aVDO9LrErpM8E1ee1vm/3kak DcnaQnxjcrdfVGy0lwY+N7qhywaeaBp07tCaU/A= X-Google-Smtp-Source: AA0mqf427AJW1JzObQrvS6YeAaU43qdBOSBTg00ztEgA6leExZNvsOuD0m2LF5ODPqjC58L5pQzObhvC14C39kr6VSc= X-Received: by 2002:a17:906:ad98:b0:7a1:e4c2:fb0a with SMTP id la24-20020a170906ad9800b007a1e4c2fb0amr11916627ejb.101.1668458728697; Mon, 14 Nov 2022 12:45:28 -0800 (PST) MIME-Version: 1.0 References: <20221107223921.3451913-1-song@kernel.org> <9e59a4e8b6f071cf380b9843cdf1e9160f798255.camel@intel.com> In-Reply-To: From: Song Liu Date: Mon, 14 Nov 2022 12:45:16 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 0/5] execmem_alloc for BPF programs To: Mike Rapoport Cc: "Edgecombe, Rick P" , "peterz@infradead.org" , "bpf@vger.kernel.org" , "linux-mm@kvack.org" , "hch@lst.de" , "x86@kernel.org" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "Lu, Aaron" Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668458733; a=rsa-sha256; cv=none; b=6ah+UsB6NMNc5LDjPNmLjW63dvbNYnPic9dfmw0UjWYaDme/QKCfhtTBIGSSGVyT8LLRze qkRadho0kUAxS0IZY767wykuucjjFTlD9wEaMSAq6ramEq49x110X40ohSsD8aYNOmibEh coHzlS3b3BmoiQk5U8Ro/t0RO/c5eOY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IQCgWBHl; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of song@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=song@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668458733; h=from:from: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=/eoltmfxhsBQW5kbqj1zICYdalEqwl1ONE/tve5V7AE=; b=5POkFvi+C27bb7ei4JCudUW5wF+QY9WJZrrHJ4yfEMW7K2iwRoDW8L2PtWNMQi7FFyGAp4 r40ru6icHaAJdlAXAPGibPqesf4dqBfB/zXHwBFIjZXefo7L0eVoy/uwf+aI66RU0EkYlb 7xATG/r2ui8W8LZWYgeXrrAweSTr3mw= X-Rspamd-Queue-Id: 6BFD740006 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IQCgWBHl; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of song@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=song@kernel.org X-Rspamd-Server: rspam06 X-Stat-Signature: gxymba34mmuu9swwwrinxsc3r4h6g6gk X-HE-Tag: 1668458733-668401 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 Sun, Nov 13, 2022 at 2:43 AM Mike Rapoport wrote: > > On Wed, Nov 09, 2022 at 09:43:50AM -0800, Song Liu wrote: > > On Wed, Nov 9, 2022 at 3:18 AM Mike Rapoport wrote: > > > > > [...] > > > > > > > > > > > > The proposed execmem_alloc() looks to me very much tailored for x86 > > > > > to be > > > > > used as a replacement for module_alloc(). Some architectures have > > > > > module_alloc() that is quite different from the default or x86 > > > > > version, so > > > > > I'd expect at least some explanation how modules etc can use execmem_ > > > > > APIs > > > > > without breaking !x86 architectures. > > > > > > > > I think this is fair, but I think we should ask ask ourselves - how > > > > much should we do in one step? > > > > > > I think that at least we need an evidence that execmem_alloc() etc can be > > > actually used by modules/ftrace/kprobes. Luis said that RFC v2 didn't work > > > for him at all, so having a core MM API for code allocation that only works > > > with BPF on x86 seems not right to me. > > > > While using execmem_alloc() et. al. in module support is difficult, folks are > > making progress with it. For example, the prototype would be more difficult > > before CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC > > (introduced by Christophe). > > > > We also have other users that we can onboard soon: BPF trampoline on > > x86_64, BPF jit and trampoline on arm64, and maybe also on powerpc and > > s390. > > Caching of large pages won't make any difference on arm64 and powerpc > because they do not support splitting of the direct map, so the only > potential benefit there is a centralized handling of text loading and I'm > not convinced execmem_alloc() will get us there. Sharing large pages helps reduce iTLB pressure, which is the second motivation here (after reducing direct map fragmentation). > > > > With execmem_alloc() as the first step I'm failing to see the large > > > picture. If we want to use it for modules, how will we allocate RO data? > > > with similar rodata_alloc() that uses yet another tree in vmalloc? > > > How the caching of large pages in vmalloc can be made useful for use cases > > > like secretmem and PKS? > > > > If RO data causes problems with direct map fragmentation, we can use > > similar logic. I think we will need another tree in vmalloc for this case. > > Since the logic will be mostly identical, I personally don't think adding > > another tree is a big overhead. > > Actually, it would be interesting to quantify memory savings/waste as the > result of using execmem_alloc() >From a random system in our fleet, execmem_alloc() saves: 139 iTLB entries (1x 2MB entry vs, 140x 4kB entries), which is more than 100% of L1 iTLB and about 10% of L2 TLB. It wastes 1.5MB memory, which is 0.0023% of system memory (64GB). I believe this is clearly a good trade-off. Thanks, Song