On Fri, 2008-11-07 at 16:09 +0000, Mel Gorman wrote:
> @@ -179,6 +180,45 @@ void free_huge_pages(void *ptr)
>       fclose(fd);
>  }
> 
> +/*
> + * Offset the buffer using bytes wasted due to alignment to avoid using the
> + * same cache lines for the start of every buffer returned by
> + * get_huge_pages(). A small effort is made to select a random cacheline
> + * rather than sequential lines to give decent behaviour on average.
> + */
> +void *cachecolor(void *buf, size_t len, ghr_t flags, size_t wastage)

I would prefer if this function only be called when we know we want to
cache color.  Then you can remove the need to couple it to GHR flags
(and remove the flags param).  The name 'wastage' makes sense in the
context of alloc_hugepage_region(), but not so much sense here in the
parameter list.  How about 'free_space' or 'max_delta'?

> +{
> +     static long cacheline_size = 0;
> +     static int linemod = 0;
> +     char *bytebuf = (char *)buf;
> +     int numlines;
> +     int line = 0;
> +
> +     /* Only colour if requested */
> +     if (!(flags & GHR_COLOR))
> +             return buf;
> +
> +     /* Lookup our cacheline size once */
> +     if (cacheline_size == 0) {
> +             cacheline_size = sysconf(_SC_LEVEL2_CACHE_LINESIZE);
> +             linemod = time(NULL);
> +     }
> +
> +     numlines = wastage / cacheline_size;
> +     DEBUG("%d lines of cacheline size %ld due to %zd wastage\n",
> +             numlines, cacheline_size, wastage);
> +     if (numlines) {
> +             line = linemod % numlines;
> +             bytebuf += cacheline_size * line;
> +
> +             /* Pseudo-ish random line selection */
> +             linemod += len % numlines;
> +     }
> +     DEBUG("Using line offset %d from start\n", line);
> +
> +     return bytebuf;
> +}
> +
-- 
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to