From patchwork Thu Jan 5 10:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 39454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp228014wrt; Thu, 5 Jan 2023 02:23:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXswIYgBNR5utgpVpg4R3O4h2iv1vah5NI+h4HMRlxXJ05QZYvmulYYr4HarsWxaJsyi4JOR X-Received: by 2002:aa7:955d:0:b0:582:d5e3:12a7 with SMTP id w29-20020aa7955d000000b00582d5e312a7mr7930778pfq.6.1672914203302; Thu, 05 Jan 2023 02:23:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672914203; cv=none; d=google.com; s=arc-20160816; b=shzV3LJhTIB72oncZ1Jcz4ByLdT2dms6oSKR8wz2IZUw/Y88cVBvhyZZqlZnfBcPC6 /7tzJDdQ/3maMQrgBeAq6sklT/CIbalX8qFmWNIZe6a/sKAqyfSByinCidnkjgPPq4b2 N04fxgv9sITJHgc2aSB4O0HgdVHlRcMAYL8SF8cI+m1wrQvn/gHwnaiq167YgpfXkWv5 Xd8OMdcw973djL7lV8i3P+EXbcC4tthvBrjMjPEQf4KAAmJi4xKe+hEWrMoUQL+Fwdez KgzWPv3aYZYH94zdDJdCqXSweFF8PQvQFvP/SBgE/QsEI9yel1vGNd3RY5TTQiMuyeb6 +iUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=fjKcTgCHQU9dL6HEL7BjnCeJzokWebjD5rXkoH4g/pM=; b=1JlJKrQRgTX6P4Hwo89R4Fh4sE2YSzGt3ZPHuc3NYS55CDs9ybZmdax7TlMFxOtLvZ iF+vz0AY4EZ8FTu6fEMP9iqV3GQPfbZt4H33xJbVoQzXltcTWaji2dAZW86WUfCH6RU4 6UhGzTYmBOw+Vfwk1+rO1Z+XtD+DKIUORKWWO4XpNZrweBOh5Mh5FHVd1KpJ/2uhMVfn GM/Au/BTDb3jVFjpo/fgVrT2EdmZKIeDgR6n8ags+UJu1O7e90L/eXCuQeF2PoywMPuz CUFE+MUgj5qNon/VVunUu+Z6YXowFb1CHWLqxa82Z4RCWgAkv46HZy5nvc2lO5s6sXmf TmxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VKrl9diS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p26-20020a056a000a1a00b005768619bd8esi40163366pfh.177.2023.01.05.02.23.10; Thu, 05 Jan 2023 02:23:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VKrl9diS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233152AbjAEKWb (ORCPT + 99 others); Thu, 5 Jan 2023 05:22:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232615AbjAEKU4 (ORCPT ); Thu, 5 Jan 2023 05:20:56 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C4C758310 for ; Thu, 5 Jan 2023 02:19:41 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4b34cf67fb6so64986277b3.6 for ; Thu, 05 Jan 2023 02:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fjKcTgCHQU9dL6HEL7BjnCeJzokWebjD5rXkoH4g/pM=; b=VKrl9diSEpwY713/gRrQ7D7jynnfdDKrTaaauRJ8Kmx76DzNiFvpsbu9cleofopMYY +vN1ez44452yYnBQYI9/ica76cicDmXhDVXewbjHC7ZvbpYxQspAVjUda//9KqW+Xs8u LR39HFBaerFN0EvlEGK+6/C5d0YJLK8kf7/07SPIgTMOJAJTpX9hXOYciZWdCmvO2ahR 6iZd5/Y9MDnIUiesI7LWvxsmnqWFe7L9Ef31ukl3F+hZHDBLwQWc9oEr3/AQYOzqITnW ykinTUIHoWMFPDqTP4+sgJ80WGoY/Y9vThhY32VjfbhOO1aAUa7akpnfIabYK+/jBMcc tlBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fjKcTgCHQU9dL6HEL7BjnCeJzokWebjD5rXkoH4g/pM=; b=dozJYGMf0EahLV50FKPQ2GA6ZqN+wjmgaIFUUjkmOXjbHLCGDbUzDUTTxrNLMdD3TN Z45uexTIULbT6DRJPPtGyye1+dJqSMggVLo7gYMlJAzbadYMnkmtVB4i4B8Bsvlik4i6 LzpgMF7K5vVx1U0VyEcTygECw6XsWw8f2xdDhULtGHqUwBCrmTu2gWkwNP/BI+zkEaBM vQWGFvawytiC/r4iOCaIuH1jUduDTPGbjI6OCfbVForg0jCPbW69Qz1Aabsf2LB9244z MbCKqOPe5HfBhFNnGYqyQNLR/GnAmkSAXDlaSe27kB32nUN0hUTCvKQQAgjumTFiiDpL Dj5Q== X-Gm-Message-State: AFqh2koyx+qFux8swDKWLjAdg4ddjew1hNvyeloe4BlvvwCM+9DguBsG wZo+J9nqhfQO2+bd32N6G9JXOh2QX9JXWe3R X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:b78c:0:b0:769:74cd:9c63 with SMTP id n12-20020a25b78c000000b0076974cd9c63mr4949127ybh.257.1672913980684; Thu, 05 Jan 2023 02:19:40 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:30 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-33-jthoughton@google.com> Subject: [PATCH 32/46] 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 , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754177683966280981?= X-GMAIL-MSGID: =?utf-8?q?1754177683966280981?= 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. This is done by looping through the hstates; however, there is no hstate for PAGE_SIZE. To handle this case, the loop intentionally goes out of bounds, and the out-of-bounds pointer is mapped to PAGE_SIZE. Signed-off-by: James Houghton --- mm/hugetlb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1e9e149587b3..1eef6968b1fa 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7780,6 +7780,24 @@ bool hugetlb_hgm_enabled(struct vm_area_struct *vma) { return vma && (vma->vm_flags & VM_HUGETLB_HGM); } +/* Should only be used by the for_each_hgm_shift macro. */ +static unsigned int __shift_for_hstate(struct hstate *h) +{ + /* If h is out of bounds, we have reached the end, so give PAGE_SIZE */ + if (h >= &hstates[hugetlb_max_hstate]) + return PAGE_SHIFT; + return huge_page_shift(h); +} + +/* + * Intentionally go out of bounds. An out-of-bounds hstate will be converted to + * PAGE_SIZE. + */ +#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 */ /*