How to free ramdisk memory

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I ask for your help in solving a puzzle regarding how to
minimize RAM in a set top box.

After boot the set top box has about 32 MB of RAM left.
After boot we download a media player from a server.  Our
media player is 15 MB so we create a 15 MB RAM disk and
download to it.  We run the media player and immediately
run out of RAM since the media player wants to allocate
an additional 15 MB of buffers.   If only we could load
the program into memory, free the RAM disk, and then
allocate the buffers from the freed RAM.  We have all
source code.

THE QUESTIONS:
- Do you know of a way to load a program into
memory so that the open file to the executable can be
closed allowing the unmounting of the file system?

- The video codec only has drivers for the 2.2 kernel.
Do you know if CRAMFS and execute-in-place will work
with a 2.2 kernel?


Thanks in advance
Bob Smith

Re: How to free ramdisk memory
Quoted text here. Click to load it

Here is some simple code to illustrate the question.

# Make and mount a small RAM disk
dd if=/dev/zero of=/dev/ram1 bs=1k count10%0
mke2fs /dev/ram1
mkdir /mnt/test
mount /dev/ram1 /mnt/test

# Build a trivial app and put it in /mnt/test
cat >/mnt/test/hello.c <<HELLO_WORLD_APP
#include <stdio.h>
main()
{
   while (1) {
     printf("Hello World!\n");
     sleep(10);
   }
}
HELLO_WORLD_APP
gcc -o /mnt/test/hello /mnt/test/hello.c

# Run the app, delete the executable, and fail unmounting the RAM disk
/mnt/test/hello &
rm -f /mnt/test/hello
umount /mnt/test

# We can't unmount because the executable file is still open
lsof | grep hello


So the question is, can we load a program entirely into memory in such
a way as to be able to close the open file to the executable?



thanks,
Bob



Re: How to free ramdisk memory

Quoted text here. Click to load it

Not that I know of.

The route to solving your problem is to use a filesystem which supports
"execute in place". I believe a short time ago Montavista open-sourced a
file system they had developed which permits this.

With execute-in-place the memory required for the application is mapped
onto the device directly, so the code is basically run directly out of
the device instead of being copied into memory. If you create a ramdisk
using Montavista's filesystem you should be able to achieve this. The
only trick is, I think, that it needs to be allocated a region of memory
outside of the kernel's domain.

Re: How to free ramdisk memory
Quoted text here. Click to load it
Since you use a ram file system with a fixed size you loose all the
memory that it takes.
"ramfs" however just takes the memory that is used. If you delete a
file, the memory returns to the heap. So there no need to unmount the
file system for releasing the memory(if you delete the unused files)
To use ramfs:
- check that it is included in your kernel (very likely)
- mount is by:
   > mkdir /mnt/test
   > mount -t ramfs none /mnt/test
Quoted text here. Click to load it

Site Timeline