From patchwork Thu Jul 7 22:35:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 12910364 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 56819C433EF for ; Thu, 7 Jul 2022 22:36:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EB546B007B; Thu, 7 Jul 2022 18:36:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 725CC6B007D; Thu, 7 Jul 2022 18:36:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DC036B007E; Thu, 7 Jul 2022 18:36:34 -0400 (EDT) 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 363B06B007B for ; Thu, 7 Jul 2022 18:36:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 18F9E606FB for ; Thu, 7 Jul 2022 22:36:34 +0000 (UTC) X-FDA: 79661764308.23.FBAA1D9 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf08.hostedemail.com (Postfix) with ESMTP id 9C792160015 for ; Thu, 7 Jul 2022 22:36:33 +0000 (UTC) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 267KPxCE000753 for ; Thu, 7 Jul 2022 15:36:32 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h5kgpqxk0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 07 Jul 2022 15:36:32 -0700 Received: from twshared0725.22.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) 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 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ouni0F4mbSbavV6OFrwxstpkI4j4E0UX X-Proofpoint-GUID: ouni0F4mbSbavV6OFrwxstpkI4j4E0UX 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657233393; a=rsa-sha256; cv=none; b=oXCKMqK0Z65ze8Ez9zsFW+mecFgKL6Y1mU1z65XbLlUTS3ixBAnBtVKecccTPJ4tSWu78k CP+Wp/+yEQZQn1F6QtPVPcalV0RhjvenJbKyhPUwNg8ThB0/GGLxGXoDa7H+NvlRVqZQHc 2c4MCfkEtASFiea73QbUX+35V6KqS80= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=none (imf08.hostedemail.com: domain of "prvs=8187d1962c=songliubraving@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=8187d1962c=songliubraving@fb.com"; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657233393; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=arf+ZE5uvAQHwO/XYDInL6YozP4LMI1hCPKixw7SNiQ=; b=54QNOXIjXLGqKx46UR7tRIllmK7cyVGgdwchwdYmAZHsYlMEvoDWQJWoSgy/Zq2F1fGmCg dI+Xd/PNZw4H0lAIif+I1JJ2jlZZv+yne5M3yfNn5dBBA/H4m+PKxITkVr/biGguo1IlSN je6RHrR6mhxQi2EWo9Bh2M2ko21OQAE= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9C792160015 Authentication-Results: imf08.hostedemail.com; dkim=none; spf=none (imf08.hostedemail.com: domain of "prvs=8187d1962c=songliubraving@fb.com" has no SPF policy when checking 67.231.145.42) smtp.mailfrom="prvs=8187d1962c=songliubraving@fb.com"; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=kernel.org (policy=none) X-Stat-Signature: b6hpys7wzmnhh94cuh13kwgzrofw7dp5 X-Rspam-User: X-HE-Tag: 1657233393-499750 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 --- 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; }