Message ID | 20221021163703.3218176-33-jthoughton@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 A686CFA373D for <linux-mm@archiver.kernel.org>; Fri, 21 Oct 2022 16:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3A928E0020; Fri, 21 Oct 2022 12:37:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E776B8E0001; Fri, 21 Oct 2022 12:37:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C53908E0020; Fri, 21 Oct 2022 12:37:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A1DE08E0001 for <linux-mm@kvack.org>; Fri, 21 Oct 2022 12:37:47 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8047341481 for <linux-mm@kvack.org>; Fri, 21 Oct 2022 16:37:47 +0000 (UTC) X-FDA: 80045512974.28.B3D26A5 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 1CE8780003 for <linux-mm@kvack.org>; Fri, 21 Oct 2022 16:37:46 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id f9-20020a25b089000000b006be298e2a8dso3756008ybj.20 for <linux-mm@kvack.org>; Fri, 21 Oct 2022 09:37:46 -0700 (PDT) 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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=nd84xfoSk805dVcAVyuoNqGohV7P5cWuxEwnitdbs1rkx0N7wPZbXDeJ4RvhkuBQuI 1v5ieZAWL4fzYytJgsDwUG418qnEFB1/qmZtj48lT3wl5WE9DVb2V1XTv+zdOICQ5pda 5diZHurVjQaoJ7Iv2PjP8DCGO1/4fukcBNdxrI/uAXh+hc99Z5wn2kayMv2lFTeOX5T6 kP7/z1HmhxO1WbkpEmUOZN3ey0YjwgIFaCUcG52wZtr3jBV58ShZQQ9oLg2hp/N1Ghjm Ji/V0BtPfvSDPqTGOkZQH+0TcxQ7lca6EKfHqsThwhdtFcp6XI9rp8phcpX8i0ybjokl Tk3Q== 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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=3TESg5xbRC9Rvpd8f7Md3xRlM7Sioip8p2ZoQ7BMUAmr+YUyIf/nntJdMrC29vxKhq Lx7UL7EpO4/1s2MNAwdEWw7BnPsBbFy5OoNXcPWk4QvNg1aD9tCxoi9GTg7HbVL7wa6g 2CSlcODRXwhClDaHTfgGXXh1QsuJgajn5n5no08CvKtIa7lHERPX/WeiNmvsD0t3vAM/ Ara9HDUkrzYEAY1yjE7IHl0ctQGWQa0HQKsoTF1jarNaq8tqnwl6Yw18kdbiq3W3pe7B ytWWDXA6T/l0ZhsSsfM9AUqYkfRMTPVsbZVPhj/ubEzUa8fuayiqu2NzHihc/rpIl+Yf YjuQ== X-Gm-Message-State: ACrzQf0vGmYhFbZPH16pJ5uIC+r1BkIUJmD+hZQvN0aqy3xCb2odb7el i7dqoPEUJHE7yZzia1367crFM23qe8REl6HU X-Google-Smtp-Source: AMsMyM4H5gt46GP7GjF8ARtqp9296GvSN14OD4CSfEEEt+Wku4dIzgl6cgqSu20XIEbBbUbyH8kZp+Wknizu7ee3 X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:1027:b0:6ca:71ca:e68b with SMTP id x7-20020a056902102700b006ca71cae68bmr2934076ybt.2.1666370266458; Fri, 21 Oct 2022 09:37:46 -0700 (PDT) Date: Fri, 21 Oct 2022 16:36:48 +0000 In-Reply-To: <20221021163703.3218176-1-jthoughton@google.com> Mime-Version: 1.0 References: <20221021163703.3218176-1-jthoughton@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221021163703.3218176-33-jthoughton@google.com> Subject: [RFC PATCH v2 32/47] hugetlb: add for_each_hgm_shift From: James Houghton <jthoughton@google.com> To: Mike Kravetz <mike.kravetz@oracle.com>, Muchun Song <songmuchun@bytedance.com>, Peter Xu <peterx@redhat.com> Cc: David Hildenbrand <david@redhat.com>, David Rientjes <rientjes@google.com>, Axel Rasmussen <axelrasmussen@google.com>, Mina Almasry <almasrymina@google.com>, "Zach O'Keefe" <zokeefe@google.com>, Manish Mishra <manish.mishra@nutanix.com>, Naoya Horiguchi <naoya.horiguchi@nec.com>, "Dr . David Alan Gilbert" <dgilbert@redhat.com>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, Vlastimil Babka <vbabka@suse.cz>, Baolin Wang <baolin.wang@linux.alibaba.com>, Miaohe Lin <linmiaohe@huawei.com>, Yang Shi <shy828301@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton <jthoughton@google.com> Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nd84xfoS; spf=pass (imf02.hostedemail.com: domain of 32spSYwoKCNsGQELRDEQLKDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32spSYwoKCNsGQELRDEQLKDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666370267; a=rsa-sha256; cv=none; b=4nfPrbFyDDmnyh8zAezVPoeDTf7LUCT/b4tnnypxB/F8mS2OgouDuzKF7fFHa7eCxXFtST F6CNoK9Nnwwdlm8BhmNv9dRe4+e1yvbGnrZeh4qF8o8y+IOEmAvHCmVqNtHqMGf8+PZEYD OHR4ZIz0OSI4qcN5mk++YK/HMu0F1wM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666370267; 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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=xaqDUsRS9rF88xjfkq6KFlCxyMlT9hzH3bJ89F0dIEtjXkIEBg4HqEUGfEcn7z54xJ/ZY+ ULs06PNGkbelKYYaZUamhHvXBTsOhe/JtbnbCEx4JVwJVYZJxkdEd6DQIXgf/+ZYqlUL4w 4awpc6JJTosbELcj7vmquXGs0eZyFNs= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nd84xfoS; spf=pass (imf02.hostedemail.com: domain of 32spSYwoKCNsGQELRDEQLKDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32spSYwoKCNsGQELRDEQLKDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: yxq8ohfy6izpw55uypqkg77hnu6m6wbw X-Rspamd-Queue-Id: 1CE8780003 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666370266-211939 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: <linux-mm.kvack.org> |
Series |
hugetlb: introduce HugeTLB high-granularity mapping
|
expand
|
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d6f07968156c..6eaec40d66ad 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7856,6 +7856,25 @@ int enable_hugetlb_hgm(struct vm_area_struct *vma) hugetlb_unshare_all_pmds(vma); return 0; } + +/* 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 */ /*
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 <jthoughton@google.com> --- mm/hugetlb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)