From patchwork Wed May 17 07:44:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9732121 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 1A3BF6022E for ; Wed, 17 May 2017 23:40:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2283287D6 for ; Wed, 17 May 2017 23:40:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6102287F4; Wed, 17 May 2017 23:40:51 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 313A4287D6 for ; Wed, 17 May 2017 23:40:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C00256E4A2; Wed, 17 May 2017 23:37:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3ECB6E3B1 for ; Wed, 17 May 2017 07:44:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5E5BDAC8C; Wed, 17 May 2017 07:44:55 +0000 (UTC) Date: Wed, 17 May 2017 09:44:53 +0200 From: Michal Hocko To: Chris Wilson Subject: Re: [PATCH] drm: use kvmalloc_array for drm_malloc* Message-ID: <20170517074453.GC18247@dhcp22.suse.cz> References: <20170516090606.5891-1-mhocko@kernel.org> <20170516093119.GW19912@nuc-i3427.alporthouse.com> <20170516105352.GH2481@dhcp22.suse.cz> <20170516110908.GE26693@nuc-i3427.alporthouse.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170516110908.GE26693@nuc-i3427.alporthouse.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Mailman-Approved-At: Wed, 17 May 2017 23:35:44 +0000 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Tue 16-05-17 12:09:08, Chris Wilson wrote: > On Tue, May 16, 2017 at 12:53:52PM +0200, Michal Hocko wrote: > > On Tue 16-05-17 10:31:19, Chris Wilson wrote: > > > On Tue, May 16, 2017 at 11:06:06AM +0200, Michal Hocko wrote: > > > > From: Michal Hocko > > > > > > > > drm_malloc* has grown their own kmalloc with vmalloc fallback > > > > implementations. MM has grown kvmalloc* helpers in the meantime. Let's > > > > use those because it a) reduces the code and b) MM has a better idea > > > > how to implement fallbacks (e.g. do not vmalloc before kmalloc is tried > > > > with __GFP_NORETRY). > > > > > > Better? The same idea. The only difference I was reluctant to hand out > > > large pages for long lived objects. If that's the wisdom of the core mm, > > > so be it. > > > > vmalloc tends to fragment physical memory more os it is preferable to > > try the physically contiguous request first and only fall back to > > vmalloc if the first attempt would be too costly or it fails. > > Not relevant for the changelog in this patch, but it would be nice to > have that written in kvmalloc() as to why the scatterring of 4k vmapped > pages prevents defragmentation when compared to allocating large pages. Well, it is not as much about defragmentation because both vmapped and kmalloc allocations are very likely to be unmovable (at least currently). Theoretically there shouldn't be a problem to make vmapped pages movable as the ptes can be modified but this is not implemented... The problem is that vmapped pages are more likely to break up more larger order blocks. kmalloc will naturally break a single larger block. > I have vague recollections of seeing the conversation, but a summary as > to the reason why kvmalloc prefers large pages will be good for future > reference. Does the following sound better to you? diff --git a/mm/util.c b/mm/util.c index 464df3489903..87499f8119f2 100644 --- a/mm/util.c +++ b/mm/util.c @@ -357,7 +357,10 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) WARN_ON_ONCE((flags & GFP_KERNEL) != GFP_KERNEL); /* - * Make sure that larger requests are not too disruptive - no OOM + * We want to attempt a large physically contiguous block first because + * it is less likely to fragment multiple larger blocks and therefore + * contribute to a long term fragmentation less than vmalloc fallback. + * However make sure that larger requests are not too disruptive - no OOM * killer and no allocation failure warnings as we have a fallback */ if (size > PAGE_SIZE) {