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=-5.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 7553DC433E6 for ; Tue, 2 Feb 2021 11:48:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BFD3864ECE for ; Tue, 2 Feb 2021 11:48:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFD3864ECE 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 51C286B0073; Tue, 2 Feb 2021 06:48:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 450FF6B0075; Tue, 2 Feb 2021 06:48:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 340096B0078; Tue, 2 Feb 2021 06:48:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 1F21A6B0073 for ; Tue, 2 Feb 2021 06:48:31 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DC99E8249980 for ; Tue, 2 Feb 2021 11:48:30 +0000 (UTC) X-FDA: 77773155180.26.story60_530c216275ca Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id B0CDB1804B661 for ; Tue, 2 Feb 2021 11:48:30 +0000 (UTC) X-HE-Tag: story60_530c216275ca X-Filterd-Recvd-Size: 2699 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 11:48:30 +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 184F1AD6A; Tue, 2 Feb 2021 11:48:29 +0000 (UTC) Subject: Re: [PATCH net-next v2 1/4] mm: page_frag: Introduce page_frag_alloc_align() To: Ioana Ciornei , Kevin Hao Cc: "David S . Miller" , Jakub Kicinski , Andrew Morton , "netdev@vger.kernel.org" , "linux-mm@kvack.org" , Eric Dumazet References: <20210131074426.44154-1-haokexin@gmail.com> <20210131074426.44154-2-haokexin@gmail.com> <20210202113618.s4tz2q7ysbnecgsl@skbuf> From: Vlastimil Babka Message-ID: <2d406568-5b1d-d941-5503-68ba2ed49f34@suse.cz> Date: Tue, 2 Feb 2021 12:48:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210202113618.s4tz2q7ysbnecgsl@skbuf> 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 2/2/21 12:36 PM, Ioana Ciornei wrote: > On Sun, Jan 31, 2021 at 03:44:23PM +0800, 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. > > Isn't the memory wasted even with this change? Yes, but less of it. Not always full amount of align, but up to it. Perhaps even zero. > I am not familiar with the frag allocator so I might be missing > something, but from what I understood each page_frag_cache keeps only > the offset inside the current page being allocated, offset which you > ALIGN_DOWN() to match the alignment requirement. I don't see how that > memory between the non-aligned and aligned offset is going to be used > again before the entire page is freed. True, thath's how page_frag is designed. The align amounts would be most likely too small to be usable anyway.