From patchwork Fri Nov 20 06:43:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11919577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D903CC56201 for ; Fri, 20 Nov 2020 06:47:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 523F8223AC for ; Fri, 20 Nov 2020 06:47:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="M6IhaA17" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 523F8223AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5D276B006C; Fri, 20 Nov 2020 01:47:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D340D6B006E; Fri, 20 Nov 2020 01:47:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD3EF6B0081; Fri, 20 Nov 2020 01:47:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 842A76B006C for ; Fri, 20 Nov 2020 01:47:29 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 180DF3649 for ; Fri, 20 Nov 2020 06:47:29 +0000 (UTC) X-FDA: 77503865418.14.bee84_2e0870a27349 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id EE4A318229818 for ; Fri, 20 Nov 2020 06:47:28 +0000 (UTC) X-HE-Tag: bee84_2e0870a27349 X-Filterd-Recvd-Size: 6253 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 06:47:28 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id y22so4367608plr.6 for ; Thu, 19 Nov 2020 22:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GD9EigNNKRkrYvbwZ0SeMCORAMhN9mHUi42wBVrQ1sc=; b=M6IhaA17NTPYeoH5WAYNp/+O2LM6jFTQPmYOzJTbEw9D2jVsZvJ5a/I5mYV8i81jNI qb9mbcwMf/JxbvZwRp7xElyiRzktBY4kKk+QQEksn2nZRl318paFEMfF6YrhcNlvXVWH +O1EIb0vY07XgagefcqaCPL5s0MKcQxpTp8Z5Vll5k9ntdQBNdCl3CE1r5Bkybk7yKLP 9UWKn4hpDxJYm99a51hvyqCu9VBlvQs1bI+08VPiqkMFOm1duJurnOIzOFx2DvQ0L08K 3Z2uzz6Nii9C0pawN8UISX6hAZLa29BPoHzdayJTN6g9TjLZKp2TAwq8IA0D66j5umdu KGAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GD9EigNNKRkrYvbwZ0SeMCORAMhN9mHUi42wBVrQ1sc=; b=oX/TVaIh/RjNIa9SkHfQ/HQsttKfu9M1Qu+4xQNOWLr8+dxGlpBknmdFnUaND0aRjG Y7o1BKtUpfnvdg2SNZgTitQvX04JHEtcwNwsGxenJs/YIAC5xFZbT3fb/6MO2gcQkdy7 gKBDjB+COq8EIThwIMBpVMnc3hpNZfddtkUBIKcSZYpYI7lhmazdsjUaju8XNeSThS3x kqDtm8vEuNrP8YQLKSOodZtiwFACzj6mMmerqTWuxXSWo+2Yr+CG2XVlNWxXlZGxcTap w+kQ5BTXA95TmUm+hplH+ehCjzR23S3ieG+r+QXdnoT1GQmC3l0C8MXea35F4baloDLE nbvg== X-Gm-Message-State: AOAM533iSfHLvItuiNpYbzVxFAwsSwWrFryj6eTXt+fx4G+adW5GwZVm z7auSEzcrRj+VEnBBA2HPhsoCA== X-Google-Smtp-Source: ABdhPJyefP+Gp0PGH1d3/XSCN8gM3MTiZzdY/wm6TKrtmOrDyrITyhpoOVQgIKb9R9DZmvQ6/vrZCg== X-Received: by 2002:a17:902:7d89:b029:d7:de0d:1a7f with SMTP id a9-20020a1709027d89b02900d7de0d1a7fmr12146683plm.69.1605854847604; Thu, 19 Nov 2020 22:47:27 -0800 (PST) Received: from localhost.localdomain ([103.136.221.72]) by smtp.gmail.com with ESMTPSA id 23sm2220278pfx.210.2020.11.19.22.47.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2020 22:47:26 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song Subject: [PATCH v5 08/21] mm/hugetlb: Initialize page table lock for vmemmap Date: Fri, 20 Nov 2020 14:43:12 +0800 Message-Id: <20201120064325.34492-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201120064325.34492-1-songmuchun@bytedance.com> References: <20201120064325.34492-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: In the later patch, we will use the vmemmap page table lock to guard the splitting of the vmemmap PMD. So initialize the vmemmap page table lock. Signed-off-by: Muchun Song --- mm/hugetlb_vmemmap.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index ec70980000d8..bc8546df4a51 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -99,6 +99,8 @@ */ #define pr_fmt(fmt) "HugeTLB Vmemmap: " fmt +#include +#include #include #include #include "hugetlb_vmemmap.h" @@ -208,3 +210,70 @@ void __init hugetlb_vmemmap_init(struct hstate *h) pr_debug("can free %d vmemmap pages for %s\n", h->nr_free_vmemmap_pages, h->name); } + +static int __init vmemmap_pud_entry(pud_t *pud, unsigned long addr, + unsigned long next, struct mm_walk *walk) +{ + struct page *page = pud_page(*pud); + + /* + * The page->private shares storage with page->ptl. So make sure + * that the PG_private is not set and initialize page->private to + * zero. + */ + VM_BUG_ON_PAGE(PagePrivate(page), page); + set_page_private(page, 0); + + BUG_ON(!pmd_ptlock_init(page)); + + return 0; +} + +static void __init vmemmap_ptlock_init_section(unsigned long start_pfn) +{ + unsigned long section_nr; + struct mem_section *ms; + struct page *memmap, *memmap_end; + struct mm_struct *mm = &init_mm; + + const struct mm_walk_ops ops = { + .pud_entry = vmemmap_pud_entry, + }; + + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); + memmap_end = memmap + PAGES_PER_SECTION; + + mmap_read_lock(mm); + BUG_ON(walk_page_range_novma(mm, (unsigned long)memmap, + (unsigned long)memmap_end, + &ops, NULL, NULL)); + mmap_read_unlock(mm); +} + +static void __init vmemmap_ptlock_init_node(int nid) +{ + unsigned long pfn, end_pfn; + struct pglist_data *pgdat = NODE_DATA(nid); + + pfn = pgdat->node_start_pfn; + end_pfn = pgdat_end_pfn(pgdat); + + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) + vmemmap_ptlock_init_section(pfn); +} + +static int __init vmemmap_ptlock_init(void) +{ + int nid; + + if (!hugepages_supported()) + return 0; + + for_each_online_node(nid) + vmemmap_ptlock_init_node(nid); + + return 0; +} +core_initcall(vmemmap_ptlock_init);