From patchwork Wed Apr 29 22:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11518929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 302AC912 for ; Wed, 29 Apr 2020 22:56:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EDBFA2083B for ; Wed, 29 Apr 2020 22:56:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDBFA2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 297178E0005; Wed, 29 Apr 2020 18:56:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 23AAA8E0001; Wed, 29 Apr 2020 18:56:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12B1F8E0005; Wed, 29 Apr 2020 18:56:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id EC6BC8E0001 for ; Wed, 29 Apr 2020 18:56:34 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AE646181AC9C6 for ; Wed, 29 Apr 2020 22:56:34 +0000 (UTC) X-FDA: 76762403508.06.bulb65_909e49efe6c22 X-Spam-Summary: 2,0,0,8eab4f11a341c806,d41d8cd98f00b204,yang.shi@linux.alibaba.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1261:1345:1431:1437:1534:1543:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3353:3743:3865:3866:3867:5007:6261:8957:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12895:13161:13229:14096:14181:14721:21060:21080:21451:21627:21990:30003:30054:30070,0,RBL:115.124.30.54:@linux.alibaba.com:.lbl8.mailshell.net-64.201.201.201 62.20.2.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: bulb65_909e49efe6c22 X-Filterd-Recvd-Size: 4311 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Apr 2020 22:56:33 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Tx2iHl3_1588200982; Received: from localhost(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tx2iHl3_1588200982) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Apr 2020 06:56:30 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, hughd@google.com, aarcange@redhat.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [linux-next PATCH 1/2] mm: khugepaged: add exceed_max_ptes_* helpers Date: Thu, 30 Apr 2020 06:56:21 +0800 Message-Id: <1588200982-69492-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The max_ptes_{swap|none|shared} are defined to tune the behavior of khugepaged. The are checked at a couple of places with open coding. Replace the opencoding to exceed_pax_ptes_{swap|none_shared} helpers to improve the readability. Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: Andrea Arcangeli Signed-off-by: Yang Shi --- mm/khugepaged.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a02a4c5..0c8d30b 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -339,6 +339,21 @@ struct attribute_group khugepaged_attr_group = { }; #endif /* CONFIG_SYSFS */ +static inline bool exceed_max_ptes_none(unsigned int *nr_ptes) +{ + return (++(*nr_ptes) > khugepaged_max_ptes_none); +} + +static inline bool exceed_max_ptes_swap(unsigned int *nr_ptes) +{ + return (++(*nr_ptes) > khugepaged_max_ptes_swap); +} + +static inline bool exceed_max_ptes_shared(unsigned int *nr_ptes) +{ + return (++(*nr_ptes) > khugepaged_max_ptes_shared); +} + int hugepage_madvise(struct vm_area_struct *vma, unsigned long *vm_flags, int advice) { @@ -604,7 +619,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, if (pte_none(pteval) || (pte_present(pteval) && is_zero_pfn(pte_pfn(pteval)))) { if (!userfaultfd_armed(vma) && - ++none_or_zero <= khugepaged_max_ptes_none) { + !exceed_max_ptes_none(&none_or_zero)) { continue; } else { result = SCAN_EXCEED_NONE_PTE; @@ -624,7 +639,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, VM_BUG_ON_PAGE(!PageAnon(page), page); if (page_mapcount(page) > 1 && - ++shared > khugepaged_max_ptes_shared) { + exceed_max_ptes_shared(&shared)) { result = SCAN_EXCEED_SHARED_PTE; goto out; } @@ -1234,7 +1249,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, _pte++, _address += PAGE_SIZE) { pte_t pteval = *_pte; if (is_swap_pte(pteval)) { - if (++unmapped <= khugepaged_max_ptes_swap) { + if (!exceed_max_ptes_swap(&unmapped)) { /* * Always be strict with uffd-wp * enabled swap entries. Please see @@ -1252,7 +1267,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, } if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) { if (!userfaultfd_armed(vma) && - ++none_or_zero <= khugepaged_max_ptes_none) { + !exceed_max_ptes_none(&none_or_zero)) { continue; } else { result = SCAN_EXCEED_NONE_PTE; @@ -1286,7 +1301,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, } if (page_mapcount(page) > 1 && - ++shared > khugepaged_max_ptes_shared) { + exceed_max_ptes_shared(&shared)) { result = SCAN_EXCEED_SHARED_PTE; goto out_unmap; } @@ -1961,7 +1976,7 @@ static void khugepaged_scan_file(struct mm_struct *mm, continue; if (xa_is_value(page)) { - if (++swap > khugepaged_max_ptes_swap) { + if (exceed_max_ptes_swap(&swap)) { result = SCAN_EXCEED_SWAP_PTE; break; } From patchwork Wed Apr 29 22:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11518931 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C48A0912 for ; Wed, 29 Apr 2020 22:56:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BD8D2176D for ; Wed, 29 Apr 2020 22:56:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BD8D2176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D602F8E0006; Wed, 29 Apr 2020 18:56:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D37D38E0001; Wed, 29 Apr 2020 18:56:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4CD18E0006; Wed, 29 Apr 2020 18:56:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id B17178E0001 for ; Wed, 29 Apr 2020 18:56:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7B9AA181AC9C6 for ; Wed, 29 Apr 2020 22:56:42 +0000 (UTC) X-FDA: 76762403844.10.north44_3e64ed8d708 X-Spam-Summary: 2,0,0,7cc8d4879dec2ece,d41d8cd98f00b204,yang.shi@linux.alibaba.com,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1261:1345:1359:1431:1437:1534:1541:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:3872:3874:4321:4385:4390:4395:5007:6261:7903:8957:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:13069:13255:13311:13357:14096:14181:14384:14721:21060:21080:21451:21627:21795:21987:30051:30054,0,RBL:115.124.30.130:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: north44_3e64ed8d708 X-Filterd-Recvd-Size: 3216 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Apr 2020 22:56:41 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Tx2rN9y_1588200990; Received: from localhost(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tx2rN9y_1588200990) by smtp.aliyun-inc.com(127.0.0.1); Thu, 30 Apr 2020 06:56:38 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, hughd@google.com, aarcange@redhat.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [linux-next PATCH 2/2] mm: khugepaged: don't have to put being freed page back to lru Date: Thu, 30 Apr 2020 06:56:22 +0800 Message-Id: <1588200982-69492-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1588200982-69492-1-git-send-email-yang.shi@linux.alibaba.com> References: <1588200982-69492-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When khugepaged successfully isolated and copied data from base page to collapsed THP, the base page is about to be freed. So putting the page back to lru sounds not that productive since the page might be isolated by vmscan but it can't be reclaimed by vmscan since it can't be unmapped by try_to_unmap() at all. Actually khugepaged is the last user of this page so it can be freed directly. So, clearing active and unevictable flags, unlocking and dropping refcount from isolate instead of calling putback_lru_page(). Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: Andrea Arcangeli Signed-off-by: Yang Shi --- mm/khugepaged.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 0c8d30b..c131a90 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -559,6 +559,17 @@ void __khugepaged_exit(struct mm_struct *mm) static void release_pte_page(struct page *page) { mod_node_page_state(page_pgdat(page), + NR_ISOLATED_ANON + page_is_file_lru(page), -compound_nr(page)); + ClearPageActive(page); + ClearPageUnevictable(page); + unlock_page(page); + /* Drop refcount from isolate */ + put_page(page); +} + +static void release_pte_page_to_lru(struct page *page) +{ + mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page), -compound_nr(page)); unlock_page(page); @@ -576,12 +587,12 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, page = pte_page(pteval); if (!pte_none(pteval) && !is_zero_pfn(pte_pfn(pteval)) && !PageCompound(page)) - release_pte_page(page); + release_pte_page_to_lru(page); } list_for_each_entry_safe(page, tmp, compound_pagelist, lru) { list_del(&page->lru); - release_pte_page(page); + release_pte_page_to_lru(page); } }