Cheat Sheet virsh: Limit Resource VPS KVM

VPS #kvm#vps Last updated
Library

Flag dasar#

Flag Efek
--live Langsung berlaku, hilang saat VM restart (VM harus running)
--config Permanen di XML, berlaku boot berikutnya (VM running/mati)
--live --config Langsung + permanen

Virtualizor: panel bisa menimpa XML saat VPS diedit/restart dari panel. Pakai virsh --live untuk penanganan cepat, lalu set limit permanen di Edit VPS di Virtualizor.

Cek VM dulu#

virsh dominfo v1079        # vCPU, RAM, state
virsh domblklist v1079     # target disk: vda, vdb
virsh domiflist v1079      # interface: vnetX

1. Disk I/O โ€” blkdeviotune (live)#

virsh blkdeviotune v1079 vda    # lihat limit sekarang

Contoh: VM membebani RAID SSD, batasi 2000 IOPS dan 100 MB/s:

virsh blkdeviotune v1079 vda --total-iops-sec 2000 --total-bytes-sec 104857600 --live --config

Contoh: read longgar, write ketat:

virsh blkdeviotune v1079 vda --read-iops-sec 4000 --write-iops-sec 1000 --live --config

Contoh: normal 2000 IOPS, boleh burst 6000 IOPS selama 60 detik:

virsh blkdeviotune v1079 vda --total-iops-sec 2000 --total-iops-sec-max 6000 \
  --total-iops-sec-max-length 60 --live --config

Hapus limit:

virsh blkdeviotune v1079 vda --total-iops-sec 0 --total-bytes-sec 0 --live --config

Catatan: total-* tidak bisa digabung dengan read-*/write-* sejenis. 0 = unlimited. 100 MB/s = 104857600.


2. CPU % โ€” schedinfo (live)#

Rumus: quota / period ร— 100%, period default 100000.

virsh schedinfo v1079    # lihat nilai sekarang

Contoh: VM pakai 800% CPU, batasi total maksimal 400% (4 core):

virsh schedinfo v1079 --live --config --set global_period=100000
virsh schedinfo v1079 --live --config --set global_quota=400000

Contoh: setiap vCPU maksimal 50% core:

virsh schedinfo v1079 --live --config --set vcpu_quota=50000

Contoh: turunkan prioritas saja (tetap boleh full saat host longgar):

virsh schedinfo v1079 --live --config --set cpu_shares=50

Cek nilai default cpu_shares VM lain dulu, lalu set lebih rendah dari itu.

Hapus limit:

virsh schedinfo v1079 --live --config --set global_quota=-1
virsh schedinfo v1079 --live --config --set vcpu_quota=-1

3. Jumlah vCPU โ€” setvcpus#

virsh vcpucount v1079    # current vs maximum

Contoh: upgrade 4 โ†’ 8 vCPU tanpa reboot (maximum harus โ‰ฅ 8):

virsh setvcpus v1079 8 --live --config

Contoh: naikkan batas maximum ke 16 (berlaku setelah VM mati lalu start):

virsh setvcpus v1079 16 --maximum --config

Contoh: downgrade 8 โ†’ 4 vCPU (aman dilakukan offline):

virsh shutdown v1079
virsh setvcpus v1079 4 --config
virsh start v1079

Jika CPU baru tidak online di guest: echo 1 > /sys/devices/system/cpu/cpuN/online


4. Pinning core โ€” vcpupin / emulatorpin (live)#

Contoh: isolasi noisy neighbor ke core 80โ€“87:

virsh vcpupin v1079 --live --config 0 80-87    # ulangi untuk tiap vCPU
virsh emulatorpin v1079 80-87 --live --config
virsh vcpupin v1079                            # verifikasi

Cek NUMA dulu dengan lscpu | grep -i numa. Jangan pin satu VM menyeberangi dua NUMA node.


5. RAM โ€” setmem / setmaxmem#

Contoh: turunkan RAM live 32G โ†’ 16G via balloon (butuh virtio-balloon di guest):

virsh setmem v1079 16G --live --config
virsh dommemstat v1079    # cek actual & rss

Contoh: naikkan batas maksimum ke 64G (VM harus mati):

virsh setmaxmem v1079 64G --config
virsh setmem v1079 64G --config

Hindari memtune --hard-limit yang terlalu rendah: QEMU bisa di-OOM-kill dan VM mati.


6. Network โ€” domiftune (live)#

Satuan KiB/s, format average,peak,burst. 100 Mbps โ‰ˆ 12500.

Contoh: VM unlimited menyedot uplink, batasi 100 Mbps dua arah:

virsh domiftune v1079 vnet5 --inbound 12500,25000,10240 \
  --outbound 12500,25000,10240 --live --config

Hapus limit:

virsh domiftune v1079 vnet5 --inbound 0 --outbound 0 --live --config

7. Monitoring#

virsh domstats v1079 --vcpu --block --balloon --interface
virsh domblkstat v1079 vda --human
virsh domifstat v1079 vnet5
virt-top                          # dnf install virt-top

Counter bersifat kumulatif: ambil 2 sampel berjeda, hitung selisihnya.


Ringkasan live / offline#

Kebutuhan Perintah Live
IOPS / MB/s disk blkdeviotune Ya
CPU % cap schedinfo quota Ya
Prioritas CPU schedinfo cpu_shares Ya
Tambah vCPU (โ‰ค max) setvcpus --live Ya
Kurangi vCPU setvcpus --config Offline
Ubah max vCPU / max RAM --maximum / setmaxmem Offline
Pinning core vcpupin Ya
RAM (โ‰ค maxmem) setmem Ya (balloon)
Bandwidth domiftune Ya

Back to library

Keyboard shortcuts

/
Focus search
Esc
Close dialogs, menus and messages
?
Show this help
Ctrl S
Save in the admin editor