3

I have an embedded system with a low amount of memory. The system has allocation issues. Maybe due to fragmentation: Memory allocation issue on NOMMU? The platform is a NOMMU platform and so I suspect that the linux caching is the cause of this fragmentation. Maybe it is, maybe it isn't. The thing is, I can't really see what my system would gain from caching. The system is built from the following partitions:

  1. RAM partition. (Kernel, user space fs, etc.)
  2. SPI Flash. (Some config data. Maybe a few kb.)
  3. SD Card. (Logged data. Will never be read.)

Here's the output from my top command:

Mem: 23376K used, 5912K free, 0K shrd, 1624K buff, 8404K cached
CPU:  10% usr  42% sys   0% nic   0% idle  47% io   0% irq   0% sirq
Load average: 1.07 1.00 0.96 2/68 4299
...

My system has 15M free ram when booted. Within a few minutes more than 60% is used for cache. Normally that wouldn't matter, except if it causing fragmentation issues due to NOMMU difficulties. Now, what is it that the kernel wants to cache anyway? The RAM partition? (Bit foolish.) The SPI Flash? (Good idea. But there's only a few kb there.) The SD card? (It doesn't need caching in this particular scenario.)

How do see what is being cached? And how do I reduce the caching scheme? (I really don't need that much caching. There's no gain.)

I've tried to mount the sd card and the spi flash with -o sync. But it doesn't make a difference.

  • The ram partition (tmpfs) is just cache, with no backing store (anonymous anon). I can not remember how it is reported, probably as cache. Use df to see how much space it uses. – ctrl-alt-delor Aug 25 '14 at 12:58
  • Have you tried disabling logging, and preferably un-mounting sd card; You should test your hypothesis before creating a solution. – ctrl-alt-delor Aug 25 '14 at 13:00
  • Which is why I wanted to see 'what is being cached'. Disabling the logging might be a way to test it. But the purpose of the system, is to log to the sd card. Without that it won't have any activity at all. (Nothing to cache.) – Illishar Aug 25 '14 at 13:22
  • If you can ,easily, get the system to do everything except the actual writing of the logs to the sd, then you can use this as a diagnostic. See if cache usage changes, see if performance changes. (One way no to this, is to write a script to delete or truncate the logs regularly. This will drop the buffers, hopefully before they get large. If it takes minutes to fill the cache, then this should keep it under control). If this improves performance then there is motivation to disable caching of this write-only file-system. – ctrl-alt-delor Aug 25 '14 at 13:34
  • Performance is not an issue. I don't mind if it has horrible read/write performance. You mention "disable caching". How would I do that? The -o sync doesn't effect the issue. "echo 1 > /proc/sys/vm/drop_caches" will purge the cache not disable it. (And a cronjob with 'purge' is a bit pathetic.) – Illishar Aug 25 '14 at 13:49
2

This is a nice utility, part of linux-ftools. You have to give the file name as input, and it will stats for the files that are in the cache now.

# fincore --pages=false --summarize --only-cached <file_name>

fincore [options] files...

  --pages=false      Do not print pages
  --summarize        When comparing multiple files, print a summary report
  --only-cached      Only print stats for files that are actually in cache.

root@xxxxxx:/var/lib/mysql/blogindex# fincore --pages=false --summarize --only-cached * 
stats for CLUSTER_LOG_2010_05_21.MYI: file size=93840384 , total pages=22910 , cached pages=1 , cached size=4096, cached perc=0.004365 
stats for CLUSTER_LOG_2010_05_22.MYI: file size=417792 , total pages=102 , cached pages=1 , cached size=4096, cached perc=0.980392 
stats for CLUSTER_LOG_2010_05_23.MYI: file size=826368 , total pages=201 , cached 
---
total cached size: xxx

Also the tmpfs or ramfs filesystem is part of the cache.

As noted in the tmpfs documentation

Since tmpfs lives completely in the page cache and on swap, all tmpfs
pages currently in memory will show up as cached. It will not show up
as shared or something like that

tmpfs has three mount options for sizing:

size:      The limit of allocated bytes for this tmpfs instance. The 
           default is half of your physical RAM without swap. 

           **If you oversize your tmpfs instances the machine will deadlock
           since the OOM handler will not be able to free that memory.**

nr_blocks: The same as size, but in blocks of PAGE_CACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default
           is half of the number of your physical RAM pages, or (on a
           machine with highmem) the number of lowmem RAM pages,
           whichever is the lower.

You can limit the tmpfs filesystem

# mount -t tmpfs -o size=60M tmpfs /tmp -> Size limited to 60M

You can also tune your /proc/sys/vm/* entries for better caching mechanism.

I wrote a blog post here about linux caching. Probably this might help you.

  • Great blog post – Illishar Nov 17 '14 at 7:56
  • @Illishar Thanks. Hopefully it helped you. – Joe Nov 18 '14 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.