thp_settings.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __THP_SETTINGS_H__
  3. #define __THP_SETTINGS_H__
  4. #include <stdbool.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. enum thp_enabled {
  8. THP_NEVER,
  9. THP_ALWAYS,
  10. THP_INHERIT,
  11. THP_MADVISE,
  12. };
  13. enum thp_defrag {
  14. THP_DEFRAG_ALWAYS,
  15. THP_DEFRAG_DEFER,
  16. THP_DEFRAG_DEFER_MADVISE,
  17. THP_DEFRAG_MADVISE,
  18. THP_DEFRAG_NEVER,
  19. };
  20. enum shmem_enabled {
  21. SHMEM_NEVER,
  22. SHMEM_ALWAYS,
  23. SHMEM_WITHIN_SIZE,
  24. SHMEM_ADVISE,
  25. SHMEM_INHERIT,
  26. SHMEM_DENY,
  27. SHMEM_FORCE,
  28. };
  29. #define NR_ORDERS 20
  30. struct hugepages_settings {
  31. enum thp_enabled enabled;
  32. };
  33. struct khugepaged_settings {
  34. bool defrag;
  35. unsigned int alloc_sleep_millisecs;
  36. unsigned int scan_sleep_millisecs;
  37. unsigned int max_ptes_none;
  38. unsigned int max_ptes_swap;
  39. unsigned int max_ptes_shared;
  40. unsigned long pages_to_scan;
  41. };
  42. struct shmem_hugepages_settings {
  43. enum shmem_enabled enabled;
  44. };
  45. struct thp_settings {
  46. enum thp_enabled thp_enabled;
  47. enum thp_defrag thp_defrag;
  48. enum shmem_enabled shmem_enabled;
  49. bool use_zero_page;
  50. struct khugepaged_settings khugepaged;
  51. unsigned long read_ahead_kb;
  52. struct hugepages_settings hugepages[NR_ORDERS];
  53. struct shmem_hugepages_settings shmem_hugepages[NR_ORDERS];
  54. };
  55. int read_file(const char *path, char *buf, size_t buflen);
  56. int write_file(const char *path, const char *buf, size_t buflen);
  57. unsigned long read_num(const char *path);
  58. void write_num(const char *path, unsigned long num);
  59. int thp_read_string(const char *name, const char * const strings[]);
  60. void thp_write_string(const char *name, const char *val);
  61. unsigned long thp_read_num(const char *name);
  62. void thp_write_num(const char *name, unsigned long num);
  63. void thp_write_settings(struct thp_settings *settings);
  64. void thp_read_settings(struct thp_settings *settings);
  65. struct thp_settings *thp_current_settings(void);
  66. void thp_push_settings(struct thp_settings *settings);
  67. void thp_pop_settings(void);
  68. void thp_restore_settings(void);
  69. void thp_save_settings(void);
  70. void thp_set_read_ahead_path(char *path);
  71. unsigned long thp_supported_orders(void);
  72. unsigned long thp_shmem_supported_orders(void);
  73. bool thp_available(void);
  74. bool thp_is_enabled(void);
  75. #endif /* __THP_SETTINGS_H__ */