Skip to content

Commit

Permalink
mm: khugepaged: recalculate min_free_kbytes after stopping khugepaged
Browse files Browse the repository at this point in the history
When initializing transparent huge pages, min_free_kbytes would be
calculated according to what khugepaged expected.

So when transparent huge pages get disabled, min_free_kbytes should be
recalculated instead of the higher value set by khugepaged.

Link: https://lkml.kernel.org/r/1633937809-16558-1-git-send-email-liangcaifan19@gmail.com
Signed-off-by: Liangcai Fan <liangcaifan19@gmail.com>
Signed-off-by: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Liangcai Fan authored and Linus Torvalds committed Nov 6, 2021
1 parent 8531fc6 commit bd3400e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,7 @@ extern void memmap_init_range(unsigned long, int, unsigned long,
unsigned long, unsigned long, enum meminit_context,
struct vmem_altmap *, int migratetype);
extern void setup_per_zone_wmarks(void);
extern void calculate_min_free_kbytes(void);
extern int __meminit init_per_zone_wmark_min(void);
extern void mem_init(void);
extern void __init mmap_init(void);
Expand Down
10 changes: 8 additions & 2 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,11 @@ static void set_recommended_min_free_kbytes(void)
int nr_zones = 0;
unsigned long recommended_min;

if (!khugepaged_enabled()) {
calculate_min_free_kbytes();
goto update_wmarks;
}

for_each_populated_zone(zone) {
/*
* We don't need to worry about fragmentation of
Expand Down Expand Up @@ -2334,6 +2339,8 @@ static void set_recommended_min_free_kbytes(void)

min_free_kbytes = recommended_min;
}

update_wmarks:
setup_per_zone_wmarks();
}

Expand All @@ -2355,12 +2362,11 @@ int start_stop_khugepaged(void)

if (!list_empty(&khugepaged_scan.mm_head))
wake_up_interruptible(&khugepaged_wait);

set_recommended_min_free_kbytes();
} else if (khugepaged_thread) {
kthread_stop(khugepaged_thread);
khugepaged_thread = NULL;
}
set_recommended_min_free_kbytes();
fail:
mutex_unlock(&khugepaged_mutex);
return err;
Expand Down
7 changes: 6 additions & 1 deletion mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8469,7 +8469,7 @@ void setup_per_zone_wmarks(void)
* 8192MB: 11584k
* 16384MB: 16384k
*/
int __meminit init_per_zone_wmark_min(void)
void calculate_min_free_kbytes(void)
{
unsigned long lowmem_kbytes;
int new_min_free_kbytes;
Expand All @@ -8483,6 +8483,11 @@ int __meminit init_per_zone_wmark_min(void)
pr_warn("min_free_kbytes is not updated to %d because user defined value %d is preferred\n",
new_min_free_kbytes, user_min_free_kbytes);

}

int __meminit init_per_zone_wmark_min(void)
{
calculate_min_free_kbytes();
setup_per_zone_wmarks();
refresh_zone_stat_thresholds();
setup_per_zone_lowmem_reserve();
Expand Down

0 comments on commit bd3400e

Please sign in to comment.