- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
POSIX.1 2008 specifies setrlimit()
和 getrlimit()
函数。为 resource
参数提供了各种常量,其中一些在下面复制以便更容易理解我的问题。
The following resources are defined:
(...)
RLIMIT_DATA
This is the maximum size of a data segment of the process, in bytes. If this limit is exceeded, the malloc() function shall fail with errno set to [ENOMEM].
(...)
RLIMIT_STACK
This is the maximum size of the initial thread's stack, in bytes. The implementation does not automatically grow the stack beyond this limit. If this limit is exceeded, SIGSEGV shall be generated for the thread. If the thread is blocking SIGSEGV, or the process is ignoring or catching SIGSEGV and has not made arrangements to use an alternate stack, the disposition of SIGSEGV shall be set to SIG_DFL before it is generated.
RLIMIT_AS
This is the maximum size of total available memory of the process, in bytes. If this limit is exceeded, the malloc() and mmap() functions shall fail with errno set to [ENOMEM]. In addition, the automatic stack growth fails with the effects outlined above.
此外,POSIX.1 2008 defines 数据段如下:
3.125 Data Segment
Memory associated with a process, that can contain dynamically allocated data.
我了解 RLMIT_DATA
资源传统上用于表示可以通过 brk()
函数分配给进程的最大内存量。 POSIX.1 的最新版本不再指定此函数,并且许多操作系统(例如 Mac OS X)不支持将此函数作为系统调用。相反,它是用 mmap()
的变体来模拟的,它不是 POSIX.1 2008 的一部分。
我对 RLIMIT_DATA
资源的语义和使用有点困惑。以下是我的具体问题:
栈可以按照本规范作为数据段的一部分吗?
标准中关于 RLIMIT_DATA
的说法是:“如果超出此限制,malloc() 函数将失败,并将 errno 设置为 [ENOMEM]。”这是否意味着用 malloc()
分配的内存必须是数据段的一部分?
在 Linux 上,使用 mmap()
分配的内存不计入数据段。只有用 brk()
或 sbrk()
分配的内存是数据段的一部分。最新版本的 glibc 使用 malloc()
实现,它使用 mmap()
分配所有内存。因此,RLIMIT_DATA
的值不会影响您可以使用此 malloc()
实现分配的内存量。
这是否违反了 POSIX.1 2008?
其他平台是否表现出类似的行为?
关于 RLIMIT_AS
的标准说:“如果超出此限制,malloc() 和 mmap() 函数将失败,并且将 errno 设置为 [ENOMEM]。”由于 RLIMIT_DATA
没有指定 mmap()
的失败,因此我认为从 mmap()
获得的内存不计入数据段.
这个假设是真的吗?这是否仅适用于 mmap()
的非 POSIX 变体?
最佳答案
FreeBSD 也分享了 malloc(3) 在默认 malloc 实现中使用 mmap(2) 实现的问题。我在将产品从 FreeBSD 6 移植到 7 时遇到了这个问题,发生了切换。我们将每个进程的默认限制从 RLIMIT_DATA=512M 更改为 RLIMIT_VMEM=512M,即将虚拟内存分配限制为 512MB。
至于这是否违反POSIX,我不知道。我的直觉是,很多东西都违反了 POSIX,而 100% 符合 POSIX 的系统与严格确认的 C 编译器一样罕见。
编辑:呵呵,现在我看到 FreeBSD 的名称 RLIMIT_VMEM 是非标准的;他们将 RLIMIT_AS 定义为 RLIMIT_VMEM 以实现 POSIX 兼容性。
关于memory - POSIX 限制 : What exactly can we assume about RLIMIT_DATA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23768601/
先决条件 POSIX.1 2008 specifies setrlimit() 和 getrlimit() 函数。为 resource 参数提供了各种常量,其中一些在下面复制以便更容易理解我的问题。
我正在尝试使用 setrlimit 来限制我在 Linux 系统上的内存使用,以阻止我的进程使机器崩溃(我的代码使高性能集群上的节点崩溃,因为一个错误导致内存消耗超过 100 GiB)。我似乎找不到要
我是一名优秀的程序员,十分优秀!