xip.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 initially 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_mem is used to retrieve references
  35. to a page frame number and a kernel address. To obtain these values a reference
  36. to an address_space is provided. This function assigns values to the kmem and
  37. pfn parameters. The third argument indicates whether the function should allocate
  38. blocks if needed.
  39. This address space operation is mutually exclusive with readpage&writepage that
  40. do page cache read/write operations.
  41. The following filesystems support it as of today:
  42. - ext2: the second extended filesystem, see Documentation/filesystems/ext2.txt
  43. A set of file operations that do utilize get_xip_page can be found in
  44. mm/filemap_xip.c . The following file operation implementations are provided:
  45. - aio_read/aio_write
  46. - readv/writev
  47. - sendfile
  48. The generic file operations do_sync_read/do_sync_write can be used to implement
  49. classic synchronous IO calls.
  50. Shortcomings
  51. ------------
  52. This implementation is limited to storage devices that are cpu addressable at
  53. all times (no highmem or such). It works well on rom/ram, but enhancements are
  54. needed to make it work with flash in read+write mode.
  55. Putting the Linux kernel and/or its modules on a xip filesystem does not mean
  56. they are not copied.