7장. KSM
qemu-kvm
프로세스의 메모리만 상속합니다. 게스트 가상 머신이 실행되면 게스트가 동일한 운영 체제 또는 애플리케이션을 실행할 때 게스트 가상 머신 운영 체제 이미지의 콘텐츠를 공유할 수 있습니다.
/sys/kernel/mm/ksm/merge_across_nodes
튜닝 가능 항목을 0
으로 변경합니다. 커널 메모리 회계 통계는 대량의 교차 노드 병합 후 결국 서로 모순될 수 있습니다. 따라서 KSM 데몬에서 대량의 메모리를 병합한 후 numad가 혼동될 수 있습니다. 시스템에 사용 가능한 메모리가 많은 경우 KSM 데몬을 끄고 비활성화하여 더 높은 성능을 얻을 수 있습니다. NUMA에 대한 자세한 내용은 Red Hat Enterprise Linux 성능 튜닝 가이드 를 참조하십시오.
ksm
서비스는 KSM 커널 스레드를 시작하고 중지합니다.ksmtuned
서비스는 동일한 페이지 병합을 동적으로 관리하면서ksm
을 제어하고 조정합니다.ksmtuned
서비스는ksm
을 시작하고 메모리 공유가 필요하지 않은 경우ksm
서비스를 중지합니다.ksmtuned
서비스에 새 게스트가 생성 또는 삭제될 때 실행할retune
매개변수가 있어야 합니다.
KSM 서비스
ksm
서비스는 qemu-kvm 패키지에 포함되어 있습니다. KSM은 Red Hat Enterprise Linux 6에서 기본적으로 꺼져 있습니다. 그러나 Red Hat Enterprise Linux 6를 KVM 호스트 물리적 시스템으로 사용하는 경우 ksm/ksmtuned
서비스를 통해 켜질 수 있습니다.
ksm
서비스가 시작되지 않으면 KSM은 2000 페이지만 공유합니다. 이 기본값은 낮으며 제한된 메모리 저장 이점을 제공합니다.
ksm
서비스가 시작되면 KSM은 호스트 물리적 시스템 기본 메모리의 절반까지 공유합니다. KSM이 더 많은 메모리를 공유할 수 있도록 ksm
서비스를 시작합니다.
service ksm start
# service ksm start
Starting ksm: [ OK ]
ksm
서비스는 기본 시작 시퀀스에 추가할 수 있습니다. chkconfig 명령을 사용하여 ksm
서비스를 영구적으로 만듭니다.
chkconfig ksm on
# chkconfig ksm on
KSM Tuning Service
ksmtuned
서비스에는 옵션이 없습니다. ksmtuned
서비스 루프는 ksm
을 조정합니다. 게스트 가상 머신을 만들거나 삭제할 때 ksmtuned
서비스는 libvirt에서 알림을 받습니다.
service ksmtuned start
# service ksmtuned start
Starting ksmtuned: [ OK ]
retune
매개변수를 사용하여 ksmtuned
서비스를 조정할 수 있습니다. retune
매개변수는 ksmtuned
에 튜닝 기능을 수동으로 실행하도록 지시합니다.
제한
- 활성화 임계값(KB)입니다. 모든qemu-kvm
프로세스의 합계에 추가된 증가 값이 총 시스템 메모리를 초과하는 경우 KSM 주기가 트리거됩니다.이 매개변수는
KSM_THRES_COEF
에 정의된 백분율의 kbytes와 동일합니다.
/etc/ksmtuned.conf
파일은 ksmtuned
서비스의 구성 파일입니다. 아래의 파일 출력은 기본 ksmtuned.conf
파일입니다.
Configuration file for ksmtuned. How long ksmtuned should sleep between tuning adjustments KSM_MONITOR_INTERVAL=60 Millisecond sleep between ksm scans for 16Gb server. Smaller servers sleep more, bigger sleep less. KSM_SLEEP_MSEC=10 KSM_NPAGES_BOOST is added to the npages value, when free memory is less than thres. KSM_NPAGES_BOOST=300 KSM_NPAGES_DECAY Value given is subtracted to the npages value, when free memory is greater than thres. KSM_NPAGES_DECAY=-50 KSM_NPAGES_MIN is the lower limit for the npages value. KSM_NPAGES_MIN=64 KSM_NAGES_MAX is the upper limit for the npages value. KSM_NPAGES_MAX=1250 KSM_TRES_COEF - is the RAM percentage to be calculated in parameter thres. KSM_THRES_COEF=20 KSM_THRES_CONST - If this is a low memory system, and the thres value is less than KSM_THRES_CONST, then reset thres value to KSM_THRES_CONST value. KSM_THRES_CONST=2048 uncomment the following to enable ksmtuned debug information LOGFILE=/var/log/ksmtuned DEBUG=1
# Configuration file for ksmtuned.
# How long ksmtuned should sleep between tuning adjustments
# KSM_MONITOR_INTERVAL=60
# Millisecond sleep between ksm scans for 16Gb server.
# Smaller servers sleep more, bigger sleep less.
# KSM_SLEEP_MSEC=10
# KSM_NPAGES_BOOST is added to the npages value, when free memory is less than thres.
# KSM_NPAGES_BOOST=300
# KSM_NPAGES_DECAY Value given is subtracted to the npages value, when free memory is greater than thres.
# KSM_NPAGES_DECAY=-50
# KSM_NPAGES_MIN is the lower limit for the npages value.
# KSM_NPAGES_MIN=64
# KSM_NAGES_MAX is the upper limit for the npages value.
# KSM_NPAGES_MAX=1250
# KSM_TRES_COEF - is the RAM percentage to be calculated in parameter thres.
# KSM_THRES_COEF=20
# KSM_THRES_CONST - If this is a low memory system, and the thres value is less than KSM_THRES_CONST, then reset thres value to KSM_THRES_CONST value.
# KSM_THRES_CONST=2048
# uncomment the following to enable ksmtuned debug information
# LOGFILE=/var/log/ksmtuned
# DEBUG=1
KSM 변수 및 모니터링
KSM은 모니터링 데이터를 /sys/kernel/mm/ksm/
디렉토리에 저장합니다. 이 디렉터리의 파일은 커널에 의해 업데이트되며 KSM 사용량 및 통계에 대한 정확한 기록입니다.
/etc/ksmtuned.conf
파일의 설정 가능한 변수이기도 합니다.
/sys/kernel/mm/ksm/
파일
- full_scans
- 전체 검사 실행.
- pages_shared
- 총 페이지 공유.
- pages_sharing
- 현재 공유된 페이지입니다.
- pages_to_scan
- 페이지를 스캔하지 않습니다.
- pages_unshared
- 페이지가 더 이상 공유되지 않습니다.
- pages_volatile
- 휘발성 페이지 수입니다.
- run
- KSM 프로세스가 실행 중인지 여부
- sleep_millisecs
- 수면 밀리초입니다.
DEBUG=1
행이 /etc/ksmtuned.conf
파일에 추가되는 경우 KSM 튜닝 활동은 /var/log/ksmtuned
로그 파일에 저장됩니다. 로그 파일 위치는 LOGFILE
매개 변수를 사용하여 변경할 수 있습니다. 로그 파일 위치 변경은 권장되지 않으며 SELinux 설정을 특별한 설정이 필요할 수 있습니다.
KSM 비활성화
KSM에는 특정 환경 또는 물리적 머신 시스템에 비해 너무 커질 수 있는 성능 오버헤드가 있습니다.
ksmtuned
및 ksm
서비스를 중지하여 비활성화할 수 있습니다. 서비스를 중지하면 KSM이 비활성화되지만 다시 시작한 후에는 유지되지 않습니다.
service ksmtuned stop service ksm stop
# service ksmtuned stop
Stopping ksmtuned: [ OK ]
# service ksm stop
Stopping ksm: [ OK ]
chkconfig ksm off chkconfig ksmtuned off
# chkconfig ksm off
# chkconfig ksmtuned off