Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1147225ybz; Wed, 29 Apr 2020 15:59:34 -0700 (PDT) X-Google-Smtp-Source: APiQypJX3p7KAAJcgpboDSiz+IK0aOaJvZ3qAUn4tD3Z1luwsFtyEsm8XYcXThPZgDU4FUB4SWKC X-Received: by 2002:aa7:dcc3:: with SMTP id w3mr227296edu.231.1588201174669; Wed, 29 Apr 2020 15:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588201174; cv=none; d=google.com; s=arc-20160816; b=pySVJGX4pa8W7xtUzBwFmWzRPMC0dy9mIamF1pf2PvHdpHorlopkOKz+yN4Uy8RwEN 0zQJKjY8D58gLcMT3R86cSNKOqVq7S/h7Lwi+iEXGLDqgONM1nUVR7Oqybf5XYIX37jt Ai2VqicC+qaNo8a9nS9Zrwd5vz/UDzo2Luff1gerf5FGc97OWRDDPyhj7ccgzd6CLofv GcQUvehXJhzAkgIGNfKV1Njg5NGJapb6inC6P/zlVV2+MCt91oiLj2OqBDZ2xgjFCICs 8CaoxzJ0xzMXXtU/WDzR76Yn5NJgQJ7474w25X4NPdaDeRmmNIKxo+DBhIQMXbS2V+7l DDaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=mb8HNt/3wdrktbbcC54owncBwau+K/P9QRsAT/Mnis0=; b=D8zejA7yMVW9+ynD41MCgGLCAa3FiaJQ0dKKVB/bBepPglXuZs+FTKSemcE8D7o5vs xIbwSniZeShS1E4FWEh+AJ+TsUFqbelEH99b4mWgZIDiYbRR4T6ZNuTdc9L6rC3fJa1Z lZ1xTZqXvKBYxRpBNTe3OhZOD7pF92DL9HPoYB3V+BuhGzdD1EnjqSvZVYS76C2fjMc2 0CVbBKhAHRjAuDsWwZ9y3qhEwwuYxwpxkV8uSrjtqIjq+6BrIOso8VT2WM/0DWRq4rMu +BIKZsuv5gwykKPFff4+1UGfA7U8pMA5Wx7mvFDnjTw291lgN4OM5Ve2PJzpur7/UxKA B8Mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oq26si4859335ejb.105.2020.04.29.15.59.10; Wed, 29 Apr 2020 15:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgD2W4e (ORCPT + 99 others); Wed, 29 Apr 2020 18:56:34 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:34527 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726164AbgD2W4e (ORCPT ); Wed, 29 Apr 2020 18:56:34 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 1.8.3.1