From patchwork Thu Jun 20 09:09:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Laatz, Kevin" X-Patchwork-Id: 1119621 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45V7x74dHGz9s7h for ; Fri, 21 Jun 2019 03:24:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732242AbfFTRY6 (ORCPT ); Thu, 20 Jun 2019 13:24:58 -0400 Received: from mga12.intel.com ([192.55.52.136]:64663 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfFTRY5 (ORCPT ); Thu, 20 Jun 2019 13:24:57 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2019 10:24:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,397,1557212400"; d="scan'208";a="359020397" Received: from silpixa00399838.ir.intel.com (HELO silpixa00399838.ger.corp.intel.com) ([10.237.223.110]) by fmsmga006.fm.intel.com with ESMTP; 20 Jun 2019 10:24:54 -0700 From: Kevin Laatz To: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, bjorn.topel@intel.com, magnus.karlsson@intel.com Cc: bpf@vger.kernel.org, intel-wired-lan@lists.osuosl.org, bruce.richardson@intel.com, ciara.loftus@intel.com, Kevin Laatz Subject: [PATCH 10/11] samples/bpf: use hugepages in xdpsock app Date: Thu, 20 Jun 2019 09:09:57 +0000 Message-Id: <20190620090958.2135-11-kevin.laatz@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190620090958.2135-1-kevin.laatz@intel.com> References: <20190620090958.2135-1-kevin.laatz@intel.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch modifies xdpsock to use mmap instead of posix_memalign. With this change, we can use hugepages when running the application in unaligned chunks mode. Using hugepages makes it more likely that we have physically contiguous memory, which supports the unaligned chunk mode better. Signed-off-by: Kevin Laatz Acked-by: Björn Töpel --- samples/bpf/xdpsock_user.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 7b4ce047deb2..8ed63ad68428 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -74,6 +74,7 @@ static int opt_interval = 1; static u64 opt_buffer_size = XSK_UMEM__DEFAULT_FRAME_SIZE; static u32 opt_umem_flags; static int opt_unaligned_chunks; +static int opt_mmap_flags; static u32 opt_xdp_bind_flags; static __u32 prog_id; @@ -438,6 +439,7 @@ static void parse_command_line(int argc, char **argv) case 'u': opt_umem_flags |= XDP_UMEM_UNALIGNED_CHUNKS; opt_unaligned_chunks = 1; + opt_mmap_flags = MAP_HUGETLB; break; case 'b': opt_buffer_size = atoi(optarg); @@ -707,11 +709,13 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - ret = posix_memalign(&bufs, getpagesize(), /* PAGE_SIZE aligned */ - NUM_FRAMES * opt_buffer_size); - if (ret) - exit_with_error(ret); - + /* Reserve memory for the umem. Use hugepages if unaligned chunk mode */ + bufs = mmap(NULL, NUM_FRAMES * opt_buffer_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS|opt_mmap_flags, -1, 0); + if (bufs == MAP_FAILED) { + printf("ERROR: mmap failed\n"); + exit(EXIT_FAILURE); + } /* Create sockets... */ umem = xsk_configure_umem(bufs, NUM_FRAMES * opt_buffer_size);