Modern computers have a lot of memory.
Each CPU has its cache, and each running program gets assigned its portion of system RAM.
There are many different ways this memory can be used and assigned.
Shared memory is a concept that affects both CPU caches and the use of system RAM in different ways.
L1 is the smallest and fastest cache, while L3 is the largest and slowest.
Many factors make the L1 cache faster than L3.
First of all, L1 memory cells are physically bigger.
Placing a cache block within the die area of a core comes with extra complexity on multicore CPUs.
Each has its benefits and drawbacks.
A shared cache is a cache that is available to multiple or all cores in a multicore CPU.
It does come at the cost of increased access time.
L3 cache tends to be shared between many cores, though sometimes not all.
L2 varies but can be local or shared depending on the specific CPU generation architecture.
Shared Memory in Software
In modern computers, the software doesnt get to address physical memory directly.
This helps to isolate memory for individual processes, which is helpful for security.
In some cases, it may be desirable to transfer data in memory from one process to another.
The most efficient way to do this is to allow the two processes to share memory space.
In this way, both processes can read the same data and communicate with each other.
This also helps to use system RAM efficiently as the data isnt duplicated.
Conclusion
Shared memory is the concept of having one section of memory accessible by multiple things.
This can be implemented in both hardware and software.
CPU cache may be shared between multiple processor cores.
This is especially the case for higher tiers of CPU cache.
The system memory may also be shared between various physical CPUs in a single larger system.
In software, shared memory can allow IPC Inter-Process Communication.
One process allocates memory as shared with one or more specific processes.
Those other processes can then access that memory location via virtual memory mapping.
Shared memory helps ensure efficient use of memory space by avoiding data duplication in a limited space.