From patchwork Wed May 17 06:55:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9732105 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 2A7BF6022E for ; Wed, 17 May 2017 23:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3840287D6 for ; Wed, 17 May 2017 23:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8630287F5; Wed, 17 May 2017 23:39:32 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 68DDE287D6 for ; Wed, 17 May 2017 23:39:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 610D56E510; Wed, 17 May 2017 23:36:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 69BE56E39E for ; Wed, 17 May 2017 06:55:16 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id u65so1204425wmu.3 for ; Tue, 16 May 2017 23:55:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dnnNT476tlDqC5M17m9tV1xDuuhI6w1l6buQ1BIv8QE=; b=D7z6uQalpJR9BsUvWHCHViiotxtdyB0BraiElXuJgT+U2hPf8cj1Sd7/53Nc2jM2kW Bu8RYTgmAFln9bUR6t5HwJuKIo4N48nv4ixkELBcIGkAdGit+BuDoJsplB8El96zM0Kz mEcYTYutnfyP0MtrHlwEzrdQv63ZVBZFg9PMnkynnnRL7ZdYLW85rXub9FXVCVP5xYOl UST4H4cLKqTH0AhxCFgUQlBUScmdCe9ZLvunUlxEYvRAkG6Zg4sB/f/sMH7Z5wFMv8hc VNldGSI8GKB5BXezYRoHDzbQ4He5+w73rdxEG3wbm/gFrhfSIzZdKAVyI0RD4AIQxkCM QIIg== X-Gm-Message-State: AODbwcDTjhvAcTa8cC7jC+1Y54x4az/nLjpx2sqZOeLJCtrs8xXUOWq2 3Da/v7F0m1h+aA== X-Received: by 10.28.181.139 with SMTP id e133mr8821566wmf.65.1495004114973; Tue, 16 May 2017 23:55:14 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id c139sm12829083wmd.11.2017.05.16.23.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2017 23:55:14 -0700 (PDT) From: Michal Hocko To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: replace drm_[cm]alloc* by kvmalloc alternatives Date: Wed, 17 May 2017 08:55:08 +0200 Message-Id: <20170517065509.18659-1-mhocko@kernel.org> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Wed, 17 May 2017 23:35:44 +0000 Cc: Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko drm_[cm]alloc* has grown their own kvmalloc 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). drm_calloc_large needs to get __GFP_ZERO explicitly but it is the same thing as kvmalloc_array in principle. Signed-off-by: Michal Hocko --- Hi, I didn't add Reviewed-by from Chris because the original patch [1] didn't change drm_calloc_large which I have missed in that posting. This patch is the same otherwwise. [1] http://lkml.kernel.org/r/20170516090606.5891-1-mhocko@kernel.org include/drm/drm_mem_util.h | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h index d0f6cf2e5324..a1ddf55fda67 100644 --- a/include/drm/drm_mem_util.h +++ b/include/drm/drm_mem_util.h @@ -31,43 +31,18 @@ static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) { - if (size != 0 && nmemb > SIZE_MAX / size) - return NULL; - - if (size * nmemb <= PAGE_SIZE) - return kcalloc(nmemb, size, GFP_KERNEL); - - return vzalloc(size * nmemb); + return kvmalloc_array(nmemb, size, GFP_KERNEL | __GFP_ZERO); } /* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) { - if (size != 0 && nmemb > SIZE_MAX / size) - return NULL; - - if (size * nmemb <= PAGE_SIZE) - return kmalloc(nmemb * size, GFP_KERNEL); - - return vmalloc(size * nmemb); + return kvmalloc_array(nmemb, size, GFP_KERNEL); } static __inline__ void *drm_malloc_gfp(size_t nmemb, size_t size, gfp_t gfp) { - if (size != 0 && nmemb > SIZE_MAX / size) - return NULL; - - if (size * nmemb <= PAGE_SIZE) - return kmalloc(nmemb * size, gfp); - - if (gfp & __GFP_RECLAIMABLE) { - void *ptr = kmalloc(nmemb * size, - gfp | __GFP_NOWARN | __GFP_NORETRY); - if (ptr) - return ptr; - } - - return __vmalloc(size * nmemb, gfp, PAGE_KERNEL); + return kvmalloc_array(nmemb, size, gfp); } static __inline void drm_free_large(void *ptr)