From patchwork Thu Jan 5 10:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13089659 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 98A64C3DA7D for ; Thu, 5 Jan 2023 10:19:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17A8A940016; Thu, 5 Jan 2023 05:19:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10575940008; Thu, 5 Jan 2023 05:19:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD553940016; Thu, 5 Jan 2023 05:19:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BF347940008 for ; Thu, 5 Jan 2023 05:19:33 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9FD6A1C5FC3 for ; Thu, 5 Jan 2023 10:19:33 +0000 (UTC) X-FDA: 80320348626.08.CABA71E Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf02.hostedemail.com (Postfix) with ESMTP id 0E9D18000A for ; Thu, 5 Jan 2023 10:19:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="mmJynU/T"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3M6S2YwoKCHohrfmsefrmlemmejc.amkjglsv-kkitYai.mpe@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3M6S2YwoKCHohrfmsefrmlemmejc.amkjglsv-kkitYai.mpe@flex--jthoughton.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672913972; 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=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=N1KThZ7WvlLqWd2F2Oau91MU4HfD9FMPpF+lA/wflEdnMlQ8IeZB/f7Gh7hKvwW/CpU2cC Ue/voUTbhL7Lob69+eljGldzdKFsvhvrR7qrv55t4okBdMSC/0tYfbBYEC4GhO9Hg5DTA8 3v+2m8XuHP4PVvoWCrd2vOdhI51ipa4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="mmJynU/T"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3M6S2YwoKCHohrfmsefrmlemmejc.amkjglsv-kkitYai.mpe@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3M6S2YwoKCHohrfmsefrmlemmejc.amkjglsv-kkitYai.mpe@flex--jthoughton.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672913972; a=rsa-sha256; cv=none; b=qrKzPc54+c99aK/K34j8p1zS1ylSWHy+xQeaC6lnRcuvGB/1SvyV44tPRvfsD09c00QFTi pwtjRtZM6KXuCs93fethbrRYni6QPgpa401ae6qlmJwp3eMzvkfMRjIt4J2YU+DofFrxmg OZWcBZJKyoTm/0WVEJRfuYAUXQ6MyGs= Received: by mail-yb1-f202.google.com with SMTP id y66-20020a25c845000000b00733b5049b6fso36236215ybf.3 for ; Thu, 05 Jan 2023 02:19:31 -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=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=mmJynU/TU9vgbAWdVBnooR6qbWy6e6Xt4HjkahKPBivEshc97MtogxTwIBRYXaYqJ0 fSpmPH7oyypf8QtZl1TBck6C8Qnc5vP3vXChtZzIua5/HPzB+uT2N0El75+vpSdXgb3I fXUucvYApqmIOdNMwmWBYNiybAbob8pq547IG5xhW67a2+7RxSBPQsKdkno0G9NfjnHR vThJc94sL2B5jTo0R162NfJZTasyE6NQSOqGcbgqMDv7BN8cJUhlAVO1ikA07733qw6v J0FL1bdTenfsSmm7z4ZB7CRnQWtuNtJNF7SWWWGOq6wzEvgYIHYppRVKiHaPtU8vk09q t6pA== 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=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=P7II9gd7qUhGQ4/YSVU1mDI3YOKKFb4lZNjnlHjwBlPWr66BTAWd1xkgwo2Jt/KDw6 GxL+/g6nOMVO9wuoxnwJA0yTprxn4+WD1QAUWASbtRrlYDsGrH66QX2nCvbCeJPeoOnO 8Fn/G3C88Z6he97Ha2F6rHX80P7om7ElmvybACBufXtiftV6chCIJwVXN8FMoz7r2ZF4 GVahUbv+dKPwWddymDLzIfLLQD2p40ba+RyjEjHrtnsYtGZE+R7EG1Ykn6DE6qUcG1So JVu/kIHfHYpQ16CBkn3gccDiGH6DvL8/piPf9C+esC6Wcrt++JHenfqlHYYMYWGMOdxa AppQ== X-Gm-Message-State: AFqh2kpPuD+hdL3ghJISpYR7DgJQeEUpvQp1TsbBIgyyIZUI96iiu8r3 gM16+qPC5b5yoGQeYiiJ6DoaaEMfdQ4CQ8zN X-Google-Smtp-Source: AMrXdXuVcGaIehPK3ggZHRYdepJOSa1ZuL0a2MndWjzlHZKir2rPDwMHed4R9zmgcZPJJPozNStrKME793+njzVf X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:5056:0:b0:7b6:2b8f:f2c0 with SMTP id e83-20020a255056000000b007b62b8ff2c0mr25432ybb.46.1672913971225; Thu, 05 Jan 2023 02:19:31 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:23 +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-26-jthoughton@google.com> Subject: [PATCH 25/46] hugetlb: update page_vma_mapped to do high-granularity walks 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-Rspamd-Queue-Id: 0E9D18000A X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 1j5hhugpuzysoud5nty86i4yrzpbh9gb X-HE-Tag: 1672913971-862332 X-HE-Meta: U2FsdGVkX18wVVBnNkZSW+e+s3sGrdpgBTiVaUu0yQzBIHptCp3ypOWoLQ+Ood7Ek+5kq2T86xIkBAKW0U4Bx124lbmSciD7rMwokHk5An7+wH5X06xhccWKcHFgk3cngrl/PEjvvS0IN4fPJhoYQrpRzLeNbEjhr/QhNoMlslHerm3BkLytMvamBYNi9KKDn+2yVQ9qGo6IYaf5FKkSSTkbe4oUDpRAhu3RdgOUkGJLg7sDzRiHhfbMlf4ja5CUuQw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XFsj69h18pYcouoF5F7zB8wwpOCyBpKVHi4uIIuBNPfK0MWJJxVtcrNS3SurWfV9N4joMprTPigYZIglqIeu6ZuFGjfl1CZCe+U/G+p3OVyLhu2X/ 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: Update the HugeTLB logic to look a lot more like the PTE-mapped THP logic. When a user calls us in a loop, we will update pvmw->address to walk to each page table entry that could possibly map the hugepage containing pvmw->pfn. Make use of the new pte_order so callers know what size PTE they're getting. The !pte failure case is changed to call not_found() instead of just returning false. This should be a no-op, but if somehow the hstate-level PTE were deallocated between iterations, not_found() should be called to drop locks. Signed-off-by: James Houghton --- mm/page_vma_mapped.c | 59 +++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 08295b122ad6..03e8a4987272 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -133,7 +133,8 @@ static void step_forward(struct page_vma_mapped_walk *pvmw, unsigned long size) * * Returns true if the page is mapped in the vma. @pvmw->pmd and @pvmw->pte point * to relevant page table entries. @pvmw->ptl is locked. @pvmw->address is - * adjusted if needed (for PTE-mapped THPs). + * adjusted if needed (for PTE-mapped THPs and high-granularity-mapped HugeTLB + * pages). * * If @pvmw->pmd is set but @pvmw->pte is not, you have found PMD-mapped page * (usually THP). For PTE-mapped THP, you should run page_vma_mapped_walk() in @@ -165,23 +166,47 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) if (unlikely(is_vm_hugetlb_page(vma))) { struct hstate *hstate = hstate_vma(vma); - unsigned long size = huge_page_size(hstate); - /* The only possible mapping was handled on last iteration */ - if (pvmw->pte) - return not_found(pvmw); - /* - * All callers that get here will already hold the - * i_mmap_rwsem. Therefore, no additional locks need to be - * taken before calling hugetlb_walk(). - */ - pvmw->pte = hugetlb_walk(vma, pvmw->address, size); - if (!pvmw->pte) - return false; + struct hugetlb_pte hpte; + pte_t pteval; + + end = (pvmw->address & huge_page_mask(hstate)) + + huge_page_size(hstate); + + do { + if (pvmw->pte) { + if (pvmw->ptl) + spin_unlock(pvmw->ptl); + pvmw->ptl = NULL; + pvmw->address += PAGE_SIZE << pvmw->pte_order; + if (pvmw->address >= end) + return not_found(pvmw); + } - pvmw->pte_order = huge_page_order(hstate); - pvmw->ptl = huge_pte_lock(hstate, mm, pvmw->pte); - if (!check_pte(pvmw)) - return not_found(pvmw); + /* + * All callers that get here will already hold the + * i_mmap_rwsem. Therefore, no additional locks need to + * be taken before calling hugetlb_walk(). + */ + if (hugetlb_full_walk(&hpte, vma, pvmw->address)) + return not_found(pvmw); + +retry: + pvmw->pte = hpte.ptep; + pvmw->pte_order = hpte.shift - PAGE_SHIFT; + pvmw->ptl = hugetlb_pte_lock(&hpte); + pteval = huge_ptep_get(hpte.ptep); + if (pte_present(pteval) && !hugetlb_pte_present_leaf( + &hpte, pteval)) { + /* + * Someone split from under us, so keep + * walking. + */ + spin_unlock(pvmw->ptl); + hugetlb_full_walk_continue(&hpte, vma, + pvmw->address); + goto retry; + } + } while (!check_pte(pvmw)); return true; }