From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 46115C63798 for ; Thu, 19 Nov 2020 06:18:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A14232469D for ; Thu, 19 Nov 2020 06:18:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="SlQ9yXcP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A14232469D 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 183356B0068; Thu, 19 Nov 2020 01:18:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10E6E6B006C; Thu, 19 Nov 2020 01:18:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF0216B006E; Thu, 19 Nov 2020 01:18:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id BE97A6B0068 for ; Thu, 19 Nov 2020 01:18:02 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6AA091EE6 for ; Thu, 19 Nov 2020 06:18:02 +0000 (UTC) X-FDA: 77500162404.22.seat63_020809b27340 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4E9BB18003EF8 for ; Thu, 19 Nov 2020 06:18:02 +0000 (UTC) X-HE-Tag: seat63_020809b27340 X-Filterd-Recvd-Size: 5787 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Nov 2020 06:18:01 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id g7so3467520pfc.2 for ; Wed, 18 Nov 2020 22:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7pQ2zj7Jlr1PXAZIscOwv68xrKkz77uBgfi3u8q3/iE=; b=SlQ9yXcPGWcqpNgsvUA5elpHwLWom+AQYZiYOdSgGaRs4scyCqq6tE/AKEJ5uZ5b81 lF/hyH+57tlZdv2coRV+X45arqUqjkR0aAKl7EvCtUTrgZP+Uzms/5sBiY3pTURzH+NC 6Jq2WJzC83rdSI2D2P+t4I2rC91XAWEmdYYGuaTMprvtZR9RngYuSZDfDBvCIalkaajC YNIP91xlct/SLzjaBBdRAp3jZjyj7Tb1pv7IN8kaOASxqS7Gh8Z/TBedIdlo1Q/pY6JQ cWKq1j2A4i2DOxMN3dAlM7OXOublT36ylMrsTYwjHxLJk5ZpCUi0cAvL165vdMl/2bDy oXXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7pQ2zj7Jlr1PXAZIscOwv68xrKkz77uBgfi3u8q3/iE=; b=uSKUFSBzf0DqytHPwm9VdoJ/Rf/O+lIuiZf122yzevCbU3uOICADMSz/QGz6UDhh4L TMzKGn1wwea1tjdEeY6/iOt3Dg6CHE+MbhxMw6RNqMFo6F+WwyYGt4grOhRxy1GDOWuI nh9Bk4TWXYP38aX+fbd3+GevKRlmZoU9SaS+A7uiqggZzNjniFlEdX7uVE5k+UuVjhfW /3zntvYIh7wMndL/y7mo7iMmhqmeRrCfHr5Pg7DP4HuQ+ZhiJhyYbPPemTnsss7D7+jy e8/3f0yWnXjgSTbK3W/wQv3oRgCws1VsPuTJuicBbsPAPSUjlU58+tSNSZaw00nh9ULW qBMw== X-Gm-Message-State: AOAM530eKCvjalGIfvHZAOnku1UDwt56yg3tbQzEOyavN+innkaHKSCE E2ZB64xBjDBpxkrYJ9egKZjSfNKRde1Dx/Twkb4zqw== X-Google-Smtp-Source: ABdhPJzMCPjAh/2kqnjwOxyzOIsWkWSrhvfMsYkNgJM3IRKRm7eO5+zvHPlxtMjOwCYAaHDaqSWr4Tkcrzo6Lbmbiss= X-Received: by 2002:a17:90b:88b:: with SMTP id bj11mr2853956pjb.229.1605766680507; Wed, 18 Nov 2020 22:18:00 -0800 (PST) MIME-Version: 1.0 References: <20201113105952.11638-1-songmuchun@bytedance.com> <20201113105952.11638-6-songmuchun@bytedance.com> <20201117150604.GA15679@linux> In-Reply-To: <20201117150604.GA15679@linux> From: Muchun Song Date: Thu, 19 Nov 2020 14:17:21 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v4 05/21] mm/hugetlb: Introduce pgtable allocation/freeing helpers To: Oscar Salvador Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Michal Hocko , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" 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: On Tue, Nov 17, 2020 at 11:06 PM Oscar Salvador wrote: > > On Fri, Nov 13, 2020 at 06:59:36PM +0800, Muchun Song wrote: > > +#define page_huge_pte(page) ((page)->pmd_huge_pte) > > Seems you do not need this one anymore. > > > +void vmemmap_pgtable_free(struct page *page) > > +{ > > + struct page *pte_page, *t_page; > > + > > + list_for_each_entry_safe(pte_page, t_page, &page->lru, lru) { > > + list_del(&pte_page->lru); > > + pte_free_kernel(&init_mm, page_to_virt(pte_page)); > > + } > > +} > > + > > +int vmemmap_pgtable_prealloc(struct hstate *h, struct page *page) > > +{ > > + unsigned int nr = pgtable_pages_to_prealloc_per_hpage(h); > > + > > + /* Store preallocated pages on huge page lru list */ > > + INIT_LIST_HEAD(&page->lru); > > + > > + while (nr--) { > > + pte_t *pte_p; > > + > > + pte_p = pte_alloc_one_kernel(&init_mm); > > + if (!pte_p) > > + goto out; > > + list_add(&virt_to_page(pte_p)->lru, &page->lru); > > + } > > Definetely this looks better and easier to handle. > Btw, did you explore Matthew's hint about instead of allocating a new page, > using one of the ones you are going to free to store the ptes? > I am not sure whether it is feasible at all though. Hi Oscar and Matthew, I have started an investigation about this. Finally, I think that it may not be feasible. If we use a vmemmap page frame as a page table when we split the PMD table firstly, in this stage, we need to set 512 pte entry to the vmemmap page frame. If someone reads the tail struct page struct of the HugeTLB, it can get the arbitrary value (I am not sure it actually exists, maybe the memory compaction module can do this). So on the safe side, I think that allocating a new page is a good choice. Thanks. > > > > --- a/mm/hugetlb_vmemmap.h > > +++ b/mm/hugetlb_vmemmap.h > > @@ -9,12 +9,24 @@ > > #ifndef _LINUX_HUGETLB_VMEMMAP_H > > #define _LINUX_HUGETLB_VMEMMAP_H > > #include > > +#include > > why do we need this here? > > -- > Oscar Salvador > SUSE L3 -- Yours, Muchun