28 questions
3
votes
3
answers
360
views
ArrayList vs LinkedList in terms of cache locality
How does cache locality impact the performance of ArrayList compared to LinkedList in Java?
I've often heard that ArrayList has an advantage in terms of cache locality, but I don't fully understand ...
1
vote
0
answers
82
views
Why does cache-friendly design matter in lock-free queues if threads trash their cache anyway?
I'm trying to understand the practical value of "cache-friendly" design in lock-free queues. I often see people go to great lengths to pad structures, align data, and avoid false sharing — ...
0
votes
0
answers
216
views
Pimpl idiom without pointer indirection?
I'm developing a C++ API and I want to hide private implementation details from the public interface. Currently, I'm employing the Pimpl idiom for this purpose. However, I'm also mindful of minimizing ...
0
votes
2
answers
134
views
Do different ways of initializing a Vec<T> create different memory layout?
fn main() {
let vec0 = vec![0; 10];
let mut vec1 = vec![];
for _ in 0..10 {
vec1.push(0);
}
assert_eq!(vec0.len(), vec1.len());
}
In this example, vec0 and vec1 are ...
0
votes
2
answers
271
views
Can a custom allocator improve cache locality for lists?
This is a rather hypothetical question.
I only have limited knowledge about how the cpu cache works.
I know a cpu loads subsequent bytes into the cache.
Since a list uses pointers/indirection into ...
-1
votes
2
answers
1k
views
Cache Locality - weight of TLB, Cache Lines, and ...?
From my understanding the constructs which give rise to the high level concept of "cache locality" are the following:
Translation Lookaside Buffer (TLB) for virtual memory translation. ...
3
votes
1
answer
92
views
Why is inserting sorted keys into std::set so much faster than inserting shuffled keys?
I was accidentally surprised to found that inserting sorted keys into std::set is much much faster than inserting shuffled keys. This is somewhat counterintuitive since a red-black tree (I verified ...
2
votes
2
answers
2k
views
Cache misses when accessing an array in nested loop
So I have this question from my professor, and I can not figure out why vector2 is faster and has less cache misses than vector1.
Assume that the code below is a valid compilable C code.
Vector2:
void ...
0
votes
1
answer
1k
views
Determining optimal block size for blocked matrix multiplication
I am trying to implement blocked (tiled) matrix multiplication on a single processor. I have read the literature on why blocking improves memory performance, but I just wanted to ask how to determine ...
1
vote
0
answers
454
views
Improving cache locality of binary search by doing local linear search?
Binary search of a sorted array may have poor cache locality, due to random access of memory, but linear search is slow for a large array. Is it possible to design a hybrid algorithm? For example, you ...
0
votes
0
answers
83
views
Cache locality considerations
I have been trying to get better awareness of cache locality. I produced the 2 code snippets to gain better understanding of the cache locality characteristics of both.
vector<int> v1(1000, some ...
1
vote
0
answers
48
views
Detect whether a cache line is reused due to spatial or temporal locality
Is there a practical tool to detect whether a cache line is reused (a cache miss is avoided) due to either spatial or temporal locality?
I could not find a related discussion in cachegrind.
I was able ...
2
votes
0
answers
73
views
In Apache Spark, how to make a task to always execute on the same machine?
In its simplest form, RDD is merely a placeholder of chained computations that can be arbitrarily scheduled to be executed on any machine:
val src = sc.parallelize(0 to 1000)
val rdd = src....
2
votes
2
answers
1k
views
Importance of padding in Dynamic Memory Allocation
I am trying to implement a heap (implicit free list with header/footer) and deciding on whether I should add padding to it. What are the tangible benefits of adding pads? I read that it somehow ...
0
votes
1
answer
585
views
Understanding data cache locality in mips code
I have been browsing stackoverflow could not really find a example regarding to this one. I understand the concept of Temporal and Spatial locality for data cache:
Temporarl locality: address ...
2
votes
0
answers
240
views
How to benchmark random access with JMH?
I was trying to observe the effects of CPU cache spatial locality by benchmarking sequential/random reads to an array with JMH. Interestingly, the results are almost the same.
So I wonder, is this ...
6
votes
2
answers
6k
views
Does _mm_clflush really flush the cache?
I'm trying to understand how the hardware cache works by writing and running a test program:
#include <stdio.h>
#include <stdint.h>
#include <x86intrin.h>
#define LINE_SIZE 64
#...
2
votes
1
answer
172
views
Why can't modern compilers optimize row-major order accesses in loops?
In the textbook Computer Systems: a Programmer's Perspective there are some impressive benchmarks for optimizing row-major order access.
I created a small program to test for myself if a simple ...
1
vote
0
answers
109
views
Java mechanical sympathy through thread pinning
Given we have an application that is heavily polluted with concurrency constructs, multiple techniques are used (different people worked without clear architecture in mind), multiple questionable ...
0
votes
3
answers
392
views
What is the difference in the Code Snippets?
I am a beginner in operating systems, and I am trying to understand some code snippets. Can you please explain to me the difference between these code snippets??
int sum_array_rows(int a[M][N])
{
...
3
votes
2
answers
2k
views
Understanding spatial and temporal locality
I was studying for my architecture final and came across the following lines of code:
for(i = 0; i <= N ;i++){
a[i] = b[i] + c[i];
}
The question is: "How does this code snippet demonstrate ...
0
votes
1
answer
1k
views
Cache effects and importance of locality
I have read this blog and I am still unsure about the importance of locality. Why is locality important for cache performance? Is it because it leads to fewer cache misses? Furthermore, how is a ...
5
votes
2
answers
1k
views
CPU spatial cache locality in array iteration
My understanding of the L1 cache was that a memory fetch loads a cache line. Assuming the cache line size is 64 bytes, if I access memory at address p, it will load the entire block from p to p + 64 ...
0
votes
1
answer
164
views
Ranges of nested for-loops when locality is improved (C++)
I have the following nested for loop:
int n = 8;
int counter = 0;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
printf("(%d, %d)\n", i, j);
counter++;
...
0
votes
1
answer
176
views
Apache Drill database and data locality
I have two servers. The first server (A) contains the zookeeper, a mongodb database and a drillbit. The second server (B) contains a hadoop distribution with several hive tables, a postgresql database ...
1
vote
5
answers
2k
views
data locality for implementing 2d array in c/c++
Long time ago, inspired by "Numerical recipes in C", I started to use the following construct for storing matrices (2D-arrays).
double **allocate_matrix(int NumRows, int NumCol)
{
double **x;
int ...
0
votes
1
answer
2k
views
C++ : vector of vector and cache locality
I am looking for a library/solution that will alleviate the rather important number of cache miss I am experiencing in my program
class Foo{
std::vector<Foo*> myVec;
// Rest of the ...
17
votes
4
answers
43k
views
Confused between Temporal and Spatial locality in real life code
I was reading this question, I wanted to ask more about the code that he showed i.e
for(i = 0; i < 20; i++)
for(j = 0; j < 10; j++)
a[i] = a[i]*j;
The questions are,
I understand ...