Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp51086iof; Sun, 5 Jun 2022 20:48:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyAJ59I092V6k0PoFkCC+MK9LqyIdp7JxCdSyflhlvhesGCk567jps1CzISPnQKwVCaw3A X-Received: by 2002:a65:6854:0:b0:3fc:d602:3cf8 with SMTP id q20-20020a656854000000b003fcd6023cf8mr19073464pgt.176.1654487295317; Sun, 05 Jun 2022 20:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654487295; cv=none; d=google.com; s=arc-20160816; b=YEVRGlS459ABo6Neu199myMs+o73VUgAaLrmT5+gvBozpkh/FnSe558vXAsPWnPnk1 FnDVPiGIrS27nSvviEjxIc+UXicSrVBIgcJf4LZnR2Bd43u2BufNIsDbA8nKk3C815Wh 4TwXy8LXgn2sT9G1c78tJWkSpnvgeXq8hkEPMlP8oxXTAPXkM3XOgsHLfazrGbw9zAU1 p+x4FMKruWh/jNDjXCMMuFEj1MPr+dijjMviJyXtHXao/9K1KBCRgD4geEHXihSSYmYI cDmOSJFpaMLlj/PXx2BDmogXvmOUHplAUlPuQZgbqDo5jxxmUaSsK27/J7GDGprJd5eu cNfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from; bh=sIPIEILF+9Fgitt8hgtwAxMXp8jta50e1M46IuuCaio=; b=CxYb+Grl8d+0dFqqqCwyp69R72hGZ0baoYgn0Vh8V2edSJoM6AWLWeFZJP9gvKCcug vosip93SpyH6sR34J/ORD0NNK/mzpjua2HUERlZzFszF4zYvdRcebBtUeN00IW+KPAPD 49+zI7WuItPGJ+8bcmd8YPs7OQB+lxekIE1ks+RK4bYXKH87+AfnPXGm4RFmRDZh7AC/ twhinfztewmnPFvItTtU0Jtyrxsf7sXWFwAV2MM7rfX0+GGCCdHP9c57PnW6ZE+Ko3YV LCz7eYpsH916IBmzMLkmNXHTCBOQ7VOisJjs0ap1kzTgmAMOFrngAaBrOw2xD+tix/1z hlFA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p4-20020a17090ad30400b001e30a3a5f49si17359287pju.121.2022.06.05.20.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 20:48:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3796A5D1A1; Sun, 5 Jun 2022 20:41:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349516AbiFDBcx (ORCPT + 99 others); Fri, 3 Jun 2022 21:32:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245331AbiFDBcq (ORCPT ); Fri, 3 Jun 2022 21:32:46 -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 D399612D1B for ; Fri, 3 Jun 2022 18:32:43 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VFHJab9_1654306360; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VFHJab9_1654306360) by smtp.aliyun-inc.com(127.0.0.1); Sat, 04 Jun 2022 09:32:41 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] mm: Add kernel PTE level pagetable pages account Date: Sat, 4 Jun 2022 09:32:31 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 Now the kernel PTE level ptes are always protected by mm->page_table_lock instead of split pagetable lock, so the kernel PTE level pagetable pages are not accounted. To get an accurate pagetable accounting, calling new helpers pgtable_set_and_inc()/pgtable_clear_and_dec() when allocating or freeing a kernel PTE level pagetable page. Meanwhile converting architectures to use corresponding generic PTE pagetable allocation and freeing functions. Signed-off-by: Baolin Wang --- arch/csky/include/asm/pgalloc.h | 2 +- arch/microblaze/mm/pgtable.c | 2 +- arch/openrisc/mm/ioremap.c | 2 +- include/asm-generic/pgalloc.h | 10 +++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/csky/include/asm/pgalloc.h b/arch/csky/include/asm/pgalloc.h index bbbd069..2443226 100644 --- a/arch/csky/include/asm/pgalloc.h +++ b/arch/csky/include/asm/pgalloc.h @@ -29,7 +29,7 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) pte_t *pte; unsigned long i; - pte = (pte_t *) __get_free_page(GFP_KERNEL); + pte = __pte_alloc_one_kernel(mm); if (!pte) return NULL; diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c index 9f73265..e96dd1b 100644 --- a/arch/microblaze/mm/pgtable.c +++ b/arch/microblaze/mm/pgtable.c @@ -245,7 +245,7 @@ unsigned long iopa(unsigned long addr) __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm) { if (mem_init_done) - return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO); + return __pte_alloc_one_kernel(mm); else return memblock_alloc_try_nid(PAGE_SIZE, PAGE_SIZE, MEMBLOCK_LOW_LIMIT, diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c index daae13a..3453acc 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -118,7 +118,7 @@ pte_t __ref *pte_alloc_one_kernel(struct mm_struct *mm) pte_t *pte; if (likely(mem_init_done)) { - pte = (pte_t *)get_zeroed_page(GFP_KERNEL); + pte = __pte_alloc_one_kernel(mm); } else { pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE); if (!pte) diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h index 78ab9f6..f5345b2 100644 --- a/include/asm-generic/pgalloc.h +++ b/include/asm-generic/pgalloc.h @@ -18,7 +18,14 @@ */ static inline pte_t *__pte_alloc_one_kernel(struct mm_struct *mm) { - return (pte_t *)__get_free_page(GFP_PGTABLE_KERNEL); + struct page *page; + gfp_t gfp = GFP_PGTABLE_KERNEL; + + page = alloc_pages(gfp & ~__GFP_HIGHMEM, 0); + if (!page) + return NULL; + pgtable_set_and_inc(page); + return (pte_t *)page_address(page); } #ifndef __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL @@ -41,6 +48,7 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) */ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) { + pgtable_clear_and_dec(virt_to_page(pte)); free_page((unsigned long)pte); } -- 1.8.3.1