Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp815874iog; Fri, 24 Jun 2022 15:02:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1fryOKDrc0/VCbmFdXZLxsBS/G4NJKz7JFMzhdvJWzhr9ZOPxiEZtF3wIcPNGQgrVCCwd X-Received: by 2002:a05:6402:26cb:b0:436:2173:3f7 with SMTP id x11-20020a05640226cb00b00436217303f7mr1554902edd.61.1656108160288; Fri, 24 Jun 2022 15:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656108160; cv=none; d=google.com; s=arc-20160816; b=bUQgJR8RCJn4ZZX0UDpS7k19/yEbu7qLKfDHRa2l8HV+8TbaasdeMgLjDqT8gSKj6G Z4W/AU1X1AjiS70jBV6o+inXJizMEvfi2YB3j9uE3d8R8yngpmnUmopz+5lhUvIIaCmi FYMc0Avz4Q9uky45o3rWkObOy0Kd0OCGT2EA9V1OjuOGPJBLOod56wxzZsyTe1lNgEXQ HBZIq4nLG93qr2B16Zet1elyMFTTvYUhXHucxfkaFwO9+z8pURTca7e0y8BomCroh2oY 396YnStUip025pOwHv+BexwG08fl2jlOUj96g6+AjI3Ob0mdPdJ3aZ3nYbHCUB2gyGH7 EOvg== 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=FBd/o+riTofWrHtXS7dyUQ2RPTSdRq/CQF7NZxRURDY=; b=yc3f3RZDZW5ZeM5CRYrxDPuB4KmTESIFi3+aah/rl6wYblSNy4+P1ozJIzWEWEoHz1 VBiJNHxZc723LqwSo0N+zfpeYGcnzeSLAo5g68PdwRm0QZcYhwdwh0TmAog5+Lnmauo+ ogKOAXzjwVC6AB8mIMKIephGlvX4MeLblJZHL7Oao2KgZQybYu6OtLsHau52uEZQ2Dgk XcvkUUNHnXQ2WAskFb15GlrahYRwx2La23QxloT+xepCsqk/3lF19sCX3RVCBanwUDPZ 8k4BFWk+OWnRra0KlTVMr6R5joAOkUYRuiZBxkepAYBmSkEQbETRov/U2NgjkE/dhyTj 1qhQ== 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 cx9-20020a170906c80900b006ff153d1a5asi3262059ejb.246.2022.06.24.15.02.14; Fri, 24 Jun 2022 15:02:40 -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 S231924AbiFXV5o convert rfc822-to-8bit (ORCPT + 99 others); Fri, 24 Jun 2022 17:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiFXV5j (ORCPT ); Fri, 24 Jun 2022 17:57:39 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E80F87B7A for ; Fri, 24 Jun 2022 14:57:39 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25OLaDBx012630 for ; Fri, 24 Jun 2022 14:57:39 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gwcu743ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 24 Jun 2022 14:57:38 -0700 Received: from twshared34609.14.frc2.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 24 Jun 2022 14:57:38 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 11B5C94C3A4A; Fri, 24 Jun 2022 14:57:31 -0700 (PDT) From: Song Liu To: , , CC: , , , , , Song Liu Subject: [PATCH v5 bpf-next 5/5] bpf: simplify select_bpf_prog_pack_size Date: Fri, 24 Jun 2022 14:57:12 -0700 Message-ID: <20220624215712.3050672-6-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220624215712.3050672-1-song@kernel.org> References: <20220624215712.3050672-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: KrrfgsGz0Z4vm6zhzZuxbNhLCZXeXXVx X-Proofpoint-GUID: KrrfgsGz0Z4vm6zhzZuxbNhLCZXeXXVx 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-06-24_09,2022-06-24_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 83f5a98517d5..fbbfb7534979 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -854,22 +854,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