From patchwork Thu May 19 20:20:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 12856017 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 0D455C433EF for ; Thu, 19 May 2022 20:26:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 811446B0072; Thu, 19 May 2022 16:26:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F6AB6B0075; Thu, 19 May 2022 16:26:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68CBF6B0073; Thu, 19 May 2022 16:26:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5BE1B6B0071 for ; Thu, 19 May 2022 16:26:30 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2CE8E211FD for ; Thu, 19 May 2022 20:26:30 +0000 (UTC) X-FDA: 79483625340.31.1B5F81E Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf30.hostedemail.com (Postfix) with ESMTP id B7A9780013 for ; Thu, 19 May 2022 20:26:04 +0000 (UTC) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24JKPGh5029522 for ; Thu, 19 May 2022 13:26:28 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3g4d82ah2d-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 19 May 2022 13:26:28 -0700 Received: from twshared0725.22.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 19 May 2022 13:26:22 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 78BE17D58F7C; Thu, 19 May 2022 13:21:02 -0700 (PDT) From: Song Liu To: , , CC: , , , , , , , Song Liu Subject: [PATCH v2 bpf-next 8/8] bpf: simplify select_bpf_prog_pack_size Date: Thu, 19 May 2022 13:20:37 -0700 Message-ID: <20220519202037.2401584-9-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220519202037.2401584-1-song@kernel.org> References: <20220519202037.2401584-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: SHrQ4dK20kVNxae6NR_uWzNGxx0MF6HK X-Proofpoint-ORIG-GUID: SHrQ4dK20kVNxae6NR_uWzNGxx0MF6HK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-19_06,2022-05-19_03,2022-02-23_01 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B7A9780013 X-Stat-Signature: 5hczzg4kx58s4trfy1azapa5a48i6kh7 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=none; spf=none (imf30.hostedemail.com: domain of "prvs=61387cfd06=songliubraving@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=61387cfd06=songliubraving@fb.com"; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=kernel.org (policy=none) X-HE-Tag: 1652991964-912110 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: Use huge_vmalloc_supported to simplify select_bpf_prog_pack_size, so that we don't allocate some huge pages and free them immediately. Suggested-by: Rick Edgecombe Signed-off-by: Song Liu Reported-by: kernel test robot Reported-by: kernel test robot --- kernel/bpf/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b64d91fcb0ba..62c8632a59a2 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -856,20 +856,14 @@ static size_t select_bpf_prog_pack_size(void) size_t size; void *ptr; - size = BPF_HPAGE_SIZE * num_online_nodes(); - ptr = module_alloc_huge(size); - - /* Test whether we can get huge pages. If not just use PAGE_SIZE - * packs. - */ - if (!ptr || !is_vm_area_hugepages(ptr)) { + if (huge_vmalloc_supported()) { + size = BPF_HPAGE_SIZE * num_online_nodes(); + bpf_prog_pack_mask = BPF_HPAGE_MASK; + } else { size = PAGE_SIZE; bpf_prog_pack_mask = PAGE_MASK; - } else { - bpf_prog_pack_mask = BPF_HPAGE_MASK; } - vfree(ptr); return size; }