From patchwork Fri May 18 19:45:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10411983 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 8D0266031B for ; Fri, 18 May 2018 19:45:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AF4020499 for ; Fri, 18 May 2018 19:45:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F50128A4F; Fri, 18 May 2018 19:45:45 +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 BC22A20499 for ; Fri, 18 May 2018 19:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE0196B0662; Fri, 18 May 2018 15:45:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D3E246B0665; Fri, 18 May 2018 15:45:26 -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 AFDFB6B0669; Fri, 18 May 2018 15:45:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 51A6E6B0662 for ; Fri, 18 May 2018 15:45:26 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id bd7-v6so5621666plb.20 for ; Fri, 18 May 2018 12:45:26 -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:in-reply-to:references; bh=1TqlUorA67RjysCG84CqtYiBDLHOQhCESr9QNbDeLOE=; b=E1X1UrM9YPeyAS3CNBIzfc4D0yyoB0BiZ/kAHh2acr69hLFQeY/6s929qFYFM/1doA rVd97QAsUkaPmGBzXPDtYmCXQcIZpRXi9PeZTD055G/RT2od6A6idHDZtPno/s/YbEQD awrzv233Lq8almJNXSzyk1HN79CzlrSjzdf8OP7M7TzVzmqUN/FclOmJZaD1pl2+MbOI psiamlvTLUQRhl7/8R9PfJH9PbNkKLWKV/6NsMxEk6of28WS5+/LAczqJ1y/Kx7YKaKR 2cJuJ6XZi4gEvC6bqe8W/BiLj4/nHOd9kvCwgan142SDB0vEQam568O87YWn0exq+BuC ZFZA== X-Gm-Message-State: ALKqPwf9cGbsWeCyGdJ4rUNVEX3fO2KVau+XUnjTJQFrGFSZl9L0hDgO BocFtb9N+jrykb8b3i8wBHM5OpeJWnN3Nxi/siABQW4jziH+Trjmbl0aA60pFAXk1DEyIZo7mMm 4Nikpaa2NM6/BinUtUr686VkxQxr52Alzi1jwZGYY1FXjGs812qXmXD3UhBSLfnhrhA== X-Received: by 2002:a63:ae0b:: with SMTP id q11-v6mr8685224pgf.109.1526672725991; Fri, 18 May 2018 12:45:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoVQZGX0wQfsZkqd5NrAOC86dn6Imjk+G0w41EDrP7H4g6ljEmdM3Y9J8Eq4vH9CUemqOCy X-Received: by 2002:a63:ae0b:: with SMTP id q11-v6mr8685198pgf.109.1526672725175; Fri, 18 May 2018 12:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526672725; cv=none; d=google.com; s=arc-20160816; b=bP7Q+G/XkhpxCkcViZ8L3PHLEz69FAkomWL1fx5u4DtvZAx+H1x23uNvKC7mLfkhb9 YRYHzpdMcnj6czwrXUVsDIUtXRHy85ztlfGt9oh036+8i+36VqhI0n59GXJm5r71EZHa t2X/6LAkAdYwlhNsWA2WpBCJP9Td+PF/6mqM3cHZt/hqCYQAxHkTdp2EIqc0a2xPHMsZ 6FK9tDc+E4tcU+Qes4yR2rezQXf/7QV80JIvkxdF7GdSJgo5FtCE0ttm9vl4AIb0mGgf xnMrLinzEXg970th16AZFxZymtdoMdZbx+6dNp25fsvvopAcy5m8LB4vyHvNhOjGMyyN YN6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1TqlUorA67RjysCG84CqtYiBDLHOQhCESr9QNbDeLOE=; b=jNiauYliqReBL8BTxpV8Y7Z71MKLKtiRRWevCr0bW/eRqcr5FxFfH2KXfwvDu+2zqP n7MnGyOOgFoTraOrL+sPWUIWDZJjg4h3dS8FkU7SFvAakwBMAYPZnK1LDs+euYTDaF7P QbjCtDwlz9Bab2RwEziSujp4cGsK3ZbJdaYUeIPaLGRVL5Z6PXGFT4cx5HSvcNDWojKD DY9SptvCxX9xzg5pZErgjarRSlCwkgjhmPk89QCg3XAFjmfDt0TqOYvTH5yMMQmJPqD/ ecbZ/vWQxXqeRacQAPONmjXKpe32c+eKdtOIG5PJKzn10G6OjVoI9nqLzR3EB9KM3t9S n8hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=lSMEJWkB; 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 o1-v6si6468263pgp.273.2018.05.18.12.45.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 12:45:25 -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=lSMEJWkB; 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=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=1TqlUorA67RjysCG84CqtYiBDLHOQhCESr9QNbDeLOE=; b=lSMEJWkBLWY2rWcW3kjvQTQBo fN2MVX5A6Vc2w2Tw7hT6TVKhVp1WkYNrWx6/AZ5zUtkj6uhupzu4P7JRR00bip1Vr107hB5RDfG9V 4wAqgpmjo18TEl3eNhdpGG/gx0/26vlk0uPnmhYUmCNJDMgQwpXC1RCfm3IwSy5HzarYdYbArZYdK djQ5Xy0pftKPVxMU4Sxilz9qW+RlkdBaxHCRFtTb3iweTkpJ+kjQmccFPdABVLucFdlIvGMqU2Eku j1Z2kUumS00XCwDm3xkqfZvIO94Rd9oHGbSzeAak7E1F8Gfm/PojG59it/PadrgoYQ0quwlENCMso mvK9cIXkg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJlJc-00012g-KU; Fri, 18 May 2018 19:45:24 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Matthew Wilcox , Andrew Morton , "Kirill A . Shutemov" , Christoph Lameter , Lai Jiangshan , Pekka Enberg , Vlastimil Babka , Dave Hansen , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= Subject: [PATCH v6 17/17] mm: Distinguish VMalloc pages Date: Fri, 18 May 2018 12:45:19 -0700 Message-Id: <20180518194519.3820-18-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180518194519.3820-1-willy@infradead.org> References: <20180518194519.3820-1-willy@infradead.org> 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 From: Matthew Wilcox 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 --- fs/proc/page.c | 2 ++ include/linux/mm_types.h | 5 +++++ include/linux/page-flags.h | 25 +++++++++++++++++++++++++ include/uapi/linux/kernel-page-flags.h | 1 + mm/vmalloc.c | 5 ++++- tools/vm/page-types.c | 1 + 6 files changed, 38 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 530a9a2b039b..9a3b677e2c1d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -146,6 +146,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..5232433175c1 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -699,6 +699,31 @@ 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. + */ +#define MAPPING_VMalloc (void *)0x440 + +#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 5fbf27e7f956..98bc690d472d 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1535,7 +1535,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); } @@ -1704,6 +1704,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",