From: Kevin Hao <hidden> Date: 2021-01-23 12:07:12
Hi,
In the current implementation of napi_alloc_frag(), it doesn't have any
align guarantee for the returned buffer address. We would have to use
some ugly workarounds to make sure that we can get a align buffer
address for some Ethernet drivers. This patch series tries to introduce
some helper functions to make sure that an align buffer is returned.
Then we can drop the ugly workarounds and avoid the unnecessary memory
waste.
Kevin Hao (4):
mm: page_frag: Introduce page_frag_alloc_align()
net: Introduce {netdev,napi}_alloc_frag_align()
net: octeontx2: Use napi_alloc_frag_align() to avoid the memory waste
net: dpaa2: Use napi_alloc_frag_align() to avoid the memory waste
.../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 +-
.../marvell/octeontx2/nic/otx2_common.c | 3 +-
include/linux/gfp.h | 3 ++
include/linux/skbuff.h | 2 +
mm/page_alloc.c | 12 +++++-
net/core/skbuff.c | 40 ++++++++++++-------
6 files changed, 43 insertions(+), 20 deletions(-)
--
2.29.2
From: Kevin Hao <hidden> Date: 2021-01-23 12:07:21
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 <redacted>
---
include/linux/gfp.h | 3 +++
mm/page_alloc.c | 12 ++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
From: Kevin Hao <hidden> Date: 2021-01-23 12:08:17
In the current implementation of {netdev,napi}_alloc_frag(), 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 {netdev,napi}_alloc_frag() are used by these hardwares
for DMA.
buf = napi_alloc_frag(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. We have added the align
support for the page_frag functions, so add the corresponding
{netdev,napi}_frag functions.
Signed-off-by: Kevin Hao <redacted>
---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 40 ++++++++++++++++++++++++++--------------
2 files changed, 28 insertions(+), 14 deletions(-)
From: Kevin Hao <hidden> Date: 2021-01-23 12:08:30
The napi_alloc_frag_align() will guarantee that a correctly align
buffer address is returned. So use this function to simplify the buffer
alloc and avoid the unnecessary memory waste.
Signed-off-by: Kevin Hao <redacted>
---
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Kevin Hao <hidden> Date: 2021-01-23 12:08:44
The napi_alloc_frag_align() will guarantee that a correctly align
buffer address is returned. So use this function to simplify the buffer
alloc and avoid the unnecessary memory waste.
Signed-off-by: Kevin Hao <redacted>
---
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Isn't it better to make this a static inline now?
Either way you'll need to repost after net is merged into net-next
(probably ~this Friday), please mark the posting as RFC before that.
Please make sure you CC the author of the code.
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 <redacted>
Acked-by: Vlastimil Babka <redacted>
Agree with Jakub about static inline.