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.
Related videos on Youtube
![corsel](https://i.stack.imgur.com/B0Dhv.jpg?s=256&g=1)
Author by
corsel
Updated on September 18, 2022Comments
-
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'spurge
here is it'sman
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 almost 10 yearsWhat 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 almost 10 yearsNote 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 almost 10 yearsI 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 almost 10 yearsAs for why, relevant serverfault.com/q/597115/180142
-
user2914606 almost 10 years
-
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 almost 10 yearsMy
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 almost 10 yearsIt 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 almost 10 years@Mohsen: May be your Java process does not cache anything. What is output of
free -m
? -
corsel almost 10 years@Gnouc output of
free -m
: pastebin.com/raw.php?i=XCBeLe4f -
cuonglm almost 10 years@Mohsen: It seems your system can not drop cache, see this:unix.stackexchange.com/questions/53930/…
-
Ludwig Schulze almost 10 yearsTotally relevant serverfault.com/q/597115/180142
-
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).