Skip to content

Commit

Permalink
DPDK: use multiple mbufs (#3582)
Browse files Browse the repository at this point in the history
* enable second mbuf

* Check hugepages are greater than 0

* Hugepages: rework hugepage ask to allow minimum from user

* DPDK: mempool use 2048 and 8096
  • Loading branch information
mcgov authored Jan 7, 2025
1 parent 48ee75a commit 0aa0c25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
26 changes: 18 additions & 8 deletions lisa/tools/hugepages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from enum import Enum
from typing import Any, Set

from assertpy import assert_that

from lisa.executable import Tool
from lisa.tools.echo import Echo
from lisa.tools.free import Free
Expand Down Expand Up @@ -63,13 +65,14 @@ def get_hugepage_sizes_in_kb(self) -> Set[int]:
hugepage_sizes.add(int(matched_hugepage.group("hugepage_size_in_kb")))
return hugepage_sizes

def _enable_hugepages(self, hugepage_size_kb: HugePageSize) -> None:
def _enable_hugepages(
self, hugepage_size_kb: HugePageSize, request_space_kb: int
) -> None:
echo = self.node.tools[Echo]
meminfo = self.node.tools[Free]
nics_count = len(self.node.nics.get_nic_names())
numa_nodes = self.node.tools[Lscpu].get_numa_node_count()
# ask for enough space, note that we enable pages per numa node

request_space_kb = (nics_count - 1) * 1024 * 1024 * numa_nodes * 2
free_memory_kb = meminfo.get_free_memory_kb()

if free_memory_kb < request_space_kb:
Expand All @@ -79,24 +82,29 @@ def _enable_hugepages(self, hugepage_size_kb: HugePageSize) -> None:
f"Requesting {request_space_kb} KB found {free_memory_kb} "
"KB free."
)

request_pages = request_space_kb // hugepage_size_kb.value
total_request_pages = request_space_kb // hugepage_size_kb.value
pages_per_numa_node = total_request_pages // numa_nodes
assert_that(pages_per_numa_node).described_as(
"Must request huge page count > 0. Verify this system has enough "
"free memory to allocate ~2GB of hugepages"
).is_greater_than(0)
for i in range(numa_nodes):
# nr_hugepages will be written with the number calculated
# based on 2MB hugepages if not specified, subject to change
# this based on further discussion
echo.write_to_file(
f"{request_pages}",
f"{pages_per_numa_node}",
self.node.get_pure_path(
f"/sys/devices/system/node/node{i}/hugepages/"
f"hugepages-{hugepage_size_kb.value}kB/nr_hugepages"
),
sudo=True,
)

def init_hugepages(self, hugepage_size: HugePageSize) -> None:
def init_hugepages(self, hugepage_size: HugePageSize, minimum_gb: int = 2) -> None:
mount = self.node.tools[Mount]
hugepage_sizes = self.get_hugepage_sizes_in_kb()
minimum_kb = minimum_gb * 1024 * 1024
if hugepage_size.value not in hugepage_sizes:
raise UnsupportedOperationException(
f"Supported hugepage sizes in kB are: {hugepage_sizes}."
Expand All @@ -109,4 +117,6 @@ def init_hugepages(self, hugepage_size: HugePageSize) -> None:
fs_type=FileSystem.hugetlbfs,
options=f"pagesize={hugepage_size.value}KB",
)
self._enable_hugepages(hugepage_size_kb=hugepage_size)
self._enable_hugepages(
hugepage_size_kb=hugepage_size, request_space_kb=minimum_kb
)
1 change: 1 addition & 0 deletions microsoft/testsuites/dpdk/dpdktestpmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def generate_testpmd_command(
f"{self._testpmd_install_path} {core_list} "
f"{nic_include_info} -- --forward-mode={mode} "
f"-a --stats-period 2 --nb-cores={forwarding_cores} {extra_args} "
"--mbuf-size=2048,8096"
)

def run_for_n_seconds(self, cmd: str, timeout: int) -> str:
Expand Down
2 changes: 1 addition & 1 deletion microsoft/testsuites/dpdk/dpdkutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def initialize_node_resources(

# init and enable hugepages (required by dpdk)
hugepages = node.tools[Hugepages]
hugepages.init_hugepages(hugepage_size)
hugepages.init_hugepages(hugepage_size, minimum_gb=4)

assert_that(len(node.nics)).described_as(
"Test needs at least 1 NIC on the test node."
Expand Down

0 comments on commit 0aa0c25

Please sign in to comment.