Link to home
Start Free TrialLog in
Avatar of Amin El-Zein
Amin El-Zein

asked on

increase virtual memory

Hello,
I have webmin installed on vps ubuntu 16.4 it's show me notification about virtual memory is full  is 256MB how I can increase   it ?
thanks.
Avatar of noci
noci

one: in the VM manager assign it more memory
two: add swap space ...  
swapspace can be a partition: (lvmcreate for example, fdisk new partition) or a regular file:
dd if=/dev/null of=/var/tmp/mytempswap bs=1M count=1024     # (1GB) regular file
mkswap /var/tmp/mytempswap    # or the name of the partition/lvm device
swapon /var/tmp/mytempswap    # or the name of the partition/lvm device

Open in new window


Using a swap file from a VM is a REAL waste of IO bandwidth...
1) You can fix the problem as noci shows above.

2) If you have fallocate available (16.04, as I recall, installs this by default), this will be faster than dd.

fallocate -l 1G /swap1

Open in new window


3) Many hosting companies install /var/tmp + /tmp into a separate partition, so you may have to create your swap space at the root (/) for your system to work correctly.

4) And, you likely have a more pressing problem. If your VM size is only 256M you'll have a very hard time running any type of code in this VM.

Suggestion: Open another question describing your exact application + asking for assistance with memory sizing of your physical machine + VM.
I'm not sure why people bother with swap on a VM.  You should just allocate enough RAM.  Swap wastes disk I/O cycles and disk space.  The Linux Kernel and modules can be compiled to fit into the RAM that you need.

Turn off swap and size your RAM properly.  Swap wastes disk IO unnecessarily.  It was really invented to match the Windows bloat back when RAM was super expensive in the 1990s.  That was the period when 1.5x or 2x RAM was necessary.  By 2000, anyone still using that rule never experimented.  I found that limiting swap to 1 GB to 2GB was better when systems came with 1 GB to 4 GB of RAM.  If your swap went over 2 GB, the systems actually slowed down more noticeably on those really slow IDE disks.

By 2003, people should have bought enough RAM and turned off swap, especially for servers.  4 GB was the addressing limit for 32 bit OS.  I was already starting to turn off swap on half my systems.  If you still had even 1x swap, you were wasting disk and disk I/O,  By the time of 8 GB RAM systems, you should have turned off swap completely and moved to 64 bit OS.    If you didn't know that, then you never actually heavily experimented with swap and are just going off incorrect hearsay of ancient computing knowledge on the internet.

These days, you should just get 16GB or more RAM and you can turn off swap.  Set enough RAM and turn off swap and your system will run better, with longer disk life.  Disk drives are the typically the first failure point on a system and have the shortest overall life of any component on a computing system.  Why tax it unnecessarily?

P.S. If you are a developer that actually needs a dump file for debugging work, modern Windows does not need swap to create a dump.  They use a separate mechanism.
@serialband: I agree..., then again sometimes you need tempoary extra memory despite the (severe) loss of performance.
Ordering extra memory takes time or requires downtime to install...
Especialy when you consider that all Virtual IO's are done twice. (at least for SETUP/TEARDOWN) and possibly the transfer.

So swap may help sometimes.   1st advise was Increase the RAM allocated..
Sure.  Sometimes you need it.  However, if you're doing your job, the majority of the time you've ordered enough RAM and you should NOT have a pagefile or swap in use on any server.  Swap hasn't been needed it the past 15 years, except in those temporary situations you've mentioned.  If you had a spinning disk, you would also set a fixed pagefile on NTFS, or you'd just slow it even further and fragment your disk even more.  IMHO any server running swap or pagefile was created by someone that didn't know what they were doing or they had stupid finance people crippling their purchases.

Swap is still needed on those cheap ass office depot, officemax, staples, walmart junk computers they sell to the masses.  I found someone still buying those systems with only 2GB RAM for work.  They had to upgrade all their systems after their company got acquired, because they couldn't run programs that the new company needed.  They had no sysadmin or computer savvy person for advice.
As serialband suggested, once you start swapping likely your machine will crash soon.

Better to use a good chunk of memory (64G-128G+) as memory is super cheap.

I always set swap to smallest allowed amount, so I can track if swap space is ever used, which (to me) should never occur.

If I ever have any machine show swap usage > 0, then I'd find the offending LXD container + move the container elsewhere.

At this point, with large amounts of memory available + NVMe disks, which avoid seek time delays speeding up I/O, I haven't seen any swap space used on any of the 1000s of site projects I work with... in many years...

