Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Mac I use purge to free up some memory. What is equivalent to it in Linux(Ubuntu Server)? apt-get install purge gave me nothing. If you are no familiar with Mac's purge here is it's man page:

purge(8)                  BSD System Manager's Manual                 purge(8)

NAME
     purge -- force disk cache to be purged (flushed and emptied)

SYNOPSIS
     purge

DESCRIPTION
     Purge can be used to approximate initial boot conditions with a cold disk
     buffer cache for performance analysis. It does not affect anonymous mem-
     ory that has been allocated through malloc, vm_allocate, etc.

SEE ALSO
     sync(8), malloc(3)

                              September 20, 2005
share|improve this question
6  
What makes you think you need to? Linux has pretty good memory management, it should be able to do this on a need-to-do basis. –  terdon Jun 27 at 18:05
12  
Note that freeing up memory like this is used to make the machine go slower, not faster. Its if you want to benchmark something on a cold cache. –  derobert Jun 27 at 18:14
    
I have a Java process eating all of my 24GB RAM. I can't terminate it. I don't know how to open a little space for other processes? –  Mohsen Jun 27 at 18:37
    
As for why, relevant serverfault.com/q/597115/180142 –  Braiam Jun 27 at 21:39
3  
@Mohsen, If the java process has already eaten up all of your ram, chances are that the kernel has already dropped all caches to give more memory to java. Purging, or dropping caches, won't give you any more free memory of a process has already demanded all of it. –  DaboRoss Jun 27 at 23:00

1 Answer 1

up vote 12 down vote accepted

This can be do the same thing with purge:

sync && echo 3 > /proc/sys/vm/drop_caches

From man proc:

/proc/sys/vm/drop_caches (since Linux 2.6.16)
              Writing to this file causes the kernel  to  drop  clean  caches,
              dentries  and  inodes from memory, causing that memory to become
              free.

              To free pagecache, use echo  1  >  /proc/sys/vm/drop_caches;  to
              free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
              to  free  pagecache,  dentries  and  inodes,  use   echo   3   >
              /proc/sys/vm/drop_caches.

              Because this is a nondestructive operation and dirty objects are
              not freeable, the user should run sync(8) first.

And from man sync:

NAME
       sync - flush file system buffers

DESCRIPTION
       Force changed blocks to disk, update the super block.
share|improve this answer
6  
My proc(5) manpage (from 2013-09-04) has this important information added: ... causing that memory to become free. This can be useful for memory management testing and performing reproducible filesystem benchmarks. Because writing to this file causes the benefits of caching to be lost, it can degrade overall system performance. –  Dubu Jun 27 at 18:28
    
It didn't free up any memory for me. All my memory is being used by a Java process. Does it impact Java memory cache too? –  Mohsen Jun 27 at 18:39
    
@Mohsen: May be your Java process does not cache anything. What is output of free -m? –  cuonglm Jun 27 at 18:42
3  
Totally relevant serverfault.com/q/597115/180142 –  Braiam Jun 27 at 21:37
1  
@Mohsen this is a kernel feature. how is the kernel supposed to know what is a legitimate Java object and what is cache? (hint: it can't, therefore it doesn't free Java caches). –  strugee Jun 27 at 21:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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