Received: by 10.223.185.116 with SMTP id b49csp5054495wrg; Wed, 7 Mar 2018 05:46:17 -0800 (PST) X-Google-Smtp-Source: AG47ELtYAFPqbsaKU4OK2ZCqD1N7og1COK5xY/oh/XpjETjJXdhPsnoGBD5VhNPF9L/IsczhAVIT X-Received: by 10.167.128.80 with SMTP id y16mr22448982pfm.91.1520430377569; Wed, 07 Mar 2018 05:46:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520430377; cv=none; d=google.com; s=arc-20160816; b=sjT8l+p1Onjiyht+JcGHgI67wd2Ms60mkQ9wMfhuKvECSDibV1FVqPsdTbOHFz/sfM wdSkLjTXk8sNUixRz7gMojVp2j0D8bi52hq1kPiOiVs8AawDm/eqJdBkiByYMN4X9oB0 k96oy7qwqs37dA6MDFaqhL4WgISOYNKlFUtHXRktcFHnjBpg2448+M8Anj7mqNyK/jGv cH1f7u0Jhqi8ochNHZU8ICyprD/eg4diK7HHfa0I44vxbcWsHe0MVwAY878ga68G5umS UbJbsk2GBfiHS49oI63awpJcF866wOeHnIWhJIeRnbcQb7n9fkFBQ6bcwSH29mMC4Aew VHew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=y7aPPyG9s0oBchCnDHAX/ZBIjFkBIR45Pqp9XRJU7FE=; b=c06mRfVTMBvzrcteDiRRdIUgrhstVGy+zHNuZuVkBIl048HZg5fPhNUZPkvgH/sX3d CHW9OA/ZtNUDGqW91hFiIA6rgCZU40jZLDtmUNdScc4CyS0s2Wv/gpN4rZKxHmDDVRIY nhPE7uSSbZX/FAszUBCNfk0ITU3oriDYElN8FgwnDbUc0bhbfPAkelOi3tAJUETbYgFw 7b84HVHrYdOtElHTJPMw/NHoz4tq/DVW24pJ1l5JYB4qKr629MQnTLh0rdeP2o5y/foI HEqSKyEbu4+agjh4JYa9lJlkRbVmV0srfrQTFGvn5s7uhpgwPXAce0/mMEI/ZgtnBRU/ mSdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uNHm7LSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd7-v6si155002plb.474.2018.03.07.05.46.03; Wed, 07 Mar 2018 05:46:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uNHm7LSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754491AbeCGNpD (ORCPT + 99 others); Wed, 7 Mar 2018 08:45:03 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:59062 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751150AbeCGNot (ORCPT ); Wed, 7 Mar 2018 08:44:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=y7aPPyG9s0oBchCnDHAX/ZBIjFkBIR45Pqp9XRJU7FE=; b=uNHm7LSzPCQ+lfbcycD7xl5xm VmZHqelLB71eZgrXwb63Chs+A5EjxY6CZmHl6XvKGuBj5mcafMnvYueajUzBEUtzzbdXykK15BvVj yMSJXEDfzcU4hPqKD96KyzUHaFCXbJsNKweRHc0r7+LKhhBnq5DFFGSnoSrAKGM0CoIMZtwz79vM+ QhwbLzalsjk64Eg4MaOi2mAtA7SUhimyZQ5kM3d2xd0+BT26FRn+UuQKhAa16ObqkCxmRjgqNWn0u AzR88rU79J4SCaQmpdJINM+HtbJqa1gqZKFrsHZCOcPSP9rBOKPDWVjPbJS4qDcmciEAHcWkhqupe jdhHXzlyA==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1etZNA-00005S-68; Wed, 07 Mar 2018 13:44:48 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Matthew Wilcox , linux-kernel@vger.kernel.org Subject: [PATCH v5 4/4] mm: Mark pages in use for page tables Date: Wed, 7 Mar 2018 05:44:43 -0800 Message-Id: <20180307134443.32646-5-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180307134443.32646-1-willy@infradead.org> References: <20180307134443.32646-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Define a new PageTable bit in the page_type and use it to mark pages in use as page tables. This can be helpful when debugging crashdumps or analysing memory fragmentation. Add a KPF flag to report these pages to userspace and update page-types.c to interpret that flag. Note that only pages currently accounted as NR_PAGETABLES are tracked as PageTable; this does not include pgd/p4d/pud/pmd pages. Those will be the subject of a later patch. Signed-off-by: Matthew Wilcox Acked-by: Kirill A. Shutemov --- arch/tile/mm/pgtable.c | 3 +++ fs/proc/page.c | 2 ++ include/linux/mm.h | 2 ++ include/linux/page-flags.h | 6 ++++++ include/uapi/linux/kernel-page-flags.h | 1 + tools/vm/page-types.c | 1 + 6 files changed, 15 insertions(+) diff --git a/arch/tile/mm/pgtable.c b/arch/tile/mm/pgtable.c index ec5576fd3a86..6dff12db335d 100644 --- a/arch/tile/mm/pgtable.c +++ b/arch/tile/mm/pgtable.c @@ -206,6 +206,7 @@ struct page *pgtable_alloc_one(struct mm_struct *mm, unsigned long address, */ for (i = 1; i < order; ++i) { init_page_count(p+i); + __SetPageTable(p+i); inc_zone_page_state(p+i, NR_PAGETABLE); } @@ -226,6 +227,7 @@ void pgtable_free(struct mm_struct *mm, struct page *p, int order) for (i = 1; i < order; ++i) { __free_page(p+i); + __ClearPageTable(p+i); dec_zone_page_state(p+i, NR_PAGETABLE); } } @@ -240,6 +242,7 @@ void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte, for (i = 1; i < order; ++i) { tlb_remove_page(tlb, pte + i); + __ClearPageTable(pte + i); dec_zone_page_state(pte + i, NR_PAGETABLE); } } diff --git a/fs/proc/page.c b/fs/proc/page.c index c9757af919a3..80275e7a963b 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -156,6 +156,8 @@ u64 stable_page_flags(struct page *page) u |= 1 << KPF_BALLOON; if (PageVmalloc(page)) u |= 1 << KPF_VMALLOC; + if (PageTable(page)) + u |= 1 << KPF_PGTABLE; if (page_is_idle(page)) u |= 1 << KPF_IDLE; diff --git a/include/linux/mm.h b/include/linux/mm.h index ad06d42adb1a..7a15042d6828 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1829,6 +1829,7 @@ static inline bool pgtable_page_ctor(struct page *page) { if (!ptlock_init(page)) return false; + __SetPageTable(page); inc_zone_page_state(page, NR_PAGETABLE); return true; } @@ -1836,6 +1837,7 @@ static inline bool pgtable_page_ctor(struct page *page) static inline void pgtable_page_dtor(struct page *page) { pte_lock_deinit(page); + __ClearPageTable(page); dec_zone_page_state(page, NR_PAGETABLE); } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 1503d314bb3d..aa5c8c1c6d38 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -644,6 +644,7 @@ PAGEFLAG_FALSE(DoubleMap) #define PG_balloon 0x00000100 #define PG_kmemcg 0x00000200 #define PG_vmalloc 0x00000400 +#define PG_table 0x00000800 #define PageType(page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) @@ -687,6 +688,11 @@ PAGE_TYPE_OPS(Kmemcg, kmemcg) */ PAGE_TYPE_OPS(Vmalloc, vmalloc) +/* + * Marks pages in use as page tables. + */ +PAGE_TYPE_OPS(Table, table) + extern bool is_free_buddy_page(struct page *page); __PAGEFLAG(Isolated, isolated, PF_ANY); diff --git a/include/uapi/linux/kernel-page-flags.h b/include/uapi/linux/kernel-page-flags.h index 5f1735ff05b3..3c51d8bf8b7b 100644 --- a/include/uapi/linux/kernel-page-flags.h +++ b/include/uapi/linux/kernel-page-flags.h @@ -36,5 +36,6 @@ #define KPF_ZERO_PAGE 24 #define KPF_IDLE 25 #define KPF_VMALLOC 26 +#define KPF_PGTABLE 27 #endif /* _UAPILINUX_KERNEL_PAGE_FLAGS_H */ diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c index 116f59eff5e2..bbb992694f05 100644 --- a/tools/vm/page-types.c +++ b/tools/vm/page-types.c @@ -132,6 +132,7 @@ static const char * const page_flag_names[] = { [KPF_THP] = "t:thp", [KPF_BALLOON] = "o:balloon", [KPF_VMALLOC] = "V:vmalloc", + [KPF_PGTABLE] = "g:pgtable", [KPF_ZERO_PAGE] = "z:zero_page", [KPF_IDLE] = "i:idle_page", -- 2.16.1