2010-04-20 19:15:55 Does using memory for cache increase fragmentation?
Steve Strobel (UNITED STATES)
Message: 88675
I understand that on a system with a MMU, there is no harm in Linux using all otherwise-unused memory for disk cache; it can just free that memory as needed. On Blackfin systems, however, it seems that the additional allocate/free cycles might lead to memory fragmentation.
I periodically (like earlier today run into trouble getting all of my applications to run at system startup; sometimes they fail even though "free" reports plenty of available memory because none of the available memory blocks are large enough (per /proc/buddyinfo). Since I load the entire linux image into RAM from SPI flash before executing it, there is no speed advantage to caching anything. Is there a way to turn the cache off completely? Running "echo 3 > /proc/sys/vm/drop_caches" sometimes helps, but I suspect that the result is still more fragmented than it would be if the cache had never allocated the memory to begin with.
Alternately (but possibly not as helpful), is there a way to automatically drop as much of the cache memory as necessary (sometimes all of it) to fulfill each allocation request? It looks like Mike Frysinger submitted a patch from Sonic Zhang to do this, but I couldn't tell whether it was accepted or not. www.mail-archive.com/uclinux-dist-devel@blackfin.uclinux.org/msg02099.html
Thanks for any suggestions,
Steve
QuoteReplyEditDelete
2010-04-20 22:11:35 Re: Does using memory for cache increase fragmentation?
Mike Frysinger (UNITED STATES)
Message: 88684
how exactly are you running out of RAM ? are you using the uClinux MTD ? or initramfs ? or something else ?
QuoteReplyEditDelete
2010-04-26 14:56:43 Re: Does using memory for cache increase fragmentation?
Steve Strobel (UNITED STATES)
Message: 88913
Mike Frysinger wrote:
> how exactly are you running out of RAM ? are you using the uClinux MTD ? or initramfs ? or something else ?
We copy all of our custom applications into the vendors directory and use ROMFSINST to include them in the uImage.ext2 image, which ends up around 10MB. We copy that image into a 16MB SPI flash into mtdblock3.
Creating 4 MTD partitions on "m25p80":
0x00000000-0x00040000 : "bootloader"
0x00040000-0x00080000 : "bootloader-environment"
0x00080000-0x00e00000 : "kernel"
0x00e00000-0x01000000 : "file system"
U-Boot runs the commands "eeprom read $(loadaddr) 0x80000 0xD80000;bootm $(loadaddr)" to load the image into memory and boot it. The /etc/rc script mounts MTD4 (the "file system") on a path that is used only for user data that must be persistent; everything else runs on the root filesystem in RAM.
root:~> df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 24175 19363 4812 80% /
/dev/mtdblock4 2048 896 1152 44% /mnt/permanent
root:~> mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
proc on /proc type proc (rw)
ramfs on /var type ramfs (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,mode=600)
usbfs on /proc/bus/usb type usbfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
/dev/mtdblock4 on /mnt/permanent type jffs2 (rw)
We changed the U-Boot load address so we could set BLOCKS in the Makefile to give us 27MB for the root filesystem. That leaves us with marginal space for our applications, but that is a subject for another thread. Even when we have enough total free memory, we occasionally have enough fragmentation to cause failed allocations, sometimes even on startup.
I haven't yet tried running "echo 3 > /proc/sys/vm/drop_caches" before starting each application; it seems like a kludge and I think the patch mentioned in the first message of this thread should have the same effect (if it is included in uClinux-dist-2009R1.1-RC4, thus my question about that).
The real thrust of my question, however, is whether file caching should be used at all in this application. The only files that aren't already in RAM are the user data (accessed infrequently), so I don't see how caching can help significantly with speed. Even if the caches get dropped when allocations fail, if the caching process already contributed to the memory to becoming fragmented, the allocation could still fail. It seems to me that turning the caching off completely might help and couldn't hurt; is that even possible?
I noticed that it is now ADI's preference to use INITRAMFS ( docs.blackfin.uclinux.org/doku.php?id=root_file_system_structure); would that make any difference in how caching is done?
Thanks for any suggestions,
Steve
QuoteReplyEditDelete
2010-04-26 16:11:23 Re: Does using memory for cache increase fragmentation?
Mike Frysinger (UNITED STATES)
Message: 88917
dont use the uclinux mtd ext2 root then. it goes through the ramblock backing/caching system which adds overhead initramfs doesnt.
QuoteReplyEditDelete
2010-04-26 23:33:51 Re: Does using memory for cache increase fragmentation?
Sonic Zhang (CHINA)
Message: 88922
You can put your rootfs on NOR flash with JFFS2 and free more memory as well.
QuoteReplyEditDelete
2010-05-05 12:14:59 Re: Does using memory for cache increase fragmentation?
Steve Strobel (UNITED STATES)
Message: 89156
I switched from using an ext2 ramdisk to using initramfs. That seemed to free up even more memory than was being used by the the cache (I don't know why but I like it :). It is also really convenient that I don't have to specify the size of the initramfs filesystem because it just dynamically uses as much memory as it needs.
"df" doesn't seem to report on the space used by initramfs, so went looking for another way to determine how much of the memory is being used for initramfs versus running programs. It is just the size of the cache (such as can be displayed by "top" or cat /proc/meminfo)?
Mem: 49104K used, 12900K free, 0K shrd, 0K buff, 20352K cached
root:~> cat /proc/meminfo [snip]
Cached: 20352 kB
Steve
QuoteReplyEditDelete
2010-05-05 13:19:45 Re: Does using memory for cache increase fragmentation?
Robin Getz (UNITED STATES)
Message: 89157
Steve:
initramfs == the page cache - it doesn't decrease it, it just doesn't keep an extra "copy".
You are correct - as long as no other file systems are being used - the cache is the size of the initramfs.
-Robin
QuoteReplyEditDelete
2010-05-05 15:01:56 Re: Does using memory for cache increase fragmentation?
Mike Frysinger (UNITED STATES)
Message: 89158
you can run statfs on /