All of lore.kernel.org
 help / color / mirror / Atom feed
* What does drop_caches do?
@ 2011-07-28  7:06 ` Prateek Sharma
  0 siblings, 0 replies; 5+ messages in thread
From: Prateek Sharma @ 2011-07-28  6:58 UTC (permalink / raw)
  To: linux-mm, kernelnewbies

Hello everyone,
 	I've been trying to understand the role of the pagecache, starting with 
drop_caches and observing what it does.
 	From my understanding of the code (fs/drop_caches.c) , it walks over all 
the open files/inodes, and invalidates all the mapped pages. Pages which are 
*not* dropped are either dirty,in-use,anonymous,mapped(to pagetable),or 
writeback) . Is my understanding correct?
 	But, when i run drop_caches, there are still some pages which show up as 
cached. Why arent all cache pages getting dropped ?
 	My confusion runs much deeper. What exactly constitutes the pagecache? 
All filebacked pages ? mmaped files ? If i copy a bunch of files, why does my 
cache get polluted with those pages?

Thanks for reading. I'd be grateful if someone can enlighten me about some 
pagecache internals .

(Please keep me CC'ed)

<begin experiment>
root@tripitz:/etc/apt# free -m
              total       used       free     shared    buffers     cached
Mem:          1995       1854        140          0         79        700
-/+ buffers/cache:       1074        920
Swap:         4767        762       4005
root@tripitz:/etc/apt# echo 3 > /proc/sys/vm/drop_caches
root@tripitz:/etc/apt# free -m
              total       used       free     shared    buffers     cached
Mem:          1995       1373        621          0          0        363
-/+ buffers/cache:       1009        985
Swap:         4767        762       4005

<end experiment>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* What does drop_caches do?
@ 2011-07-28  7:06 ` Prateek Sharma
  0 siblings, 0 replies; 5+ messages in thread
From: Prateek Sharma @ 2011-07-28  7:06 UTC (permalink / raw)
  To: kernelnewbies

Hello everyone,
 	I've been trying to understand the role of the pagecache, starting with 
drop_caches and observing what it does.
 	From my understanding of the code (fs/drop_caches.c) , it walks over all 
the open files/inodes, and invalidates all the mapped pages. Pages which are 
*not* dropped are either dirty,in-use,anonymous,mapped(to pagetable),or 
writeback) . Is my understanding correct?
 	But, when i run drop_caches, there are still some pages which show up as 
cached. Why arent all cache pages getting dropped ?
 	My confusion runs much deeper. What exactly constitutes the pagecache? 
All filebacked pages ? mmaped files ? If i copy a bunch of files, why does my 
cache get polluted with those pages?

Thanks for reading. I'd be grateful if someone can enlighten me about some 
pagecache internals .

(Please keep me CC'ed)

<begin experiment>
root at tripitz:/etc/apt# free -m
              total       used       free     shared    buffers     cached
Mem:          1995       1854        140          0         79        700
-/+ buffers/cache:       1074        920
Swap:         4767        762       4005
root at tripitz:/etc/apt# echo 3 > /proc/sys/vm/drop_caches
root at tripitz:/etc/apt# free -m
              total       used       free     shared    buffers     cached
Mem:          1995       1373        621          0          0        363
-/+ buffers/cache:       1009        985
Swap:         4767        762       4005

<end experiment>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* What does drop_caches do?
  2011-07-28  7:06 ` Prateek Sharma
  (?)
@ 2011-08-24  5:25 ` Mulyadi Santosa
  -1 siblings, 0 replies; 5+ messages in thread
From: Mulyadi Santosa @ 2011-08-24  5:25 UTC (permalink / raw)
  To: kernelnewbies

Hi.... :)

On Thu, Jul 28, 2011 at 13:58, Prateek Sharma <prateeks@cse.iitb.ac.in> wrote:
> ? ? ? ?From my understanding of the code (fs/drop_caches.c) , it walks over all
> the open files/inodes, and invalidates all the mapped pages.

I doubt that would be open files/inodes..more likely list of pages.

>Pages which are
> *not* dropped are either dirty,in-use,

I quite agree with that....

>anonymous,

uhm..... they are not dropped...they are paged out AFAIK...

>mapped(to pagetable),
mapped, maybe.....if they are file backed...

>or
> writeback) .

you mean is still written out? then maybe yes...

