video: tegra: nvmap: don't count shared memory in full
Krishna Reddy [Thu, 19 Jun 2014 23:10:23 +0000 (16:10 -0700)]
Don't count shared memory in full in iovmm stats.
Add SHARE field to allocations info to show how many
processes are sharing the handle.
Update few comments in the code.
Remove unnecessary iovm_commit accounting.

Bug 1529015

Change-Id: I49650bf081d652dedc7139f639aae6da06965ecd
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/426274
(cherry picked from commit 92d47c10fbf7a315d4c953bafb71ee23032b7f65)
Reviewed-on: http://git-master/r/448533
Tested-by: Winnie Hsu <whsu@nvidia.com>

drivers/video/tegra/nvmap/nvmap_dev.c
drivers/video/tegra/nvmap/nvmap_handle.c
drivers/video/tegra/nvmap/nvmap_priv.h

index 9b874d3..c0281fd 100644 (file)
@@ -386,8 +386,6 @@ struct nvmap_client *__nvmap_create_client(struct nvmap_device *dev,
        client->kernel_client = true;
        client->handle_refs = RB_ROOT;
 
-       atomic_set(&client->iovm_commit, 0);
-
        for (i = 0; i < dev->nr_carveouts; i++) {
                INIT_LIST_HEAD(&client->carveout_commit[i].list);
                client->carveout_commit[i].commit = 0;
@@ -837,6 +835,25 @@ static void allocations_stringify(struct nvmap_client *client,
        nvmap_ref_unlock(client);
 }
 
+static void nvmap_get_client_mss(struct nvmap_client *client,
+                                u64 *total, bool iovmm)
+{
+       struct rb_node *n;
+
+       *total = 0;
+       nvmap_ref_lock(client);
+       n = rb_first(&client->handle_refs);
+       for (; n != NULL; n = rb_next(n)) {
+               struct nvmap_handle_ref *ref =
+                       rb_entry(n, struct nvmap_handle_ref, node);
+               struct nvmap_handle *handle = ref->handle;
+               if (handle->alloc && handle->heap_pgalloc == iovmm)
+                       *total += handle->size /
+                                 atomic_read(&handle->share_count);
+       }
+       nvmap_ref_unlock(client);
+}
+
 static int nvmap_debug_allocations_show(struct seq_file *s, void *unused)
 {
        struct nvmap_carveout_node *node = s->private;
@@ -945,14 +962,14 @@ static int nvmap_debug_iovmm_clients_show(struct seq_file *s, void *unused)
        seq_printf(s, "%-18s %18s %8s %11s\n",
                "CLIENT", "PROCESS", "PID", "SIZE");
        list_for_each_entry(client, &dev->clients, list) {
-               int iovm_commit = atomic_read(&client->iovm_commit);
+               u64 client_total;
                client_stringify(client, s);
-               seq_printf(s, " %10uK\n", K(iovm_commit));
+               nvmap_get_client_mss(client, &client_total, true);
+               seq_printf(s, " %10lluK\n", K(client_total));
        }
        spin_unlock(&dev->clients_lock);
        nvmap_iovmm_get_total_mss(NULL, NULL, &total);
        seq_printf(s, "%-18s %18s %8s %10lluK\n", "total", "", "", K(total));
-       PRINT_MEM_STATS_NOTE(SIZE);
        return 0;
 }
 
@@ -971,16 +988,16 @@ static int nvmap_debug_iovmm_allocations_show(struct seq_file *s, void *unused)
                        "", "", "BASE", "SIZE", "FLAGS", "REFS",
                        "DUPES", "PINS", "SHARE", "UID");
        list_for_each_entry(client, &dev->clients, list) {
-               int iovm_commit = atomic_read(&client->iovm_commit);
+               u64 client_total;
                client_stringify(client, s);
-               seq_printf(s, " %10uK\n", K(iovm_commit));
+               nvmap_get_client_mss(client, &client_total, true);
+               seq_printf(s, " %10lluK\n", K(client_total));
                allocations_stringify(client, s, true);
                seq_printf(s, "\n");
        }
        spin_unlock(&dev->clients_lock);
        nvmap_iovmm_get_total_mss(NULL, NULL, &total);
        seq_printf(s, "%-18s %-18s %8s %10lluK\n", "total", "", "", K(total));
-       PRINT_MEM_STATS_NOTE(SIZE);
        return 0;
 }
 
index 40ebbb0..c38af6a 100644 (file)
@@ -272,15 +272,11 @@ static void alloc_handle(struct nvmap_client *client,
                }
        } else if (type & iovmm_mask) {
                int ret;
-               size_t reserved = PAGE_ALIGN(h->size);
 
-               atomic_add(reserved, &client->iovm_commit);
                ret = handle_page_alloc(client, h,
                        h->userflags & NVMAP_HANDLE_PHYS_CONTIG);
-               if (ret) {
-                       atomic_sub(reserved, &client->iovm_commit);
+               if (ret)
                        return;
-               }
                h->heap_pgalloc = true;
                mb();
                h->alloc = true;
@@ -420,9 +416,6 @@ void nvmap_free_handle(struct nvmap_client *client,
        client->handle_count--;
        atomic_dec(&ref->handle->share_count);
 
-       if (h->alloc && h->heap_pgalloc)
-               atomic_sub(h->size, &client->iovm_commit);
-
        if (h->alloc && !h->heap_pgalloc) {
                mutex_lock(&h->lock);
                nvmap_carveout_commit_subtract(client,
@@ -603,8 +596,6 @@ struct nvmap_handle_ref *nvmap_duplicate_handle(struct nvmap_client *client,
                        nvmap_heap_to_arg(nvmap_block_to_heap(h->carveout)),
                        h->size);
                mutex_unlock(&h->lock);
-       } else {
-               atomic_add(h->size, &client->iovm_commit);
        }
 
        atomic_set(&ref->dupes, 1);
index a3c45d8..6c63063 100644 (file)
@@ -239,7 +239,6 @@ struct nvmap_carveout_commit {
 struct nvmap_client {
        const char                      *name;
        struct rb_root                  handle_refs;
-       atomic_t                        iovm_commit;
        struct mutex                    ref_lock;
        bool                            kernel_client;
        atomic_t                        count;