[lkml]   [2007]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: [PATCH] slab: deal with NULL pointers passed to kmem_cache_free
    On Mon, 19 March 2007 14:10:38 -0700, Andrew Morton wrote:
    > Would prefer to do:
    > static inline void kmem_cache_free_if_not_null(struct kmem_cache *cachep,
    > void *objp)
    > {
    > if (objp)
    > kmem_cache_free(cachep, objp);
    > }
    > so that we don't add extra overhead to all the thousands of existing,
    > well-behaved callsites.

    In principle, this would work. But two things need changing, imho:
    1. Don't inline the function. kmem_cache_free() has only about 34 NULL
    callers, if my grep is reliable, so this case is arguable. But in
    general, out-of-line functions are better than many extra
    conditionals pulled in through the inline one.
    2. Switch the names. According to Rusty's benchmark, the easiest way to
    use and interface should be the correct one. Every new driver
    written by a rookie will call kmem_cache_free(), simply because the
    name seems simpler.

    void kmem_cache_free_fast(struct kmem_cache *cachep, void *objp)
    /* old kmem_cache_free() */

    void kmem_cache_free(struct kmem_cache *cachep, void *objp)
    if (likely(objp))
    kmem_cache_free_fast(cachep, objp);


    Correctness comes second.
    Features come third.
    Performance comes last.
    Maintainability is easily forgotten.
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2007-03-19 23:11    [W:0.046 / U:5.132 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site