Ciaran McHale
Ciaran McHale

Reputation: 2244

Practical limits on prefetching a lot of reference data

I am considering doing the following:

I assume I'm not the first person to come up with such an idea. Can anybody offer advice on limitations I might run into? For example, consider the following pseudocode in the daemon process for keeping the reference data in the cache:

for (size_t i = 0; i < sizeof(referenceData); i += 64) {
    __builtin_prefetch(i + (void*)&referenceData);
}

For 50KB of reference data, the above loop would call __builtin_prefetch() 800 times in rapid succession. Would doing that cause problems, such as latency spikes when other applications try to accesses memory (other than the reference data)? If so, I could insert a sleep statement into the for-loop:

for (size_t i = 0; i < sizeof(referenceData); i += 64) {
    __builtin_prefetch(i + (char*)&referenceData);
    if (i % (64*10)) { // sleep every 10th time around the loop
        sleep_briefly();
    }
}

Advice and links to relevant sources of document are appreciated.

Edit to add additional information based on comments:

Upvotes: 2

Views: 171

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136355

A better and simpler solution is for the users of the reference data to load/cache that data in advance as they see fit.

Your process stomping the CPU cache doesn't appear reasonable at all.

On Intel you can use Cache Allocation Technology to reserve certain amount of L3 cache for your applications.

Upvotes: 2

Related Questions