Skip to content

Commit

Permalink
Allocate sendq/recvq/eventqs as separated vmallocs
Browse files Browse the repository at this point in the history
Will reduce vmalloc requirements.
  • Loading branch information
Brice Goglin committed Oct 23, 2010
1 parent ba90576 commit 615d3d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
4 changes: 0 additions & 4 deletions TODO
Expand Up @@ -2,10 +2,6 @@
+ keep something large enough to avoid wrap-arounds
* sort endpoint eventq fields for better locality

* split the allocating of sendq/recvq/eventqs into separated vmalloc
and page-align them to remove restrictions on mmapping length
+ and this will slightly reduce vmalloc requirements

* dynamically alloc the sendq_map index array out of the medium request?

* drop the mmapped jiffies
Expand Down
52 changes: 34 additions & 18 deletions driver/linux/omx_dev.c
Expand Up @@ -45,7 +45,6 @@ omx_endpoint_alloc_resources(struct omx_endpoint * endpoint)
{
struct page ** sendq_pages, ** recvq_pages;
struct omx_endpoint_desc *userdesc;
char * buffer;
int i;
int ret;

Expand All @@ -65,20 +64,31 @@ omx_endpoint_alloc_resources(struct omx_endpoint * endpoint)

/* alloc and init user queues */
ret = -ENOMEM;
buffer = omx_vmalloc_user(OMX_SENDQ_SIZE + OMX_RECVQ_SIZE + OMX_EXP_EVENTQ_SIZE + OMX_UNEXP_EVENTQ_SIZE);
if (!buffer) {
printk(KERN_ERR "Open-MX: failed to allocate queues\n");
endpoint->sendq = omx_vmalloc_user(OMX_SENDQ_SIZE);
if (!endpoint->sendq) {
printk(KERN_ERR "Open-MX: failed to allocate sendq\n");
goto out_with_desc;
}
endpoint->sendq = buffer;
endpoint->recvq = endpoint->sendq + OMX_SENDQ_SIZE;
endpoint->exp_eventq = endpoint->recvq + OMX_RECVQ_SIZE;
endpoint->unexp_eventq = endpoint->exp_eventq + OMX_EXP_EVENTQ_SIZE;
endpoint->recvq = omx_vmalloc_user(OMX_RECVQ_SIZE);
if (!endpoint->recvq) {
printk(KERN_ERR "Open-MX: failed to allocate recvq\n");
goto out_with_sendq;
}
endpoint->exp_eventq = omx_vmalloc_user(OMX_EXP_EVENTQ_SIZE);
if (!endpoint->exp_eventq) {
printk(KERN_ERR "Open-MX: failed to allocate exp eventq\n");
goto out_with_recvq;
}
endpoint->unexp_eventq = omx_vmalloc_user(OMX_UNEXP_EVENTQ_SIZE);
if (!endpoint->unexp_eventq) {
printk(KERN_ERR "Open-MX: failed to allocate unexp eventq\n");
goto out_with_exp_eventq;
}

sendq_pages = kmalloc(OMX_SENDQ_SIZE/PAGE_SIZE * sizeof(struct page *), GFP_KERNEL);
if (!sendq_pages) {
printk(KERN_ERR "Open-MX: failed to allocate sendq pages array\n");
goto out_with_userq;
goto out_with_unexp_eventq;
}
for(i=0; i<OMX_SENDQ_SIZE/PAGE_SIZE; i++) {
struct page * page;
Expand Down Expand Up @@ -119,8 +129,14 @@ omx_endpoint_alloc_resources(struct omx_endpoint * endpoint)

out_with_sendq_pages:
kfree(endpoint->sendq_pages);
out_with_userq:
vfree(endpoint->sendq); /* recvq and eventq are in the same buffer */
out_with_unexp_eventq:
vfree(endpoint->unexp_eventq);
out_with_exp_eventq:
vfree(endpoint->exp_eventq);
out_with_recvq:
vfree(endpoint->recvq);
out_with_sendq:
vfree(endpoint->sendq);
out_with_desc:
vfree(endpoint->userdesc);
out:
Expand All @@ -136,7 +152,10 @@ omx_endpoint_free_resources(struct omx_endpoint * endpoint)

kfree(endpoint->recvq_pages);
kfree(endpoint->sendq_pages);
vfree(endpoint->sendq); /* recvq, exp_eventq and unexp_eventq are in the same buffer */
vfree(endpoint->unexp_eventq);
vfree(endpoint->exp_eventq);
vfree(endpoint->recvq);
vfree(endpoint->sendq);
vfree(endpoint->userdesc);

#ifdef OMX_HAVE_DMA_ENGINE
Expand Down Expand Up @@ -765,20 +784,17 @@ omx_miscdev_mmap(struct file * file, struct vm_area_struct * vma)
} else if (offset == OMX_RECVQ_FILE_OFFSET && size == OMX_RECVQ_SIZE) { /* page-alignment enforced at init */
if (vma->vm_flags & VM_WRITE) /* may open for writing but cannot mmap for writing */
return -EPERM;
return omx_remap_vmalloc_range(vma, endpoint->sendq,
OMX_SENDQ_SIZE >> PAGE_SHIFT);
return omx_remap_vmalloc_range(vma, endpoint->recvq, 0);

} else if (offset == OMX_EXP_EVENTQ_FILE_OFFSET && size == OMX_EXP_EVENTQ_SIZE) { /* page-alignment enforced at init */
if (vma->vm_flags & VM_WRITE) /* may open for writing but cannot mmap for writing */
return -EPERM;
return omx_remap_vmalloc_range(vma, endpoint->sendq,
(OMX_SENDQ_SIZE + OMX_RECVQ_SIZE) >> PAGE_SHIFT);
return omx_remap_vmalloc_range(vma, endpoint->exp_eventq, 0);

} else if (offset == OMX_UNEXP_EVENTQ_FILE_OFFSET && size == OMX_UNEXP_EVENTQ_SIZE) { /* page-alignment enforced at init */
if (vma->vm_flags & VM_WRITE) /* may open for writing but cannot mmap for writing */
return -EPERM;
return omx_remap_vmalloc_range(vma, endpoint->sendq,
(OMX_SENDQ_SIZE + OMX_RECVQ_SIZE + OMX_EXP_EVENTQ_SIZE) >> PAGE_SHIFT);
return omx_remap_vmalloc_range(vma, endpoint->unexp_eventq, 0);

} else {
printk(KERN_ERR "Open-MX: Cannot mmap 0x%lx at 0x%lx\n", size, offset);
Expand Down

0 comments on commit 615d3d2

Please sign in to comment.