* [PATCH net-next] r8169: improve rx buffer allocation
@ 2019-01-20 10:12 Heiner Kallweit
2019-01-22 22:52 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2019-01-20 10:12 UTC (permalink / raw)
To: David Miller, Realtek linux nic maintainers
Cc: netdev@vger.kernel.org, Eric Dumazet
8 years ago, as part of 6f0333b8fde4 ("r8169: use 50% less ram for RX
ring"), the alignment requirement for rx buffers was silently changed
from 8 bytes to 16 bytes. I found nothing explaining this, also the
chip specs I have only mention an 8 byte requirement.
AFAICS kmalloc_node() guarantees allocated memory to be at least
"long long" aligned, what is 8 bytes on a 32 bit machine.
So we can take this memory as-is and avoid some overhead by changing
the alignment requirement back to 8 bytes.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index e790a4116..970c82694 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -5659,11 +5659,6 @@ static inline void rtl8169_mark_to_asic(struct RxDesc *desc)
desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE);
}
-static inline void *rtl8169_align(void *data)
-{
- return (void *)ALIGN((long)data, 16);
-}
-
static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
struct RxDesc *desc)
{
@@ -5676,15 +5671,13 @@ static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
if (!data)
return NULL;
- if (rtl8169_align(data) != data) {
- kfree(data);
- data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node);
- if (!data)
- return NULL;
+ /* Memory should be properly aligned, but better check. */
+ if (!IS_ALIGNED((unsigned long)data, 8)) {
+ netdev_err_once(tp->dev, "RX buffer not 8-byte-aligned\n");
+ goto err_out;
}
- mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE,
- DMA_FROM_DEVICE);
+ mapping = dma_map_single(d, data, R8169_RX_BUF_SIZE, DMA_FROM_DEVICE);
if (unlikely(dma_mapping_error(d, mapping))) {
if (net_ratelimit())
netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
@@ -6290,7 +6283,6 @@ static struct sk_buff *rtl8169_try_rx_copy(void *data,
struct sk_buff *skb;
struct device *d = tp_to_dev(tp);
- data = rtl8169_align(data);
dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
prefetch(data);
skb = napi_alloc_skb(&tp->napi, pkt_size);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] r8169: improve rx buffer allocation
2019-01-20 10:12 [PATCH net-next] r8169: improve rx buffer allocation Heiner Kallweit
@ 2019-01-22 22:52 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-01-22 22:52 UTC (permalink / raw)
To: hkallweit1; +Cc: nic_swsd, netdev, edumazet
From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Sun, 20 Jan 2019 11:12:01 +0100
> 8 years ago, as part of 6f0333b8fde4 ("r8169: use 50% less ram for RX
> ring"), the alignment requirement for rx buffers was silently changed
> from 8 bytes to 16 bytes. I found nothing explaining this, also the
> chip specs I have only mention an 8 byte requirement.
> AFAICS kmalloc_node() guarantees allocated memory to be at least
> "long long" aligned, what is 8 bytes on a 32 bit machine.
> So we can take this memory as-is and avoid some overhead by changing
> the alignment requirement back to 8 bytes.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Applied.
It might have been for cache line alignment or something silly like
that. But totally undocumented.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-22 22:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-20 10:12 [PATCH net-next] r8169: improve rx buffer allocation Heiner Kallweit
2019-01-22 22:52 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).