Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4258766imw; Thu, 7 Jul 2022 15:46:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKQ3s5Bc0qtPAhoPctvSKTczs96J3bX4KDHXPvrc8nmmUsaYak+1Xkd9QeTDOR2fgvvlbX X-Received: by 2002:a17:907:763b:b0:72a:ed40:190b with SMTP id jy27-20020a170907763b00b0072aed40190bmr423511ejc.622.1657233965788; Thu, 07 Jul 2022 15:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657233965; cv=none; d=google.com; s=arc-20160816; b=qNeXcFy0pTf2fFQdl3rgy/Zs7+oS63qQBrSeVNMmh7IU6BBPLxa5VGc7gVVpCPkMdo rEJGcuPCS9aDrjnkGpKXA0M9Cg6s++cNJrzW6jh5rwsaiY00+Phy6CXiJJplu8pSb6Ay HqcUqM33uhQXsqjRLpvA7FNdgKBOewMA2Q5p4xDqh5bbgVTUuOLQkuoCzAaWjVy/fERu KdDZ0YUM1QiAMCHPn4FvTBbyzkSMlMv5iqGvstAUR4EcbMwXkK2VRLlr0tkkg7xRGfTj HdWM8ACM2c3vFy3amdvLqSrm1rHGOIwqCcIOKjJUdvLDiiL1atdl0xvSwQE1QslfqQ7u W/Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JDmUcJOHYIOQVKrQvtCjwrNvPx8puV8dFknsF4KrXpc=; b=HJvk6up7eycG2rOcmASFIGIY9S9/FHKsvcCx7+zN6mGod1i+5UjQJTvq1UeJ9Xfp11 ZqF7yONS9Qjzewp6SWbbBBkk3SYptLzu9T0pB07GnwZpAi+BlaB0uBGPXj/0fdwUKsM/ B7irfhCyURsqw8b7YypW+7J0Ypzx1PbdIZtExY1cAMiPW51Wu/wiA1j7iY7Ow91I9VPg r2AjoOOvXDPsKXYBDBNEI8J2Jq1S+AUFuBoGFIv6ItKSTROpsbYu93P4sDC0ZcdSABW9 BQe4A93pjGQGkMe0MMclFPOX/1tlM1ZLttMZrknzFtUbP4ABpwyCMVJxQX3J6JWWbUPN u9RQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a056402500b00b00437deb23714si2433396eda.511.2022.07.07.15.45.40; Thu, 07 Jul 2022 15:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237062AbiGGWgj convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 Jul 2022 18:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237013AbiGGWgc (ORCPT ); Thu, 7 Jul 2022 18:36:32 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DDEE9C for ; Thu, 7 Jul 2022 15:36:31 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 267KPn7V010660 for ; Thu, 7 Jul 2022 15:36:31 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h5ashmbhe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 07 Jul 2022 15:36:31 -0700 Received: from twshared0725.22.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 7 Jul 2022 15:36:30 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 4AFEB9D349C5; Thu, 7 Jul 2022 15:36:10 -0700 (PDT) From: Song Liu To: , , CC: , , , , , , Song Liu Subject: [PATCH v6 bpf-next 5/5] bpf: simplify select_bpf_prog_pack_size Date: Thu, 7 Jul 2022 15:35:46 -0700 Message-ID: <20220707223546.4124919-6-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220707223546.4124919-1-song@kernel.org> References: <20220707223546.4124919-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: DQLoznQJNvnxq8Z1x3l3D3WFpI37C4Ct X-Proofpoint-GUID: DQLoznQJNvnxq8Z1x3l3D3WFpI37C4Ct X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-07_17,2022-06-28_01,2022-06-22_01 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/bpf/core.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index d1f32ac354d3..e1f8d36fb95c 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -857,22 +857,15 @@ static LIST_HEAD(pack_list); 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; } -- 2.30.2