为什么LuaJIT的内存在64位平台上限制为1-2 GB?

前端之家收集整理的这篇文章主要介绍了为什么LuaJIT的内存在64位平台上限制为1-2 GB?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在64位平台上,LuaJIT仅允许最多1-2GB的数据(不计算使用malloc分配的对象).这种限制来自何处,为什么这比32位平台还要少?

解决方法

LuaJIT旨在使用32位指针.在x64平台上,限制来自于使用 mmap和MAP_32BIT标志.

MAP_32BIT (since Linux 2.4.20,2.6):

Put the mapping into the first 2 Gigabytes of the process address space. This flag is supported only on x86-64,for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2GB of memory,so as to improve context-switch performance on some early 64-bit processors.

基本上使用此标志限制为前31位,而不是名称建议的前32位.在Linux内核中使用MAP_32BIT查看here以获得1GB限制的概述.

即使你的内容超过1GB,LuaJIT作者也解释了为什么这对性能有害:

  • A full GC takes 50% more time than the allocations themselves.
  • If the GC is enabled,it doubles the allocation time.
  • To simulate a real application,the links between objects are randomized in the third run. This doubles the GC time!

And that was just for 1GB! Now imagine using 8GB — a full GC cycle would keep the cpu busy for a whopping 24 seconds!
Ok,so the normal mode is to use the incremental GC. But this just means the overhead is ~30% higher,it’s mixed in between the allocations and it will evict the cpu cache every time. Basically your application will be dominated by the GC overhead and you’ll begin to wonder why it’s slow ….

tl;dr version: Don’t try this at home. And the GC needs a rewrite (postponed to LuaJIT 2.1).

总而言之,1GB限制是Linux内核和LuaJIT垃圾收集器的限制.这仅适用于LuaJIT状态内的对象,可以通过使用malloc来克服,malloc将在较低的32位地址空间之外进行分配.此外,它可以在32位模式下在x64上使用x86构建,并可以访问完整的4GB.

查看这些链接获取更多信息:

> How to get past 1gb memory limit of 64 bit LuaJIT on Linux?
> LuaJIT x64 limited to 31 bit address space,even without MAP_32BIT restrictions?
> LuaJIT strange memory limit
> Digging out the craziest bug you never heard about from 2008: a linux threading regression

原文链接:https://www.f2er.com/lua/274452.html

猜你在找的Lua相关文章