summaryrefslogtreecommitdiff
path: root/linux-core/drm_hashtab.c
diff options
context:
space:
mode:
authorThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2006-08-21 17:02:44 +0200
committerThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2006-08-21 17:02:44 +0200
commit11f9e404fb66927146de30227fa05c5485aa1726 (patch)
treedc3a4f3b3baf125c1ded30ddf54b1d13940c39c8 /linux-core/drm_hashtab.c
parent0316f93d51abc52b816e936e0ece304ac47799c3 (diff)
Avoid using vmalloc for small hash tables.
Diffstat (limited to 'linux-core/drm_hashtab.c')
-rw-r--r--linux-core/drm_hashtab.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/linux-core/drm_hashtab.c b/linux-core/drm_hashtab.c
index 48061139..40599227 100644
--- a/linux-core/drm_hashtab.c
+++ b/linux-core/drm_hashtab.c
@@ -43,7 +43,16 @@ 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->table = NULL;
+ ht->use_vmalloc = ((ht->size * sizeof(*ht->table)) > 4*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 +192,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;
}
}