Forum Stats

  • 3,727,839 Users
  • 2,245,474 Discussions


free memory = buff/cache + available memory?

User_U1UYA Member Posts: 24 Red Ribbon

Hi everybody,

It's under my impression that free memory is just by looking at available memory. I am wondering it is not correct. seems like free memory calculation = available memory + buff/cache.

What is the formula to calculate free memory?

free -h

       total    used    free   shared buff/cache  available

Mem:      15G    4.9G    596M    8.6G     10G    914M <-- available is 914M and buff/cache is 10G

Swap:     8.0G    978M    7.0G

Please shed some light on this issue.



  • Avi Miller-Oracle
    Avi Miller-Oracle Senior Solution Architect, Oracle Cloud Infrastructure Developer Adoption Melbourne, AustraliaPosts: 4,796 Employee

    I always recommend for folks who have questions about how Linux uses memory. From that site is a link to the commit which explains why free + cache is no longer accurate.

  • User_U1UYA
    User_U1UYA Member Posts: 24 Red Ribbon

    Hi Avi-Miller,

    I am not sure if I understand your link. I need to create a new database. Can you tell me, based on my snapshot here. How much memory is free and What is the formula?

    Looking at available memory 914M below, I cannot even create a new database.

    But looking at the buff/cache 10G, I certainly can.

    free -h

           total    used    free   shared buff/cache  available

    Mem:      15G    4.9G    596M    8.6G     10G    914M <-- used is 15G, free is 4.9G, available is 914M and buff/cache is 10G

    Swap:     8.0G    978M    7.0G

    Please advise.


  • Herbert van den Bergh-Oracle
    Herbert van den Bergh-Oracle Member Posts: 969 Employee

    It really depends on how "buff/cache" is currently used. If you already have a DB instance running, it may have a shm segment that is counted as "cache" but really can't be reclaimed. Maybe that's why "available" is relatively low. You may want to establish first how much of "cache" can be reclaimed by doing (as a test, not on a regular basis):

    echo 3 | sudo tee -a /proc/sys/vm/drop_caches

    This should free up any page and slab cache that can be freed up, leaving the absolute bare minimum amount of memory in use that the running apps need. The amount of free memory at that point gives you an upper limit to what any additional apps or DB instances could possibly use without running out of memory. It's the absolute bare minimum without any memory used for caching, so if you'd use all that memory for apps or another DB instance, there would be no memory left for caching. This could cause a severe increase in disk I/O. It's best to allocate only a subset of available memory to any additional DB instances or apps, and see how the system behaves. If it starts swapping, you've allocated too much and you'll have to back off. If there's still lots of memory available, you may be able to increase memory usage of additional apps and DB instances a bit more.

Sign In or Register to comment.