将代码保存在 L1 缓存中
我一直在阅读 维基百科关于 K 编程语言的文章,这就是我所看到的:
解释器的小尺寸和语言的紧凑语法使得 K 个应用程序完全适合处理器的 1 级缓存。
我很好奇。 怎么可能把整个程序都放在一级缓存里呢? 比如说,CPU 有 256kb L1 缓存。 假设我的程序远小于此,并且它需要很少的内存(例如,仅用于调用堆栈等)。 比如说,它不需要任何库(尽管如果程序用于操作系统,则需要包含 kernel32.dll 或其他库)。 操作系统不会自动为任何程序分配一些最小内存(好吧,对于可执行代码以及堆栈和堆)?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为他们所说的并不是整个程序都适合一级缓存,而是大部分时间运行的所有代码都适合一级缓存。
是的,操作系统分配了许多其他结构,但这些结构很少受到影响,因此并不重要。
当然,这都是猜测——我对“K”语言一无所知。
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.
我相信他们所说的优点是主要执行代码适合 L1 缓存; 无论分配给程序的内存如何。 一旦加载了 K 个应用程序,如果它从未接触过该内存,那么它是否根据性能进行分配(即完全位于 L1 缓存中的性能优势)并不重要。
I believe they are speaking to the advantage that the main executing code will fit in the L1 cache; regardless of the memory allocated to the program. Once the K application is loaded, if it never touches that memory then it doesn't matter if it's allocated in terms of performance (i.e. the perf benefit of being totally in L1 cache).
解释器作为操作系统管理的普通程序运行。 解释后的程序在解释器的内存空间内的数据段中运行。 许多 K 程序可以轻松地完全装入 L1 高速缓存,即使整个解释器可能无法装入。 不过,主解释器循环可能会适合。
The interpreter runs as a normal program managed by the OS. The interpreted program runs within the memory space of the interpreter, in the data segment. Many K programs may easily fit into the L1 cache completely, even though the entire interpreter may not. The main interpreter loop will probably fit though.
您将所有程序代码与最常执行的代码混淆了。
对于解释型语言来说,解释器核心无疑是最常执行的代码之一。 将最频繁执行的代码放在缓存中可以加快执行速度,就像将最频繁访问的数据放在缓存中一样。
关键部分是“最频繁”——没有必要缓存所有代码/数据才能看到显着的加速。
You confuse all the program code with the most frequently executed code.
For the interpreted languages the interpreter core is certainly among the most frequently executed code. Having most frequently executed code in cache speeds up execution the same way as having most frequently accessed data in cache does.
The key part is "most frequently" - it's not necessary to have all the code/data cached to see a significant acceleration.