From patchwork Tue Mar 29 08:16:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8683811 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 89D80C0553 for ; Tue, 29 Mar 2016 08:17:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84EAD20212 for ; Tue, 29 Mar 2016 08:17:16 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8CE3A201E4 for ; Tue, 29 Mar 2016 08:17:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C8C26E448; Tue, 29 Mar 2016 08:17:14 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id C28746E448 for ; Tue, 29 Mar 2016 08:17:11 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id 139so2959360wmn.2 for ; Tue, 29 Mar 2016 01:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zP3CZPvtrdWzhCpmNFHKxXvCadaSBs16iwWTMW8ODmU=; b=q5A6uvSphH89Mj9Z7Pz3iHGtSKZOqBt2f2lyhq5uDTGShYP/mNlfbl8QZjqGgnKZVB Za8L3O8K/8R0ghS+sUaXAs0dj3s2deMgZty/UjLYIF+MziaMNaGw8wK8/hFVb1U2CTYe IGFemJPMxxeI7Ejut8RG3CcHMvt2TWszzHHjMUZmydBPUTIhs341qcImakbzGJm58EJJ hak1ox7jKGC991pWGydw71HEr1KOeGqHVkOfoGCEvW+UVRGZF5Gu7IeUrXcYWpaN5Oqz xvRXyPU+HS+nD1Y2VnqsHnvWbqCcDLv/VY3cjlkQv0zT8odWdtQpK0fH8zs0XTpgX/nL skYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zP3CZPvtrdWzhCpmNFHKxXvCadaSBs16iwWTMW8ODmU=; b=BoH1XD1314iHXjRDZcfxrPos+ARaEoW8Mi5NyReG+TFLCotEy+Ir1Ue7SkqLUU0luR JnT+gdPud2W0hzZo6jIL3DzdzeqMDW11aikk8n8RI3v1cIKt8Jb/3DulRE1hz0P3W/DT 3RUaFFc6TNhA9gUB9CyX9nNQkiOauGF8kDNtrKsk6VHeA6ROfVAso2E/xTd20oD11Q9O gg9b2JhULawcYbeMoRx5tGmMTUoh9STrAvEqfrtmjMF69hZyeTwhyEm6/ET2uGJgeEfi cR2PBIslbkNH52zKSx6lWeFBPR3XjQdPVJzXN14tWbfSF0zkHgcAutQa543zJMbxf/Qy dapQ== X-Gm-Message-State: AD7BkJLeSiCM0RcpZLYI963dihx6dA/CubSHmHitRs/YmMUIK6ZSAnxkmNwFfaBSZ5zuYw== X-Received: by 10.195.12.113 with SMTP id ep17mr1134853wjd.102.1459239429679; Tue, 29 Mar 2016 01:17:09 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id a1sm28070615wje.43.2016.03.29.01.17.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Mar 2016 01:17:08 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 29 Mar 2016 09:16:57 +0100 Message-Id: <1459239417-25024-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <20160328161549.c77046847a8ae791cb436aff@linux-foundation.org> References: <20160328161549.c77046847a8ae791cb436aff@linux-foundation.org> Cc: linux-kernel@vger.kernel.org, Roman Peniaev , linux-mm@kvack.org, David Rientjes , Andrew Morton , Mel Gorman Subject: [Intel-gfx] [PATCH v3] mm/vmap: Add a notifier for when we run out of vmap address space X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vmaps are temporary kernel mappings that may be of long duration. Reusing a vmap on an object is preferrable for a driver as the cost of setting up the vmap can otherwise dominate the operation on the object. However, the vmap address space is rather limited on 32bit systems and so we add a notification for vmap pressure in order for the driver to release any cached vmappings. The interface is styled after the oom-notifier where the callees are passed a pointer to an unsigned long counter for them to indicate if they have freed any space. v2: Guard the blocking notifier call with gfpflags_allow_blocking() v3: Correct typo in forward declaration and move to head of file Signed-off-by: Chris Wilson Cc: Andrew Morton Cc: David Rientjes Cc: Roman Peniaev Cc: Mel Gorman Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Acked-by: Andrew Morton # for inclusion via DRM --- Thanks Andrew, may I trouble someone for a Reviewed-by? --- include/linux/vmalloc.h | 4 ++++ mm/vmalloc.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index d1f1d338af20..8b51df3ab334 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -8,6 +8,7 @@ #include struct vm_area_struct; /* vma defining user mapping in mm_types.h */ +struct notifier_block; /* in notifier.h */ /* bits in flags of vmalloc's vm_struct below */ #define VM_IOREMAP 0x00000001 /* ioremap() and friends */ @@ -187,4 +188,7 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) #define VMALLOC_TOTAL 0UL #endif +int register_vmap_purge_notifier(struct notifier_block *nb); +int unregister_vmap_purge_notifier(struct notifier_block *nb); + #endif /* _LINUX_VMALLOC_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fb42a5bffe47..12d27ac303ae 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -344,6 +345,8 @@ static void __insert_vmap_area(struct vmap_area *va) static void purge_vmap_area_lazy(void); +static BLOCKING_NOTIFIER_HEAD(vmap_notify_list); + /* * Allocate a region of KVA of the specified size and alignment, within the * vstart and vend. @@ -363,6 +366,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, BUG_ON(offset_in_page(size)); BUG_ON(!is_power_of_2(align)); + might_sleep_if(gfpflags_allow_blocking(gfp_mask)); + va = kmalloc_node(sizeof(struct vmap_area), gfp_mask & GFP_RECLAIM_MASK, node); if (unlikely(!va)) @@ -468,6 +473,16 @@ overflow: purged = 1; goto retry; } + + if (gfpflags_allow_blocking(gfp_mask)) { + unsigned long freed = 0; + blocking_notifier_call_chain(&vmap_notify_list, 0, &freed); + if (freed > 0) { + purged = 0; + goto retry; + } + } + if (printk_ratelimit()) pr_warn("vmap allocation for size %lu failed: " "use vmalloc= to increase size.\n", size); @@ -475,6 +490,18 @@ overflow: return ERR_PTR(-EBUSY); } +int register_vmap_purge_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&vmap_notify_list, nb); +} +EXPORT_SYMBOL_GPL(register_vmap_purge_notifier); + +int unregister_vmap_purge_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&vmap_notify_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier); + static void __free_vmap_area(struct vmap_area *va) { BUG_ON(RB_EMPTY_NODE(&va->rb_node));