From: Kevin Hao <hidden> Date: 2021-02-04 11:06:15
Hi,
v3:
- Adjust patch 1 and 2 according to Alexander's suggestion.
- Add Tested-by from Subbaraya.
- Add Reviewed-by from Ioana.
v2:
- Inline page_frag_alloc() and {netdev,napi}_alloc_frag()
- Adopt Vlastimil's suggestion and add his Acked-by
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 | 12 +++++--
include/linux/skbuff.h | 36 +++++++++++++++++--
mm/page_alloc.c | 8 +++--
net/core/skbuff.c | 26 ++++++--------
6 files changed, 61 insertions(+), 27 deletions(-)
--
2.29.2
From: Kevin Hao <hidden> Date: 2021-02-04 11:06:28
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>
---
v3: Use align mask as suggested by Alexander.
include/linux/gfp.h | 12 ++++++++++--
mm/page_alloc.c | 8 +++++---
2 files changed, 15 insertions(+), 5 deletions(-)
From: Kevin Hao <hidden> Date: 2021-02-04 11:07:23
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>
---
v3: Use align mask and refactor the {netdev,napi}_alloc_frag_align() as
suggested by Alexander.
include/linux/skbuff.h | 36 ++++++++++++++++++++++++++++++++++--
net/core/skbuff.c | 26 ++++++++++----------------
2 files changed, 44 insertions(+), 18 deletions(-)
From: Kevin Hao <hidden> Date: 2021-02-04 11:07:32
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>
Tested-by: Subbaraya Sundeep <sbhatta@marvell.com>
---
v3: Add Tested-by from Subbaraya.
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Kevin Hao <hidden> Date: 2021-02-04 11:07:59
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>
Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
v3: Add Reviewed-by from Ioana.
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Alexander Duyck <hidden> Date: 2021-02-04 16:11:34
On Thu, Feb 4, 2021 at 3:06 AM Kevin Hao [off-list ref] 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 <redacted>
Acked-by: Vlastimil Babka <redacted>
---
v3: Use align mask as suggested by Alexander.
include/linux/gfp.h | 12 ++++++++++--
mm/page_alloc.c | 8 +++++---
2 files changed, 15 insertions(+), 5 deletions(-)
Looks good to me.
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
From: Alexander Duyck <hidden> Date: 2021-02-04 16:20:43
On Thu, Feb 4, 2021 at 3:06 AM Kevin Hao [off-list ref] wrote:
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>
---
v3: Use align mask and refactor the {netdev,napi}_alloc_frag_align() as
suggested by Alexander.
include/linux/skbuff.h | 36 ++++++++++++++++++++++++++++++++++--
net/core/skbuff.c | 26 ++++++++++----------------
2 files changed, 44 insertions(+), 18 deletions(-)
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>