Skip to contentSkip to conversation

mm: khugepaged: avoid overriding min_free_kbytes set by user

PATCH Superseded Vijay Balakrishna 2 participants 3 messages Sep 15, 2020

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: khugepaged: avoid overriding min_free_kbytes set by user

set_recommended_min_free_kbytes need to honor min_free_kbytes set by the user. Post start-of-day THP enable or memory hotplug operations can lose user specified min_free_kbytes, in particular when it is higher than calculated recommended value.

---
 mm/khugepaged.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/khugepaged.c +4 -4
index 4f7107476a6f..b4b753ba411a 100644
@@ -2253,7 +2253,7 @@ static void set_recommended_min_free_kbytes(void)
 {
 	struct zone *zone;
 	int nr_zones = 0;
-	unsigned long recommended_min;
+	int recommended_min;
 
 	for_each_populated_zone(zone) {
 		/*
@@ -2280,12 +2280,12 @@ static void set_recommended_min_free_kbytes(void)
 
 	/* don't ever allow to reserve more than 5% of the lowmem */
 	recommended_min = min(recommended_min,
-			      (unsigned long) nr_free_buffer_pages() / 20);
+			      (int) nr_free_buffer_pages() / 20);
 	recommended_min <<= (PAGE_SHIFT-10);
 
-	if (recommended_min > min_free_kbytes) {
+	if (recommended_min > user_min_free_kbytes) {
 		if (user_min_free_kbytes >= 0)
-			pr_info("raising min_free_kbytes from %d to %lu to help transparent hugepage allocations\n",
+			pr_info("raising min_free_kbytes from %d to %d to help transparent hugepage allocations\n",
 				min_free_kbytes, recommended_min);
 
 		min_free_kbytes = recommended_min;
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Vijay Balakrishna

set_recommended_min_free_kbytes need to honor min_free_kbytes set by the user. Post start-of-day THP enable or memory hotplug operations can lose user specified min_free_kbytes, in particular when it is higher than calculated recommended value.

---
 mm/khugepaged.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/khugepaged.c +0 -0
index 4f7107476a6f..b4b753ba411a 100644

mm/khugepaged.c static void set_recommended_min_free_kbytes(void) · line 2256

Quoted 5 lines
mm/khugepaged.c +1 -1
@@ -2253,7 +2253,7 @@ static void set_recommended_min_free_kbytes(void)
 {
        struct zone *zone;
        int nr_zones = 0;
-       unsigned long recommended_min;
+       int recommended_min;

Hi Vijay,

Please explain in log the type change. user_min_free_kbytes is of "int" type and is initialized to -1, so comparing to unsigned leads to undesired effect.

mm/khugepaged.c static void set_recommended_min_free_kbytes(void) · line 2286

Quoted 13 lines
mm/khugepaged.c +2 -2
        for_each_populated_zone(zone) {
                /*
@@ -2280,12 +2280,12 @@ static void set_recommended_min_free_kbytes(void)
 
        /* don't ever allow to reserve more than 5% of the lowmem */
        recommended_min = min(recommended_min,
-                             (unsigned long) nr_free_buffer_pages() / 20);
+                             (int) nr_free_buffer_pages() / 20);
        recommended_min <<= (PAGE_SHIFT-10);
 
-       if (recommended_min > min_free_kbytes) {
+       if (recommended_min > user_min_free_kbytes) {

Took me a while to understand, but this change is correct. It is the same logic that is done in init_per_zone_wmark_min().

Please join the two patches you have in one patch series.

Thank you,
Pasha

#2 lore raw
Quoted 27 lines · Pavel Tatashin
Quoted 17 lines · Vijay Balakrishna

set_recommended_min_free_kbytes need to honor min_free_kbytes set by the user. Post start-of-day THP enable or memory hotplug operations can lose user specified min_free_kbytes, in particular when it is higher than calculated recommended value.

---
  mm/khugepaged.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
mm/khugepaged.c +0 -0
index 4f7107476a6f..b4b753ba411a 100644

mm/khugepaged.c static void set_recommended_min_free_kbytes(void) · line 2256

Quoted 5 lines
mm/khugepaged.c +1 -1
@@ -2253,7 +2253,7 @@ static void set_recommended_min_free_kbytes(void)
  {
         struct zone *zone;
         int nr_zones = 0;
-       unsigned long recommended_min;
+       int recommended_min;

Hi Vijay,

Quoted 3 lines

Please explain in log the type change. user_min_free_kbytes is of "int" type and is initialized to -1, so comparing to unsigned leads to undesired effect.

Hi Pasha,

I will update log. I uncovered it when trying to understand why one-line change to address issue raised by Kirill didn't work!

Quoted 13 lines
Quoted 13 lines
mm/khugepaged.c +1 -1
         for_each_populated_zone(zone) {
                 /*
@@ -2280,12 +2280,12 @@ static void set_recommended_min_free_kbytes(void)
 
         /* don't ever allow to reserve more than 5% of the lowmem */
         recommended_min = min(recommended_min,
-                             (unsigned long) nr_free_buffer_pages() / 20);
+                             (int) nr_free_buffer_pages() / 20);
         recommended_min <<= (PAGE_SHIFT-10);
 
Quoted 8 lines

mm/khugepaged.c static void set_recommended_min_free_kbytes(void) · line 2286

Quoted 2 lines
mm/khugepaged.c +1 -1
-       if (recommended_min > min_free_kbytes) {
+       if (recommended_min > user_min_free_kbytes) {

Took me a while to understand, but this change is correct. It is the same logic that is done in init_per_zone_wmark_min().

Please join the two patches you have in one patch series.

Will do.

Thanks,
Vijay

Quoted 4 lines

Thank you,
Pasha