-#if defined (CONFIG_DEBUG_MEMORY) && defined(__KERNEL__)
-static spinlock_t obd_memlist_lock = SPIN_LOCK_UNLOCKED;
-static struct hlist_head *obd_memtable = NULL;
-static unsigned long obd_memtable_size = 0;
-
-static int lvfs_memdbg_init(int size)
-{
- struct hlist_head *head;
- int i;
-
- LASSERT(size > sizeof(sizeof(struct hlist_head)));
- obd_memtable_size = size / sizeof(struct hlist_head);
-
- CWARN("Allocating %lu memdbg entries.\n",
- (unsigned long)obd_memtable_size);
-
- LASSERT(obd_memtable == NULL);
- obd_memtable = kmalloc(size, GFP_KERNEL);
- if (!obd_memtable)
- return -ENOMEM;
-
- i = obd_memtable_size;
- head = obd_memtable;
- do {
- INIT_HLIST_HEAD(head);
- head++;
- i--;
- } while(i);
-
- return 0;
-}
-
-static int lvfs_memdbg_cleanup(void)
-{
- struct hlist_node *node = NULL, *tmp = NULL;
- struct hlist_head *head;
- struct obd_mem_track *mt;
- int i;
-
- spin_lock(&obd_memlist_lock);
- for (i = 0, head = obd_memtable; i < obd_memtable_size; i++, head++) {
- hlist_for_each_safe(node, tmp, head) {
- mt = hlist_entry(node, struct obd_mem_track, mt_hash);
- hlist_del_init(&mt->mt_hash);
- kfree(mt);
- }
- }
- spin_unlock(&obd_memlist_lock);
- kfree(obd_memtable);
- return 0;
-}
-
-static inline unsigned long const hashfn(void *ptr)
-{
- return (unsigned long)ptr &
- (obd_memtable_size - 1);
-}
-
-static void __lvfs_memdbg_insert(struct obd_mem_track *mt)
-{
- struct hlist_head *head = obd_memtable +
- hashfn(mt->mt_ptr);
- hlist_add_head(&mt->mt_hash, head);
-}
-
-void lvfs_memdbg_insert(struct obd_mem_track *mt)
-{
- spin_lock(&obd_memlist_lock);
- __lvfs_memdbg_insert(mt);
- spin_unlock(&obd_memlist_lock);
-}
-EXPORT_SYMBOL(lvfs_memdbg_insert);
-
-static void __lvfs_memdbg_remove(struct obd_mem_track *mt)
-{
- hlist_del_init(&mt->mt_hash);
-}
-
-void lvfs_memdbg_remove(struct obd_mem_track *mt)
-{
- spin_lock(&obd_memlist_lock);
- __lvfs_memdbg_remove(mt);
- spin_unlock(&obd_memlist_lock);
-}
-EXPORT_SYMBOL(lvfs_memdbg_remove);
-
-static struct obd_mem_track *__lvfs_memdbg_find(void *ptr)
-{
- struct hlist_node *node = NULL;
- struct obd_mem_track *mt = NULL;
- struct hlist_head *head;
-
- head = obd_memtable + hashfn(ptr);
-
- hlist_for_each(node, head) {
- mt = hlist_entry(node, struct obd_mem_track, mt_hash);
- if ((unsigned long)mt->mt_ptr == (unsigned long)ptr)
- break;
- mt = NULL;
- }
- return mt;
-}
-
-struct obd_mem_track *lvfs_memdbg_find(void *ptr)