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 1BBAFC433E0 for ; Sat, 23 Jan 2021 12:07:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9CB7023AC0 for ; Sat, 23 Jan 2021 12:07:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CB7023AC0 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 03A536B0007; Sat, 23 Jan 2021 07:07:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F2D756B0008; Sat, 23 Jan 2021 07:07:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1D206B000A; Sat, 23 Jan 2021 07:07:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id CE6026B0007 for ; Sat, 23 Jan 2021 07:07:19 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9F0E23652 for ; Sat, 23 Jan 2021 12:07:19 +0000 (UTC) X-FDA: 77736914598.19.rake70_4e1500527574 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 8553F1AD1B5 for ; Sat, 23 Jan 2021 12:07:19 +0000 (UTC) X-HE-Tag: rake70_4e1500527574 X-Filterd-Recvd-Size: 5470 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Sat, 23 Jan 2021 12:07:19 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id m6so5577930pfk.1 for ; Sat, 23 Jan 2021 04:07:19 -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=aYdi7spG9SxhM13xI9xxV28HYEwFIC9BJrWUDMA/0iVrqydKUD29XD3DLeuorTenvY fICb0tcdTPje4fnAsk8n77x4A+E9bBNa+vxtfxZUVYCd8M5zh9hw09HGo6h6RCj963Ln /m3bIN/r1WD9/hy9fBCDQ8ASMJlZ+tXbyaLx+f2Dhy/E8fbsPNp+n3XkLJTXcpqSyIyo CV4gNXb4NFV9cWvzXM18+XHoRbgdAp4mpDTjblDb7LqLHBh0AWy5NHyXk8WSQNUHZuXZ g5jBRuSksmHa+KIDgMSOPA4T0n5BG2s76Y+o4NPG9fuQjMf20LL18qgBu8W1OvGG4Bo2 JOlA== X-Gm-Message-State: AOAM532BQav9GbpOdCj5N1Z9C7TNUVMeww5Xo/QAWTyspIIHSuNhNPyi RRi2G93jeu0Q5veEg9m7h+c= 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 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 --- 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 i= nt order); =20 struct page_frag_cache; extern void __page_frag_cache_drain(struct page *page, unsigned int coun= t); +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, 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; @@ -5188,10 +5188,18 @@ void *page_frag_alloc(struct page_frag_cache *nc, } =20 nc->pagecnt_bias--; + offset =3D align ? ALIGN_DOWN(offset, align) : offset; nc->offset =3D offset; =20 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); =20 /* --=20 2.29.2