4

I recently reads about the cache coloring of slab system and didn't understand. Why the cache coloring that adds various offsets to object in different slabs could enhance performance?

My initial guess is: the slab allocator with cache offsets, try to put first objects of slabs at memory of different cache color. If a client allocate N objects from these slabs, it will get N objects with N cache colors.

Is my guess correct or can someone give me more hints on this? thanks a lot,

Houcheng
  • 2,674
  • 25
  • 32

2 Answers2

6

I would suggest to go through "Understanding Linux virtual memory" book - slab allocator chapter. As it quotes,

The final task of the slab allocator is optimal hardware cache use. If there is space left over after objects are packed into a slab, the remaining space is used to color the slab. Slab coloring is a scheme that attempts to have objects in different slabs use different lines in the cache. By placing objects at a different starting offset within the slab, objects will likely use different lines in the CPU cache, which helps ensure that objects from the same slab cache will be unlikely to flush each other.

I think this answers your doubt.

0x07FC
  • 523
  • 1
  • 6
  • 33
0

I answer the same question in another question. You can refer to it.

https://stackoverflow.com/a/57345687/3762471

Victor Choy
  • 4,006
  • 28
  • 35