xip.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Execute-in-place for file mappings
  2. ----------------------------------
  3. Motivation
  4. ----------
  5. File mappings are performed by mapping page cache pages to userspace. In
  6. addition, read&write type file operations also transfer data from/to the page
  7. cache.
  8. For memory backed storage devices that use the block device interface, the page
  9. cache pages are in fact copies of the original storage. Various approaches
  10. exist to work around the need for an extra copy. The ramdisk driver for example
  11. does read the data into the page cache, keeps a reference, and discards the
  12. original data behind later on.
  13. Execute-in-place solves this issue the other way around: instead of keeping
  14. data in the page cache, the need to have a page cache copy is eliminated
  15. completely. With execute-in-place, read&write type operations are performed
  16. directly from/to the memory backed storage device. For file mappings, the
  17. storage device itself is mapped directly into userspace.
  18. This implementation was initialy written for shared memory segments between
  19. different virtual machines on s390 hardware to allow multiple machines to
  20. share the same binaries and libraries.
  21. Implementation
  22. --------------
  23. Execute-in-place is implemented in three steps: block device operation,
  24. address space operation, and file operations.
  25. A block device operation named direct_access is used to retrieve a
  26. reference (pointer) to a block on-disk. The reference is supposed to be
  27. cpu-addressable, physical address and remain valid until the release operation
  28. is performed. A struct block_device reference is used to address the device,
  29. and a sector_t argument is used to identify the individual block. As an
  30. alternative, memory technology devices can be used for this.
  31. The block device operation is optional, these block devices support it as of
  32. today:
  33. - dcssblk: s390 dcss block device driver
  34. An address space operation named get_xip_page is used to retrieve reference
  35. to a struct page. To address the target page, a reference to an address_space,
  36. and a sector number is provided. A 3rd argument indicates whether the
  37. function should allocate blocks if needed.
  38. This address space operation is mutually exclusive with readpage&writepage that
  39. do page cache read/write operations.
  40. The following filesystems support it as of today:
  41. - ext2: the second extended filesystem, see Documentation/filesystems/ext2.txt
  42. A set of file operations that do utilize get_xip_page can be found in
  43. mm/filemap_xip.c . The following file operation implementations are provided:
  44. - aio_read/aio_write
  45. - readv/writev
  46. - sendfile
  47. The generic file operations do_sync_read/do_sync_write can be used to implement
  48. classic synchronous IO calls.
  49. Shortcomings
  50. ------------
  51. This implementation is limited to storage devices that are cpu addressable at
  52. all times (no highmem or such). It works well on rom/ram, but enhancements are
  53. needed to make it work with flash in read+write mode.
  54. Putting the Linux kernel and/or its modules on a xip filesystem does not mean
  55. they are not copied.