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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 0CA8BC433E0 for ; Tue, 26 Jan 2021 16:20:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BCBE22EBD for ; Tue, 26 Jan 2021 16:20:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BCBE22EBD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D68AC8D00F0; Tue, 26 Jan 2021 11:20:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D19C08D00B0; Tue, 26 Jan 2021 11:20:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE1768D00F0; Tue, 26 Jan 2021 11:20:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id A405C8D00B0 for ; Tue, 26 Jan 2021 11:20:09 -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 5C34A1EF1 for ; Tue, 26 Jan 2021 16:20:09 +0000 (UTC) X-FDA: 77748438138.09.pan44_0c0361a2758f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 33F55180AD838 for ; Tue, 26 Jan 2021 16:20:09 +0000 (UTC) X-HE-Tag: pan44_0c0361a2758f X-Filterd-Recvd-Size: 3128 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Jan 2021 16:19:56 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7774CACF5; Tue, 26 Jan 2021 16:19:55 +0000 (UTC) Subject: Re: [PATCH net-next 1/4] mm: page_frag: Introduce page_frag_alloc_align() To: Kevin Hao , "David S . Miller" , Jakub Kicinski , Andrew Morton Cc: netdev@vger.kernel.org, linux-mm@kvack.org References: <20210123115903.31302-1-haokexin@gmail.com> <20210123115903.31302-2-haokexin@gmail.com> From: Vlastimil Babka Message-ID: <42fecf9d-70c9-b686-d2f7-080b299060d9@suse.cz> Date: Tue, 26 Jan 2021 17:19:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210123115903.31302-2-haokexin@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 1/23/21 12:59 PM, Kevin Hao wrote: > 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 Agree with Jakub about static inline. > --- 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; We don't change offset if align == 0, so I'd go with simpler if (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); > > /* >