From patchwork Thu Jun 2 18:21:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12868043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E44FEC43334 for ; Thu, 2 Jun 2022 18:22:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 645896B0074; Thu, 2 Jun 2022 14:22:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7B06B0075; Thu, 2 Jun 2022 14:22:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41AD06B0078; Thu, 2 Jun 2022 14:22:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2C2E46B0074 for ; Thu, 2 Jun 2022 14:22:08 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 0A589813E0 for ; Thu, 2 Jun 2022 18:22:08 +0000 (UTC) X-FDA: 79534115136.21.D7B130B Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf29.hostedemail.com (Postfix) with ESMTP id 15B00120057 for ; Thu, 2 Jun 2022 18:21:53 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id n18so5170098plg.5 for ; Thu, 02 Jun 2022 11:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D/C1dubPl+rj/RbGuMLBKXaMg54FT3nuKqdm5O29Xsg=; b=FRrND4uki4knPZ0gSWutNMQKlOfS5LJi4uIMfHYUiv+1a8lr0Xem3mWuTw7DfDlSY3 9tRImdO5zSIr4nPyQ8HcKICzyQCFdpFFWdXtHalaE6GGfEw4F98wdnuF73lw2uk6p0xH nr9CoqMB8CGi9J52LmD84U6h8P08cVzicro/KUR77FT60PiVBDVCTuWBX4zI70ktKx+N R6wDi3C47n7AWxDnJ1DtU604BHF7nH8hFZsXeJ9ieLzroSjoD+x/6sG7zHK5ArGZulnD axyJD0uVhxDY1agFrwfOHh8N38BgADp3plNxnDatVLAmFHHdJ0no0cbEE1Sw7JXJcci9 Ap/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D/C1dubPl+rj/RbGuMLBKXaMg54FT3nuKqdm5O29Xsg=; b=iE1a16CnElBr8q2UE319RPUBXhAinJeRKw9AE7a0bR+MPrHVOPoB2Z60cU90iqQYDE lJpHkQeHIuvXApZnlwatFLxcsdly1hcTqBAs+o072ZUrqtRn9AGGrP/VkijIT1LU0SeJ BlUbeWmXaA94L2Mhh/o86swfioDoGxb0mL0Rgf4t/pkvi1B6Y983ZfQkZHUCJHnKbyFO dj5MeA8fl3eZz0tqsfiRqp+PQVypqagAvXpyBDihw+pl/t4KUj7v5Ho42fLWrLxocuXm 7T6XSd8KspqT6zHJqO+SS8x+Vjc0rUaEJLsylnmuKZHy85X16mo8PRk8+r0Cb/ZhiTr6 zUig== X-Gm-Message-State: AOAM531TDC0N52GSi5bjjmR1Fb0+JZBPbXRuCJOVA16zymBEwmTA8lCW 7Q3vUKMxz/dX+pb5b6R1rrg= X-Google-Smtp-Source: ABdhPJzy/X13hVsWfZKyg71A7q6Qroq+HiX2lAOxkS2DH/C0df1y1IyvvBp0ImlM7TMfCrMNVybNWw== X-Received: by 2002:a17:902:7597:b0:15e:b5d3:267d with SMTP id j23-20020a170902759700b0015eb5d3267dmr6206049pll.55.1654194126432; Thu, 02 Jun 2022 11:22:06 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id t10-20020a1709027fca00b0015f2d549b46sm3866779plb.237.2022.06.02.11.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 11:22:05 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper Date: Thu, 2 Jun 2022 11:21:54 -0700 Message-Id: <20220602182159.248387-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220602182159.248387-1-shy828301@gmail.com> References: <20220602182159.248387-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 15B00120057 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=FRrND4uk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Stat-Signature: 1a7az64focx743z9zns98pokn5sj6o1w X-Rspam-User: X-HE-Tag: 1654194113-889162 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: There are couple of places that check whether the vma size is ok for THP or not, they are open coded and duplicate, introduce transhuge_vma_size_ok() helper to do the job. Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 17 +++++++++++++++++ mm/huge_memory.c | 5 +---- mm/khugepaged.c | 12 ++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 648cb3ce7099..a8f61db47f2a 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -116,6 +116,18 @@ extern struct kobj_attribute shmem_enabled_attr; extern unsigned long transparent_hugepage_flags; +/* + * The vma size has to be large enough to hold an aligned HPAGE_PMD_SIZE area. + */ +static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) +{ + if (round_up(vma->vm_start, HPAGE_PMD_SIZE) < + (vma->vm_end & HPAGE_PMD_MASK)) + return true; + + return false; +} + static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, unsigned long addr) { @@ -345,6 +357,11 @@ static inline bool transparent_hugepage_active(struct vm_area_struct *vma) return false; } +static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) +{ + return false; +} + static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, unsigned long addr) { diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 48182c8fe151..36ada544e494 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -71,10 +71,7 @@ unsigned long huge_zero_pfn __read_mostly = ~0UL; bool transparent_hugepage_active(struct vm_area_struct *vma) { - /* The addr is used to check if the vma size fits */ - unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE; - - if (!transhuge_vma_suitable(vma, addr)) + if (!transhuge_vma_size_ok(vma)) return false; if (vma_is_anonymous(vma)) return __transparent_hugepage_enabled(vma); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 84b9cf4b9be9..d0f8020164fc 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -454,6 +454,9 @@ bool hugepage_vma_check(struct vm_area_struct *vma, vma->vm_pgoff, HPAGE_PMD_NR)) return false; + if (!transhuge_vma_size_ok(vma)) + return false; + /* Enabled via shmem mount options or sysfs settings. */ if (shmem_file(vma->vm_file)) return shmem_huge_enabled(vma); @@ -512,9 +515,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, unsigned long vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && - khugepaged_enabled() && - (((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) < - (vma->vm_end & HPAGE_PMD_MASK))) { + khugepaged_enabled()) { if (hugepage_vma_check(vma, vm_flags)) __khugepaged_enter(vma->vm_mm); } @@ -2142,10 +2143,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, progress++; continue; } - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; + + hstart = round_up(vma->vm_start, HPAGE_PMD_SIZE); hend = vma->vm_end & HPAGE_PMD_MASK; - if (hstart >= hend) - goto skip; if (khugepaged_scan.address > hend) goto skip; if (khugepaged_scan.address < hstart)