1

I have an eMMC backed Linux 3.10 development device (Android) and I am trying to better understand when Linux is actually reading from the eMMC as opposed to the page cache. Specifically, I am interested in the ELF loading process and I cannot explain the following results.

I have placed an ELF file on the filesystem that is run by init and does not exit. The ELF file data resides in blocks 0x22d930-0x22da78 and I have modified the kernel to log any eMMC read accesses to blocks there blocks. During boot, the log shows that the entire ELF file is read from the eMMC.

mmc read block: 0x22d930, num_blocks: 0x20
mmc read block: 0x22d9f0, num_blocks: 0x88
mmc read block: 0x22d950, num_blocks: 0xa0

This makes sense to me as I would expect the full ELF to be read from eMMC when init first fork/execve's my ELF (0x20 + 0x88 + 0xa0 = 0x22da78 - 0x22d930).

My confusion arises when I drop the page cache and kill my process. When I kill my process, init is configured to automatically restart the process through another fork/execve. By dropping the page cache, I would expect the full ELF to again be read from the eMMC. However, I only see partial eMMC read accesses after issuing the following command.

echo 3 > /proc/sys/vm/drop_caches && kill -9 <pid>

mmc read block: 0x22d960, num_blocks: 0x10
mmc read block: 0x22d988, num_blocks: 0x8
mmc read block: 0x22d9a0, num_blocks: 0x8
mmc read block: 0x22d9c0, num_blocks: 0x40
mmc read block: 0x22da40, num_blocks: x018
mmc read block: 0x22da60, num_blocks: 0x18

My process is successfully restarted with a new pid, but I cannot understand why Linux did not reread the full ELF from disk? Linux does not even reread the ELF header, which I know is the first file read done by execve.

Are parts of the original file mapping from my original process still in some cache/RAM? The following command only shows my process.

lsof | grep <ELF name>  

I would appreciate any help in explaining this behavior and where my perceived logic is at fault.

1 Answer 1

0

The problem appears to be timing between init restarting the process and the page cache being dropped. Instead of issuing kill -9 <pid> && echo 3 > /proc/sys/vm/drop_caches, the proper sequence appears to be the following.

stop <service>
echo 3 > /proc/sys/vm/drop_caches
start <service>

Once the service is stopped, the file mapping is no longer locked in the page cache and can now be dropped. This forces Linux to reread the ELF from disk when the service is started again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .