Skip to content

Commit f050897

Browse files
rientjestorvalds
authored andcommitted
mm, thp: khugepaged should scan when sleep value is written
If a large value is written to scan_sleep_millisecs, for example, that period must lapse before khugepaged will wake up for periodic collapsing. If this value is tuned to 1 day, for example, and then re-tuned to its default 10s, khugepaged will still wait for a day before scanning again. This patch causes khugepaged to wakeup immediately when the value is changed and then sleep until that value is rewritten or the new value lapses. Link: http://lkml.kernel.org/r/alpine.DEB.2.10.1605181453200.4786@chino.kir.corp.google.com Signed-off-by: David Rientjes <rientjes@google.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a53eaff commit f050897

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

mm/huge_memory.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static unsigned int khugepaged_full_scans;
8989
static unsigned int khugepaged_scan_sleep_millisecs __read_mostly = 10000;
9090
/* during fragmentation poll the hugepage allocator once every minute */
9191
static unsigned int khugepaged_alloc_sleep_millisecs __read_mostly = 60000;
92+
static unsigned long khugepaged_sleep_expire;
9293
static struct task_struct *khugepaged_thread __read_mostly;
9394
static DEFINE_MUTEX(khugepaged_mutex);
9495
static DEFINE_SPINLOCK(khugepaged_mm_lock);
@@ -467,6 +468,7 @@ static ssize_t scan_sleep_millisecs_store(struct kobject *kobj,
467468
return -EINVAL;
468469

469470
khugepaged_scan_sleep_millisecs = msecs;
471+
khugepaged_sleep_expire = 0;
470472
wake_up_interruptible(&khugepaged_wait);
471473

472474
return count;
@@ -494,6 +496,7 @@ static ssize_t alloc_sleep_millisecs_store(struct kobject *kobj,
494496
return -EINVAL;
495497

496498
khugepaged_alloc_sleep_millisecs = msecs;
499+
khugepaged_sleep_expire = 0;
497500
wake_up_interruptible(&khugepaged_wait);
498501

499502
return count;
@@ -2791,15 +2794,25 @@ static void khugepaged_do_scan(void)
27912794
put_page(hpage);
27922795
}
27932796

2797+
static bool khugepaged_should_wakeup(void)
2798+
{
2799+
return kthread_should_stop() ||
2800+
time_after_eq(jiffies, khugepaged_sleep_expire);
2801+
}
2802+
27942803
static void khugepaged_wait_work(void)
27952804
{
27962805
if (khugepaged_has_work()) {
2797-
if (!khugepaged_scan_sleep_millisecs)
2806+
const unsigned long scan_sleep_jiffies =
2807+
msecs_to_jiffies(khugepaged_scan_sleep_millisecs);
2808+
2809+
if (!scan_sleep_jiffies)
27982810
return;
27992811

2812+
khugepaged_sleep_expire = jiffies + scan_sleep_jiffies;
28002813
wait_event_freezable_timeout(khugepaged_wait,
2801-
kthread_should_stop(),
2802-
msecs_to_jiffies(khugepaged_scan_sleep_millisecs));
2814+
khugepaged_should_wakeup(),
2815+
scan_sleep_jiffies);
28032816
return;
28042817
}
28052818

0 commit comments

Comments
 (0)