From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 445E0C433E0 for ; Sun, 31 Jan 2021 07:54:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CB3A564E24 for ; Sun, 31 Jan 2021 07:54:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB3A564E24 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 604E86B0006; Sun, 31 Jan 2021 02:54:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B63D6B006C; Sun, 31 Jan 2021 02:54:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CB656B006E; Sun, 31 Jan 2021 02:54:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 388976B0006 for ; Sun, 31 Jan 2021 02:54:54 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EA5AB1EE6 for ; Sun, 31 Jan 2021 07:54:53 +0000 (UTC) X-FDA: 77765308866.09.way10_36015a0275b7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id CACEE180AD838 for ; Sun, 31 Jan 2021 07:54:53 +0000 (UTC) X-HE-Tag: way10_36015a0275b7 X-Filterd-Recvd-Size: 5845 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Sun, 31 Jan 2021 07:54:53 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id x9so2308975plb.5 for ; Sat, 30 Jan 2021 23:54:53 -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=jqNTc3taooEGAe6NyLfpGbPnLN2+ksi09jHdju+UGdA=; b=M8AzrAaFS1ZVyFvtlXhTwOuAvyAv3aBASXTq49HKZOQOGaWer7HfI+3Eijv6S88Z/a IMSCK4vhveucdLTk1QhlGbrEFBphmVDzuFbh7WMLE4GlM21Lew0k3m10J2C694DZgKX2 0INLtCxOD/1qDCaqdpxoUX7SkM0FZXRTEEFbmOKoWdUQAphBLrYrZq+WLubmXB+o3Rw2 hqEVWBfKvZxfxMV+NK3QOpKJpBEPtjRi22mm5lKi9/QTE1tVMpGljg4Uitr3TfDcrwjT 0HZ88yxQDSHIPGtBvOE6r+2wWPNG/BtUcoFSOpc7dY2QEFAxI+UOuwf8S1coULoHpCcv 34WQ== 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=jqNTc3taooEGAe6NyLfpGbPnLN2+ksi09jHdju+UGdA=; b=bOOpfTneDE5qIX5JOt+EaQuIGfqPI91ef/luQ8vHNVi9c3hAwmmCXzq0fXxP4VzhGD X5xnxcAUYF+lIUjYH0RqSUowx82sA/mK4lMQlgA75DvWaV9gcGi49o8SiroAkCGOzuTI BpRzdkL+XraoOseRxmLhLrhYAhu/+oDQhLg4nBVA+YSD6wS819XZ4pO79ynDrKuoMiUM evLKiMTavjLACO9BZH+yttaAqTwhD6HrsmrvIe383t38eGBklpybDaDvmzFLP3AIOiG1 UQLsi7ynj0yXTWvZUWVm9mZlv0tg6n3VGbFv1piDr2nLJJvkvtWHBwg7PIDkZTp5R0zp OS+A== X-Gm-Message-State: AOAM530Nj+FP2fRfXv87MBXpBpTAEcZ7RPwOJI/7iHtuTzgD9og3+CY0 NXEAORStjFklMbqbjbyKt9g= X-Google-Smtp-Source: ABdhPJwEw8l6sPqxwHtES9zOBOuhFlNS4KTRemUbIJQZ7T+uBlUIILVDdqN/tc3afG5ifPqk9eJ9Qg== X-Received: by 2002:a17:90a:a516:: with SMTP id a22mr12118376pjq.192.1612079692422; Sat, 30 Jan 2021 23:54:52 -0800 (PST) Received: from pek-lpggp6.wrs.com (unknown-105-123.windriver.com. [147.11.105.123]) by smtp.gmail.com with ESMTPSA id h23sm13931290pgh.64.2021.01.30.23.54.45 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Jan 2021 23:54:51 -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 Subject: [PATCH net-next v2 1/4] mm: page_frag: Introduce page_frag_alloc_align() Date: Sun, 31 Jan 2021 15:44:23 +0800 Message-Id: <20210131074426.44154-2-haokexin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210131074426.44154-1-haokexin@gmail.com> References: <20210131074426.44154-1-haokexin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 =3D page_frag_alloc(really_needed_size + align); buf =3D 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 --- v2:=20 - Inline page_frag_alloc() - Adopt Vlastimil's suggestion and add his Acked-by =20 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 6e479e9c48ce..39f4b3070d09 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); =20 struct page_frag_cache; extern void __page_frag_cache_drain(struct page *page, unsigned int coun= t); -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, + int align); + +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, 0); +} + extern void page_frag_free(void *addr); =20 #define __free_page(page) __free_pages((page), 0) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 519a60d5b6f7..4667e7b6993b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5137,8 +5137,8 @@ void __page_frag_cache_drain(struct page *page, uns= igned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); =20 -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 =3D PAGE_SIZE; struct page *page; @@ -5190,11 +5190,13 @@ void *page_frag_alloc(struct page_frag_cache *nc, } =20 nc->pagecnt_bias--; + if (align) + offset =3D ALIGN_DOWN(offset, align); nc->offset =3D offset; =20 return nc->va + offset; } -EXPORT_SYMBOL(page_frag_alloc); +EXPORT_SYMBOL(page_frag_alloc_align); =20 /* * Frees a page fragment allocated out of either a compound or order 0 p= age. --=20 2.29.2