The patch titled Subject: mm, thp: avoid unnecessary swapin in khugepaged has been added to the -mm tree. Its filename is mm-thp-avoid-unnecessary-swapin-in-khugepaged.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-thp-avoid-unnecessary-swapin-in-khugepaged.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-thp-avoid-unnecessary-swapin-in-khugepaged.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Ebru Akagunduz <ebru.akagunduz@xxxxxxxxx> Subject: mm, thp: avoid unnecessary swapin in khugepaged Currently khugepaged makes swapin readahead to improve THP collapse rate. This patch checks vm statistics to avoid workload of swapin, if unnecessary. So that when system under pressure, khugepaged won't consume resources to swapin and won't trigger direct reclaim when swapin readahead. The patch was tested with a test program that allocates 800MB of memory, writes to it, and then sleeps. The system was forced to swap out all. Afterwards, the test program touches the area by writing, it skips a page in each 20 pages of the area. When waiting to swapin readahead left part of the test, the memory forced to be busy doing page reclaim. There was enough free memory during test, khugepaged did not swapin readahead due to business. Test results: After swapped out ------------------------------------------------------------------- | Anonymous | AnonHugePages | Swap | Fraction | ------------------------------------------------------------------- With patch | 0 kB | 0 kB | 800000 kB | %100 | ------------------------------------------------------------------- Without patch | 0 kB | 0 kB | 800000 kB | %100 | ------------------------------------------------------------------- After swapped in ------------------------------------------------------------------- | Anonymous | AnonHugePages | Swap | Fraction | ------------------------------------------------------------------- With patch | 385120 kB | 102400 kB | 414880 kB | %26 | ------------------------------------------------------------------- Without patch | 389728 kB | 194560 kB | 410272 kB | %49 | ------------------------------------------------------------------- Signed-off-by: Ebru Akagunduz <ebru.akagunduz@xxxxxxxxx> Acked-by: Rik van Riel <riel@xxxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Naoya Horiguchi <n-horiguchi@xxxxxxxxxxxxx> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Cc: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxx> Cc: Boaz Harrosh <boaz@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/huge_memory.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff -puN mm/huge_memory.c~mm-thp-avoid-unnecessary-swapin-in-khugepaged mm/huge_memory.c --- a/mm/huge_memory.c~mm-thp-avoid-unnecessary-swapin-in-khugepaged +++ a/mm/huge_memory.c @@ -102,6 +102,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khugepage */ static unsigned int khugepaged_max_ptes_none __read_mostly; static unsigned int khugepaged_max_ptes_swap __read_mostly = HPAGE_PMD_NR/8; +static unsigned long allocstall; static int khugepaged(void *none); static int khugepaged_slab_init(void); @@ -2429,7 +2430,7 @@ static void collapse_huge_page(struct mm struct page *new_page; spinlock_t *pmd_ptl, *pte_ptl; int isolated = 0, result = 0; - unsigned long hstart, hend; + unsigned long hstart, hend, swap, curr_allocstall; struct mem_cgroup *memcg; unsigned long mmun_start; /* For mmu_notifiers */ unsigned long mmun_end; /* For mmu_notifiers */ @@ -2484,7 +2485,14 @@ static void collapse_huge_page(struct mm goto out; } - __collapse_huge_page_swapin(mm, vma, address, pmd); + swap = get_mm_counter(mm, MM_SWAPENTS); + curr_allocstall = sum_vm_event(ALLOCSTALL); + /* + * When system under pressure, don't swapin readahead. + * So that avoid unnecessary resource consuming. + */ + if (allocstall == curr_allocstall && swap != 0) + __collapse_huge_page_swapin(mm, vma, address, pmd); anon_vma_lock_write(vma->anon_vma); @@ -2878,14 +2886,17 @@ static void khugepaged_wait_work(void) if (!khugepaged_scan_sleep_millisecs) return; + allocstall = sum_vm_event(ALLOCSTALL); wait_event_freezable_timeout(khugepaged_wait, kthread_should_stop(), msecs_to_jiffies(khugepaged_scan_sleep_millisecs)); return; } - if (khugepaged_enabled()) + if (khugepaged_enabled()) { + allocstall = sum_vm_event(ALLOCSTALL); wait_event_freezable(khugepaged_wait, khugepaged_wait_event()); + } } static int khugepaged(void *none) @@ -2894,6 +2905,7 @@ static int khugepaged(void *none) set_freezable(); set_user_nice(current, MAX_NICE); + allocstall = sum_vm_event(ALLOCSTALL); while (!kthread_should_stop()) { khugepaged_do_scan(); _ Patches currently in -mm which might be from ebru.akagunduz@xxxxxxxxx are mm-make-optimistic-check-for-swapin-readahead.patch mm-make-swapin-readahead-to-improve-thp-collapse-rate.patch mm-vmstat-calculate-particular-vm-event.patch mm-thp-avoid-unnecessary-swapin-in-khugepaged.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html