Tip: Good target. 0% swap usage. If you have >0, likely time to do some fast debugging before your machine dies.
I find that the only useful use for swap is as a safety net. I do configure it for systems that need HA. Then it serves as a warning if it ever becomes slightly used (alarm for swap != 0) to act in planning extending systems (in case the growth rate of the system load is faster/spikier then trend analisys shows).
actually, i would consider NOT havind a swap file as a safety net. i'd rather see one daemon OOM-killed and instantly restarted with adequate notifications than having the whole machine crawling its way in a near death state for hours ;) properly designed servers should use a roughly constant amount of ram so this would seldom happen until all ram exhaustion possibilities are fixed.

that said, in a vm context, you probably should allocate either more memory, or a small extra drive to use a swap space. this could probably be done without shutting the vm off, depending on the guest os and virt software you use.
Avatar of Amin El-Zein

ASKER

Hello,
sorry for you answers but could you please helpe me how to do it step by step because I am not familiar too much with Linux
if you follow the universal recommendation in this thread, you need to add more ram.
there is nothing to do on the linux side.
once more ram has been configured in whatever virtualization software you are using, just reboot the guest.

32bits machines will not handle more than 4G without specific options. if you need more, either switch to 64bits or look into PAE options. most likely, you do not need to bother since your initial ram is only 256M
Hello,
I already have 2 gb of ram but the vps hosting company when setup the server , setup it with 265 mb of ram ! because of that I want to reduce it
thanks.
If you want to reduce memory  footprint you need to run less programs or configure programs to use LESS memory otherwise (less buffers, less concurrency...).
There is no way around it... (you cannot demand to only use 0,5 of a CPU..  you always have at least one and they go in discrete values).

Using less memory will most often mean you need to do work multiple times.
Note: I do what noci does. I always run some swap space... as a canary in a coal mine... an early warning the machine may be on the edge of swapping, which means it's time to relocate the highest resource usage site or sites to another machine.
You asked, "sorry for you answers but could you please help me how to do it step by step because I am not familiar too much with Linux".

1) If you're using Linux, you'll have to dig into Linux + learn basic admin skills.

2) As mentioned above, running any Linux system with 256M is almost impossible. Even at the 2G mark, you'll have problems.

3) Start with a 16G+ machine (I normally start with 64G-128G+), to allow memory to spare for disk i/o buffers + tuning SQL systems like MariaDB/MySQL.

4) Memory is cheap, so you can run a large memory system for a month. Do your testing. Determine your actual memory requirements. Then next month, allocate a smaller memory footprint machine if required.

You can always use a company like OVH which provides weekly machine leases, if a week provides you enough time for a good measure of resource usage.
I believe he's saying that his RAM is 2GB and his swap(virtual RAM) is 256MB.

The hosting company should increase the RAM to 3GB or 4GB.  Then you can delete that swap with the swapoff command.  Don't disable it until you get the extra RAM you need.

https://www.tecmint.com/disable-swap-partition-in-centos-ubuntu/
https://www.addictivetips.com/ubuntu-linux-tips/disable-swap-on-linux/
https://askubuntu.com/questions/214805/how-do-i-disable-swap
ubuntu 16.4 will NOT run properly with less than 256Mb memory.
minimal guest setups will usually require 1Gb for very frugal apps and several G for pretty much anything else.
my personnal defeult setting for basic hosts running "a few" services with not too many clients or one propely crafted service and basic ecosystem woul be 2G.
i'd very easily climb the 8G ramp, and think twice about my design whenever i need more than that without some obvious reason.

anything less would much likely run more effectively in a container or if the hypervisor barrier is really needed in a specially crafted os. for the latter you'd think about a single usage vm most likely running a linux/bsd kernel and whatever service is needed as init.
ASKER CERTIFIED SOLUTION
Avatar of Amin El-Zein
Amin El-Zein

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should have added more RAM.

RAM is not swap.
@Amin:    For you information SWAP space is (extending) ram storage with the speed of a disk (ie. about 1 million times slower).  
Swap space is from a time when RAM was 64kB up to a Whopping 1MB (1980's).  The 1MB would set you back 1$ for each byte of memory.
(And RAM & Disk speed difference was about 1000- 10000 times or so).  
So RAM was limited by technical constraints or monetary constraints.

wrt. Hardware pricing:
Currently you will get 8GB or RAM for only 25-50$   that is 8000 times the amount of that memory  against 1/20000 of the price.
(1MB of 1980's memory would get you between 160TB-320TB of RAM now,maybe more if you negotiate right, which might very
well be beyond current hardware limits for a single board.system).

So in the 1970's - 1980's and maybe even the early part of 1990's there was a business case for Swapspace....
+1 more swap is plain dumb imho