From: Eric Dumazet <dada1@cosmosbay.com>
To: Michael Chan <mchan@broadcom.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
Matt Carlson <mcarlson@broadcom.com>,
Benjamin Li <benli@broadcom.com>
Subject: [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations
Date: Thu, 13 Nov 2008 06:49:14 +0100 [thread overview]
Message-ID: <491BBFDA.9000303@cosmosbay.com> (raw)
In-Reply-To: <1226531404-26118-5-git-send-email-mchan@broadcom.com>
[-- Attachment #1: Type: text/plain, Size: 825 bytes --]
Hi all
# grep bnx2 /proc/vmallocinfo
0xf8218000-0xf821a000 8192 bnx2_alloc_rx_mem+0x33/0x310 pages=1 vmalloc
0xf821b000-0xf821d000 8192 bnx2_alloc_rx_mem+0x33/0x310 pages=1 vmalloc
0xf8220000-0xf8234000 81920 bnx2_init_board+0x104/0xae0 phys=f6000000 ioremap
0xf8240000-0xf8254000 81920 bnx2_init_board+0x104/0xae0 phys=fa000000 ioremap
Any chance bnx2_alloc_rx_mem doesnt use vmalloc() to allocate less than a page of memory ?
Thank you
[PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations
Add two helper functions to allocate and free memory, using kzalloc() or vmalloc()
depending of the size of the allocation
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
drivers/net/bnx2.c | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
[-- Attachment #2: bnx2.patch --]
[-- Type: text/plain, Size: 2038 bytes --]
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 0853b3c..93c8256 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -523,6 +523,24 @@ bnx2_free_tx_mem(struct bnx2 *bp)
}
}
+static void *
+bnx2_alloc_kmem(size_t sz)
+{
+ if (sz <= PAGE_SIZE)
+ return kzalloc(sz, GFP_KERNEL);
+ else
+ return __vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+}
+
+static void
+bnx2_free_kmem(void *ptr, size_t sz)
+{
+ if (sz <= PAGE_SIZE)
+ kfree(ptr);
+ else
+ vfree(ptr);
+}
+
static void
bnx2_free_rx_mem(struct bnx2 *bp)
{
@@ -541,7 +559,8 @@ bnx2_free_rx_mem(struct bnx2 *bp)
rxr->rx_desc_ring[j] = NULL;
}
if (rxr->rx_buf_ring)
- vfree(rxr->rx_buf_ring);
+ bnx2_free_kmem(rxr->rx_buf_ring,
+ SW_RXBD_RING_SIZE * bp->rx_max_ring);
rxr->rx_buf_ring = NULL;
for (j = 0; j < bp->rx_max_pg_ring; j++) {
@@ -552,7 +571,8 @@ bnx2_free_rx_mem(struct bnx2 *bp)
rxr->rx_pg_desc_ring[i] = NULL;
}
if (rxr->rx_pg_ring)
- vfree(rxr->rx_pg_ring);
+ bnx2_free_kmem(rxr->rx_pg_ring,
+ SW_RXPG_RING_SIZE * bp->rx_max_pg_ring);
rxr->rx_pg_ring = NULL;
}
}
@@ -590,13 +610,10 @@ bnx2_alloc_rx_mem(struct bnx2 *bp)
int j;
rxr->rx_buf_ring =
- vmalloc(SW_RXBD_RING_SIZE * bp->rx_max_ring);
+ bnx2_alloc_kmem(SW_RXBD_RING_SIZE * bp->rx_max_ring);
if (rxr->rx_buf_ring == NULL)
return -ENOMEM;
- memset(rxr->rx_buf_ring, 0,
- SW_RXBD_RING_SIZE * bp->rx_max_ring);
-
for (j = 0; j < bp->rx_max_ring; j++) {
rxr->rx_desc_ring[j] =
pci_alloc_consistent(bp->pdev, RXBD_RING_SIZE,
@@ -607,13 +624,10 @@ bnx2_alloc_rx_mem(struct bnx2 *bp)
}
if (bp->rx_pg_ring_size) {
- rxr->rx_pg_ring = vmalloc(SW_RXPG_RING_SIZE *
- bp->rx_max_pg_ring);
+ rxr->rx_pg_ring = bnx2_alloc_kmem(SW_RXPG_RING_SIZE *
+ bp->rx_max_pg_ring);
if (rxr->rx_pg_ring == NULL)
return -ENOMEM;
-
- memset(rxr->rx_pg_ring, 0, SW_RXPG_RING_SIZE *
- bp->rx_max_pg_ring);
}
for (j = 0; j < bp->rx_max_pg_ring; j++) {
next prev parent reply other threads:[~2008-11-13 5:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
2008-11-13 0:01 ` David Miller
2008-11-12 23:10 ` [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU Michael Chan
2008-11-13 0:02 ` David Miller
2008-11-12 23:10 ` [PATCH net-next 4/5] bnx2: Reorganize timeout constants Michael Chan
2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
2008-11-13 0:03 ` David Miller
2008-11-13 5:49 ` Eric Dumazet [this message]
2008-11-13 6:49 ` [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations David Miller
2008-11-13 0:01 ` [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=491BBFDA.9000303@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=benli@broadcom.com \
--cc=davem@davemloft.net \
--cc=mcarlson@broadcom.com \
--cc=mchan@broadcom.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).