- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
来自指南了解 linux 内核第 3 版,第 8.2.10 章,Slab 着色-
We know from Chapter 2 that the same hardware cache line maps many different blocks of RAM. In this chapter, we have also seen that objects of the same size end up being stored at the same offset within a cache. Objects that have the same offset within different slabs will, with a relatively high probability, end up mapped in the same cache line. The cache hardware might therefore waste memory cycles transferring two objects from the same cache line back and forth to different RAM locations, while other cache lines go underutilized. The slab allocator tries to reduce this unpleasant cache behavior by a policy called slab coloring : different arbitrary values called colors are assigned to the slabs.
(1) 我无法理解 slab 着色试图解决的问题。当正常进程访问数据时,如果它不在缓存中并且遇到缓存未命中,则将数据与进程尝试访问的数据周围地址的数据一起提取到缓存中以提高性能。怎么会发生相同的特定缓存行不断交换的情况?一个进程在两个不同内存区域的内存区域中不断访问相同偏移量的两个不同数据地址的可能性非常低。即使它确实发生了,缓存策略通常会根据某些议程(例如 LRU、随机等)选择要交换的行。不存在根据被访问地址的最低有效位匹配来选择逐出行的策略.
(2) 我无法理解 slab 着色如何解决缓存问题,它从 slab 的末尾到开头获取空闲字节,并导致不同的 slab 具有不同的偏移量-交换问题?
[SOLVED] 经过小型调查后,我相信我找到了问题的答案。答案已发布。
最佳答案
经过多次研究和思考,我得到的解释似乎更合理,而不仅仅是具体地址示例。首先,你必须学习缓存、标签、集合、线路分配等基础知识。
从linux内核代码可以确定colour_off的单位是cache_line_size。 colour_off
是基本偏移单元,colour
是struct kmem_cache
中colour_off的个数。
int __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
cachep->align = ralign;
cachep->colour_off = cache_line_size(); // colour_off's unit is cache_line_size
/* Offset must be a multiple of the alignment. */
if (cachep->colour_off < cachep->align)
cachep->colour_off = cachep->align;
.....
err = setup_cpu_cache(cachep, gfp);
https://elixir.bootlin.com/linux/v4.6/source/mm/slab.c#L2056
所以我们可以分两种情况来分析。 首先是缓存 > slab。 你看到 slab 1 slab2 slab3 ... 不可能发生碰撞,主要是因为缓存足够大,除了 slab1 和 slab5 可能发生碰撞。所以着色机制在提高性能的情况下并不是那么清晰。但是对于 slab1 和 slab5 我们只是忽略了解释它的原因,我相信你在阅读以下内容后会解决它。
第二个是slab > 缓存。 空行表示 color_off 或缓存行。很明显,slab1 和 slab2 不可能在 tick 和 slab2 slab3 标记的线上发生碰撞。我们确保着色机制优化两个相邻 slab 之间的两条线,更不用说 slab1 vs slab3 优化更多的线,2+2 = 4 线,你可以数一下。
总而言之,着色机制通过尽可能使用原本无用的内存来优化缓存性能(具体只是优化开头和结尾的一些 colour_off 行,而不是其他仍然可能发生冲突的行)。
关于Linux slab 分配器和缓存性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731933/
我阅读了有关 JSR 107 缓存 (JCache) 的内容。 我很困惑:据我所知,每个 CPU 都管理其缓存内存(无需操作系统的任何帮助)。 那么,为什么我们需要 Java 缓存处理程序? (如果C
好吧,我是 jQuery 的新手。我一直在这里和那里搞乱一点点并习惯它。我终于明白了(它并不像某些人想象的那么难)。因此,鉴于此链接:http://jqueryui.com/sortable/#dis
我正在使用 Struts 2 和 Hibernate。我有一个简单的表,其中包含一个日期字段,用于存储有关何时发生特定操作的信息。这个日期值显示在我的 jsp 中。 我遇到的问题是hibernate更
我有点不确定这里发生了什么,但是我试图解释正在发生的事情,也许一旦我弄清楚我到底在问什么,就可能写一个更好的问题。 我刚刚安装了Varnish,对于我的请求时间来说似乎很棒。这是一个Magneto 2
解决 Project Euler 的问题后,我在论坛中发现了以下 Haskell 代码: fillRow115 minLength = cache where cache = ((map fill
我正试图找到一种方法来为我网络上的每台计算机缓存或存储某些 python 包。我看过以下解决方案: pypicache但它不再被积极开发,作者推荐 devpi,请参见此处:https://bitbuc
我想到的一个问题是可以从一开始就缓存网络套接字吗?在我的拓扑中,我在通过双 ISP 连接连接到互联网的 HAProxy 服务器后面有 2 个 Apache 服务器(带有 Google PageSpee
我很难说出不同缓存区域 (OS) 之间的区别。我想简要解释一下磁盘\缓冲区\交换\页面缓存。他们住在哪里?它们之间的主要区别是什么? 据我了解,页面缓存是主内存的一部分,用于存储从 I/O 设备获取的
1.题目 请你为最不经常使用(LFU)缓存算法设计并实现数据结构。 实现 LFUCache 类: LFUCache(int capacity) - 用数据结构的容量 capacity 初始化对象 in
1.题目 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类: ① LRUCache(int capacity) 以正整数作为容量 capacity
我想在访问该 View 时关闭某些页面的缓存。它适用于简单查询模型对象的页面。 好像什么时候 'django.middleware.cache.FetchFromCacheMiddleware', 启
documents为 ExePackage element state Cache属性的目的是 Whether to cache the package. The default is "yes".
我知道 docker 用图层存储每个图像。如果我在一台开发服务器上有多个用户,并且每个人都在运行相同的 Dockerfile,但将镜像存储为 user1_myapp . user2 将其存储为 use
在 Codeigniter 中没有出现缓存问题几年后,我发现了一个问题。我在其他地方看到过该问题,但没有适合我的解决方案。 例如,如果我在 View 中更改一些纯 html 文本并上传新文件并按 F5
我在 Janusgraph 文档中阅读了有关 Janusgraph Cache 的内容。关于事务缓存,我几乎没有怀疑。我在我的应用程序中使用嵌入式 janusgrah 服务器。 如果我只对例如进行读取
我想知道是否有来自终端的任何命令可以用来匹配 Android Studio 中执行文件>使缓存无效/重新启动的使用。 谢谢! 最佳答案 According to a JetBrains employe
我想制作一个 python 装饰器来内存函数。例如,如果 @memoization_decorator def add(a, b, negative=False): print "Com
我经常在 jQuery 事件处理程序中使用 $(this) 并且从不缓存它。如果我愿意的话 var $this = $(this); 并且将使用变量而不是构造函数,我的代码会获得任何显着的额外性能吗?
是的,我要说实话,我不知道varnish vcl,我可以解决一些基本问题,但是我不太清楚,这就是为什么我遇到问题了。 我正在尝试通过http请求设置缓存禁止,但是该请求不能通过DNS而是通过 Varn
在 WP 站点上加载约 4000 个并发用户时遇到此问题。 这是我的配置: F5 负载均衡器 ---> Varnish 4,8 核,32 Gb RAM ---> 9 个后端,4 个核,每个 16 RA
我是一名优秀的程序员,十分优秀!