4

At my system always available some "Free" and "Inactive" memory, but sometimes system move couple megabytes to swap. Per night it maybe around 100MB, but for a few days in swap could be more than 4000MB.

How can I determine required memory for my system?

  • Looks like you've answered your own question in the question itself. You've got a good handle on what your setup needs. If you had another 4GB you'd probably hardly ever hit the swap drive. It is possible that the service using this space prefers the swap to RAM and that getting more RAM will not affect your swap usage but that is rare. – krowe Jul 22 '14 at 12:43
  • Seems a bit strange that your swap should increase regularly. Is this a server with a regular workload or a workstation/test env.? – Mat Jul 22 '14 at 14:47
  • @krowe I have already added RAM to this server, but this doesn't solve the problem. – moronizzz Jul 22 '14 at 19:06
  • @Mat This is server with many apache prefork instances with mod_php. Many of these use APC with allocated memory 64-256MB. Apache handlers have from ~150MB to ~450MB "virtual size", wich changes depending on query to it and allocated memory for APC. – moronizzz Jul 22 '14 at 19:17
  • @moronizzz Once again you have the answer already. You've increased RAM and saw no improvement. That means you have more than enough RAM. The fact that the swap is being used on occasion is perfectly normal and optimal. You could move the swap to RAM like this: # mkswap /dev/ram0 # swapoff -a # swapon /dev/ram0 but that is a very bad idea because your system will most likely hang if you ever exceeded you physical memory. Another (much better) option would be to just put your swap on an SSD. – krowe Jul 23 '14 at 22:03
4

FreeBSD divides memory into 5 lists:

  • wired (locked in memory, unpageable)
  • active (recently used)
  • inactive (not recently used)
  • cache
  • free

Some of those have minimum free and target free levels, e.g.

Pool     Minimum Target
Free       0.7%    3%
Cache      3%      6%
Inactive   0%      4.5%

(Source: The Design and Implementation of the FreeBSD Operating System', rather dated: 2004 covering FreeBSD 5.2 -- these numbers have changed since then, but the general approach has not I believe.)

The pagedaemon is tasked with maintaining the levels, and paging out as need.

From a FreeBSD 9.0 VM I have here, these are some of the relevant numbers:

hw.availpages: 3138511
vm.stats.vm.v_inactive_target: 121342     # 3.9%
vm.stats.vm.v_free_target: 80895          # 2.6%
vm.stats.vm.v_free_reserved: 4011         # 0.1%
vm.stats.vm.v_free_min: 19221             # 0.6%
vm.stats.vm.v_cache_min: 80895            # 2.6%
vm.stats.vm.v_cache_max: 161790           # 5.1%

(I'm not certain how they are calculated, it depends on physical memory and presumably kern.maxusers).

FreeBSD will proactively pageout to increase available cache so just because swap is used doesn't mean your system is under pressure. It's far more useful to inspect (and graph!) the rates of paging and other indicators of load such disk I/O and CPU ticks, systat -io is a start. Running locate/updatedb is a good way to shift memory usage around overnight.

Using swap even when there is free memory is normal behaviour, it's effectively preparing for possible future memory demands while idle, so swap usage alone is not a reliable way to determine RAM requirements. FreeBSD is quite good at telling you when you need to tune something (grep "see tuning" in the messages file).

Other useful reading:

3

if you have spare memory increasing memory not working you should change the swappiness parameter. it tells the kernel how often use non physical memory (swap).

check swappiness value:

cat /proc/sys/vm/swappiness

change the swappiness value temporary (lost on reboot) to value 10 (good value that decreases swap usage)

sudo sysctl vm.swappiness=10

if you want to change it permanent use config file:

sudo vim /etc/sysctl.conf

search for vm.swappiness and change it to desired value.

vm.swappiness=10

save and reboot.


desciption:

what is swappines?

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

swappiness can have a value of between 0 and 100

swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible

swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache

The default setting in Ubuntu is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10 is recommended, but feel free to experiment. Note: Ubuntu server installations have different performance requirements to desktop systems, and the default value of 60 is likely more suitable.

  • 1
    Please always cite the sources you quote - at least an URL pointing to that documentation if it's online, or the title and author of the work otherwise. AFAIK, what you say is for Linux only. Question is tagged FreeBSD. Does it apply there? – Mat Jul 22 '14 at 13:59
  • source: askubuntu.com/questions/103915/how-do-i-configure-swappiness/… askubuntu.com/questions/157793/… it works for debian and other debian based linuxes – amir jj Jul 22 '14 at 14:18
  • 6
    You should edit the link into your question. FreeBSD isn't a Linux at all. – Mat Jul 22 '14 at 14:46
  • posted another answer for freeBSD. – amir jj Jul 23 '14 at 5:38
0

my previous answer doesn't apply freeBSD but i leave it. i tested it and it worked like a charm on debian. for freeBSD you can use following command from sysctl to see if swap is enabled or not:

-bash-2.05b$ sysctl vm.swap_enabled
  vm.swap_enabled: 1

1 - Enabled

0 - Disabled

you can disable it with writing following line in /etc/sysctl.conf :

vm.swap_enabled=0

with this link you can earn more information about your swap and physical memory.

  • 1
    The question isn't about enabling/disabling swap, I don't really see how this answers it. – Mat Jul 23 '14 at 5:47
  • @Mat. so i don't really get this question. i saw a server with 32 RAM and just started without any heavy services on it but swap wasn't empty. so i answer this question like this if you don't want use swap, disable it because kernel will use it. the kernel do not use swap arbitrary. swap will not be used if the memory is truly idle. i think kernel will move unused pages to swap regardless of memory size. see freebsd.org/doc/en_US.ISO8859-1/books/faq/misc.html#idp68642992 – amir jj Jul 23 '14 at 6:01
  • @amirjj I just want to determine how much memory needed for server because sometimes processes killed with error "out of swap space". – moronizzz Jul 26 '14 at 10:11
0

A short research pointed out this: Why is swappiness set to 60 by default? which explains in even more details about swappiness

And this: https://www.kernel.org/doc/Documentation/sysctl/vm.txt which explains about all vm related parameters. If you're into single process memory management, it can help knowing about other memory related restrictions/parameters.

  • 3
    Does this apply to FreeBSD (the question is tagged as such)? – Mat Jul 22 '14 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.