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 EE785C388F9 for ; Thu, 19 Nov 2020 06:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8836C2469D for ; Thu, 19 Nov 2020 06:18:02 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726195AbgKSGSC (ORCPT ); Thu, 19 Nov 2020 01:18:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgKSGSB (ORCPT ); Thu, 19 Nov 2020 01:18:01 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA59C0613CF for ; Wed, 18 Nov 2020 22:18:00 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id 62so3272837pgg.12 for ; Wed, 18 Nov 2020 22:18:00 -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=YXSLD+e7yEOePyR1BYOxJ0K8wzlu4gpL056/L2ixTQDp9J9kZKcc8GtQ8o/F2GBRvg N65OFPJEkku1ilTKYcBOQUffwFBe9fTrd1LQlXpvRq8SYV0f2PwFK5KcJDvHyCkEPsZC f9s09qToEz2/BeXTv55FzLZrvtxAtv/k/9+7vc1yGQTXaHmwzVyqQ0j+hU4COvhGoet2 MtQMpZRwMbDU8MMzgU8YoeiRXIUmISqSoardK+DDMBhvcMckQ0Z6PAkH2a5qqwKXfRse el8GrKzW3gb9qQzEwq5mDkZxjhP3P0BtfIqeIqfTuCjoJkhUbNup9tRG4h/8zPVJON9g aP/Q== X-Gm-Message-State: AOAM53360+bF/7ehz6Scr6JMpJEec//aKjiRiHmLvrGDC5ze2kRElE/l 5g7GZt6+ePCsjTb79G1fY664CkoEa9yogFtmvNsnhQ== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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