From patchwork Thu Feb 4 10:56:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12067001 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9163C433E0 for ; Thu, 4 Feb 2021 11:07:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 908ED64F5E for ; Thu, 4 Feb 2021 11:07:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235583AbhBDLHK (ORCPT ); Thu, 4 Feb 2021 06:07:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235499AbhBDLHG (ORCPT ); Thu, 4 Feb 2021 06:07:06 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60096C0613D6 for ; Thu, 4 Feb 2021 03:06:26 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id r38so1814259pgk.13 for ; Thu, 04 Feb 2021 03:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bzd7HKkd3Ts7ESkt/aXKI/JaGnhZL+skqDucX4yLTCQ=; b=C3c5dyJb6O/yirl0WF84J4RT6j6OM2oYPdgzYChKvnn7e54EVcapMYrooxphRQCGtc EHnKKcL4T46bfTuSE5iSFN5XH6Gh/ONPzXb3LmrgV2UcE3ajgNE/zRs+EQt+c/aM3DRw q1f+9cOQuRfs++EeRILkxm4qzsfr+6pTSa09hZBe+F7NzGwhIuqo3OThZyeOeWlk12eO GMnD4svgDEm3KNS9aHJkY1yGOJYSUpX5jXHmUrz5bPZyC28e0qzshMfE/o51ztssDV55 y1I4YtZsJJ5hRlC0LJ87EzhiFMK9qIGtcpx2InevX16Jw6mlaSM07T/Eyhq52poqLorN KOLw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bzd7HKkd3Ts7ESkt/aXKI/JaGnhZL+skqDucX4yLTCQ=; b=L0cUffIPKuYPkZfrNEeo1GyLNbCHtdtjF8sNYMNFieixxKFStGdr2CvbAe/sKsR23k EwOTA0mpVjmB3aNkrb5TbPizyeGl6mHq11Kgnvw0nd8iSL44aa7SZtPnH1T7N67hOU4N 0Ml/tTODakd9zcw6Uwba7TfhsgKnc8ABW9THd9afMZWZJ2Ih0qwsIf5TCqoCbNq8OHVX 4xMnueJNofwywZY/QZ+2sCycjs0GrjWLUepbsmrbT7J+Tb98YW9QvrwnLVBguA51sbPY udKQxYuhFCRq9J8OcaqbHEbKZyONgxXl1dfQ8N3uPeUoZlflu3gdCy/JOf+H9J+f9m+Y N4SA== X-Gm-Message-State: AOAM531pFSquSQgmDilAurQ6G0+uXO0Vpg7C3FwGcGLRiaoVsVjR8+FA ygWQYhQbVduwA1BaQOTg9Qg= X-Google-Smtp-Source: ABdhPJwxg80JL7uzJYm6e8ZqRQQZBcVyE1xoR7h7pgijaY23L3+J6ubz96J9mZG3Ijj2ipr1a1XCTA== X-Received: by 2002:aa7:96bc:0:b029:1d3:3d93:5a11 with SMTP id g28-20020aa796bc0000b02901d33d935a11mr5652568pfk.4.1612436785982; Thu, 04 Feb 2021 03:06:25 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id y15sm5283351pju.20.2021.02.04.03.06.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Feb 2021 03:06:25 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski , Andrew Morton Cc: netdev@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Eric Dumazet , Alexander Duyck Subject: [PATCH net-next v3 1/4] mm: page_frag: Introduce page_frag_alloc_align() Date: Thu, 4 Feb 2021 18:56:35 +0800 Message-Id: <20210204105638.1584-2-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210204105638.1584-1-haokexin@gmail.com> References: <20210204105638.1584-1-haokexin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In the current implementation of page_frag_alloc(), it doesn't have any align guarantee for the returned buffer address. But for some hardwares they do require the DMA buffer to be aligned correctly, so we would have to use some workarounds like below if the buffers allocated by the page_frag_alloc() are used by these hardwares for DMA. buf = page_frag_alloc(really_needed_size + align); buf = PTR_ALIGN(buf, align); These codes seems ugly and would waste a lot of memories if the buffers are used in a network driver for the TX/RX. So introduce page_frag_alloc_align() to make sure that an aligned buffer address is returned. Signed-off-by: Kevin Hao Acked-by: Vlastimil Babka Reviewed-by: Alexander Duyck --- v3: Use align mask as suggested by Alexander. include/linux/gfp.h | 12 ++++++++++-- mm/page_alloc.c | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 53caa9846854..52cd415b436c 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -583,8 +583,16 @@ extern void free_pages(unsigned long addr, unsigned int order); struct page_frag_cache; extern void __page_frag_cache_drain(struct page *page, unsigned int count); -extern void *page_frag_alloc(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask); +extern void *page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align_mask); + +static inline void *page_frag_alloc(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask) +{ + return page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); +} + extern void page_frag_free(void *addr); #define __free_page(page) __free_pages((page), 0) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ad3ed3ec4dd5..3583c6accd88 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5137,8 +5137,9 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); -void *page_frag_alloc(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask) +void *page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align_mask) { unsigned int size = PAGE_SIZE; struct page *page; @@ -5190,11 +5191,12 @@ void *page_frag_alloc(struct page_frag_cache *nc, } nc->pagecnt_bias--; + offset &= align_mask; nc->offset = offset; return nc->va + offset; } -EXPORT_SYMBOL(page_frag_alloc); +EXPORT_SYMBOL(page_frag_alloc_align); /* * Frees a page fragment allocated out of either a compound or order 0 page. From patchwork Thu Feb 4 10:56:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12067023 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48643C433E0 for ; Thu, 4 Feb 2021 11:07:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1282E64DE1 for ; Thu, 4 Feb 2021 11:07:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235587AbhBDLHV (ORCPT ); Thu, 4 Feb 2021 06:07:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235499AbhBDLHO (ORCPT ); Thu, 4 Feb 2021 06:07:14 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63E65C061786 for ; Thu, 4 Feb 2021 03:06:34 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id f63so1880531pfa.13 for ; Thu, 04 Feb 2021 03:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TzRX1HfoeK2op0+prNfA/idHix5q68PSODuxm8/cIYM=; b=R0N6gAaPC7JgOLunC1tZpT2+L+NPJEUeEG6XTRefQTEPj7zzkV0kgMAt2J7mOJafoY 32md2We20b/pzzRgCgPP13mYlF7BiNlby80x1XLJcyhbo0eMADNOjYwMMlZoeIS1b8pZ 10xgraO/wGtXWAsz/qJvmrAu6wfc1Bp31vLAGerVGcd2bDH69yPLRHSf6SVb0ikMhf1I DwUJ8P2XRAdigOyfEizoZ1S4vyEe5MePjW4yQHrJdqvdUf5hjoSKbz9XGpvVNewwHLc5 5pe4VJ/pkbvwsOedWN44tWlvcHOwsorMr30kr3nps+HOhUceif+BKpPTrbyaG/N8Ih5o +6Xw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TzRX1HfoeK2op0+prNfA/idHix5q68PSODuxm8/cIYM=; b=XPo0fadmPzuhKWjJwDN+cRiGBjgMYZ/oNKXNMoMw9w63/+V/fnd3PhKOZYa1J+XYdt UDKokd+oz1YY4pVoX5JFzvs4zGrkOv6coejzi/18sBY14CKr5wl3l+fnWKnVU0mabBbk /OLwUdCAeVy4+gEPlwwwTrnkCfVVoX985vr9uZJiRArewcGTZOXUZ1SztP53mNwDH40x a2nf/8i4LmpxzJlI7J2yg32putWRmR1n9woummto6wFlCrOc2f0e9KkCnYtJaQBShNxc lz3tqjvlKBbt0J+zUyBvYsFL1el0fydy0ExGeFvNw6XCokbzSk6kLTfM2qH0SwWkRTKs jjvw== X-Gm-Message-State: AOAM530rldNWu3pFm33xmCfTfevNGg4BnMa6YgfBA7S9N68+anNqPadp eZvhhkudTtVFWT05DsycMRY= X-Google-Smtp-Source: ABdhPJwLLKd/sOGOgGu+kcgF9rf8T1k2S0b430KT8VlReHaedaYquO2N1s2UghD9Uec5tBvvwlEBKQ== X-Received: by 2002:aa7:8016:0:b029:1d5:ea54:d7be with SMTP id j22-20020aa780160000b02901d5ea54d7bemr801383pfi.29.1612436793940; Thu, 04 Feb 2021 03:06:33 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id y15sm5283351pju.20.2021.02.04.03.06.28 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Feb 2021 03:06:33 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Eric Dumazet , Alexander Duyck Subject: [PATCH net-next v3 2/4] net: Introduce {netdev,napi}_alloc_frag_align() Date: Thu, 4 Feb 2021 18:56:36 +0800 Message-Id: <20210204105638.1584-3-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210204105638.1584-1-haokexin@gmail.com> References: <20210204105638.1584-1-haokexin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In the current implementation of {netdev,napi}_alloc_frag(), it doesn't have any align guarantee for the returned buffer address, But for some hardwares they do require the DMA buffer to be aligned correctly, so we would have to use some workarounds like below if the buffers allocated by the {netdev,napi}_alloc_frag() are used by these hardwares for DMA. buf = napi_alloc_frag(really_needed_size + align); buf = PTR_ALIGN(buf, align); These codes seems ugly and would waste a lot of memories if the buffers are used in a network driver for the TX/RX. We have added the align support for the page_frag functions, so add the corresponding {netdev,napi}_frag functions. Signed-off-by: Kevin Hao Reviewed-by: Alexander Duyck --- v3: Use align mask and refactor the {netdev,napi}_alloc_frag_align() as suggested by Alexander. include/linux/skbuff.h | 36 ++++++++++++++++++++++++++++++++++-- net/core/skbuff.c | 26 ++++++++++---------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9313b5aaf45b..c875b36c43fc 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2818,7 +2818,26 @@ void skb_queue_purge(struct sk_buff_head *list); unsigned int skb_rbtree_purge(struct rb_root *root); -void *netdev_alloc_frag(unsigned int fragsz); +void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask); + +/** + * netdev_alloc_frag - allocate a page fragment + * @fragsz: fragment size + * + * Allocates a frag from a page for receive buffer. + * Uses GFP_ATOMIC allocations. + */ +static inline void *netdev_alloc_frag(unsigned int fragsz) +{ + return __netdev_alloc_frag_align(fragsz, ~0u); +} + +static inline void *netdev_alloc_frag_align(unsigned int fragsz, + unsigned int align) +{ + WARN_ON_ONCE(!is_power_of_2(align)); + return __netdev_alloc_frag_align(fragsz, -align); +} struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length, gfp_t gfp_mask); @@ -2877,7 +2896,20 @@ static inline void skb_free_frag(void *addr) page_frag_free(addr); } -void *napi_alloc_frag(unsigned int fragsz); +void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask); + +static inline void *napi_alloc_frag(unsigned int fragsz) +{ + return __napi_alloc_frag_align(fragsz, ~0u); +} + +static inline void *napi_alloc_frag_align(unsigned int fragsz, + unsigned int align) +{ + WARN_ON_ONCE(!is_power_of_2(align)); + return __napi_alloc_frag_align(fragsz, -align); +} + struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int length, gfp_t gfp_mask); static inline struct sk_buff *napi_alloc_skb(struct napi_struct *napi, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 2af12f7e170c..063b365ce5b2 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -374,29 +374,23 @@ struct napi_alloc_cache { static DEFINE_PER_CPU(struct page_frag_cache, netdev_alloc_cache); static DEFINE_PER_CPU(struct napi_alloc_cache, napi_alloc_cache); -static void *__napi_alloc_frag(unsigned int fragsz, gfp_t gfp_mask) +static void *__alloc_frag_align(unsigned int fragsz, gfp_t gfp_mask, + unsigned int align_mask) { struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); - return page_frag_alloc(&nc->page, fragsz, gfp_mask); + return page_frag_alloc_align(&nc->page, fragsz, gfp_mask, align_mask); } -void *napi_alloc_frag(unsigned int fragsz) +void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) { fragsz = SKB_DATA_ALIGN(fragsz); - return __napi_alloc_frag(fragsz, GFP_ATOMIC); + return __alloc_frag_align(fragsz, GFP_ATOMIC, align_mask); } -EXPORT_SYMBOL(napi_alloc_frag); +EXPORT_SYMBOL(__napi_alloc_frag_align); -/** - * netdev_alloc_frag - allocate a page fragment - * @fragsz: fragment size - * - * Allocates a frag from a page for receive buffer. - * Uses GFP_ATOMIC allocations. - */ -void *netdev_alloc_frag(unsigned int fragsz) +void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) { struct page_frag_cache *nc; void *data; @@ -404,15 +398,15 @@ void *netdev_alloc_frag(unsigned int fragsz) fragsz = SKB_DATA_ALIGN(fragsz); if (in_irq() || irqs_disabled()) { nc = this_cpu_ptr(&netdev_alloc_cache); - data = page_frag_alloc(nc, fragsz, GFP_ATOMIC); + data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask); } else { local_bh_disable(); - data = __napi_alloc_frag(fragsz, GFP_ATOMIC); + data = __alloc_frag_align(fragsz, GFP_ATOMIC, align_mask); local_bh_enable(); } return data; } -EXPORT_SYMBOL(netdev_alloc_frag); +EXPORT_SYMBOL(__netdev_alloc_frag_align); /** * __netdev_alloc_skb - allocate an skbuff for rx on a specific device From patchwork Thu Feb 4 10:56:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12067025 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D613DC433E0 for ; Thu, 4 Feb 2021 11:07:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FC1364F43 for ; Thu, 4 Feb 2021 11:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235520AbhBDLHb (ORCPT ); Thu, 4 Feb 2021 06:07:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235488AbhBDLH3 (ORCPT ); Thu, 4 Feb 2021 06:07:29 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D1AC06178A for ; Thu, 4 Feb 2021 03:06:48 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id x23so397031pfn.6 for ; Thu, 04 Feb 2021 03:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MpxBx7CFidjEvv2qNlKhDCm20O5t175GcwGcP4QIJDY=; b=krLkjUlMsjgJPggCxPNXbj6yWEVNtfwDGkfWvaGIqn9cPMtKQLqhb6CHl69LjCgfAd oZd0JerLfFLPzmcakW7/WZ0D6xrFGHDW8A/3nZlOmyjkre/uiNwsr7RItiPzQGWsiASp tJzEEGUaH/5TcKu32mHhE6Ne0LKCvUd9JXSt3tb1KSn/M1LAMiKaSTG020IVloGOg3JC aRIe/PAoK37yQO949gZi9h31kN6dq7XRIDnZWF/BradEQztHdaB+z0vmZQWxLRD39Zie MIvBHqFXpGziOzS/jCVhQjfWkZcanOPBzRMwtmQWF8VasSD2HIrF/r2neCi5iFewe1pC VGAQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=MpxBx7CFidjEvv2qNlKhDCm20O5t175GcwGcP4QIJDY=; b=BDnMxq8VqazC8GRB1PdarLtsg8/yF9BRLXr1H/b9hS1lUAGcWObLZnonqUSc1+aFRa fR91v48Agvc4FUKDlZYvB7/UOqSXXXWBfeVg6ijzf+PsgvPHkEj7cvs2Hc1uFoRXzLk5 E0FIahEnTepvdZN2khbkm3RtmEOndkrl2NzmvzyGdCkeYO/0iYeCu71dIR+CQVBQL5a8 /QD6N9vl1RD86eq+unZ4i+PVVYN9l+MuZzgxRiWEQ1N+iIkEuvQQC9txXJouuI+Gp+V1 /YULuwRqlDXtcnw1sLFucoHmzAvUkO2tvYd+XEAJ2WA4nZwQOinezEa4pYkIfi7hEtTS m04Q== X-Gm-Message-State: AOAM531L6d6F4ni9lKDBzSAmDJXVtXdH8a6awhDApl7QzPJ8Q8mv+MOj kkbCyt7X1w9yoKMePCzbC3A= X-Google-Smtp-Source: ABdhPJyWNxEw23YnZjMMzMzNbWoakj/41AQpCmR06mLqQ46q+dIDmZoAwydwG7AGkPjLxZGNcYxsRw== X-Received: by 2002:a63:884a:: with SMTP id l71mr6529590pgd.75.1612436808390; Thu, 04 Feb 2021 03:06:48 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id y15sm5283351pju.20.2021.02.04.03.06.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Feb 2021 03:06:47 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad Subject: [PATCH net-next v3 3/4] net: octeontx2: Use napi_alloc_frag_align() to avoid the memory waste Date: Thu, 4 Feb 2021 18:56:37 +0800 Message-Id: <20210204105638.1584-4-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210204105638.1584-1-haokexin@gmail.com> References: <20210204105638.1584-1-haokexin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The napi_alloc_frag_align() will guarantee that a correctly align buffer address is returned. So use this function to simplify the buffer alloc and avoid the unnecessary memory waste. Signed-off-by: Kevin Hao Tested-by: Subbaraya Sundeep --- v3: Add Tested-by from Subbaraya. drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c index 5ddedc3b754d..cbd68fa9f1d6 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -488,11 +488,10 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool) dma_addr_t iova; u8 *buf; - buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN); + buf = napi_alloc_frag_align(pool->rbsize, OTX2_ALIGN); if (unlikely(!buf)) return -ENOMEM; - buf = PTR_ALIGN(buf, OTX2_ALIGN); iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize, DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); if (unlikely(dma_mapping_error(pfvf->dev, iova))) { From patchwork Thu Feb 4 10:56:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12067027 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC281C433DB for ; Thu, 4 Feb 2021 11:07:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E72E64F43 for ; Thu, 4 Feb 2021 11:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235534AbhBDLHm (ORCPT ); Thu, 4 Feb 2021 06:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235562AbhBDLHh (ORCPT ); Thu, 4 Feb 2021 06:07:37 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E5EAC061573 for ; Thu, 4 Feb 2021 03:06:57 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id n10so1830506pgl.10 for ; Thu, 04 Feb 2021 03:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TzBEGVs7ShXuDuudJL55FJtZbtZ13P6PAznQ6B819Zs=; b=NvrYJt4cYzVPmvdcY65Wqd7/gTCtQGKApwC66eoftgcffwPOoLMYfKlsMt/UmCFzk1 imya2h91ptbuWQeFh299/jSt+Sl7YlwFvw+0e0ZoQEQGz0vfeasUJCvVK2LY4Xj9LXm2 h69Xb7cm997Q8qnZA7yZgDbH1wg+8eymMQ6ceuhUs3bdNtHC9cKUw64bGO8JVIn+xdIp TnfjcLX0Fe04JDQRu8oEhKs5NH8m7MrEzYbfOnx/yl1KmdbOOlNBpVHnBv77jBTJDKwr 4qzkdyHQ5dkiRwvAFINZ0T5CxuhW78ZjXVp/EKJK11EQQHoEBq+dKzitR97swWlBIWl9 S+pw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TzBEGVs7ShXuDuudJL55FJtZbtZ13P6PAznQ6B819Zs=; b=CZ9aWjWQxtp/1x3r2HExXH3AWFCwnXWSAQ+8I1AVej/apWUEI55MzttosxW6cfovlq eXWAbAJakBaVD6QP2ePoEml1LUBeNAv+6p8r5AB2IA/wO7dZ3fo1bx5j8QUiSadNmbfx W2zXko9MU4HF7d3GU7hYChafWHENXok+X83czWV37zIhUDXMhMhyDasYYKkjLgkvcamG XL90+qHcs8jOvgcDVVNB0+z/byXdu+HWRI12Vs2oOVaSHrFtmYaDgQAIQunDEdKIO2xo e/rLrk6rzCdaool1m1YLF0S/4uK4LIOoditPzZ6eVEiDQrmWLB6FNw67jbvazTmQ9GjL HP+w== X-Gm-Message-State: AOAM531H+TMLUmOH8Lt5Gld4CY2ayT70+2sRrpgqsYVfJBIORL70Msi+ JudGQNJIQXruw/8SKsCA6W4= X-Google-Smtp-Source: ABdhPJx6ie01JeK5jWxGkYMlNH5zUqdQO8xPZvsK3KFfwTKw+dh7B63pLQn0mLSzhxGc08O8Nfnn2g== X-Received: by 2002:a62:800d:0:b029:1bc:9cd1:8ee1 with SMTP id j13-20020a62800d0000b02901bc9cd18ee1mr7673873pfd.69.1612436816640; Thu, 04 Feb 2021 03:06:56 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id y15sm5283351pju.20.2021.02.04.03.06.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Feb 2021 03:06:56 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Ioana Ciornei , Ioana Radulescu Subject: [PATCH net-next v3 4/4] net: dpaa2: Use napi_alloc_frag_align() to avoid the memory waste Date: Thu, 4 Feb 2021 18:56:38 +0800 Message-Id: <20210204105638.1584-5-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210204105638.1584-1-haokexin@gmail.com> References: <20210204105638.1584-1-haokexin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The napi_alloc_frag_align() will guarantee that a correctly align buffer address is returned. So use this function to simplify the buffer alloc and avoid the unnecessary memory waste. Signed-off-by: Kevin Hao Reviewed-by: Ioana Ciornei --- v3: Add Reviewed-by from Ioana. drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 41e225baf571..882b32a04f5e 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -764,12 +764,11 @@ static int dpaa2_eth_build_sg_fd(struct dpaa2_eth_priv *priv, /* Prepare the HW SGT structure */ sgt_buf_size = priv->tx_data_offset + sizeof(struct dpaa2_sg_entry) * num_dma_bufs; - sgt_buf = napi_alloc_frag(sgt_buf_size + DPAA2_ETH_TX_BUF_ALIGN); + sgt_buf = napi_alloc_frag_align(sgt_buf_size, DPAA2_ETH_TX_BUF_ALIGN); if (unlikely(!sgt_buf)) { err = -ENOMEM; goto sgt_buf_alloc_failed; } - sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN); memset(sgt_buf, 0, sgt_buf_size); sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset);