From patchwork Fri Jun 24 17:36:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 12894935 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 B1FCCC43334 for ; Fri, 24 Jun 2022 17:37:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69FDE8E0248; Fri, 24 Jun 2022 13:37:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4043A8E0244; Fri, 24 Jun 2022 13:37:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B94A8E0248; Fri, 24 Jun 2022 13:37:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E63808E0244 for ; Fri, 24 Jun 2022 13:37:24 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BB2FC35296 for ; Fri, 24 Jun 2022 17:37:24 +0000 (UTC) X-FDA: 79613836008.10.FCF562C Received: from mail-vk1-f202.google.com (mail-vk1-f202.google.com [209.85.221.202]) by imf12.hostedemail.com (Postfix) with ESMTP id 5C95240019 for ; Fri, 24 Jun 2022 17:37:24 +0000 (UTC) Received: by mail-vk1-f202.google.com with SMTP id p185-20020a1fd8c2000000b0036c453f2ea4so918053vkg.18 for ; Fri, 24 Jun 2022 10:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BHwQikGJ0T9dngSuqajvJzRNJRNB+p1hBOZL6v8gtdU=; b=SJaLm0XrTpsH4nsCpNczOnWA4pAKrfnpfCQD7J/A/w8ZLuyF3qMil1lg2kFawB2M4a itbVC6Cy96FvwmkCOrHBppgxya0l4XK+nbemqmVGl2TtO1nxOedDpeGypnCjJRZS7QQN NDC0hCezqTOYHNT6HpGvGH8b8GjOJaayBlAgzsQ6R71RrjTlRa2+jtXbsXNhdPHlJ6Xj Bf0Xtsg/vvdXkEZqCE7ZRTpn6YWG/VddVaye5OHuJMLgDbbZwZkgCRO6djsmySZP8iDS KKIDvmk/HJlHB4lLRHC4SCJoBQ4oZp4rMf+AAsSXjtVnRk/loJUaiEBO6jLZd1OibD+8 oWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BHwQikGJ0T9dngSuqajvJzRNJRNB+p1hBOZL6v8gtdU=; b=JUnaE0FVRMUxBoyJ3d6Ajoz6kK2FmgbyicBtPsLUkbmAeaXfCnxiVaFXvrpZMJRxWa au56A8CcVLdpYaIOeyI3BYlcMRewIkp7/Jm8apKdcyy9EvPGWOHTbVItgm57t7sFGVnn 8d69m9P6+CgoFyZIjaEQlRx4UMIxyQiCcvtKVB5R2KPhtAkYpsCBuqKN2/FXsCT7nKhR phATEuOJY1i5SsdseGThoyqQoxzspdlbsb1PSIwqgeah7ICvF517bhLvWnlXFQtSKyKj 11syfCvpbZZkfI8okFfZ4H2kB5gzPwQ3Bv8jvP6i9hHq/gh2TnuQhyK5SsZeSItRbL1a PT6Q== X-Gm-Message-State: AJIora9jemVFJFHemJRE5dpeZLeImdbM0fcaFZd4qR8ucyzfTY7cUo+x xpV4C9neHvkD0RhUPPutQSZnT0VsMKU/4R6I X-Google-Smtp-Source: AGRyM1vwAeqnR6McfUFoedAHpp3M9GTRsmGOf0kSjUYrMb74mEmizd7GUpekp5x9kN5nii0pCQDDYM1i4RCw9Zq8 X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a67:d785:0:b0:354:355b:60cd with SMTP id q5-20020a67d785000000b00354355b60cdmr14256935vsj.65.1656092243596; Fri, 24 Jun 2022 10:37:23 -0700 (PDT) Date: Fri, 24 Jun 2022 17:36:40 +0000 In-Reply-To: <20220624173656.2033256-1-jthoughton@google.com> Message-Id: <20220624173656.2033256-11-jthoughton@google.com> Mime-Version: 1.0 References: <20220624173656.2033256-1-jthoughton@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [RFC PATCH 10/26] hugetlb: add for_each_hgm_shift From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Jue Wang , Manish Mishra , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SJaLm0Xr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3U_a1YgoKCDQZjXekWXjedWeeWbU.SecbYdkn-ccalQSa.ehW@flex--jthoughton.bounces.google.com designates 209.85.221.202 as permitted sender) smtp.mailfrom=3U_a1YgoKCDQZjXekWXjedWeeWbU.SecbYdkn-ccalQSa.ehW@flex--jthoughton.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656092244; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BHwQikGJ0T9dngSuqajvJzRNJRNB+p1hBOZL6v8gtdU=; b=dJQrf05ls5K263dIbr3X1K0tJkr6eC+ajGanplrdJymGifURw2wZPpltTTqO2nKt06guLq 3TwJKvN1hqTbYo2hibMvl3z/+xH3xuiwMVO9zZ2h2BqYAZcMDU8srnm2xBMSqEYHaziKBb CpRO++r3sGkgduJd4PmyYDdmhA0V4Bs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656092244; a=rsa-sha256; cv=none; b=GD1FohfoUvv5K4HQ1hy1O4Dr72L88hNS5xendNh5//pL0m3UbDhoyo7F8INCobQgZkusHB 7HpmYmNssjOxAR8k6JGFp8D8sugMDFKyjoPxspw8dGud9bhJCUUJkZwcd1JOiwOKsNdK6J MAp5Makakzz2C/W7i3N2Wg/gxbO+QGc= X-Stat-Signature: ni8aiim9ez44zct6uycyhd5eherd7e4i X-Rspamd-Queue-Id: 5C95240019 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SJaLm0Xr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3U_a1YgoKCDQZjXekWXjedWeeWbU.SecbYdkn-ccalQSa.ehW@flex--jthoughton.bounces.google.com designates 209.85.221.202 as permitted sender) smtp.mailfrom=3U_a1YgoKCDQZjXekWXjedWeeWbU.SecbYdkn-ccalQSa.ehW@flex--jthoughton.bounces.google.com X-Rspamd-Server: rspam12 X-HE-Tag: 1656092244-176499 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: This is a helper macro to loop through all the usable page sizes for a high-granularity-enabled HugeTLB VMA. Given the VMA's hstate, it will loop, in descending order, through the page sizes that HugeTLB supports for this architecture; it always includes PAGE_SIZE. Signed-off-by: James Houghton reviewed-by:manish.mishra@nutanix.com --- mm/hugetlb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8b10b941458d..557b0afdb503 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6989,6 +6989,16 @@ bool hugetlb_hgm_enabled(struct vm_area_struct *vma) /* All shared VMAs have HGM enabled. */ return vma->vm_flags & VM_SHARED; } +static unsigned int __shift_for_hstate(struct hstate *h) +{ + if (h >= &hstates[hugetlb_max_hstate]) + return PAGE_SHIFT; + return huge_page_shift(h); +} +#define for_each_hgm_shift(hstate, tmp_h, shift) \ + for ((tmp_h) = hstate; (shift) = __shift_for_hstate(tmp_h), \ + (tmp_h) <= &hstates[hugetlb_max_hstate]; \ + (tmp_h)++) #endif /* CONFIG_HUGETLB_HIGH_GRANULARITY_MAPPING */ /*