Skip to content

Commit 25bb040

Browse files
Huge pages support (#113)
Co-authored-by: Krishnamurthy Jambur <[email protected]>
1 parent 87b7788 commit 25bb040

File tree

3 files changed

+61
-76
lines changed

3 files changed

+61
-76
lines changed

standalone-node/docs/user-guide/desktop-virtualization-cloud-init.md

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
- NOTE: The username `guest` is used throughout this configuration (e.g., in sudoers, systemd user services, etc.).
44
To use a different user, replace all occurrences of `guest` with the `user_name` that is set in the `User Credentials` section of the `config-file`.
55
For example, if your user is 'myuser', replace `guest` with `myuser` in:
6-
- /etc/sudoers.d/idv_scripts
7-
- /etc/systemd/system/[email protected]/autologin.conf
8-
- runcmd section (sudo -u ...)
9-
- Any other relevant locations in this file.
10-
11-
Author(s): Krishna, Shankar
12-
13-
Last updated: 25/06/2025
6+
- /etc/sudoers.d/idv_scripts
7+
- /etc/systemd/system/[email protected]/autologin.conf
8+
- runcmd section (sudo -u ...)
9+
- Any other relevant locations in this file.
1410

1511
## Abstract
1612

@@ -48,38 +44,7 @@ write_files:
4844
append: true
4945
content: |
5046
export INTEL_IDV_GPU_PRODUCT_ID=$(cat /sys/devices/pci0000:00/0000:00:02.0/device | sed 's/^0x//')
51-
export INTEL_IDV_GPU_VENDOR_ID=$(cat /sys/devices/pci0000:00/0000:00:02.0/vendor | sed 's/^0x//')
52-
53-
# hugepages.service pre-allocates enough 2MB hugepages for 2 VMs with 6GB RAM each.
54-
# Formula: 6 (memory per VM in GB) * 2048 (2MB pages per GB) * 2 (Number of VMs) = total hugepages needed.
55-
# Adjust the 'memory per VM in GB' and 'number of VMs' as needed.
56-
- path: /usr/bin/allocate_hugepages.sh
57-
permissions: '0755'
58-
content: |
59-
#!/bin/bash
60-
HUGEPAGES=$(( 6 * 2048 * 2 ))
61-
HUGEPAGES_KB=$((HUGEPAGES * 2048))
62-
MEM_TOTAL_KB=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
63-
MEM_FREE_KB=$(awk '/MemFree/ {print $2}' /proc/meminfo)
64-
if [ "$MEM_TOTAL_KB" -le "$HUGEPAGES_KB" ] || [ "$MEM_FREE_KB" -le "$HUGEPAGES_KB" ]; then
65-
echo "ERROR: Not enough memory for hugepages allocation: need $HUGEPAGES_KB kB, total $MEM_TOTAL_KB kB, free $MEM_FREE_KB kB" >&2
66-
exit 1
67-
fi
68-
echo $HUGEPAGES > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
69-
70-
- path: /etc/systemd/system/hugepages.service
71-
permissions: '0644'
72-
content: |
73-
[Unit]
74-
Description=Configure Hugepages
75-
Before=k3s.service
76-
77-
[Service]
78-
Type=oneshot
79-
ExecStart=/usr/bin/allocate_hugepages.sh
80-
81-
[Install]
82-
WantedBy=multi-user.target
47+
export INTEL_IDV_GPU_VENDOR_ID=$(cat /sys/devices/pci0000:00/0000:00:02.0/vendor | sed 's/^0x//')
8348
8449
# autologin.conf configures automatic login for the specified user on tty1.
8550
# Change AUTOLOGIN_USER to your intended username if not using 'guest' user.
@@ -156,15 +121,10 @@ write_files:
156121
runcmd:
157122
# Source /etc/environment to ensure newly created environment variables are available to subsequent commands in this boot sequence
158123
- source /etc/environment
159-
- udevadm control --reload-rules
160-
- systemctl enable hugepages.service
161-
- systemctl start hugepages.service
124+
- udevadm control --reload-rules
162125
# Change `guest` to your intended username if not using 'guest' user.
163126
- sudo -u guest XDG_RUNTIME_DIR=/run/user/$(id -u guest) systemctl --user enable idv-init.service
164127
- sudo -u guest XDG_RUNTIME_DIR=/run/user/$(id -u guest) systemctl --user start idv-init.service
165128
- test -f /opt/user-apps/network_config.sh && bash /opt/user-apps/network_config.sh /etc/cloud/custom_network.conf || echo "network_config.sh is missing"
166-
- test -f /opt/user-apps/apply_bridge_nad.sh && bash /opt/user-apps/apply_bridge_nad.sh /etc/cloud/custom_network.conf > /etc/cloud/apply_bridge_nad.log 2>&1 &
167-
- sudo systemctl restart k3s.service && while [ "$(systemctl is-active k3s.service)" != "active" ]; do echo "Waiting for k3s.service"; sleep 5; done; echo "k3s started"
168-
- k wait --for=condition=ready pod --all --timeout=300s
169-
129+
- test -f /opt/user-apps/apply_bridge_nad.sh && bash /opt/user-apps/apply_bridge_nad.sh /etc/cloud/custom_network.conf > /etc/cloud/apply_bridge_nad.log 2>&1 & || echo "apply_bridge_nad.sh is missing"
170130
```

standalone-node/installation_scripts/config-file

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ host_type="kubernetes"
5454
# Note: If the Edge Node has only a single hard disk, update the lvm_size_ingb value; otherwise, skip it.
5555
lvm_size_ingb="0"
5656

57+
# -------------------- Huge Page Size Configuration --------------------
58+
# Configure the huge page size for guest VMs (optional).
59+
# Set this value based on the requirements of your guest VMs.
60+
# Leave it empty if huge pages are not needed.
61+
#
62+
# Default hugepage table size is 2048.
63+
# If the hugepage table size is 2048, then the total memory allocated for hugepages is simply the product of these two values. For example, with a 2MB hugepage size, 2048 hugepages would consume 4GB of memory (2048 * 2MB = 4GB)
64+
# Example:
65+
# huge_page_config="12 * 1024"
66+
# This sets up 24GB of huge pages, huge page size of 2MB (2048).
67+
# Calculation: 12 * 1024 * 2048 bytes = 24GB
68+
69+
huge_page_config=""
5770

5871
# -------------------Custom cloud-init Config file---------------------
5972
# This section is to customize the cloud-init config file as per User Wish

standalone-node/provisioning_scripts/install-os.sh

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -555,39 +555,51 @@ custom_cloud_init_updates() {
555555
# Check the host type and update cloud-init accordingly
556556
host_type=$(grep '^host_type=' "$CONFIG_FILE" | cut -d '=' -f2)
557557
host_type=$(echo "$host_type" | tr -d '"')
558+
huge_page_size=$(grep '^huge_page_config=' "$CONFIG_FILE" | cut -d '=' -f2 | tr -d '"')
558559

560+
# Update cloud-init file to start k3s stack installations for hosty type kubernetes
559561
if [ "$host_type" == "kubernetes" ]; then
560-
# Update cloud-init file to start k3s stack installations
561-
awk '
562-
BEGIN {
563-
line1 = "chmod +x /etc/cloud/k3s-configure.sh"
564-
line2 = "bash /etc/cloud/k3s-configure.sh"
562+
563+
# If huge page value set make this line as start of cloud-init file
564+
if [ -n "$huge_page_size" ]; then
565+
line0="echo $(( huge_page_size )) | tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages"
566+
else
567+
line0=""
568+
fi
569+
# K3 configuration
570+
line1="chmod +x /etc/cloud/k3s-configure.sh"
571+
line2="bash /etc/cloud/k3s-configure.sh"
572+
573+
awk -v line0="$line0" -v line1="$line1" -v line2="$line2" '
574+
BEGIN {
565575
runcmd = 0
566576
in_block = 0
567-
}
568-
569-
/^runcmd:/ { runcmd = 1 }
570-
571-
runcmd && /^ - \|/ { in_block = 1 }
572-
{
573-
print
574-
next_line = $0
575-
}
576-
577-
in_block && $0 !~ /^ / {
578-
print " " line1
579-
print " " line2
580-
in_block = 0
581-
runcmd = 0
582-
}
583-
584-
END {
585-
if (in_block) {
586-
print " " line1
587-
print " " line2
588-
}
589-
}
590-
' "$CLOUD_INIT_FILE" > "${CLOUD_INIT_FILE}.tmp" && mv "${CLOUD_INIT_FILE}.tmp" "$CLOUD_INIT_FILE"
577+
}
578+
579+
/^runcmd:/ { runcmd = 1 }
580+
581+
runcmd && /^ - \|/ { in_block = 1 }
582+
{
583+
print
584+
}
585+
586+
in_block && $0 !~ /^ / {
587+
if (line0 != "") print " " line0
588+
print " " line1
589+
print " " line2
590+
in_block = 0
591+
runcmd = 0
592+
}
593+
594+
END {
595+
if (in_block) {
596+
if (line0 != "") print " " line0
597+
print " " line1
598+
print " " line2
599+
}
600+
}
601+
' "$CLOUD_INIT_FILE" > "${CLOUD_INIT_FILE}.tmp" && mv "${CLOUD_INIT_FILE}.tmp" "$CLOUD_INIT_FILE"
602+
591603
elif [ "$host_type" == "container" ]; then
592604
# TODO: will be expand in future
593605
echo "host type is container , docker services will start"

0 commit comments

Comments
 (0)