From patchwork Wed May 2 15:27:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10375919 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 201EB60234 for ; Wed, 2 May 2018 15:27:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D0132880C for ; Wed, 2 May 2018 15:27:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0141F28847; Wed, 2 May 2018 15:27:38 +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 3345B2880C for ; Wed, 2 May 2018 15:27:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADA9D6B0005; Wed, 2 May 2018 11:27:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A8A076B0006; Wed, 2 May 2018 11:27:36 -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 97A986B000A; Wed, 2 May 2018 11:27:36 -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 56E0D6B0005 for ; Wed, 2 May 2018 11:27:36 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id k3so13122655pff.23 for ; Wed, 02 May 2018 08:27:36 -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:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=T6d32rLGmrerDGAMdnxpNEGErWxYdzQAf0HmXHbptMU=; b=DSlZpPsUirSEFcTK6iTogc7Q7cICNK7gtNT1FDBozr95i4B+6IHyLy0XV77VNF9P50 zsO4hDA9NEyhff8PReqV3RxJHehatdzJiJJ2Zx+FkyeT9SQ9r75r2+hAs7/Kin/ECnFg Y4qGo1hIfUCUkklpE7ZdOvRutM0GhgxhLvauC/P+cIkkxt2JhET2C88PRnkZNFoKPe8z MuW4mMUGOqjpGe94D8L63cs7JGNPN4jR3ySNshmzSkXZZVvUBNEDF0u3r7o/FXLBzMgj Ubz5Ehy7yjprBKHWQaJJnwKLIJRufp9dZexy374USduw11DjSuvoWK3xPtZx9Skh/Pr8 x0mg== X-Gm-Message-State: ALQs6tCtgPQAhVYGXM+xvtisuZ3QBeKacUVztQFg40Edb+Wb/RWiqiGt LUTbt4Ir4rjs/khkx4ozgDZRm3+7WvK4akw7hxuWzuX1zvo66ug/j3+HmbtosMmCpZF4+/R2Xfj V7scZRRVAt/znxFjgBKG3IEg0puPxyvc+3rDOy9U26KDfcHW8o+tlFzKyt3nDYtXHiw== X-Received: by 2002:a65:608c:: with SMTP id t12-v6mr2569576pgu.182.1525274855888; Wed, 02 May 2018 08:27:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZosbiYBk+/sc0177u0mfU1cfG9cAtwEKm4ukZdY4PzhY0hoG/pDUu2hmvVmfNUTC9AFBeJf X-Received: by 2002:a65:608c:: with SMTP id t12-v6mr2569530pgu.182.1525274854863; Wed, 02 May 2018 08:27:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525274854; cv=none; d=google.com; s=arc-20160816; b=v4/8Hch4RAaDDoYLoJPiqyPFd56S8gPRwW5jv26wFOMiSwy+lMIqRC1+u0hilZThw9 ZwK8As+yDF7Rh2akfzcK0RiLqWEhF1DbHWyVLPreFSP+v3iFUkZ65oMdNmbiRJRl9ZS+ DqTtl8AD73pgDk36xbpIivHRHaCPNDa6CW5HzcdArzvlADzdnx/Bw1l485VEul9oVAB/ gijt7UYiXuCdibaMpTZmNK2+xynxKNwtfPBy3Ax0ACAkWZKp6/xBt3nz5wv6WDBUBsev RGDDiapZtArxP6B5jAlrtxBPsoSVcTFy16UVPTDusN5y4tZuhNioiu+b2dKf5uT99+Q0 3cWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=T6d32rLGmrerDGAMdnxpNEGErWxYdzQAf0HmXHbptMU=; b=yQqxSBpNAwOKEnjulb6LVowRvbrZ23tXjvFyp2VO46aJWKv6CrU1VZ1EkX5ZnfWrvb GuFRKuPgnd9xETqrCxmEDrVg3i1ZsEP9fWsM6eh2Wf5u7gUmDyKUSYcI9jWqiiskGmeI pfhfEVI+g8rd2NhezZSfbDNVBQcHHy14s0Td+3fH46mRI8ZOd9C0c9tWQnMA/XTbuT1r cJjaezMmiwII9bYHFdT1LMFmUTR2sY0s1ASXyv/82TUmeQ3T1YFDYNs2m5nMpfYswBCx Nu4B8W2Dnp8uriGTgwGtH4vAP9XZgT+C+IhmeRZnpHfhue4fMtUh++JYXrz0CcarQoHw TeGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=QfZgUB1B; 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 z6si11710753pfk.194.2018.05.02.08.27.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 May 2018 08:27:34 -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=QfZgUB1B; 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=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To: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=T6d32rLGmrerDGAMdnxpNEGErWxYdzQAf0HmXHbptMU=; b=QfZgUB1BxQkcck7+bIlGG4kQPX UPRyRVVPqW9WIEmcT0eeSp1VjSlfsuudHPF0r/3UX8lrcPXGrilOBZ2kW30OTC81nRD6+FkvRHNED o6i+2DTLBLlt2JLYpyW+T57e97zbcMMRXNTzWFu1Vgut1J9WbPkDzq/+HAjibJPMGg/RGs7P8SQiC 736wSUzcxo4T4jomK5wb/GHjDjCScjOz9pxE/fYxLs4IiYSLddbvD1b0ySXz1hFJ5pTcfmRekDRBt DvpDTpRgrneA2fQznRZsHUbpaB2WsOBeKaIJ3FNuanRIRHhiWRv3s7s08ibmy31B5kKBvupYBGc9v KaYgkipQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fDtfK-0000Fh-1I; Wed, 02 May 2018 15:27:34 +0000 Date: Wed, 2 May 2018 08:27:33 -0700 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Igor Stoppa Subject: [RFC] Distinguish vmalloc pages Message-ID: <20180502152733.GB2737@bombadil.infradead.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) 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 --- This patch would be a superset of Igor's patch to add an ->area field to struct page. It's on top of my recent series to rearrange struct page. I think it's a nice demonstration of how you don't have to go hunting around for fields that may or may not be in use; you just add your own little struct to the union, and you're done. As well as being *really* useful for debugging, of course! 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 42619e16047f..c51ddd27bfb4 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -141,6 +141,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",