Skip to contentSkip to conversation

General question about caching

DISCUSSION Christopher R. Johnson 2 participants 4 messages Apr 2, 2004

lore
Share & tools
lore
#0 lore raw

I have a tight footprint, and no swapping (in fact no disks). I notice that /proc/meminfo reports:

total: used: free: shared: buffers: cached:

Mem:  31686656 30740480   946176        0  4591616 12210176
Swap:        0        0        0
MemTotal:        30944 kB
MemFree:           924 kB
MemShared:           0 kB
Buffers:          4484 kB
Cached:          11924 kB
SwapCached:          0 kB
Active:          22196 kB
Inactive:         5416 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:        30944 kB
LowFree:           924 kB
SwapTotal:           0 kB
SwapFree:            0 kB

I only have rom and ram-based file systems, so I believe that disk caching could and maybe should be reduced to use less space. Can I control this? How? I notice that most of the cache_init routines running in init/main.c use mempages as the arg. What would be the ramifications of simply reporting less memory to those functions? Downside? Danger?

Your input is appreciated!

cj

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 3 lines · Christopher R. Johnson

I have a tight footprint, and no swapping (in fact no disks). I notice that /proc/meminfo reports:

...

Quoted 2 lines

I only have rom and ram-based file systems, so I believe that disk caching could and maybe should be reduced to use less space. Can I

Why? What's wrong with the way it is? Is it impacting performance? Thrashing? I can see a vague argument that its (nearly) pointless to cache buffers from ramdisk ... but it would take some work to flesh out this argument.

That said, you can play with parameters in /proc/sys/vm although none of those directly affect the buffer cache size. Indirectly, setting the flush times to zero might shrink the effective buffer cache, though... maybe. And it might hurt performance, maybe ...

--linas

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw

Ok, I'll give it a shot.

1. Isn't it taking up memory? If not then what does "Cached: 11924kB" mean in meminfo? With my embedded application, I desperately need every byte I can get; 11924k is HUGE in my little 32MB environment.

2. Not sure why its vague that avoiding needless caching in ram of stuff that's already in ram is silly. Perhaps the performance hit is minimal, but its still silly. At the very least won't there be some needless data copying?

Which cache is used for file contents? That would be the one I don't need.

Quoted 16 lines · [email protected] wrote:
Quoted 3 lines · Christopher R. Johnson

I have a tight footprint, and no swapping (in fact no disks). I notice that /proc/meminfo reports:

...

Quoted 3 lines

I only have rom and ram-based file systems, so I believe that disk caching could and maybe should be reduced to use less space. Can I

Why? What's wrong with the way it is? Is it impacting performance? Thrashing? I can see a vague argument that its (nearly) pointless to cache buffers from ramdisk ... but it would take some work to flesh out this argument.

Quoted 8 lines

That said, you can play with parameters in /proc/sys/vm although none of those directly affect the buffer cache size. Indirectly, setting the flush times to zero might shrink the effective buffer cache, though... maybe. And it might hurt performance, maybe ...

--linas

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 6 lines · Christopher R. Johnson

Ok, I'll give it a shot.

1. Isn't it taking up memory? If not then what does "Cached: 11924kB" mean in meminfo? With my embedded application, I desperately need every byte I can get; 11924k is HUGE in my little 32MB environment.

Its only using space that no one else is using. If you malloc more space for yourself, the cache will shrink; but for the most part the kernel will try to use all of the memory it can. No harm in that, it usually helps.

Quoted 4 lines

2. Not sure why its vague that avoiding needless caching in ram of stuff that's already in ram is silly. Perhaps the performance hit is minimal, but its still silly. At the very least won't there be some needless data copying?

Yes, there's probably some needless copying, although I haven't really read through the linux kernel ramdisk implementation, so I don't really know. They might have gotten smart. But things like buffer heads contain all sorts of flags and locks and linked lists and what-not in there, so you can't just poof-and-make it go away.

Quoted 1 line

Which cache is used for file contents? That would be the one I don't need.

Not sure what you mean. The buffer cache?

Maybe you're thinking about the /proc/slabinfo? It hold the various allocated and free blocks of various sizes, it speeds up allocation.

Different filesystems organize thier data in different ways; e.g. reiserfs packs file tails into one block. There's no trivial way to figure out what data is where in a file system, which is why the the "users" usually go through buffers. You can layer block devices onto files in arbitrary file systems on block devices ad infinitum; there's no trivial untangling of this stuff.

--linas

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/