Guest User

Untitled

a guest
Feb 15th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. diff -pru a/include/linux/mm.h b/include/linux/mm.h
  2. --- a/include/linux/mm.h 2020-12-30 19:54:29.000000000 +0900
  3. +++ b/include/linux/mm.h 2021-02-16 03:44:03.789770868 +0900
  4. @@ -205,6 +205,11 @@ extern int sysctl_max_map_count;
  5. extern unsigned long sysctl_user_reserve_kbytes;
  6. extern unsigned long sysctl_admin_reserve_kbytes;
  7.  
  8. +#if defined(CONFIG_PROTECT_FILE)
  9. +extern unsigned long sysctl_file_low_kbytes;
  10. +extern unsigned long sysctl_file_min_kbytes;
  11. +#endif
  12. +
  13. extern int sysctl_overcommit_memory;
  14. extern int sysctl_overcommit_ratio;
  15. extern unsigned long sysctl_overcommit_kbytes;
  16. diff -pru a/kernel/sysctl.c b/kernel/sysctl.c
  17. --- a/kernel/sysctl.c 2020-12-30 19:54:29.000000000 +0900
  18. +++ b/kernel/sysctl.c 2021-02-16 03:44:03.789770868 +0900
  19. @@ -111,6 +111,19 @@
  20. static int sixty = 60;
  21. #endif
  22.  
  23. +#if defined(CONFIG_PROTECT_FILE)
  24. +#if CONFIG_PROTECT_FILE_LOW_KBYTES < 0
  25. +#error "CONFIG_PROTECT_FILE_LOW_KBYTES should be >= 0"
  26. +#endif
  27. +#if CONFIG_PROTECT_FILE_MIN_KBYTES < 0
  28. +#error "CONFIG_PROTECT_FILE_MIN_KBYTES should be >= 0"
  29. +#endif
  30. +unsigned long sysctl_file_low_kbytes __read_mostly =
  31. + CONFIG_PROTECT_FILE_LOW_KBYTES;
  32. +unsigned long sysctl_file_min_kbytes __read_mostly =
  33. + CONFIG_PROTECT_FILE_MIN_KBYTES;
  34. +#endif
  35. +
  36. static int __maybe_unused neg_one = -1;
  37. static int __maybe_unused two = 2;
  38. static int __maybe_unused four = 4;
  39. @@ -3082,6 +3095,22 @@ static struct ctl_table vm_table[] = {
  40. .extra2 = SYSCTL_ONE,
  41. },
  42. #endif
  43. +#if defined(CONFIG_PROTECT_FILE)
  44. + {
  45. + .procname = "file_low_kbytes",
  46. + .data = &sysctl_file_low_kbytes,
  47. + .maxlen = sizeof(sysctl_file_low_kbytes),
  48. + .mode = 0644,
  49. + .proc_handler = proc_doulongvec_minmax,
  50. + },
  51. + {
  52. + .procname = "file_min_kbytes",
  53. + .data = &sysctl_file_min_kbytes,
  54. + .maxlen = sizeof(sysctl_file_min_kbytes),
  55. + .mode = 0644,
  56. + .proc_handler = proc_doulongvec_minmax,
  57. + },
  58. +#endif
  59. {
  60. .procname = "user_reserve_kbytes",
  61. .data = &sysctl_user_reserve_kbytes,
  62. diff -pru a/mm/Kconfig b/mm/Kconfig
  63. --- a/mm/Kconfig 2020-12-30 19:54:29.000000000 +0900
  64. +++ b/mm/Kconfig 2021-02-16 03:44:03.789770868 +0900
  65. @@ -63,6 +63,20 @@ config SPARSEMEM_MANUAL
  66.  
  67. endchoice
  68.  
  69. +config PROTECT_FILE
  70. + def_bool y
  71. + depends on SYSCTL
  72. +
  73. +config PROTECT_FILE_LOW_KBYTES
  74. + int "Default value for vm.file_low_kbytes"
  75. + depends on PROTECT_FILE
  76. + default "0"
  77. +
  78. +config PROTECT_FILE_MIN_KBYTES
  79. + int "Default value for vm.file_min_kbytes"
  80. + depends on PROTECT_FILE
  81. + default "0"
  82. +
  83. config DISCONTIGMEM
  84. def_bool y
  85. depends on (!SELECT_MEMORY_MODEL && ARCH_DISCONTIGMEM_ENABLE) || DISCONTIGMEM_MANUAL
  86. diff -pru a/mm/vmscan.c b/mm/vmscan.c
  87. --- a/mm/vmscan.c 2020-12-30 19:54:29.000000000 +0900
  88. +++ b/mm/vmscan.c 2021-02-16 03:54:29.737443977 +0900
  89. @@ -120,6 +120,10 @@ struct scan_control {
  90. /* The file pages on the current node are dangerously low */
  91. unsigned int file_is_tiny:1;
  92.  
  93. +#if defined(CONFIG_PROTECT_FILE)
  94. + unsigned int file_is_min:1;
  95. +#endif
  96. +
  97. /* Allocation order */
  98. s8 order;
  99.  
  100. @@ -2242,6 +2246,13 @@ static void get_scan_count(struct lruvec
  101. unsigned long ap, fp;
  102. enum lru_list lru;
  103.  
  104. +#if defined(CONFIG_PROTECT_FILE)
  105. + if (sc->file_is_min) {
  106. + scan_balance = SCAN_ANON;
  107. + goto out;
  108. + }
  109. +#endif
  110. +
  111. /* If we have no swap space, do not bother scanning anon pages. */
  112. if (!sc->may_swap || mem_cgroup_get_nr_swap_pages(memcg) <= 0) {
  113. scan_balance = SCAN_FILE;
  114. @@ -2762,6 +2773,14 @@ again:
  115. file + free <= total_high_wmark &&
  116. !(sc->may_deactivate & DEACTIVATE_ANON) &&
  117. anon >> sc->priority;
  118. +
  119. +#if defined(CONFIG_PROTECT_FILE)
  120. + file <<= (PAGE_SHIFT - 10);
  121. + sc->file_is_min = file <= sysctl_file_min_kbytes;
  122. + if (file <= sysctl_file_low_kbytes)
  123. + sc->file_is_tiny = true;
  124. +#endif
  125. +
  126. }
  127.  
  128. shrink_node_memcgs(pgdat, sc);
  129.  
  130.  
Advertisement
Add Comment
Please, Sign In to add comment