I was looking for DAX (Direct Access), and saw that it is introduced as a replacement of XIP (Execute In Place); however, I have doubts if it indeed makes applications executed without being copied to RAM. It says that it is "Direct Access for files", but an executable is also a file to kernel isn't it? So does it make the kernel execute files without copying them to RAM? If yes, how it works? Does it keep the .text region in place, but create a copy of .data region?
I have an experiment setup: I configured my Linux kernel 4.6.2, with DAX support. Created a ram backed block device. Mounted a ramdisk with dax option:
# mount -t ramfs -o dax,size=8m ext2 /ramdisk # mount rootfs on / type rootfs (rw,size=59124k,nr_inodes=14781) proc on /proc type proc (rw,relatime) tmpfs on /tmp type tmpfs (rw,relatime) ext2 on /ramdisk type ramfs (rw,relatime,dax,size=8m) #
Now, I have ramfs mounted to /ramdisk, formatted with ext2 and has dax support. If I now copy an application to /ramdisk, and execute; how can I be sure that it is not copied to any other place on the RAM, and executed from there?
Unfortunately, dax has so little documentation. It's kernel explanation says that:
For block devices that are memory-like, the page cache pages would be unnecessary copies of the original storage. The DAX code removes the extra copy by performing reads and writes directly to the storage device. For file mappings, the storage device is mapped directly into userspace.
This seems as if it will give me the execution without copying the executable to a second place in RAM. However, it is also said that:
Even if the kernel or its modules are stored on a filesystem that supports DAX on a block device that supports DAX, they will still be copied into RAM.
In summary, I am confused with DAX feature, and curious if it can provide me a way to execute applications, without copying them to another place on RAM (Copying to cache is out of topic for me). I would be pleased to hear explanations of how it works.