如何配置Linux主机仅使用12个物理核心运行游戏服务器?
Hey Alex, let's tackle this for your game server setup. First, a quick hardware recap: your two X5650 CPUs deliver 12 physical cores (6 per socket) and 24 logical cores (via Hyper-Threading, 2 per physical core). Since game servers often rely heavily on single-core performance, we’ve got two tailored solutions to match your request:
Option 1: Disable Hyper-Threading to Use Only 12 Physical Cores
If your game is primarily single-threaded, Hyper-Threading can sometimes hurt performance by sharing physical core resources (like L1/L2 cache). Disabling it will let you use just the 12 physical cores, which is ideal for single-core-focused workloads.
Temporary fix (resets on reboot):
First, confirm your core topology withlscpu:lscpu | grep -E 'Core\(s\) per socket|Socket\(s\)|Thread\(s\) per core'You’ll see
Thread(s) per core: 2for your X5650s. Next, map logical cores to physical ones:for i in $(seq 0 23); do echo "Logical CPU $i → Physical Core $(cat /sys/devices/system/cpu/cpu$i/topology/core_id), Socket $(cat /sys/devices/system/cpu/cpu$i/topology/physical_package_id)" doneEach physical core will have two logical cores (e.g., physical core 0 maps to logical 0 and 1). To disable the hyper-threaded logical cores, run:
# Example: Disable every odd-numbered logical core (adjust if your mapping differs) for cpu in $(seq 1 2 23); do echo 0 > /sys/devices/system/cpu/cpu$cpu/online donePermanent fix (best practice):
The most reliable way is to disable Hyper-Threading directly in your server’s BIOS. Look for an option labeled "Hyper-Threading Technology" or similar, set it toDisabled, save changes, and reboot. Your system will now only recognize and use the 12 physical cores.
Option 2: Keep Hyper-Threading, but Bind Game Server to Physical Core Pairs
If your game can leverage multi-threading, you can keep Hyper-Threading enabled but ensure your game server uses both logical cores tied to each physical core, while isolating these cores from other system processes.
Step 1: Identify core pairs:
Use the same mapping command from Option 1 to note which logical cores belong to each physical core. For example:Logical CPU 0 → Physical Core 0, Socket 0
Logical CPU 1 → Physical Core 0, Socket 0
Logical CPU 2 → Physical Core 1, Socket 0
...Step 2: Bind your game server to specific cores:
Use thetasksetcommand to launch your game server with core affinity. For single-core performance focus, bind to one logical core per physical core:# Bind to the first logical core of each physical core (12 total) taskset -c 0,2,4,6,8,10,12,14,16,18,20,22 ./your_game_server_executableIf you want to use all 24 logical cores (utilizing Hyper-Threading), use:
taskset -c 0-23 ./your_game_server_executableIf you’re managing the game server via systemd, edit its service file (e.g.,
/etc/systemd/system/game-server.service) to set persistent core affinity:[Service] CPUAffinity=0,2,4,6,8,10,12,14,16,18,20,22 ExecStart=/path/to/your_game_server_executableThen reload systemd and restart the service:
systemctl daemon-reload systemctl restart game-server.service
Extra Optimizations for Game Servers
To further boost performance for latency-sensitive games:
- Add kernel parameters to reduce scheduling overhead. Edit
/etc/default/gruband update theGRUB_CMDLINE_LINUXline:
ReplaceGRUB_CMDLINE_LINUX="... nohz_full=0-11 rcu_nocbs=0-11"0-11with the range of logical cores you’re using (e.g.,0-23if using all cores). Then update GRUB:# Debian/Ubuntu update-grub # CentOS/RHEL grub2-mkconfig -o /boot/grub2/grub.cfg - Disable unnecessary system services to free up CPU resources for your game server.
内容的提问来源于stack exchange,提问作者Alex Ulmer




