Permalink
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
Shinpei Kato
Shinpei Kato committed Sep 6, 2012
2 parents 776beea + a7b06c4 commit bc7179383cb21da13a0364c47744517c5191f59a
Showing with 27 additions and 14 deletions.
  1. +0 −12 common/gdev_api.c
  2. +27 −1 common/gdev_nvidia_mem.c
  3. +0 −1 common/gdev_nvidia_shm.c
View
@@ -737,9 +737,6 @@ uint64_t gmalloc(struct gdev_handle *h, uint64_t size)
}
}
- /* size could have been rounded up. */
- gdev->mem_used += gdev_mem_getsize(mem);
-
return gdev_mem_getaddr(mem);
fail:
@@ -752,7 +749,6 @@ uint64_t gmalloc(struct gdev_handle *h, uint64_t size)
*/
uint64_t gfree(struct gdev_handle *h, uint64_t addr)
{
- struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
uint64_t size;
@@ -762,8 +758,6 @@ uint64_t gfree(struct gdev_handle *h, uint64_t addr)
size = gdev_mem_getsize(mem);
gdev_mem_free(mem);
- gdev->mem_used -= size;
-
return size;
fail:
@@ -785,9 +779,6 @@ void *gmalloc_dma(struct gdev_handle *h, uint64_t size)
else if (!(mem = gdev_mem_alloc(vas, size, GDEV_MEM_DMA)))
goto fail;
- /* size could have been rounded up. */
- gdev->dma_mem_used += gdev_mem_getsize(mem);
-
return gdev_mem_getbuf(mem);
fail:
@@ -800,7 +791,6 @@ void *gmalloc_dma(struct gdev_handle *h, uint64_t size)
*/
uint64_t gfree_dma(struct gdev_handle *h, void *buf)
{
- struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
uint64_t size;
@@ -810,8 +800,6 @@ uint64_t gfree_dma(struct gdev_handle *h, void *buf)
size = gdev_mem_getsize(mem);
gdev_mem_free(mem);
- gdev->dma_mem_used -= size;
-
return size;
fail:
View
@@ -136,6 +136,7 @@ void gdev_mem_unlock_all(struct gdev_vas *vas)
/* allocate a new memory object. */
struct gdev_mem *gdev_mem_alloc(struct gdev_vas *vas, uint64_t size, int type)
{
+ struct gdev_device *gdev = vas->gdev;
struct gdev_mem *mem;
switch (type) {
@@ -155,6 +156,17 @@ struct gdev_mem *gdev_mem_alloc(struct gdev_vas *vas, uint64_t size, int type)
gdev_nvidia_mem_setup(mem, vas, type);
gdev_nvidia_mem_list_add(mem);
+ /* update the size of memory used on the gdev device; mem->size
+ * could have been rounded up */
+ gdev_mutex_lock(&gdev->shm_mutex);
+ if (type == GDEV_MEM_DEVICE) {
+ gdev->mem_used += mem->size;
+ }
+ else {
+ gdev->dma_mem_used += mem->size;
+ }
+ gdev_mutex_unlock(&gdev->shm_mutex);
+
return mem;
fail:
@@ -173,6 +185,9 @@ struct gdev_mem *gdev_mem_share(struct gdev_vas *vas, uint64_t size)
goto fail;
gdev_mutex_unlock(&gdev->shm_mutex);
+ /* gdev->mem_used does not have to be updated, since the size of
+ * available device memory did not change after a memory sharing */
+
return new;
fail:
@@ -185,18 +200,29 @@ void gdev_mem_free(struct gdev_mem *mem)
{
struct gdev_vas *vas = mem->vas;
struct gdev_device *gdev = vas->gdev;
+ int mem_size_freed = mem->size;
/* if the memory object is associated with shared memory, detach the
shared memory. note that the memory object will be freed if users
become zero.
free the memroy object otherwise. */
gdev_mutex_lock(&gdev->shm_mutex);
- if (mem->shm)
+ if (mem->shm) {
+ /* if # of shm users > 1, the buffer object won't be freed yet,
+ * so the size of available device memory won't change */
+ if(mem->type == GDEV_MEM_DEVICE && mem->shm->users > 1)
+ mem_size_freed = 0;
gdev_shm_detach(mem);
+ }
else {
gdev_nvidia_mem_list_del(mem);
gdev_raw_mem_free(mem);
}
+
+ if(mem->type == GDEV_MEM_DEVICE)
+ gdev->mem_used -= mem_size_freed;
+ else
+ gdev->dma_mem_used -= mem_size_freed;
gdev_mutex_unlock(&gdev->shm_mutex);
}
View
@@ -310,7 +310,6 @@ struct gdev_mem *gdev_shm_attach(struct gdev_vas *vas, struct gdev_mem *mem, uin
fail_swap:
gdev_raw_mem_unshare(new);
fail_shm:
- mem->shm->users--;
fail_heap:
fail_victim:

0 comments on commit bc71793

Please sign in to comment.