From patchwork Fri Nov 13 10:59:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11902987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B076C138B for ; Fri, 13 Nov 2020 11:02:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 616DE22253 for ; Fri, 13 Nov 2020 11:02: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="Qs7/EY2O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 616DE22253 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 8CECD6B00B1; Fri, 13 Nov 2020 06:02:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 87E216B00B2; Fri, 13 Nov 2020 06:02:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71DE96B00B3; Fri, 13 Nov 2020 06:02:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 445E36B00B1 for ; Fri, 13 Nov 2020 06:02:29 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DD0A38249980 for ; Fri, 13 Nov 2020 11:02:28 +0000 (UTC) X-FDA: 77479106376.20.girl22_09104402730e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id B5290180C07AB for ; Fri, 13 Nov 2020 11:02:28 +0000 (UTC) X-Spam-Summary: 1,0,0,563aa1653d7763e7,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:4117:4321:4385:5007:6119:6261:6653:6737:6738:7903:8957:9010:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14110:14181:14394:14721:21080:21222:21444:21451:21627:21990:30029:30054,0,RBL:209.85.210.196:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04y8wrgocrf9rh9ubq4oihj4aq5xfoc9kbp7t314x9bzhrbrhn9depucqfee5ma.sb41zsw6kc6nsz3xtmikr3pf1hx3wowihjscm1kmtitxquhujyxrd1opku3qx9e.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:69,LUA_SUMMARY:none X-HE-Tag: girl22_09104402730e X-Filterd-Recvd-Size: 6168 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 11:02:28 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id c66so7348052pfa.4 for ; Fri, 13 Nov 2020 03:02:27 -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=Cn1eur0hRRQaGJzuu65rghQYy8+1f9C2xe6gNwoWm68=; b=Qs7/EY2O7pRYN07lxQyNdfBkhlRaUWLkq0EuDrDXsHifqGUSi5pr8HXyqf8Xst8cLQ dSzl5OUZ0F4lAkTKSBFUZ9l+yO63guzHlT+LZZieFQoWkpTyJ9Ss6Dz0f/1grscLe8ai Qp45KvGwqMIQQJ5/l5iDlIkabIi14mdtPEDbVDoIOXOPxcg9QCxeocUYZ36ndhTv5zHO mJrd7MeM2yQawQnn1CrJaLMepWz2dNjx+V1h9paZUAySAdU0JaAeoYI+8fPlwBC1wwnS d4UwcY6yLfjtZrr8DORBjA/dI0KVQpXavlyny76UGOejpABWicFbHCoJyI4pO0pM7zXV bvUQ== 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=Cn1eur0hRRQaGJzuu65rghQYy8+1f9C2xe6gNwoWm68=; b=tKc4MRlpRBbcvcm1S1b73XTPiipGDclmXvaEOuSdqn2MXtitlZt1FtrFqp1I0RzPOF ScaFq+hSDpNcR4R3kOeiLdBT3jCE7q1UMoTUc7p9P/GXCAGJa6JDtJz+9nLAviVLSxU6 iPdB/krtIzNkfxUbvv0mDcjO+LWUa4xflhk35wf8ZqwnZ0d0tDCtaMm9Tr+MMdNPSJoA jUnpxNOHmkovMO8RURRJfwEE8WuAo6UV1WehvzMAgQ6hrSYAhYJpIdeiavJy1YttfDcY +mfGpZgVp40OhU+f1dOhunxu/7Q5Uld+TNGzQwMSaLN8bXl9DwjxRysTmfloSjX29tWT ZrNQ== X-Gm-Message-State: AOAM533gwlnv7FH8rttCS5bxDGbp/e/HQw3LIh3zfdOY/9dRhua0l2G1 IrBG9Z3jEYnkzpS03rcfBNWjZg== X-Google-Smtp-Source: ABdhPJzfdPOUWv4x55loz+dkhdJH7Hla0oplT8khLvEfFiSk7stTfJ/zpEiwFwrNbNgwR3+YM3+COA== X-Received: by 2002:a63:2f41:: with SMTP id v62mr1647071pgv.10.1605265347250; Fri, 13 Nov 2020 03:02:27 -0800 (PST) Received: from localhost.localdomain ([61.120.150.78]) by smtp.gmail.com with ESMTPSA id f1sm8909959pfc.56.2020.11.13.03.02.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Nov 2020 03:02: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 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 v4 08/21] mm/hugetlb: Initialize page table lock for vmemmap Date: Fri, 13 Nov 2020 18:59:39 +0800 Message-Id: <20201113105952.11638-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201113105952.11638-1-songmuchun@bytedance.com> References: <20201113105952.11638-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 b7dfa97b4ea9..332c131c01a8 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -71,6 +71,8 @@ */ #define pr_fmt(fmt) "HugeTLB Vmemmap: " fmt +#include +#include #include #include #include "hugetlb_vmemmap.h" @@ -179,3 +181,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);