What is equivalent to Mac's purge in Linux?

7,440

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:
7,440

Related videos on Youtube

corsel
Author by

corsel

Updated on September 18, 2022

Comments

  • corsel
    corsel almost 2 years

    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
    
    • terdon
      terdon almost 10 years
      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.
    • derobert
      derobert almost 10 years
      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.
    • corsel
      corsel almost 10 years
      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?
    • Ludwig Schulze
      Ludwig Schulze almost 10 years
      As for why, relevant serverfault.com/q/597115/180142
    • user2914606
      user2914606 almost 10 years
    • daboross
      daboross almost 10 years
      @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.
  • mleonard
    mleonard almost 10 years
    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.
  • corsel
    corsel almost 10 years
    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?
  • cuonglm
    cuonglm almost 10 years
    @Mohsen: May be your Java process does not cache anything. What is output of free -m?
  • corsel
    corsel almost 10 years
    @Gnouc output of free -m: pastebin.com/raw.php?i=XCBeLe4f
  • cuonglm
    cuonglm almost 10 years
    @Mohsen: It seems your system can not drop cache, see this:unix.stackexchange.com/questions/53930/…
  • Ludwig Schulze
    Ludwig Schulze almost 10 years
  • user2914606
    user2914606 almost 10 years
    @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).