In computer science, cache coloring (also known as page coloring) is the process of attempting to allocate free pages that are contiguous from the CPU cache's point of view, in order to maximize the total number of pages cached by the processor. Cache coloring is typically employed by low-level dynamic memory allocation code in the operating system, when mapping virtual memory to physical memory. A virtual memory subsystem that lacks cache coloring is less deterministic with regard to cache performance, as differences in page allocation from one program run to the next can lead to large differences in program performance.

Details of operations

edit
Illustration of cache coloring. Left is virtual memory spaces, center is the physical memory space, and right is the CPU cache.

A physically indexed CPU cache is designed such that addresses in adjacent physical memory blocks take different positions ("cache lines") in the cache, but this is not the case when it comes to virtual memory; when virtually adjacent but not physically adjacent memory blocks are allocated, they could potentially both take the same position in the cache. Coloring is a technique implemented in memory management software, which solves this problem by selecting pages that do not contend with neighbor pages.

Physical memory pages are "colored" so that pages with different "colors" have different positions in CPU cache memory. When allocating sequential pages in virtual memory for processes, the kernel collects pages with different "colors" and maps them to the virtual memory. In this way, sequential pages in virtual memory do not contend for the same cache line.

Implementations

edit

This code adds a significant amount of complexity to the virtual memory allocation subsystem, but the result is well worth the effort.[1] Page coloring makes virtual memory as deterministic as physical memory with regard to cache performance. Page coloring is employed in operating systems such as Solaris,[2] FreeBSD,[1] NetBSD,[3] and Windows NT.[4]

References

edit
  1. ^ a b Matthew Dillon. "Page Coloring". Design elements of the FreeBSD VM system. FreeBSD Foundation. Retrieved 2007-02-02.
  2. ^ "Solaris Operating System What's New". Solaris marketing material. Sun Microsystems, Inc. Retrieved 2007-01-13.
  3. ^ Matt Thomas. "Improving NetBSD/mips" (PDF). Managing Page Colors. The NetBSD Foundation. Retrieved 2012-09-24.
  4. ^ Edouard Bugnion; Jennifer M. Anderson; Todd C. Mowry*; Mendel Rosenblum; Monica S. Lam. "Compiler Directed Page-Coloring for Multiprocessors". Stanford University. Retrieved 2009-10-06.
edit

📚 Artikel Terkait di Wikipedia

CPU cache

A CPU cache is a hardware cache used by the central processing unit (CPU) of a computer to reduce the average cost (time or energy) to access data from

Cache placement policies

associative cache. Associativity Cache replacement policy Cache hierarchy Writing Policies Cache coloring "The Basics of Cache" (PDF). "Cache Placement

Cache (computing)

perspective of neighboring layers. Cache coloring Cache hierarchy Cache-oblivious algorithm Cache stampede Cache language model Cache manifest in HTML5 Dirty bit

Register allocation

form, the graph coloring portion of the register allocation problem can be solved in linear time. What causes the general graph coloring problem to be NP-complete

Resource contention

S2CID 9202433. Zhang, Xiao (2009). "Towards practical page coloring-based multicore cache management". Proceedings of the 4th ACM European conference

National Register of Historic Places listings in Cache County, Utah

in Cache County, Utah. This is intended to be a complete list of the properties and districts on the National Register of Historic Places in Cache County

CPUID

describing any caches. In the below table, fields that are defined for leaf 4 but not for leaf 8000'001Dh are highlighted with yellow cell coloring and a (#4)

Distributed computing

as input to a computer. The computer program finds a coloring of the graph, encodes the coloring as a string, and outputs the result. Parallel algorithms