openzfsonosx / spl

Solaris Porting Layer for OpenZFS on OS X
https://openzfsonosx.org/
Other
117 stars 28 forks source link

Future allocator enhancements #5

Closed brendonhumphrey closed 10 years ago

brendonhumphrey commented 10 years ago

Thoughts on some work to be done to the allocator as time arises:

lundman commented 10 years ago

To use built in lists, you do code like

/* Create list */
        list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
            offsetof(znode_t, z_link_node));
/* The list name is then z_all_znodes, which is a list of type znode_t, and inside znode_t
 * the "next,prev" private element is called "z_link_node". The offsetof does the math to work out
 * the offset to the private data inside the struct znode_t
 */

struct z_node_t {
/* your fields */
    list_node_t     z_link_node;  /* list's private node */
};

/* Allocating a new znode_t sutrct ,call */
        list_link_init(&zp->z_link_node);

/* Freeing a node, nothing is required, but you can do sanity */
        ASSERT(!list_link_active(&zp->z_link_node));

/* Freeing the list */
        list_destroy(&zfsvfs->z_all_znodes);

/* list API, should be protected by mutex or similar */
        list_insert_tail(&zfsvfs->z_all_znodes, zp);

        list_remove(&zfsvfs->z_all_znodes, zp);

        zp = list_head(&zfsvfs->z_reclaim_znodes);