From patchwork Sat Jan 23 11:59:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12041451 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.8 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 9E9E8C433E0 for ; Sat, 23 Jan 2021 12:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67E71233EF for ; Sat, 23 Jan 2021 12:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbhAWMIA (ORCPT ); Sat, 23 Jan 2021 07:08:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726665AbhAWMH7 (ORCPT ); Sat, 23 Jan 2021 07:07:59 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED9BC061786 for ; Sat, 23 Jan 2021 04:07:18 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id z21so5694872pgj.4 for ; Sat, 23 Jan 2021 04:07:18 -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=rYPGbLlrL+NTSiBBV8yr2vAi1NU6ocBFEQbckFDVJpw=; b=uDZJQsgEQB7Mj1PtcF2p1ayxYHYrYhMqXlN5owzLMJvcXLWCRe/YYKC7X/OaQc8Hk3 UecKo+g15Ajvd1rQxfewlaTRNR3+6m7SVu1KErb69dKGanK23wlMoMxH+0aa6jUwdvf7 jXEuMjjUuFtMgZdLMW+7veaXYpqWJA2k/ooIIPPRbXC4dhrfpPKgRxfKuvWzY0XZOD1j wrixoLnHWb8PwfZ396UfJwklrWn46KUoTnrQ07bocnW8DywzUmXZiTOT0RMgGGIGKT0p GX0fq1bRhopcXi/A2nSYPEgPtMypHvq01UuuYxC1XosmHtswgA7vQ84bEyoVUYqXsGoA jgUA== 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=rYPGbLlrL+NTSiBBV8yr2vAi1NU6ocBFEQbckFDVJpw=; b=Tagn46MM1LrpPja9Eo9VERdh1FMe4uyO8VMjqAd3B/z4X6OdZiRBOswWFxRnw8mlmM yU37lLM5RSkFcC45B4lrewPbBoJd+JzlqKewPDF1VtU/OLTBRMBQGUai5alGs0F/a4qn id1oMtZFIE9iFir2EByzQKo/KPyWP9SxI6reExMxR/5E22IXahRyC7ERrzJdceGfQOes ieC2SWNVEqcZro9rdtC9tLv2/1tJbfWWGcrHT7IoNapz3MhI1/tB1TQfp/NCYd0JDzVh R+AzsdoGO17cZCEjbNyhxpRSdmN7Hz4JmxvTt/gEHmNEEhSv/SqC5Wyuix5gOeAlaVua DnDg== X-Gm-Message-State: AOAM531MNELlH5wbDHtJ71bwd8laShjYQvACkZpeMTT41eIvwGS7kyC+ o8iNTh9IT1PYke20VIbHfzM= X-Google-Smtp-Source: ABdhPJwj/7xX5kbsGyhaegLymVfXoi5PXvQ1CKAZjDU/HcrfSOm7otarMdq7wI/s3djHT5ueIUY7ug== X-Received: by 2002:a65:628a:: with SMTP id f10mr1105422pgv.380.1611403638500; Sat, 23 Jan 2021 04:07:18 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id v9sm11471079pff.102.2021.01.23.04.07.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jan 2021 04:07:17 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski , Andrew Morton Cc: netdev@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH net-next 1/4] mm: page_frag: Introduce page_frag_alloc_align() Date: Sat, 23 Jan 2021 19:59:00 +0800 Message-Id: <20210123115903.31302-2-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210123115903.31302-1-haokexin@gmail.com> References: <20210123115903.31302-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 --- include/linux/gfp.h | 3 +++ mm/page_alloc.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 6e479e9c48ce..e76e8618e9d7 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -583,6 +583,9 @@ 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_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + int align); extern void *page_frag_alloc(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask); extern void page_frag_free(void *addr); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 027f6481ba59..80f7c5f7d738 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5135,8 +5135,8 @@ 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, int align) { unsigned int size = PAGE_SIZE; struct page *page; @@ -5188,10 +5188,18 @@ void *page_frag_alloc(struct page_frag_cache *nc, } nc->pagecnt_bias--; + offset = align ? ALIGN_DOWN(offset, align) : offset; nc->offset = offset; return nc->va + offset; } +EXPORT_SYMBOL(page_frag_alloc_align); + +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, 0); +} EXPORT_SYMBOL(page_frag_alloc); /* From patchwork Sat Jan 23 11:59:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12041453 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.8 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 5C93FC433DB for ; Sat, 23 Jan 2021 12:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C4FA233EF for ; Sat, 23 Jan 2021 12:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726859AbhAWMIJ (ORCPT ); Sat, 23 Jan 2021 07:08:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbhAWMIH (ORCPT ); Sat, 23 Jan 2021 07:08:07 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FDB3C061788 for ; Sat, 23 Jan 2021 04:07:27 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id 31so4782048plb.10 for ; Sat, 23 Jan 2021 04:07:27 -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=WUpKxwAFaQa+uUPZ4D7S7tvn/MJ+fLIoM8egUUDOIRE=; b=Pbyb8nzayzYyMAooVb2tYrdMxI7oyoo7JMVQPKFlajzhG1P2QxuCAn+6tp/tVQd+/2 NPtnIX/oxpj5OPYaBuhvodt/8zxF6bfC617L0WSYH12PdvFeWiin1V5lMUK+dK9VjMRn pm9nNml5qVYXyhbTJWFp9/XEs0Ap70yMZ9XN7/NoRjBW3XPOSR2Iw5x2T9agHe5c8/IM SiecVKEHa+VLwTGIuQU3RLH88kfDMXsMkxU6YYsGqDstHlelb3/zLqwariGBASP21Kxo Dqt3vzPOJV2p6cUgTOeIgXtc9kvSgrk3tpUorBvi1s0Hd/G7H6eh/wn1R3mjVx8Dxl3r 6oqQ== 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=WUpKxwAFaQa+uUPZ4D7S7tvn/MJ+fLIoM8egUUDOIRE=; b=tYk3OCabBp1NHp0r1YzlpNQ4u2u+9tyWtaUoZ3/p+Nj0UHcCVoQZMnZNjNmvqX4rz/ 752eW4tZrRYRtK6ZEfDdDeySqda/aq0RrVxsC2ie04TwncxE25HhE/6WdZwbASWer9kq YId+E3T2sx8C/8YlzdZf4/57q8zlk9FWxHD+JrWkkhDMNssli6MV4bb4Fr8koFUtrai8 ND6ba+Tjc23w8l18D4uAoAMjFYzb5yWs/vKiu32BG4oPNndAFZMFiBJs4Hj1palE74Pa 2PPMWE4vJYDDQnORzloydLfCKbUICCO5YN9VS3Poko+dPNumE7F92a7UhdM2mWWsFcbT BO2A== X-Gm-Message-State: AOAM531oJ/th0htICPHB7IFfDn/QvA4ViX16WcBieuthcYmbZPMsFFBx TVjxfGtNH/ZgRqFhom272Q8= X-Google-Smtp-Source: ABdhPJziHeiKV0DFst52wkp3BA7TmUFxrrrWYKSD4LhkdAWk1DHxMydY4k6pY263YMgy7xzRxI8AHA== X-Received: by 2002:a17:90a:5911:: with SMTP id k17mr10997913pji.152.1611403647002; Sat, 23 Jan 2021 04:07:27 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id v9sm11471079pff.102.2021.01.23.04.07.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jan 2021 04:07:26 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 2/4] net: Introduce {netdev,napi}_alloc_frag_align() Date: Sat, 23 Jan 2021 19:59:01 +0800 Message-Id: <20210123115903.31302-3-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210123115903.31302-1-haokexin@gmail.com> References: <20210123115903.31302-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 --- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 5f60c9e907c9..71e704732b6f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2808,6 +2808,7 @@ void skb_queue_purge(struct sk_buff_head *list); unsigned int skb_rbtree_purge(struct rb_root *root); +void *netdev_alloc_frag_align(unsigned int fragsz, int align); void *netdev_alloc_frag(unsigned int fragsz); struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length, @@ -2867,6 +2868,7 @@ static inline void skb_free_frag(void *addr) page_frag_free(addr); } +void *napi_alloc_frag_align(unsigned int fragsz, int align); void *napi_alloc_frag(unsigned int fragsz); struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int length, gfp_t gfp_mask); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 785daff48030..d01ecb4f0de4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -374,29 +374,28 @@ 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 *__napi_alloc_frag(unsigned int fragsz, gfp_t gfp_mask, int align) { 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); } -void *napi_alloc_frag(unsigned int fragsz) +void *napi_alloc_frag_align(unsigned int fragsz, int align) { fragsz = SKB_DATA_ALIGN(fragsz); - return __napi_alloc_frag(fragsz, GFP_ATOMIC); + return __napi_alloc_frag(fragsz, GFP_ATOMIC, align); +} +EXPORT_SYMBOL(napi_alloc_frag_align); + +void *napi_alloc_frag(unsigned int fragsz) +{ + return napi_alloc_frag_align(fragsz, 0); } EXPORT_SYMBOL(napi_alloc_frag); -/** - * 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, int align) { struct page_frag_cache *nc; void *data; @@ -404,14 +403,27 @@ 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); } else { local_bh_disable(); - data = __napi_alloc_frag(fragsz, GFP_ATOMIC); + data = __napi_alloc_frag(fragsz, GFP_ATOMIC, align); local_bh_enable(); } return data; } +EXPORT_SYMBOL(netdev_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) +{ + return netdev_alloc_frag_align(fragsz, 0); +} EXPORT_SYMBOL(netdev_alloc_frag); /** From patchwork Sat Jan 23 11:59:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12041455 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.8 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 3FBEAC433DB for ; Sat, 23 Jan 2021 12:08:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13B49233EF for ; Sat, 23 Jan 2021 12:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbhAWMIV (ORCPT ); Sat, 23 Jan 2021 07:08:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbhAWMIR (ORCPT ); Sat, 23 Jan 2021 07:08:17 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98A08C06174A for ; Sat, 23 Jan 2021 04:07:37 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id j21so190761pls.7 for ; Sat, 23 Jan 2021 04:07:37 -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=lLh25oDN7zLCnZK7Cfcri55AhH7wovHU7ekkGi35cG0=; b=gJ8cJfW45dRpeRUIM2i3j4j3Lr7ok0OtZf1ybZQfi4XZLuWvlnqleHaUpAo45zzIBu 1ScJPTuRQBme1NBstJc6oEZCiViSJPSxSbt3FE5pThtUJU4yYxuIob3bPuuofestEcOW tEZ5q/pv1LBGSx9ZQim/hrkOKZHCE/Vln01rFeExdwKaf3uaBMuSKSVfz8lyWTsl+UvA SH1iA1YrOWKrA9ii1N5/Sf1V7GUwIW3UOTptHZk5i8fiJmjstQxnDNiVBH5Qr9Re8siX fNP4GWrpf1hSpby0c34bvOk1T6UdK29hBMKhDSDJfDbsP42k9q53H0zZhvrlBcpAJs6m I+GA== 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=lLh25oDN7zLCnZK7Cfcri55AhH7wovHU7ekkGi35cG0=; b=gyBPd/Snhu0funqmrgobempTmBgqQm2l84DLU/2Fd7BnX7M2etNMSw2ytNvdWH//zc YqR3wE0D0Vte7V/4M2zxcP9CJddpXBVNsIPNZy2VK3FTnYQEttmWCxbzuOT95aF4zS/7 pLTWBV1EtbYtFYLMTv+tmSyz02Z9nPKqjdt89IdAfnBKufsnnAfS4NrxBKs9ZlgRnZnr aMIEFqGys02DkFPix3kxFe8BPSNVjsacubHmv3czKXIYuu0GpJqyQSHOy/yJFSpxvjdB t+CbBWtaebkBDHpOqz0j7Op66fX311gqSQeKuWFO0hLM0RYZUztRHrtYtRQcbKeGz3VR P2EA== X-Gm-Message-State: AOAM5336EBAsYoT++Lctp/ePNwHHKEN3TfuHZtinFTXJdNgIMIeTwaKf KmCrJraH++Cm7vSsC3730fk= X-Google-Smtp-Source: ABdhPJyh/eogwAXHe84EEzB0o3ejH93w2KCJVnaJy6+TaOMQfIU94XUI80/hXamq3IKygyW6NwVGqQ== X-Received: by 2002:a17:902:26a:b029:da:af47:77c7 with SMTP id 97-20020a170902026ab02900daaf4777c7mr9945055plc.10.1611403657192; Sat, 23 Jan 2021 04:07:37 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id v9sm11471079pff.102.2021.01.23.04.07.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jan 2021 04:07:35 -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 3/4] net: octeontx2: Use napi_alloc_frag_align() to avoid the memory waste Date: Sat, 23 Jan 2021 19:59:02 +0800 Message-Id: <20210123115903.31302-4-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210123115903.31302-1-haokexin@gmail.com> References: <20210123115903.31302-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 --- 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 e6869435e1f3..6fbceabae1ac 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c @@ -478,11 +478,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 Sat Jan 23 11:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 12041457 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.8 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 D9F8FC433E0 for ; Sat, 23 Jan 2021 12:08:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABC1323B08 for ; Sat, 23 Jan 2021 12:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726379AbhAWMIn (ORCPT ); Sat, 23 Jan 2021 07:08:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbhAWMIY (ORCPT ); Sat, 23 Jan 2021 07:08:24 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B108C06178B for ; Sat, 23 Jan 2021 04:07:44 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id g15so5557247pjd.2 for ; Sat, 23 Jan 2021 04:07:44 -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=Ib5yrjhRxj1gxfBqNCCgQcI6y8o+/2z4BcgmutvFBFQ=; b=FLwmC5MYLBs1IceoqIt2nKlJK8x1hpKFBQAToFC/+Hfoyxoc39v7QqhAAvBe/BpM1I fxO++3hW/t5UAtVN6x5xZVTiHCWzrvBIBSSnFEGcXbpYPKlJ8CJpZR87T6qq+KRL87bn 68TUwomsj/RkUXX590WLzUiuAAxR8ccET3YxKMK/SMd0EFMg9x2fCDiTiVClv6Ki6qB7 vWL1lp6VswMD48rRCLW5p1sxWQXuwuyW0ovcM7hkY9Ul187fYZdgdMRotl9jJsbhFl7g g9pxz4ZMz1E26V2T71lZ0e5tZCVrO/j8M61Zz2wuJwM8aIxa2QAVD9H51lSw5UZ7CVcU s20Q== 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=Ib5yrjhRxj1gxfBqNCCgQcI6y8o+/2z4BcgmutvFBFQ=; b=bbjwddoGAROkHOfLBnWaBJ+zKBOA4b+tC5a7xskiMQ1MvP5Q50ujsQ5eTDCx29kVR5 UyCYSWVkkhqvdYaVZQKP78IuuD3oIyZGg7kuqhOydkibtzB4hWZ/7Nflg9EYuKepBMas P/+7Y4y4x9e5kKLNT9FBCrpiyUBBPZCmxVbfWDNuwDdoz/W6lp2pEPuN8aIEa2ziK4QD rIVBXHxxVebmPK1Vwkk47jc8BwL+rdNxtjTCeRk7439Vz/fEUwE/xrvyyuDeXkwAmJEQ BIjCwgkMSaWt/7YJ9G1Wq35mQZZdOnmZmsvoiKtXDlxfAiqOfUdlRkT9D9i3VRNALNUy j0LQ== X-Gm-Message-State: AOAM530U48kvUSyspwHK3tdEkwfXvdQoOyAqsa6wOARIkXCXfx5ZHwGF jkPleACyMzf3AVZpsPq1Z8M5N1hA7+Q= X-Google-Smtp-Source: ABdhPJz6NmyGBIXCMIXd2nGE0F/4oGvckAlNEWACSloaHUJrKjaa2tvmarDjfoFaVQaeCegtr5LC5A== X-Received: by 2002:a17:902:bf06:b029:dc:1f:ac61 with SMTP id bi6-20020a170902bf06b02900dc001fac61mr9985382plb.16.1611403663905; Sat, 23 Jan 2021 04:07:43 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id v9sm11471079pff.102.2021.01.23.04.07.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Jan 2021 04:07:43 -0800 (PST) From: Kevin Hao To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Ioana Ciornei , Ioana Radulescu Subject: [PATCH net-next 4/4] net: dpaa2: Use napi_alloc_frag_align() to avoid the memory waste Date: Sat, 23 Jan 2021 19:59:03 +0800 Message-Id: <20210123115903.31302-5-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210123115903.31302-1-haokexin@gmail.com> References: <20210123115903.31302-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 --- 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 fb0bcd18ec0c..b7aaf4b4f3fb 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -768,12 +768,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);