Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping your code in L1 cache

I have been reading Wikipedia's article on K programming language and this is what I saw:

The small size of the interpreter and compact syntax of the language makes it possible for K applications to fit entirely within the level 1 cache of the processor.

I am intrigued. How is it possible to have the whole program in L1 cache? Say, CPU has 256kb L1 cache. Say my program is way less than that and it needs a very little amount of memory (say, just for the call stack and such). Say, it doesn't need any libraries (although if a program is for an OS, it would need to include kernel32.dll or whatever). And doesn't OS automatically allocates some minimal memory for any program (well, for executable code and stack and heap)?

Thank you.

like image 575
pitr Avatar asked Jun 24 '09 18:06

pitr


People also ask

What is stored in L1 cache?

A level 1 cache (L1 cache) is a memory cache that is directly built into the microprocessor, which is used for storing the microprocessor's recently accessed information, thus it is also called the primary cache. It is also referred to as the internal cache or system cache.

Is more L1 cache better?

L1 cache memory has the lowest latency, being the fastest and closest to the core, and L3 has the highest. Memory cache latency increases when there is a cache miss as the CPU has to retrieve the data from the system memory. Latency continues to decrease as computers become faster and more efficient.

Is L1 cache faster than main memory?

CPUs often have a data cache, an instruction cache (for code), and a unified cache (for anything). Accessing these caches are much faster than accessing the RAM: Typically, the L1 cache is about 100 times faster than the RAM for data access, and the L2 cache is 25 times faster than RAM for data access.

Why is L1 cache so expensive?

L1 is closer to the processor, and is accessed on every memory access so its accesses are very frequent. Thus, it needs to return the data really fast (usually within on clock cycle). It also needs lots of read/write ports and high access bandwidth.


1 Answers

I think what they're saying is not that the entire program fits in L1 cache, but that all the code that runs most of the time fits in the L1 cache.

Yes, the OS allocates lots of other structures, but those are hit rarely enough to not matter.

Of course, this is all speculation -- I know nothing about the 'K' language.

like image 198
Jonathan Rupp Avatar answered Sep 28 '22 04:09

Jonathan Rupp