From patchwork Fri May 4 18:33:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10381353 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 D6C2360541 for ; Fri, 4 May 2018 18:59:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C41712957B for ; Fri, 4 May 2018 18:59:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B839E2957C; Fri, 4 May 2018 18:59:05 +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 5E7862958E for ; Fri, 4 May 2018 18:59:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AC826B0274; Fri, 4 May 2018 14:33:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 95A1D6B0275; Fri, 4 May 2018 14:33:31 -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 823206B0276; Fri, 4 May 2018 14:33:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id 3FC5D6B0275 for ; Fri, 4 May 2018 14:33:31 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id w3-v6so14176565pgv.17 for ; Fri, 04 May 2018 11:33:31 -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=HNPwl4YuFQXP5ryWzI9uy5vJBKYGey9hz/UDHYOGzwI=; b=jtTZxyhVZhPU7+sC3qwNvSXMfQg6kKzx2ZOo5Abg1AAIlq9/4Fz5cE6aKhoZeJpIdS cd1vdwvsCoau1WupwwqQCvSZrtpGca7GsfwPkN2Q9LZ76fmMeWKtHsnkKkjnNUICcdQf LoN0nthe9OBQ2xEjuro8yd090fRVTpxIWN2Wa0yFIxPAUfbl2cUepX8w3pcFwXJc2/3e Qxa8ECbNdGv0wt1A8VbUhCglbM1l3IC+MARJzD4erq7A9PhMCWF8XqcJ/qVOboAxCPI+ Sc7HpGmTgK9Kqg4zmHAM90GDFDx4fLzXVGqMno1mk/wCVKIWAHWdSdeem7m/Vso20KZt FNUQ== X-Gm-Message-State: ALQs6tCqEWWMn5NtQyVz0YoBziSmVm7b087BJnc60oun6RRC7ZLP3HpF UzydtAyPEbNvOa7Px9mzf4Sm3EIhoO4oyn7bV73/0ciGw2nhAJenTNYzjwgvmYCVjtT5RypuFmw UCBlJj7IZM1v3dYdX8HWiorAfZOww/sF+yBDI5/8Yt6bet2wM8+dFDG6ru9GpXrhwnw== X-Received: by 2002:a63:6dcb:: with SMTP id i194-v6mr22273870pgc.402.1525458810917; Fri, 04 May 2018 11:33:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoumQwhfbwNqxvuIKVefYF0pc9apkw/eeiOfrogu0YJn+IN/fFz/ciSUFTym2TF2c3bCgAJ X-Received: by 2002:a63:6dcb:: with SMTP id i194-v6mr22273832pgc.402.1525458809844; Fri, 04 May 2018 11:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525458809; cv=none; d=google.com; s=arc-20160816; b=iIN13x8mCsZfXOgBU8NB4QLwW5ZcvppmDJgFxKk4sq4f0JWw7q4VQFxIGoOrBM+S2Q S41U1Xd9H7l/kzNZ91wJnfTr6HZ9YHI3J463Z2l5JH1tOuDwrOufao/VF2b41XOPoFXE DPwmNRK1Sq5f1oAXBVmupvOHUy7r+dFHCURwWnFiutyKpiWfk4s17Z6AOwZUNpcQXDwB 1Oruo1n0C9XOlESxmnNEAPoM6g6NhhdmMtqQtwqjWKozXMeIE7eON0Jy8RZwlWRrQwSY LmAs/xU6rdG058Mjfp9iWkxrgtJP26flCV7oR7aCmfcuAcMpIQGJm3tMUgMu7Yjr8gM8 N2ig== 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=HNPwl4YuFQXP5ryWzI9uy5vJBKYGey9hz/UDHYOGzwI=; b=pK+dmMVJfTfP87CVnixLPuS0/E35UhmTbdFDAmTRzv5vqaRNhSVZEtPf2kdoAov3ru NBLNM04mzuL/Rp2fGfW9fU2HN+7/gAao77CBrRpuvk8a9F0euTvb5R1LkfT1cHnm0wwE 8TvTbbZX9+mz4fjui8SWdZFhB4O8U428DSmvcZSFlg/R3sjTfL95OUSAlu03X8Y3jdFf yapa4BJD74kqzkDPVpLuf7kYWsXWDTGIQfXm6Bc4XdvFWzsOFRa4MrdXVfsVa3iGBbIA NNLFN6o32R1QhflcLljf2t4PfQgugPMFZfD/C4F1D2ru66nDCW2x3i9/bhMbnaqr+VFf MW3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Ha0c6DeA; 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 b8-v6si13709400pgs.456.2018.05.04.11.33.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 May 2018 11:33:29 -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=Ha0c6DeA; 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=HNPwl4YuFQXP5ryWzI9uy5vJBKYGey9hz/UDHYOGzwI=; b=Ha0c6DeAO+kHLjwef3nQ/tRtm 7kHgBuWyYZHDkBgEFzoKhcDr6/XykoOVoXHLAhLzKE8ADew4ADdvHLC2OkljKy92vcfHYsx/iXrkV XjNimsso4CG9vlwijm+FX3O2c9St1TSfBOIXi+5OPN5aLWqaxrl3jwnF2gCfUhYgSvQlfeHsE2/M6 WSdxV54MDh9delG/Uv0n/K8AYBr6lkrro5HsBSFU/m83A/WmjPmO24+SI5S24MDLBMg4crrw4X2g5 yBq928RjB6dt0HDv5w4J2I0nroeLoVcO8Ex01dWbNZRbm0iF5zqE0MI9qm6cMyxm69eo/Bqej0Y1e RngEfqEAQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEfWK-0003og-HB; Fri, 04 May 2018 18:33:28 +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 v5 17/17] mm: Distinguish VMalloc pages Date: Fri, 4 May 2018 11:33:18 -0700 Message-Id: <20180504183318.14415-18-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180504183318.14415-1-willy@infradead.org> References: <20180504183318.14415-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 fa05e6ca31ed..199f43b50cf4 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 */ + }; /** @rcu_head: You can use this to free a page by RCU. */ struct rcu_head rcu_head; 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",