limiting-resources.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Limiting the Host Resources Usage
  3. *********************************
  4. While you sometimes need to :doc:`speed up a build
  5. </dev-manual/speeding-up-build>`, you may also need to limit the resources used
  6. by the :term:`OpenEmbedded Build System`, especially on shared infrastructures
  7. where multiple users start heavy-load builds, or when building on low-power
  8. machines.
  9. This document aims at giving the different configuration variables available to
  10. limit the resources used by the build system. These variables should be set from
  11. a :term:`configuration file` and thus take effect over the entire build environment.
  12. For each variable, also see the variable description in the glossary for more
  13. details.
  14. - :term:`BB_NUMBER_THREADS`:
  15. This sets a hard limit on the number of threads :term:`BitBake` can run at the
  16. same time. Lowering this value will set a limit to the number of
  17. :term:`BitBake` threads, but will not prevent a single task from starting more
  18. compilation threads (see :term:`PARALLEL_MAKE`).
  19. - :term:`BB_NUMBER_PARSE_THREADS`:
  20. Like :term:`BB_NUMBER_THREADS`, but this variable sets a limit on the number
  21. of threads during the parsing of the environment (before executing tasks).
  22. - :term:`PARALLEL_MAKE`:
  23. This variable should be set in the form of ``-jN``, where ``N`` is a positive
  24. integer. This integer controls the number of threads used when starting
  25. ``make``. Note that this variable is not limited to the usage of ``make``,
  26. but extends to the compilation (:ref:`ref-tasks-compile` task) commands
  27. defined by the :ref:`ref-classes-meson`, :ref:`ref-classes-cmake` and such
  28. classes.
  29. If you want to have a different limit from the rest of the build for a
  30. recipe, it is also possible to achieve with the following line added to your
  31. ``local.conf`` :term:`configuration file`::
  32. PARALLEL_MAKE:pn-linux-yocto = "-j4"
  33. The above example will limit the number of threads used by ``make`` for the
  34. ``linux-yocto`` recipe to 4.
  35. - :term:`PARALLEL_MAKEINST`:
  36. Like :term:`PARALLEL_MAKE`, but this variable controls the number of threads
  37. used during the :ref:`ref-tasks-install` task.
  38. The default value of :term:`PARALLEL_MAKEINST` is the value of
  39. :term:`PARALLEL_MAKE`.
  40. .. note::
  41. While most of the variables in this document help to limit the CPU load, it
  42. is also possible that the host system runs out of physical RAM when running
  43. builds. This can trigger the out-of-memory killer and stop the related
  44. processes abruptly. This can create strange looking failures in the output
  45. log of the tasks in question. The out-of-memory killer only logs in the
  46. kernel dmesg logs, so it is advised to monitor it closely with the ``dmesg``
  47. command when encountering unexpected failures during builds.
  48. In these situations, lowering the value of :term:`PARALLEL_MAKE` and
  49. :term:`BB_NUMBER_THREADS` is recommended.
  50. - :term:`BB_PRESSURE_MAX_CPU`, :term:`BB_PRESSURE_MAX_IO` and
  51. :term:`BB_PRESSURE_MAX_MEMORY`:
  52. These variables control the limit of pressure (PSI as defined by
  53. https://docs.kernel.org/accounting/psi.html) on the system, and will
  54. limit the number of :term:`BitBake` threads dynamically depending on the
  55. current pressure of the system. This also means that your host must support
  56. the PSI kernel feature (otherwise see :term:`BB_LOADFACTOR_MAX` below).
  57. These variables take a positive integer between 1 (extremely low limit) and
  58. 1000000 (value unlikely ever reached). Setting an extremely low value, such
  59. as 2, is not desirable as it will result in :term:`BitBake` limiting the
  60. number of threads to 1 most of the time.
  61. To determine a reasonable value to set for your host, follow the steps below:
  62. #. In a Bash shell, start the following script, which will provide an
  63. estimate of the current pressure on your host:
  64. .. code-block:: bash
  65. pressure="0"
  66. while true; do
  67. prev_pressure="$pressure"
  68. pressure=$(head -1 /proc/pressure/cpu | cut -d' ' -f5 | cut -d'=' -f2)
  69. echo $(( $pressure - $prev_pressure ))
  70. sleep 1
  71. done
  72. .. note::
  73. Change ``/proc/pressure/cpu`` to ``/proc/pressure/io`` or
  74. ``/proc/pressure/memory`` to change the pressure type to monitor.
  75. This script can be stopped by pressing Control + C.
  76. #. Then, start a heavy-load build, for example::
  77. bitbake virtual/kernel -c compile -f
  78. You can stop the build at anytime with Control + C.
  79. #. Monitor the values printed on the console. These should indicate how the
  80. pressure evolves during the build. You can take a value below the maximum
  81. printed value as a starting point.
  82. After setting initial values, :term:`BitBake` will print messages on the
  83. console in the following format each time the current pressure exceeds of the
  84. limit set by the above variables::
  85. Pressure status changed to CPU: True, IO: False, Mem: False (CPU: 1105.9/2.0, IO: 0.0/2.0, Mem: 0.0/2.0) - using 1/64 bitbake threads
  86. Take a look at the value between parenthesis: ``CPU: 1105.9/2.0, IO: 0.0/2.0,
  87. Mem: 0.0/2.0``. They correspond to the current pressure value for the CPU, IO
  88. and memory respectively. If :term:`BitBake` prints these messages a lot, it
  89. is likely that your pressure limit is too low, and thus can be raised to a
  90. higher value.
  91. - :term:`BB_LOADFACTOR_MAX`:
  92. This variable will limit the number of threads :term:`BitBake` will start
  93. by monitoring the current CPU load of the host system. :term:`BitBake` will
  94. print the following when the limit set by :term:`BB_LOADFACTOR_MAX` is
  95. reached::
  96. Load average limiting set to True as load average: 0.7188262939453125 - using 37/64 bitbake threads
  97. This variable has no effect when any of :term:`BB_PRESSURE_MAX_CPU`,
  98. :term:`BB_PRESSURE_MAX_IO` or :term:`BB_PRESSURE_MAX_MEMORY` is set, as it
  99. was designed for systems that do not have pressure information available.