TPT
Enthusiast
Enthusiast

how to release vm swap file without reboot

Hi all

I got a 128GB vswp file that I would like to clean out and reduce the size somewhat and I can't do a reboot. Which is what I find to the most common way of clearing that file.

I also tried setting memory reservation but that didn't work because all the server's memory is going to this VM anyway.

So any ideas on what can I do short of finding a maintenance window?

davy

Tags (1)
0 Kudos
4 Replies
npadmani
Virtuoso
Virtuoso

after increasing Memory reservation, simplest way is to reboot that VM.

alternatively. see following, I haven't tested it myself so consider doing a little test first.

I am going with certain assumptions.

Let's say you have this VM with 128 GB RAM allocation and 0 reservation, it got powered on with vswp file size 128 GB. and VM's VSWP file location is with VM base directory.

now you want to avoid down time and still want to reduce vswp file size.

If you have another ESXi host where you can vMotion this VM, configure host specific vswp datastore in that host, change VM's vswp file location to Host specific datastore and also increase memory reservation to desired value, let's say we are doing 50 GB RAM reservation, and perform vMotion of the VM from current host to next host.

check new vswp file size, should be coming out as 128 - 50 = 78 GB.

Narendra Padmani VCIX6-DCV | VCIX7-CMA | VCI | TOGAF 9 Certified
haripadmam
Hot Shot
Hot Shot

Hi davy,

I don't think of any other way to clear swap file than power off the VM. Once you power on the VM back, swap file will be created to the location based on your configuration. Setting VM memory reservation will not have any change in swap file size unless you take power recycle.

You can wait and see other experts comments.

All the best!

Hari.

0 Kudos
cpetty223
Contributor
Contributor

As of ESXi 6.0 you can use the localcli command to unswap virtual machine memory while the VM is running.

See:  I have memory pages swapped, can vSphere unswap them? - Yellow Bricks

Example:

First make sure the ESXi host has enough free memory to unswap the VM.

Then run ps | grep vmm0:<vmname> to get the world ID of the VM.  The WID is in the first column of the output.

In this example we are unswapping 1 GB of memory for the VM with WID 1031226.

localcli --plugin-dir=/usr/lib/vmware/esxcli/int vm process unswap -w 1031226 -s 1 -u GB

Usage parameters:

-w XX : world ID of the VM (use ps | grep vmm0:<vmname>)

-s XX : number of units to unswap

-u XX : specify the units to use (GB or MB)

Note: unswapping memory can affect the VM.  Sometimes the VM is paused while memory is unswapped, and if you are unswapping several gigabytes it could take a few minutes, so it might be better to unswap in small increments rather than unswapping all memory all at once.

Log Messages in vmkernel.log

Swap: vm 1031226: 4864: Starting prefault for the reg file

Swap: vm 1031226: 5175: Finish swapping in reg file. (faulted 262144 pages, pshared 12806 pages). Success.

Note: 1 memory page = 4KB

0 Kudos
Alex_Romeo
Leadership
Leadership

Hi,

https://www.virten.net/2014/09/remove-virtual-machine-swap-file-vswp/

Alessandro Romeo

Blog: https://www.aleadmin.it/
0 Kudos