Message ID | Y6FHN9RyUKsQLo0i@qemulion |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2786788wrn; Mon, 19 Dec 2022 21:38:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ngLxci9Ef4KBulazLjnqbX3yPqYQhl+1pybKIoaSAm0sYOWYbNJUQsCt+j2ppHGoXfogu X-Received: by 2002:a17:90a:e545:b0:219:b79d:c2f4 with SMTP id ei5-20020a17090ae54500b00219b79dc2f4mr40332809pjb.18.1671514721048; Mon, 19 Dec 2022 21:38:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671514721; cv=none; d=google.com; s=arc-20160816; b=TRLavXFIHpdiE6c1CrX6a5SunTIGOdm9mbBu0/yb9xNo6fF3/FnwBhYsVDvtl8mYSV DZjmXpUSNv8rAwNTinzhZ16lIt8xNXPR+Spnu4k+Xwajf/J456VZYdtV8WtZpRXSX817 6Vo6dHbUkS9z4blysn0rYtR6D4D+ootKHI9zVSz8+76lLytjNB4phJu3R1auURtR+F3S +ak5e+jpm3CVn+wFFtRYcUJBuMIinbjDHXrxNLJA7l9zL6ar9+kV0np7ziri2QLFRoPl 370ivok4LtSRxtEiKxmnOb1a1ja8cY7Lz+5IDJRjxyNLB9KPlYbP4coI1eiP550deA7p 4Sfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=IDZY0exge1y0ypk/10nNU3r8ZayyqxLCW56Ho7hV0v8=; b=VqiNkyhFvXIKaZpXLqOV1ch94Y30i66sGPe2AVlNN9gGhYp44R9H42Fypa/WiA+lQe hTuX+PFTX6j3GXfu7i7UhkPVpwTaNnxF8BJJn5+s2QWxB46b+rGky8fvHaTlc5ohIbYy 73Sw4M48T/hFJwOjz8kdLd3yoddE/Wm+EOzrF/tLedyxT3vW7hlI0NbmArBm9PoGyjak cX6oTyKrQalrIYhM4i06QVRsZR4qObMFMgsjfLFoTSbLhFIfTKH7oNJiO6dZy0SFxUHL DP76EA+HfsoCQ9Z96rPsFhvp2lIPv0wBvJwO2Iwk8bC1gTsyV1WMEveR5GEEllzXwXl8 N2Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e0NyAsLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hi9-20020a17090b30c900b001fab0d18bcasi12375521pjb.66.2022.12.19.21.38.28; Mon, 19 Dec 2022 21:38:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e0NyAsLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232716AbiLTFZi (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Tue, 20 Dec 2022 00:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiLTFZg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 20 Dec 2022 00:25:36 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF61C12759 for <linux-kernel@vger.kernel.org>; Mon, 19 Dec 2022 21:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1671513916; bh=sFskYXbidjd/kcmqsM6ylTeRnbnKAC12byfrx9G5ZBw=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=e0NyAsLbQs/avEnwiC7ZsVK9GU4zrPuQ2XS2Ty1xYms0TvZepQfGJFyoXdovGjoPg nLFh9Azc+zv2bYdeL81WbyjoQwjCRe+8KHm/0j+9fgCl8r4OFQLTKGwboLCvlQzsrA h66ImFahB2Wf5lr5pJmUA8uWAo9X2/daha3s3yRU= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Tue, 20 Dec 2022 06:25:16 +0100 (CET) X-EA-Auth: UI0gHJBKyazNjZiXWvC0DmV1kOkEQvUhUW4KYOzbDoHDVw8pLiXzVtXTgzUhY3wuuWiIusiFO/ZVMxGyeNWUeIXmzD/eWeUJ Date: Tue, 20 Dec 2022 10:55:11 +0530 From: Deepak R Varma <drv@mailo.com> To: Russell King <linux@armlinux.org.uk>, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar <ssengar@microsoft.com>, Praveen Kumar <kumarpraveen@linux.microsoft.com>, drv@mailo.com Subject: [PATCH] ARM/dma-mapping: use kvzalloc for fallback memory allocation need Message-ID: <Y6FHN9RyUKsQLo0i@qemulion> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752710220277090096?= X-GMAIL-MSGID: =?utf-8?q?1752710220277090096?= |
Series |
ARM/dma-mapping: use kvzalloc for fallback memory allocation need
|
|
Commit Message
Deepak R Varma
Dec. 20, 2022, 5:25 a.m. UTC
When the memory sizes are not known upfront, it is preferred to use the
kvzalloc helper function instead of direct conditional evaluation of
size and kzalloc/vzalloc fallback design. The kvzalloc helper function
in this case is more efficient as it avoids indefinite kzalloc retries
when a small memory size is needed but is unavailable.
This LWN article has further details on the advantages of using
kvzalloc in case of fallback memory allocation needs:
https://lwn.net/Articles/711653/
This patch proposal is based on following Coccinelle warning using the
kvmalloc.cocci semantic patch.
arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Note: The patch proposal is compile tested only.
arch/arm/mm/dma-mapping.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
--
2.34.1
Comments
On Tue, Dec 20, 2022 at 10:55:11AM +0530, Deepak R Varma wrote: > When the memory sizes are not known upfront, it is preferred to use the > kvzalloc helper function instead of direct conditional evaluation of > size and kzalloc/vzalloc fallback design. The kvzalloc helper function > in this case is more efficient as it avoids indefinite kzalloc retries > when a small memory size is needed but is unavailable. > This LWN article has further details on the advantages of using > kvzalloc in case of fallback memory allocation needs: > https://lwn.net/Articles/711653/ > > This patch proposal is based on following Coccinelle warning using the > kvmalloc.cocci semantic patch. > > arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc > > Signed-off-by: Deepak R Varma <drv@mailo.com> Hello, May I please request a review and feedback on this patch proposal? Thank you, ./drv > --- > Note: The patch proposal is compile tested only. > > arch/arm/mm/dma-mapping.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index c135f6e37a00..2b79af377a81 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -855,10 +855,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, > int i = 0; > int order_idx = 0; > > - if (array_size <= PAGE_SIZE) > - pages = kzalloc(array_size, GFP_KERNEL); > - else > - pages = vzalloc(array_size); > + pages = kvzalloc(array_size, GFP_KERNEL); > if (!pages) > return NULL; > > -- > 2.34.1 >
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index c135f6e37a00..2b79af377a81 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -855,10 +855,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, int i = 0; int order_idx = 0; - if (array_size <= PAGE_SIZE) - pages = kzalloc(array_size, GFP_KERNEL); - else - pages = vzalloc(array_size); + pages = kvzalloc(array_size, GFP_KERNEL); if (!pages) return NULL;