Patchwork [net-next-2.6,3/8] vxge: Align the memory only if it is misaligned.

login
register
mail settings
Submitter Sreenivasa Honnur
Date March 29, 2010, 8:09 a.m.
Message ID <Pine.GSO.4.10.11003290409080.4435-100000@guinness>
Download mbox | patch
Permalink /patch/48814/
State Accepted
Delegated to: David Miller
Headers show

Comments

Sreenivasa Honnur - March 29, 2010, 8:09 a.m.
- Align the memory only if it is misaligned.

Signed-off-by: Sreenivasa Honnur <sreenivasa.honnur@neterion.com>
Signed-off-by: Ramkrishna Vepa <ram.vepa@neterion.com>
---

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - March 29, 2010, 11:59 p.m.
From: Sreenivasa Honnur <Sreenivasa.Honnur@neterion.com>
Date: Mon, 29 Mar 2010 04:09:47 -0400 (EDT)

> - Align the memory only if it is misaligned.
> 
> Signed-off-by: Sreenivasa Honnur <sreenivasa.honnur@neterion.com>
> Signed-off-by: Ramkrishna Vepa <ram.vepa@neterion.com>

Applied, but this vxge_os_dma_malloc code is completely
unnecessary.

If you want to allocate 4K chunks and make sure they are at least 128
byte aligned, you can allocated pages (which are always PAGE_SIZE
aligned) and chop them up into the appropriate block size as needed.

This is exactly how drivers/net/niu.c handles this situation.

See drivers/net/niu.c:niu_rbr_add_page()
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ramkrishna Vepa - March 30, 2010, 12:04 a.m.
> From: Sreenivasa Honnur <Sreenivasa.Honnur@neterion.com>
> Date: Mon, 29 Mar 2010 04:09:47 -0400 (EDT)
> 
> > - Align the memory only if it is misaligned.
> >
> > Signed-off-by: Sreenivasa Honnur <sreenivasa.honnur@neterion.com>
> > Signed-off-by: Ramkrishna Vepa <ram.vepa@neterion.com>
> 
> Applied, but this vxge_os_dma_malloc code is completely
> unnecessary.
> 
> If you want to allocate 4K chunks and make sure they are at least 128
> byte aligned, you can allocated pages (which are always PAGE_SIZE
> aligned) and chop them up into the appropriate block size as needed.
> 
> This is exactly how drivers/net/niu.c handles this situation.
> 
> See drivers/net/niu.c:niu_rbr_add_page()
Thanks. We'll make this change.

Ram
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ramkrishna Vepa - April 1, 2010, 10:05 p.m.
> If you want to allocate 4K chunks and make sure they are at least 128
> byte aligned, you can allocated pages (which are always PAGE_SIZE
> aligned) and chop them up into the appropriate block size as needed.
> 
> This is exactly how drivers/net/niu.c handles this situation.
> 
> See drivers/net/niu.c:niu_rbr_add_page()
Thanks Dave! There's quite a bit of change required in the driver for
this. We'll submit the current set of patches we are working on and then
look into submitting this change.

Ram
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff -urpN patch2/drivers/net/vxge/vxge-config.h patch3/drivers/net/vxge/vxge-config.h
--- patch2/drivers/net/vxge/vxge-config.h	2010-03-19 16:08:43.000000000 +0530
+++ patch3/drivers/net/vxge/vxge-config.h	2010-03-22 12:15:04.000000000 +0530
@@ -1914,20 +1914,32 @@  static inline void *vxge_os_dma_malloc(s
 	gfp_t flags;
 	void *vaddr;
 	unsigned long misaligned = 0;
+	int realloc_flag = 0;
 	*p_dma_acch = *p_dmah = NULL;
 
 	if (in_interrupt())
 		flags = GFP_ATOMIC | GFP_DMA;
 	else
 		flags = GFP_KERNEL | GFP_DMA;
-
-	size += VXGE_CACHE_LINE_SIZE;
-
+realloc:
 	vaddr = kmalloc((size), flags);
 	if (vaddr == NULL)
 		return vaddr;
-	misaligned = (unsigned long)VXGE_ALIGN(*((u64 *)&vaddr),
+	misaligned = (unsigned long)VXGE_ALIGN((unsigned long)vaddr,
 				VXGE_CACHE_LINE_SIZE);
+	if (realloc_flag)
+		goto out;
+
+	if (misaligned) {
+		/* misaligned, free current one and try allocating
+		 * size + VXGE_CACHE_LINE_SIZE memory
+		 */
+		kfree((void *) vaddr);
+		size += VXGE_CACHE_LINE_SIZE;
+		realloc_flag = 1;
+		goto realloc;
+	}
+out:
 	*(unsigned long *)p_dma_acch = misaligned;
 	vaddr = (void *)((u8 *)vaddr + misaligned);
 	return vaddr;