boot-time-mm.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ===========================
  2. Boot time memory management
  3. ===========================
  4. Early system initialization cannot use "normal" memory management
  5. simply because it is not set up yet. But there is still need to
  6. allocate memory for various data structures, for instance for the
  7. physical page allocator. To address this, a specialized allocator
  8. called the :ref:`Boot Memory Allocator <bootmem>`, or bootmem, was
  9. introduced. Several years later PowerPC developers added a "Logical
  10. Memory Blocks" allocator, which was later adopted by other
  11. architectures and renamed to :ref:`memblock <memblock>`. There is also
  12. a compatibility layer called `nobootmem` that translates bootmem
  13. allocation interfaces to memblock calls.
  14. The selection of the early allocator is done using
  15. ``CONFIG_NO_BOOTMEM`` and ``CONFIG_HAVE_MEMBLOCK`` kernel
  16. configuration options. These options are enabled or disabled
  17. statically by the architectures' Kconfig files.
  18. * Architectures that rely only on bootmem select
  19. ``CONFIG_NO_BOOTMEM=n && CONFIG_HAVE_MEMBLOCK=n``.
  20. * The users of memblock with the nobootmem compatibility layer set
  21. ``CONFIG_NO_BOOTMEM=y && CONFIG_HAVE_MEMBLOCK=y``.
  22. * And for those that use both memblock and bootmem the configuration
  23. includes ``CONFIG_NO_BOOTMEM=n && CONFIG_HAVE_MEMBLOCK=y``.
  24. Whichever allocator is used, it is the responsibility of the
  25. architecture specific initialization to set it up in
  26. :c:func:`setup_arch` and tear it down in :c:func:`mem_init` functions.
  27. Once the early memory management is available it offers a variety of
  28. functions and macros for memory allocations. The allocation request
  29. may be directed to the first (and probably the only) node or to a
  30. particular node in a NUMA system. There are API variants that panic
  31. when an allocation fails and those that don't. And more recent and
  32. advanced memblock even allows controlling its own behaviour.
  33. .. _bootmem:
  34. Bootmem
  35. =======
  36. (mostly stolen from Mel Gorman's "Understanding the Linux Virtual
  37. Memory Manager" `book`_)
  38. .. _book: https://www.kernel.org/doc/gorman/
  39. .. kernel-doc:: mm/bootmem.c
  40. :doc: bootmem overview
  41. .. _memblock:
  42. Memblock
  43. ========
  44. .. kernel-doc:: mm/memblock.c
  45. :doc: memblock overview
  46. Functions and structures
  47. ========================
  48. Common API
  49. ----------
  50. The functions that are described in this section are available
  51. regardless of what early memory manager is enabled.
  52. .. kernel-doc:: mm/nobootmem.c
  53. Bootmem specific API
  54. --------------------
  55. These interfaces available only with bootmem, i.e when ``CONFIG_NO_BOOTMEM=n``
  56. .. kernel-doc:: include/linux/bootmem.h
  57. .. kernel-doc:: mm/bootmem.c
  58. :nodocs:
  59. Memblock specific API
  60. ---------------------
  61. Here is the description of memblock data structures, functions and
  62. macros. Some of them are actually internal, but since they are
  63. documented it would be silly to omit them. Besides, reading the
  64. descriptions for the internal functions can help to understand what
  65. really happens under the hood.
  66. .. kernel-doc:: include/linux/memblock.h
  67. .. kernel-doc:: mm/memblock.c
  68. :nodocs: