Re: [PATCH net-next v2 1/4] mm: page_frag: Introduce page_frag_alloc_align()
From: Vlastimil Babka <hidden>
Date: 2021-02-02 11:48:32
Also in:
linux-mm
On 2/2/21 12:36 PM, Ioana Ciornei wrote:
On Sun, Jan 31, 2021 at 03:44:23PM +0800, Kevin Hao wrote:quoted
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.