Caches in modules

From: Andreas Gruenbacher (a.gruenbacher@bestbits.at)
Date: Thu Feb 24 2000 - 01:08:58 EST


Hi,

I'm trying to implement a cache in a module.

Currently, the only way I see is to implement a cache with a fixed size. I'd
much prefer a cache similar to the dentry and inode caches, but there's no
mechanism to get the cache shrinked when memory fills up. (This needs to be
handled in mm/vmscan.c's do_try_to_free_pages).

What's the opinion towards adding register_cache() and unregister_cache()
functions so that user-defined caches can be shrunk automatically? Something
along these lines?

In some header file
-------------------

struct cache_definition {
        const char *name;
        int (*shrink)(int, unsigned int, struct zone_struct *);
        struct list_head link;
};

extern void register_cache(struct cache_definition *);
extern void unregister_cache(struct cache_definition *);

Somewhere in mm/vmscan.c
------------------------

static LIST_HEAD(cache_definitions);

void register_cache(struct cache_definition *cache)
{
        list_add(&cache->link, &cache_definitions);
}

void unregister_cache(struct cache_definition *cache)
{
        list_del(&cache->link);
}

In do_try_to_free_pages():
--------------------------

struct list_head *cl;
for (cl=cache_definitions.next;
     cl != &cache_definitions;
     cl = cl->next) {
        struct cache_definition *cache =
                list_entry(cl, struct cache_definition, link);
        count -= cache->shrink(priority, gfp_mask, zone);
}
if (count < 0)
        goto done;

Regards,
Andreas

------------------------------------------------------------------------
 Andreas Gruenbacher, a.gruenbacher@computer.org
 Contact information: http://www.bestbits.at/~agruenba

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:09 EST