
Vzmem: visual consistent memory allocation for OpenVZ

How to use dklab_vzmem
Vzmem is a command-line utility that allows you to "visually" distribute physical memory between multiple OpenVZ virtual machines so that one machine does not "crawl" onto another. Those. if you need to increase the memory for any of the machines, you can always see where this memory is to be "bitten off" from: from one of the existing machines or from a pool of free blocks.
Install vzmem on the serverThe memory allocation is set in the text file / etc / vz / conf / MEM-MAP, which looks something like this:cd / usr / sbin wget https://raw.github.com/DmitryKoterov/dklab_vzmem/master/vzmem chmod + x vzmem
File / etc / vz / conf / MEM-MAP300 10003 vps1.example.com =========== 109552K 10004 vps2.example.com =============================== 335503K 20004 vps3.example.com ========== ++++++++++++++++ 109552K + 221324K swap FREE ======================== 513525K
- Each "=" symbolizes a piece of physical memory (in this example, 1/300 of it) and affects the value of the OpenVZ VMGUARPAGES parameter (and also sets the SHMPAGES value). By moving the "=" icons between different virtual machines, you can redistribute the memory (the utility makes sure that the total number of blocks remains equal to 300).
- The “+” symbols symbolize “additional memory from currently unused blocks or SWAP”. They can be added as many as you want (but preferably not very much so that the machine does not go into SWAP too much in critical situations). In total, the number of "=" and "+" icons indicates the value of the PRIVVMPAGES parameter (the same value is recorded in OOMGUARPAGES).
- Well, the values in kilobytes after the "=" and "+" icons are calculated automatically - they do not need to be changed by hand.
Applying Changes to MEM-MAP
When changes have been made to the MEM-MAP, run the following command:
Applying Changes to / etc / vz / conf / MEM-MAPTotal:vzmem -a
- VMGUARPAGES = SHMPAGES = number of digits ("=")
- PRIVVMPAGES = OOMGUARPAGES = number of digits ("=") + number of digits ("+")
Initial creation of a MEM-MAP file
To initially create / etc / vz / conf / MEM-MAP based on your OpenVZ configuration, run the command:
Initial creation of the / etc / vz / conf / MEM-MAP fileInstead of 300, you can specify any number that determines how many "blocks" should be divided into physical memory. Set this number so that it is more convenient to move the "=" and "+" icons from one line to another.vzmem -i 300
If the memory at the time of the call to vzmem -i was already allocated in a contradictory way, vzmem tries to distribute the number of "=" icons between the machines in a proportional way. Just in case, check the result after initialization.
PS
The vzmem script takes 200 lines on Perl ( vzmem on GitHub ). If suddenly I invented a bicycle, write in the comments. Other similar in spirit small utilities for OpenVZ: vzfirewall , vzset , vzenter .