Clearing ram from VM

adamb

Famous Member
Mar 1, 2012
1,329
77
113
I have made a few posts about VM's with large amount of ram and live migration. After giving it some thought I was thinking I could simply clear what's in ram before the live migration but it looks like the host itself won't let go.

I can run the following on the guest which drops the contents of the ram with no issues
echo 3 > /proc/sys/vm/drop_caches

I then look on the host and the ram is not being released, is there a way I could release the ram from the host so that live migration won't attempt to transfer all the contents, I was really hoping I could just drop cache before a live migration and all would be well.

Is there anytype of kvm commands which could do this for me? I appreciate the input!
 
Looks like I might be able to pull this off if I was to put the memory inside of a balloon and just take it back when I want to do a live migration. So I would need to clear the cache on the guest, then pull the balloon of ram, and kick off a migration. Not exactly what I am looking for, but I think it will work.

Open to any suggestions.
 
I am guessing this mapped memory gets mlocked on the host as I can't even clear it with drop caches on the host. I wish there was a way to unlock these pages, no one has any idea on how memory management works? I guess I should start to look at some kvm lists.
 
I have made a few posts about VM's with large amount of ram and live migration. After giving it some thought I was thinking I could simply clear what's in ram before the live migration but it looks like the host itself won't let go.

I can run the following on the guest which drops the contents of the ram with no issues
echo 3 > /proc/sys/vm/drop_caches

I then look on the host and the ram is not being released, is there a way I could release the ram from the host so that live migration won't attempt to transfer all the contents, I was really hoping I could just drop cache before a live migration and all would be well.

Is there anytype of kvm commands which could do this for me? I appreciate the input!
Hello :)
12 years after... Did you find a solution for that?
For example, should the following script work?
Code:
#!/bin/bash
# Hook script per Proxmox - clear cache pre-migration

PHASE="$2"

if [ "$PHASE" = "pre-migrate" ]; then
    echo "clear cache in VM $1 before migration..."
    # Run inside the VM through qm guest exec (qemu-guest-agent needed to be active)
    qm guest exec $1 -- bash -c "sync; echo 3 > /proc/sys/vm/drop_caches"
    qm guest exec $1 -- bash -c "swapoff -a && swapon -a"
fi

Code:
chmod +x /var/lib/vz/snippets/clear_cache_hook.sh

Code:
qm set 101 --hookscript local:snippets/clear_cache_hook.sh