]> err.no Git - linux-2.6/commitdiff
drm: port over use_vmalloc code from git hashtab
authorDave Airlie <airlied@linux.ie>
Sun, 18 Feb 2007 06:14:09 +0000 (17:14 +1100)
committerDave Airlie <airlied@linux.ie>
Sun, 11 Mar 2007 01:07:17 +0000 (12:07 +1100)
Signed-off-by: Dave Airlie <airlied@linux.ie>
drivers/char/drm/drm_hashtab.c
drivers/char/drm/drm_hashtab.h

index a0b2d6802ae4323c69908b3fb930798fa0650967..df0c48539ca451f58dcc28fb2a8ea2e6a1ab6fb5 100644 (file)
@@ -43,7 +43,15 @@ int drm_ht_create(drm_open_hash_t *ht, unsigned int order)
        ht->size = 1 << order;
        ht->order = order;
        ht->fill = 0;
-       ht->table = vmalloc(ht->size*sizeof(*ht->table));
+       ht->use_vmalloc = ((ht->size * sizeof(*ht->table)) > PAGE_SIZE);
+       if (!ht->use_vmalloc) {
+               ht->table = drm_calloc(ht->size, sizeof(*ht->table),
+                                      DRM_MEM_HASHTAB);
+       }
+       if (!ht->table) {
+               ht->use_vmalloc = 1;
+               ht->table = vmalloc(ht->size*sizeof(*ht->table));
+       }
        if (!ht->table) {
                DRM_ERROR("Out of memory for hash table\n");
                return -ENOMEM;
@@ -183,7 +191,11 @@ int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item)
 void drm_ht_remove(drm_open_hash_t *ht)
 {
        if (ht->table) {
-               vfree(ht->table);
+               if (ht->use_vmalloc)
+                       vfree(ht->table);
+               else
+                       drm_free(ht->table, ht->size * sizeof(*ht->table),
+                                DRM_MEM_HASHTAB);
                ht->table = NULL;
        }
 }
index 40afec05bff80fd37ec9e90332275cbcbfc263d6..613091c970af932775630b06a593ef4bfd6cab45 100644 (file)
@@ -47,6 +47,7 @@ typedef struct drm_open_hash{
        unsigned int order;
        unsigned int fill;
        struct hlist_head *table;
+       int use_vmalloc;
 } drm_open_hash_t;