> ? ? ? ?But, when i run drop_caches, there are still some pages which show up as
> cached. Why arent all cache pages getting dropped ?

AFAIK there are few reasons: they are locked in RAM, allocated
strictly for kernel usage (loading kernel modules, kernel image
etc)....maybe more...

> ? ? ? ?My confusion runs much deeper. What exactly constitutes the pagecache?

it caches the reading from device....to be precise, block
devices,either being read through VFS layer or directly from block
layer (we call it "raw access")

>If i copy a bunch of files, why does my
> cache get polluted with those pages?

because files content are put into page cache once it is read :)


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What does drop_caches do?
  2011-07-28  7:06 ` Prateek Sharma
@ 2011-08-24  7:18   ` Greg Freemyer
  -1 siblings, 0 replies; 5+ messages in thread
From: Greg Freemyer @ 2011-08-24  7:18 UTC (permalink / raw)
  To: Prateek Sharma; +Cc: linux-mm, kernelnewbies

On Thu, Jul 28, 2011 at 2:58 AM, Prateek Sharma <prateeks@cse.iitb.ac.in> wrote:
> Hello everyone,
>        I've been trying to understand the role of the pagecache, starting with
> drop_caches and observing what it does.
>        From my understanding of the code (fs/drop_caches.c) , it walks over all
> the open files/inodes, and invalidates all the mapped pages.

Stepping up a little, I think you're missing
drop_caches_sysctl_handler() in that same file.  It is the entry point
I believe that implements the userspace ABI defined in
Documentation/sysctl/vm.txt.

==============================================================
 139
 140drop_caches
 141
 142Writing to this will cause the kernel to drop clean caches, dentries and
 143inodes from memory, causing that memory to become free.
 144
 145To free pagecache:
 146        echo 1 > /proc/sys/vm/drop_caches
 147To free dentries and inodes:
 148        echo 2 > /proc/sys/vm/drop_caches
 149To free pagecache, dentries and inodes:
 150        echo 3 > /proc/sys/vm/drop_caches
 151
 152As this is a non-destructive operation and dirty objects are not
freeable, the
 153user should run `sync' first.
 154
 155==============================================================

Note the corresponding logic in /fs/drop_caches.c that implements the
above binary logic.


  61              if (sysctl_drop_caches & 1)
  62                        iterate_supers(drop_pagecache_sb, NULL);
  63                if (sysctl_drop_caches & 2)
  64                        drop_slab();

Greg

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* What does drop_caches do?
@ 2011-08-24  7:18   ` Greg Freemyer
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Freemyer @ 2011-08-24  7:18 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Jul 28, 2011 at 2:58 AM, Prateek Sharma <prateeks@cse.iitb.ac.in> wrote:
> Hello everyone,
> ? ? ? ?I've been trying to understand the role of the pagecache, starting with
> drop_caches and observing what it does.
> ? ? ? ?From my understanding of the code (fs/drop_caches.c) , it walks over all
> the open files/inodes, and invalidates all the mapped pages.

Stepping up a little, I think you're missing
drop_caches_sysctl_handler() in that same file.  It is the entry point
I believe that implements the userspace ABI defined in
Documentation/sysctl/vm.txt.

==============================================================
 139
 140drop_caches
 141
 142Writing to this will cause the kernel to drop clean caches, dentries and
 143inodes from memory, causing that memory to become free.
 144
 145To free pagecache:
 146        echo 1 > /proc/sys/vm/drop_caches
 147To free dentries and inodes:
 148        echo 2 > /proc/sys/vm/drop_caches
 149To free pagecache, dentries and inodes:
 150        echo 3 > /proc/sys/vm/drop_caches
 151
 152As this is a non-destructive operation and dirty objects are not
freeable, the
 153user should run `sync' first.
 154
 155==============================================================

Note the corresponding logic in /fs/drop_caches.c that implements the
above binary logic.


  61              if (sysctl_drop_caches & 1)
  62                        iterate_supers(drop_pagecache_sb, NULL);
  63                if (sysctl_drop_caches & 2)
  64                        drop_slab();

Greg

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-08-24  7:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-28  6:58 What does drop_caches do? Prateek Sharma
2011-07-28  7:06 ` Prateek Sharma
2011-08-24  5:25 ` Mulyadi Santosa
2011-08-24  7:18 ` Greg Freemyer
2011-08-24  7:18   ` Greg Freemyer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.