Colderleo's blog Colderleo's blog
首页
Linux
C++
Python
前端
工具软件
mysql
索引
关于
GitHub (opens new window)

Colder Leo

热爱代码的打工人
首页
Linux
C++
Python
前端
工具软件
mysql
索引
关于
GitHub (opens new window)
  • 常见程序性能开销cost、latency延迟耗时的经验值
  • 面试常见问题
  • 静态链接-动态链接-elf详解-elfloader
  • 动态库和静态库的依赖问题
  • glibc和ld的编译调试-为某程序单独设置ld
  • dl_iterate_phdr遍历linkmap头、获取so加载地址
  • shell、bash语法和脚本模板
  • so文件查找路径
  • 逻辑地址-线性地址or虚拟地址-物理地址
  • 通过ELF读取当前进程的符号表并获取符号的版本信息
  • 虚拟内存,cache,TLB,页表
  • 用户内存空间分布和mmap
  • numa网卡绑定
  • 隔核绑核、服务器优化
    • 关闭服务
    • 查看核隔离情况
    • 隔核
    • 绑核
    • 可能有用的优化
      • 看起来重要的
      • 看起来不重要的
      • 其他可选(未必是优化):
      • 解释
      • 关闭下面的服务
      • 查看隔核效果
  • popen底层原理和仿照实现-execl
  • tmux用法
  • ASLR机制
  • 程序后台运行、恢复前台nohup
  • 大页内存huge_page
  • 用perf查看page-fault
  • Bash设置显示全部路径
  • 查看socket fd状态,设置nonblock
  • cout输出到屏幕的过程
  • 多进程写同一文件-write原子性-log日志
  • vim用法
  • epoll用法
  • signal信号、软中断、硬中断、alarm
  • 内核模块
  • 读写锁之pthread_rwlock和内核rwlock自旋读写锁
  • systemtap
  • xargs、awk用法
  • openssl libssl.so.10.so缺失问题
  • netstat用法
  • fork函数
  • tcp延迟确认ack
  • 90.centos7上一次std-string编译错误定位
  • docker用法
  • find用法
  • dmesg
  • gcc编译用法
  • avx-sse切换惩罚
  • Centos7防火墙
  • chmod用法
  • kernel-devel安装版本
  • Linux-Centos7系统安装、网络设置、常见报错
  • linux下g++编译c++文件
  • MegaCli 安装及使用
  • mysql
  • mysql忘记密码修改方法
  • set用法
  • crontab
  • ssh传文件scp
  • ssh连接
  • tcpdump、tshark、tcpreplay用法
  • ubantu root登录以及创建新用户
  • ubuntu安装g++和gdb
  • uClibc编译失败解决方法
  • win10安装WSL open-ssh
  • yum升级git
  • 比较so文件版本-md5sum
  • 查看磁盘信息
  • 合并两个硬盘,挂载到一个文件夹下
  • 软件安装目录usr-local-src
  • 下载centos历史版本
  • sh脚本转可执行文件、加密
  • Linux
gaoliu
2021-11-28
目录

隔核绑核、服务器优化

# 关闭服务

NetworkManager 超线程

# 查看核隔离情况

$ more /proc/cmdline 
BOOT_IMAGE=/vmlinuz-3.10.0-1062.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root r
d.lvm.lv=centos/swap rhgb quiet skew_tick=1 isolcpus=2-3 intel_pstate=disable nosoftlockup
1
2
3

# 隔核

https://blog.csdn.net/Frederick_Fung/article/details/116698835 (opens new window)

# 修改/etc/default/grub: GRUB_CMDLINE_LINUX="... isolcpus=1-2,7-8" 隔离1,2,7,8核心
vim /etc/default/grub 

# 更新配置 centos
grub2-mkconfig -o /boot/grub2/grub.cfg 

# 更新配置 ubuntu
update-grub

#  重启
reboot

#  查看结果
cat /proc/cmdline
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 绑核

https://blog.csdn.net/lanyzh0909/article/details/50404664

#include<sched.h>

// 绑定进程到cpu上
void set_cpu_affinity(int id)
{
    cpu_set_t mask;
    CPU_ZERO(&mask);
    CPU_SET(id, &mask);
    if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
    {
        fprintf(stderr, "warning: could not set CPU affinity/n");
    }
}

// 绑定线程到cpu上
int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 可能有用的优化

# 看起来重要的

isolcpus=2-17 nohz_full=2-17 nohz=on rcu_nocbs=2-17 rcu_nocb_poll intel_idle.max_cstate=0 processor.max_cstate=0 intel_pstate=disable idle=poll pcie_aspm.policy=performance irqaffinity=0

# 看起来不重要的

mce=ignore_ce ipmi_si.force_kipmid=0 nmi_watchdog=0 hpet=disabled clocksource=tsc tsc=reliable audit=0 acpi_irq_nobalance noht iommu=off intel_iommu=off noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off

# 其他可选(未必是优化):

transparent_hugepage=never

# 解释

  • noht 禁用超线程

  • nohz_full=2-17 nohz=on 禁用时间片时钟中断 查看时间片长度(通常是100ms): cat /proc/sys/kernel/sched_rr_timeslice_ms

# 关闭下面的服务

参考https://cloud.tencent.com/developer/article/1583554 (opens new window)

for SERVICE in
   avahi-daemon.service     crond.service        dnsmasq.service
   firewalld.service         lvm2-monitor.service     postfix.service
   rpcgssd.service          rpcidmapd.service          rpcsvcgssd.service
   wpa_supplicant.service    irqbalance.service
do systemctl  disable $SERVICE
    systemctl stop $SERVICE
done
1
2
3
4
5
6
7
8

以及 cpupower cpuspeed cpufreqd powerd irqbalance firewalld

# 查看隔核效果

命令行查看:

watch -d cat /proc/interrupts
1

测试程序查看

irq_test.cpp:

#include <iostream>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
using namespace std;

uint64_t now() { return __builtin_ia32_rdtsc(); }

int test() {
  unit64_t last = now();
  unit64_t start = now();
  int irq_times = 0;
  int irq_total_cycle = 0;

  unit64_t total_run_cycle = 1024*1024*1024;
  unit64_t irq_threshold = 300;
  while(1) {
    unit64_t cur = now(); //point B
    unit64_t diff = cur - last;
    if(diff > irq_threshold) { //check diff from point A -> B 
      irq_times++;
      irq_total_cycle += diff;
      cur = now();
      if(cur-start > total_run_cycle) break;
    }
    last = cur; //point A
  }
  printf("total_run_cycle=%ld, irq_times=%ld, irq_threshold=%d, irq_avg=%ld\n",
    total_run_cycle, irq_times, irq_threshold, irq_total_cycle/irq_times);
}
int main()
{
    test();
    test();
    test();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

编译运行

g++ irq_test.cpp
taskset -c 5 ./a.out
1
2
编辑 (opens new window)
上次更新: 2023/05/07, 17:27:54
numa网卡绑定
popen底层原理和仿照实现-execl

← numa网卡绑定 popen底层原理和仿照实现-execl→

最近更新
01
通过模板实现结构体成员拷贝-按成员名匹配
05-07
02
c++17通过模板获取类成员的个数
05-01
03
avx-sse切换惩罚
04-30
更多文章>
Theme by Vdoing | Copyright © 2019-2023 Colder Leo | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×