Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp19262pxb; Tue, 12 Apr 2022 15:35:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5bA54G6+o8OLDgG0a2KPGGZ0Wv3ZYI6t+0fKTYzJVaEDFPWJ+4/KYQQgJe3/1xNH0ytKD X-Received: by 2002:a05:6a02:18b:b0:399:365e:f09c with SMTP id bj11-20020a056a02018b00b00399365ef09cmr33104397pgb.238.1649802928418; Tue, 12 Apr 2022 15:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649802928; cv=none; d=google.com; s=arc-20160816; b=D6cPb5c21VFm00PhjXOx4UTprIDuu8EHt/hwhe0yKJphgPqkHBjZapgdUKzWQJges4 al7Zv4tiBpvGuaQVRQIh1nzdWyNpXiE+3NtXpaTLnlyi7YolSiPki2BYWeh4b6vi3eSQ wXhI4iy9LaUTVSv86tAtDV1MlSEoPmGpy8O0Ffrt/ovn8WD1NhtiX/VyTAozS18vlA/l fORhIb1wyAQYHBG1ql+fckzDbBrtLktogN0AG5dTUpyiL1P46HaTi3j13V+W6jwnjVm7 15Ssu7+5uCTdry8Act7T1T6wkr+WUxexPOBgCoQqEPw86jXjIKhqW2/42u8lLE6kThaJ IQ0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=v58AtPisgONPGrESvFi97ulC9KOM2pgxYYIy/lVsYZU=; b=Uw6bLaTzQ8FSBOZYge62dlpCzYluBGPYZ9HG6v2GvbSxmtAgFg/9w5aqvWHRkoZlP1 sFndtMW8uC46C2rLgOUzQdd9jfjXZlcErk6jZaarlKR2w3gOdvKEbLgiHA6rDvDCJ4r3 wKKEk8uWnXwuiV8PJpUG+4TnAZtXrsdkmv1AK5wMW04bj9i93KznSCDbe4sYbwI1ktUH ErafV/WoXl0+9syPGj+B3JA10QX5W2SF6LAVF63NuidQiUfoIf7jPFFxVg0LlY8uQWsH x8rD1pnhsUUqej1znXrvuZQtFB7TavxUw9D2u2u2LQAVF4FqSAPvBBChi8V4p1SxpgA2 sXbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jdxbEG/c"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t4-20020a632244000000b003988eefb957si4029528pgm.536.2022.04.12.15.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:35:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jdxbEG/c"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3FC32197AFC; Tue, 12 Apr 2022 14:12:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237353AbiDKXzO (ORCPT + 99 others); Mon, 11 Apr 2022 19:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbiDKXzM (ORCPT ); Mon, 11 Apr 2022 19:55:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BACC27167; Mon, 11 Apr 2022 16:52:57 -0700 (PDT) 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 E1E3AB819B3; Mon, 11 Apr 2022 23:52:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94439C385B0; Mon, 11 Apr 2022 23:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649721174; bh=MA2honiXWGeOzO9WdwjpEsoZG2CtJDXDu3X4YUBIiQc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jdxbEG/cJ9bBPd0gnfltrog660KLU3COJSzzRSbWXk0ogQLHldVpvIsV35eeIAPq8 ulRhfQGXvvJPezfASRtce2+HmrpPTMIHbiSVMKVOt+QGSZ/AGS/Icda7n7BLqU3Nj8 dg9q7uGUmHZSoIlI9WttHJ+1tZjxSWtEX0nz+w0O2+XUWmLjpNqYD2aq56s0R9hX/7 Zqfwk9d8RFuZeLkafNhpc46EGa6nfi3rqTnc2vihzYdHGNxoqI7VO/b18TzLOsOqb9 8vZl9lfuDwzzS0yvHFYbJMI/xXlgZccHednOvnvhb6IwHus09/2iMAdod66G1iBTFq QmthySP0p+TZg== Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-2ec42eae76bso34234617b3.10; Mon, 11 Apr 2022 16:52:54 -0700 (PDT) X-Gm-Message-State: AOAM531pb5/lSEtlYb3HABuX+kYca0qHLlSa9dPRVRqySZKd4WJuwgQh kdlyLGp6w114o5X1w28U/SI6X5v25o8TmJTYuGs= X-Received: by 2002:a81:14c8:0:b0:2eb:eb91:d88f with SMTP id 191-20020a8114c8000000b002ebeb91d88fmr14373906ywu.148.1649721173532; Mon, 11 Apr 2022 16:52:53 -0700 (PDT) MIME-Version: 1.0 References: <20220411233549.740157-1-song@kernel.org> <20220411233549.740157-4-song@kernel.org> In-Reply-To: <20220411233549.740157-4-song@kernel.org> From: Song Liu Date: Mon, 11 Apr 2022 16:52:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 bpf 3/3] bpf: use module_alloc_huge for bpf_prog_pack To: bpf , Linux-MM , open list Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Andrew Morton , rick.p.edgecombe@intel.com, Christoph Hellwig , imbrenda@linux.ibm.com, Luis Chamberlain Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Mon, Apr 11, 2022 at 4:41 PM Song Liu wrote: > > module_alloc_huge for bpf_prog_pack so that BPF programs sit on PMD_SIZE > pages. This benefits system performance by reducing iTLB miss rate. > > Signed-off-by: Song Liu I am really sorry for spamming the list twice. The first set experienced long lag, so I thought it didn't get through. I also updated the commit log of 3/3, and this one is the latest version. Thanks, Song > --- > kernel/bpf/core.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > index 13e9dbeeedf3..fd45bdd80a75 100644 > --- a/kernel/bpf/core.c > +++ b/kernel/bpf/core.c > @@ -857,7 +857,7 @@ static size_t select_bpf_prog_pack_size(void) > void *ptr; > > size = BPF_HPAGE_SIZE * num_online_nodes(); > - ptr = module_alloc(size); > + ptr = module_alloc_huge(size); > > /* Test whether we can get huge pages. If not just use PAGE_SIZE > * packs. > @@ -881,7 +881,7 @@ static struct bpf_prog_pack *alloc_new_pack(void) > GFP_KERNEL); > if (!pack) > return NULL; > - pack->ptr = module_alloc(bpf_prog_pack_size); > + pack->ptr = module_alloc_huge(bpf_prog_pack_size); > if (!pack->ptr) { > kfree(pack); > return NULL; > @@ -889,7 +889,6 @@ static struct bpf_prog_pack *alloc_new_pack(void) > bitmap_zero(pack->bitmap, bpf_prog_pack_size / BPF_PROG_CHUNK_SIZE); > list_add_tail(&pack->list, &pack_list); > > - set_vm_flush_reset_perms(pack->ptr); > set_memory_ro((unsigned long)pack->ptr, bpf_prog_pack_size / PAGE_SIZE); > set_memory_x((unsigned long)pack->ptr, bpf_prog_pack_size / PAGE_SIZE); > return pack; > @@ -970,7 +969,9 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr) > if (bitmap_find_next_zero_area(pack->bitmap, bpf_prog_chunk_count(), 0, > bpf_prog_chunk_count(), 0) == 0) { > list_del(&pack->list); > - module_memfree(pack->ptr); > + set_memory_nx((unsigned long)pack->ptr, bpf_prog_pack_size / PAGE_SIZE); > + set_memory_rw((unsigned long)pack->ptr, bpf_prog_pack_size / PAGE_SIZE); > + vfree(pack->ptr); > kfree(pack); > } > out: > -- > 2.30.2 > >