[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Memory usage: buffer and cache



On Fri, 2004-10-22 at 20:05, Paul Johnson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Eric Gaumer <gaumerel@ecs.fullerton.edu> writes:
> 
> > On Fri, 2004-10-22 at 00:37, Paul Johnson wrote:
> > Kernel cache stores cached kernel data structures. So say you create a
> > process, a new task_struct may be created. When that process is
> > destroyed, the kernel will cache that data structure so that it doesn't
> > have to keep allocating and destroying common data structures. This is
> > the purpose of the slab layer.
> 
> Ah, there we go.  That makes sense.  So it's kind of like a buffer for
> system calls?

No the slab cache (above) is used to cache kernel data structures. When
a process is created it consists of several data structures (process
control block, etc...). Rather than destroy that structure when we
destroy the process, we keep the structure around to use for a new
process. This saves some overhead of having to create these objects
(imagine how many processes are created and destroyed over time). It
also helps with memory fragmentation. This shows up in meminfo under
"slab" (in 2.6).

The "Cache" in meminfo is pagecache.

Pagecache has two main purposes.

o It reduces disk reads
o Serves as the basis for the page replacement

Pages read from disk are stored in a hash table. The table is then
searched before the disk is accessed. When I page is written to
(referred to as "dirty") then the data is copied to the buffer cache
where it will eventually be written to disk.

So pagecache is to buffer cache as CPU cache is to main memory. Disk I/O
is expensive and pagecache helps reduce that cost.

The page replacement stuff is more obscure and requires a firm
understanding of operating system design.

If you are interested, you can search "pagecache" in google and it will
turn up tons of insightful links.

Hope this clears up your question.


-- 
Eric Gaumer <gaumerel@ecs.fullerton.edu>

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: