# Controlling swap usage and buffer levels



## jozze (Jun 6, 2013)

Hello again,

I have noticed that FreeBSD starts using swap relatively fast and keeps quite a lot of memory in the buffers. According to tuning(7)(), one is able to control some of these parameters with sysctl(8)(), but I don't think this utility offers enough control.

Is there a way I can decrease the level of buffers or even flush them? And also, can I control the "swappiness" of my operating system? I want for example start committing to swap when I only have 4 MB of free RAM left.

Thank you for your time,

JoÅ¾e


----------



## wblock@ (Jun 6, 2013)

Can't answer that question directly, but FreeBSD memory usage is often misunderstood.  Be careful about preconceptions from other operating systems.  There are a couple of FAQs about this: https://www.freebsd.org/doc/en_US.ISO8859-1/books/faq/misc.html#idp76852784


----------



## kpa (Jun 6, 2013)

Swapping can be a good thing. For example if you have a service running that doesn't do any real work except for a short time at times that can't be predicted in advance because the service wakes up in response to some external trigger. You certainly don't want the code and data of that service to be in memory all the time but to be swapped out until the service wakes up to do what it's supposed to do.


----------



## jozze (Jun 6, 2013)

I am not against swapping, but what concerns me is if swapping occurs too early.

If I have to diagonalize a large matrix for example, I noticed that swapping occurs too early, when there is still usable space left in RAM. I don't really know which programs are being transferred there, but I want that numerical program to use as much RAM as possible (so to prioritize it).


----------



## kpa (Jun 6, 2013)

Active processes that have pages in memory with usage timestamps not too old will never be swapped out unless there's a real shortage of memory.


----------

