Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5476441iog; Wed, 22 Jun 2022 21:43:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uORwrBfihNGHaZZZH7AtiP+ONFo8s72MxfzVIRUoTj+RFmq+hJ6jB+srwpmXk1mwGpgcDc X-Received: by 2002:a05:6402:14c4:b0:435:717a:fd63 with SMTP id f4-20020a05640214c400b00435717afd63mr8552850edx.395.1655959434023; Wed, 22 Jun 2022 21:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655959434; cv=none; d=google.com; s=arc-20160816; b=NEkQ1ZHK3fxjAuMQtxN1/v8Uh5T08VWr646gUk+bNcJM1mbtO8649HENl1ZqOot5JZ wi6DrH5BPzAqcMCtrs8M0Pg22lLccjlgtWhufKlQb0t9hnnv2jy0/8euFb16KY7aewjB CWRB8DRqP/J7zbCjmRGYaFdvPXzqWLRe5+ybkXejWPJpBexl6xD9mI/qTqQYMpsr7I47 ZnR+3hJQDCS/zb0y+FtdGptW2/BLgHaLtwrQREZ7ekviLJISxAaSZfxLlm0tk/vqe8xP k3s/oH5hKOxJjOR+33IqTiRe3xKRdAJNPUrVKNsPv6blYs65gqQml1O1chpEbR938BZz wfGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=SsOwJBIU7CPKh/UAyCprmdYS2LgLNs6jWqV8vXcrxC0=; b=XnRccgN/g8Ukll5CMHiGGlNCHmmdaQY6mRSs65/KRKFSSWtonct2Hu6hsHIpYDai4O a+v4hnQaBJUx6UxUJNrx4jOUKR7vdrWMVBFuCKN5sNBhU/c+4GVq4GPznTzlGdAL0vxn Cx3dPL8qEjilhUl46nrBr3IJZlSD/nlCdZJtT3kR7sHRxgOXJdTDNAzQX2WOZcsmDFP+ qhBv5VrY6R+FDfQMT3JXxO7Qn4AOVE/3yJmoSf6xeNCcZf5aMDhTu788vBUY9GJIVhhO gRhwoqujq6K9TZo/BLYGN5rallh8yknkFeyfflu62hnZKfUos0vBx2YPR5OxqwSORxnr QtNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb12-20020a1709076d8c00b007184d442227si29249097ejc.983.2022.06.22.21.43.18; Wed, 22 Jun 2022 21:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbiFWEl5 (ORCPT + 99 others); Thu, 23 Jun 2022 00:41:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239635AbiFWDcg (ORCPT ); Wed, 22 Jun 2022 23:32:36 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 365D83584F for ; Wed, 22 Jun 2022 20:32:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VH9dVlt_1655955150; Received: from 30.97.48.163(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VH9dVlt_1655955150) by smtp.aliyun-inc.com; Thu, 23 Jun 2022 11:32:31 +0800 Message-ID: Date: Thu, 23 Jun 2022 11:32:37 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [RFC PATCH v2 2/3] mm: Add PUD level pagetable account To: Mike Rapoport Cc: akpm@linux-foundation.org, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/2022 10:38 PM, Mike Rapoport wrote: > On Wed, Jun 22, 2022 at 04:58:53PM +0800, Baolin Wang wrote: >> Now the PUD level ptes are always protected by mm->page_table_lock, >> which means no split pagetable lock needed. So the generic PUD level >> pagetable pages allocation will not call pgtable_pte_page_ctor/dtor(), >> that means we will miss to account PUD level pagetable pages. >> >> Adding pagetable account by calling pgtable_set_and_inc() or >> pgtable_clear_and_dec() when allocating or freeing PUD level pagetable >> pages to help to get an accurate pagetable accounting. >> >> Moreover this patch will also mark the PUD level pagetable with PG_table >> flag, which will help to do sanity validation in unpoison_memory() and >> get more accurate pagetable accounting by /proc/kpageflags interface. >> >> Meanwhile converting the architectures with using generic PUD pagatable >> allocation to add corresponding pgtable_set_and_inc() or pgtable_clear_and_dec() >> to account PUD level pagetable. >> >> Signed-off-by: Baolin Wang >> --- >> arch/arm64/include/asm/tlb.h | 5 ++++- >> arch/loongarch/include/asm/pgalloc.h | 11 ++++++++--- >> arch/mips/include/asm/pgalloc.h | 11 ++++++++--- >> arch/s390/include/asm/tlb.h | 1 + >> arch/x86/mm/pgtable.c | 5 ++++- >> include/asm-generic/pgalloc.h | 12 ++++++++++-- >> 6 files changed, 35 insertions(+), 10 deletions(-) >> >> diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h >> index c995d1f..47e0623 100644 >> --- a/arch/arm64/include/asm/tlb.h >> +++ b/arch/arm64/include/asm/tlb.h >> @@ -94,7 +94,10 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, >> static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, >> unsigned long addr) >> { >> - tlb_remove_table(tlb, virt_to_page(pudp)); >> + struct page *page = virt_to_page(pudp); >> + >> + pgtable_clear_and_dec(page); >> + tlb_remove_table(tlb, page); >> } >> #endif >> >> diff --git a/arch/loongarch/include/asm/pgalloc.h b/arch/loongarch/include/asm/pgalloc.h >> index b0a57b2..50a896f 100644 >> --- a/arch/loongarch/include/asm/pgalloc.h >> +++ b/arch/loongarch/include/asm/pgalloc.h >> @@ -89,10 +89,15 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) >> static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) >> { >> pud_t *pud; >> + struct page *pg; > > struct page *page; > > looks better IMO. Sure. > >> + >> + pg = alloc_pages(GFP_KERNEL & ~__GFP_HIGHMEM, PUD_ORDER); >> + if (!pg) >> + return NULL; >> >> - pud = (pud_t *) __get_free_pages(GFP_KERNEL, PUD_ORDER); >> - if (pud) >> - pud_init((unsigned long)pud, (unsigned long)invalid_pmd_table); >> + pgtable_set_and_inc(pg); >> + pud = (pud_t *)page_address(pg); > > I don't think __get_free_pages() should be replaced with alloc_pages() > here, just call pgtable_set_and_inc() with virt_to_page(pud). > > The same applies for the cases below. Sure. Will do in next version. Thanks.