From patchwork Tue Jul 10 16:53:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10517363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22DC8600CA for ; Tue, 10 Jul 2018 16:53:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FA1929249 for ; Tue, 10 Jul 2018 16:53:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0209F2924F; Tue, 10 Jul 2018 16:53:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3AFA29249 for ; Tue, 10 Jul 2018 16:53:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80C2A6B0005; Tue, 10 Jul 2018 12:53:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7BD176B0006; Tue, 10 Jul 2018 12:53:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D3926B0007; Tue, 10 Jul 2018 12:53:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 2D7656B0005 for ; Tue, 10 Jul 2018 12:53:49 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id h14-v6so14373802pfi.19 for ; Tue, 10 Jul 2018 09:53:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=VaB0whcHXEasPaw0cHW91zn7BThy5ypXiIGlIFB3AVg=; b=Juu2pySA5RUr4MZjq8eADBTbjQsE4W9V82MP/6yM30/fyZO+9jfCy6mp9lNFSLtEQi qEQZjC8OAheZA6I1q4VvcvEBKTcOqc/4zldNbAywXrzF4dGcNZaOgmSTCIJ1TzhmFGYh lcWa0NNEA++xamKwvQq99W5IY3pT5f0moJDNrqbAUiLoxjjlSZCSGjYPOPROhCP5k5wV C0L3OWu9DwKeUU0OWjuTgKaymdsDsGaTrhBsFXR8IUur0p9eiwE1+xGUbcbCL4MMtqK4 cYHtrdNrLKMBLTqRVUyT8rFzN25EaO98QRR7F0VVahFtGpi0sVi61fN7GXArhwVxqHbC 0rTg== X-Gm-Message-State: APt69E3VMtSYvJpM6cuaA/iRwgMYOFL/oLJiFzyzDWzW0max5LtW1+8d Nex2RphqBEyfGeyIF9nn81+7Z5tJ1mCOMGe1tyhOwCfi/tYlAU94/ERDI8ymTxXGliq9sTNoGL0 oOz9grO6aRpEfe5FMlXrY5f27rjrqTUoEfri/oV+LZeWzgGUHV86XRO0OkPHMRC0onw== X-Received: by 2002:a17:902:a24:: with SMTP id 33-v6mr25359976plo.88.1531241628716; Tue, 10 Jul 2018 09:53:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcpW1pDLZE16czAIBLshjw/PUWKmaBfM2as8ETu9rCxDNEfcolgJ0VE8vIZh65nSYlJRO9X X-Received: by 2002:a17:902:a24:: with SMTP id 33-v6mr25359929plo.88.1531241627745; Tue, 10 Jul 2018 09:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531241627; cv=none; d=google.com; s=arc-20160816; b=LvoqSaWmsCKIGEPiTYwDLzF9T5cgiEMr7SrEVzIpcdkZpvmGc4PIXn22JH59xrFIdQ y807zwjEpZIE4+/wK396UKai7Dv/fkM12TpK/hkt35M8/bCsTV/wIAQfdWhRQ6Hz2KNO SMyNcav+nmk0PpwfubCyOb2VZ07jS33LY7ZzDBqJnm7j/AUEFo9G8Q/u2lbps/7NGCmB UqhpRcPnvqK3HiRRYa8aUJmX0t0kjJn2TVWjohuA/VPIRGgP664vRFK+TIO5l1yyiIow mPRhw8OijCwa9vKhTWJQkBkhG+RbBbQqI/H3nifDdpkDPd7b1kTVxmsGUcOygZ0F9nhy J21Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=VaB0whcHXEasPaw0cHW91zn7BThy5ypXiIGlIFB3AVg=; b=LGYoWeCBiS1aVQ3dLP9iHYtgANvN84/eoUF1ldN/WkmW1DpvRZ1PDkwca+kgh3xvDk 4rn3PhPmV4KaT/xvtGz44zjIe6vPqzZNvHGLSFgDjw4L2+v1MvAoY6y7ywjMuq/MrOxR 1gPb84tw81VH6KJLJ6glfjUpMFRa5+uHNLOL3QF2k5EPKQwp2yEE+s5cNfXvgPpGyR25 OBgFLaokJjtMzJtDN2bcg/TsGjlzbovFIJa+Dhow41LP2ljE6I5VnmOhyQ8cywJFdQ2W wTHudDa7l525vyb4txweTnnnxYnhOJ2oYzXPy7wvpd7Va8sgzVs/u5iW8+VQ3Eu8YzRS qG7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=hLiGmho9; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id f12-v6si15760657pgq.559.2018.07.10.09.53.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jul 2018 09:53:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=hLiGmho9; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=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:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VaB0whcHXEasPaw0cHW91zn7BThy5ypXiIGlIFB3AVg=; b=hLiGmho9hy3i0IvobDyejsSFQ CdSxgXgVyemLPHC1QWnWosEeHrxGKGfmhBJ239+IYStIqmrP4UJYeW78nbAOo2t2qJ4C5AH7brsGP +C9ESEba1Iid1pOC5YU9/+PcBEd1W2Lb3h8i1CbQERT5Ps+6IB/oRC3iYVqmExJq5HmsovZwPsAo6 0pOPeERBnpu98J4+8fZWnDIXwjkO2v15gIAkSdOQ6l4hsrWlI8P1o6DtJ5WIXO9Aqgg0rdL1ccKsR E4TCFvtVPOrt1ZSNWAvlXbyAU5QSz1ua73QGxbwLaghuzpDZ0qHk0LTSDWuKXDWmMI9GQOeOGSy1B 7InvQzNjA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fcvtY-0002Sa-Qr; Tue, 10 Jul 2018 16:53:44 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , Andrey Ryabinin , linux-mm@kvack.org, "Kirill A. Shutemov" , Christoph Lameter , Lai Jiangshan , Pekka Enberg , Vlastimil Babka , Dave Hansen , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= Subject: [PATCH v7] mm: Distinguish VMalloc pages Date: Tue, 10 Jul 2018 09:53:26 -0700 Message-Id: <20180710165326.9378-1-willy@infradead.org> X-Mailer: git-send-email 2.14.4 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: X-Virus-Scanned: ClamAV using ClamSMTP For diagnosing various performance and memory-leak problems, it is helpful to be able to distinguish pages which are in use as VMalloc pages. Unfortunately, we cannot use the page_type field in struct page, as this is in use for mapcount by some drivers which map vmalloced pages to userspace. Use a special page->mapping value to distinguish VMalloc pages from other kinds of pages. Also record a pointer to the vm_struct and the offset within the area in struct page to help reconstruct exactly what this page is being used for. Signed-off-by: Matthew Wilcox --- v7: Use a value which has the bottom bit set so that page_mapping() returns NULL. Comments updated to note this bit of "cleverness". fs/proc/page.c | 2 ++ include/linux/mm_types.h | 5 +++++ include/linux/page-flags.h | 26 ++++++++++++++++++++++++++ include/uapi/linux/kernel-page-flags.h | 1 + mm/vmalloc.c | 5 ++++- tools/vm/page-types.c | 1 + 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index 792c78a49174..fc83dae1af7b 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 (PageTable(page)) u |= 1 << KPF_PGTABLE; + if (PageVMalloc(page)) + u |= 1 << KPF_VMALLOC; if (page_is_idle(page)) u |= 1 << KPF_IDLE; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 21e1b6a9f113..8a4698b368de 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -153,6 +153,11 @@ struct page { spinlock_t ptl; #endif }; + struct { /* VMalloc pages */ + struct vm_struct *vm_area; + unsigned long vm_offset; + unsigned long _vm_id; /* MAPPING_VMalloc */ + }; struct { /* ZONE_DEVICE pages */ /** @pgmap: Points to the hosting device page map. */ struct dev_pagemap *pgmap; diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 901943e4754b..588b8dd28a85 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -699,6 +699,32 @@ PAGE_TYPE_OPS(Kmemcg, kmemcg) */ PAGE_TYPE_OPS(Table, table) +/* + * vmalloc pages may be mapped to userspace, so we need some other way + * to distinguish them from other kinds of pages. Use page->mapping for + * this purpose. Values below 0x1000 cannot be real pointers. Setting + * the bottom bit makes page_mapping() return NULL, which is what we want. + */ +#define MAPPING_VMalloc (void *)0x441 + +#define PAGE_MAPPING_OPS(name) \ +static __always_inline int Page##name(struct page *page) \ +{ \ + return page->mapping == MAPPING_##name; \ +} \ +static __always_inline void __SetPage##name(struct page *page) \ +{ \ + VM_BUG_ON_PAGE(page->mapping != NULL, page); \ + page->mapping = MAPPING_##name; \ +} \ +static __always_inline void __ClearPage##name(struct page *page) \ +{ \ + VM_BUG_ON_PAGE(page->mapping != MAPPING_##name, page); \ + page->mapping = NULL; \ +} + +PAGE_MAPPING_OPS(VMalloc) + 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 21b9113c69da..6800968b8f47 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_PGTABLE 26 +#define KPF_VMALLOC 27 #endif /* _UAPILINUX_KERNEL_PAGE_FLAGS_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 1863390fa09c..99331453e114 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1522,7 +1522,7 @@ static void __vunmap(const void *addr, int deallocate_pages) for (i = 0; i < area->nr_pages; i++) { struct page *page = area->pages[i]; - BUG_ON(!page); + __ClearPageVMalloc(page); __free_pages(page, 0); } @@ -1691,6 +1691,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, area->nr_pages = i; goto fail; } + __SetPageVMalloc(page); + page->vm_area = area; + page->vm_offset = i; area->pages[i] = page; if (gfpflags_allow_blocking(gfp_mask)) cond_resched(); diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c index cce853dca691..25cc21855be4 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_PGTABLE] = "g:pgtable", + [KPF_VMALLOC] = "V:vmalloc", [KPF_ZERO_PAGE] = "z:zero_page", [KPF_IDLE] = "i:idle_page",