Re: L1/L2 Cache Coloring from Userland ?

Larry McVoy (lm@cobaltmicro.com)
Thu, 18 Sep 1997 22:25:29 -0700


In a previous life I came up with the following hack which approximates
page coloring (my hack was in the swap system, a different area, but the
problems were quite similar).

Suppose you know all the page color stuff you need to, i.e., cache size,
associativity, etc. So that if you could do it, you had all the info
necessary to stuff pages in buckets and allocate them properly.

It's sort of a bitch to keep track of all that stuff and Linus has shot down
past attempts to do anything about because he doesn't want to screw up
page allocation performance.

What if: the pages were "sorted" on the free page list such that if an
allocation occurs then the pages allocated will be colored properly.
In other words, you don't think at alloca time, you think at free time.

To some extent this is robbing peter to pay paul so mebbe Linus will
shoot it down again but I thought I'd throw the idea out there.

: Hi all,
:
: Is there any way for a program to control or find out to which L1/L2 cache
: lines/regions certain areas of memory are mapped ? Take the following
: example:
:
: void DoProcessing(unsigned char *src, unsigned char *dest, int count) {
:
: char *t1 = malloc(256);
: char *t2 = malloc(256);
: char *t3 = malloc(256);
: int i;
:
: ... Init tables t1, t2 and t3
:
: for(i = 0; i < count; i+= 2) {
:
: dest[i] = t1[src[i]] + t2[src[i+1]];
: dest[i+1] = t2[src[i]] + t3[src[i + 1]];
:
: }
: }
:
: Performance-wise, it would be most unfortunate if any of t1, t2, t3, src or
: dest mapped to the same areas in cache. Can this be avoided ?
:
: Sincerely,
:
: Jan-Derk Bakker.
:
: Life. In order of importance: food, shelter and a pair of very loud speakers.
: