如何在多写情况下对文件支持的共享内存中的大页面进行故障处理

问题描述 投票:1回答:1

我有多个编写器,它们将mmap()多个共享(即指定为MAP_SHARED)大页面由文件支持。

归零(例如memset(ptr, 0, size))这些大页面可能会提前使页面出错。

但是,如果我有多个作者(多个进程),那么在第一次映射这些页面时,可能只有一个作者应该将页面清零,因为这样,我不必担心读者仍在阅读或担心作家归零时仍在写作的作家。

问题:

  1. 除了对页面进行清零/写入之外,是否还有办法提前对页面进行故障处理?
  2. 如果否,在不影响正在阅读的读者和正在撰写的作者的情况下,对页面进行错误处理的常见方法是什么?>>
  3. [mmap(2)表示mmap(2)可能会对页面进行预故障处理:

mlock()

但是,MAP_LOCKED (since Linux 2.5.37) Mark the mapped region to be locked in the same way as mlock(2). This implementation will try to populate (prefault) the whole range but the mmap() call doesn't fail with ENOMEM if this fails. Therefore major faults might happen later on. So the semantic is not as strong as mlock(2). One should use mmap() plus mlock(2) when major faults are not acceptable after the initialization of the mapping. The MAP_LOCKED flag is ignored in older kernels. 并未明确声明调用mlock(2)时页面将出现故障。有想法吗?

我有多个编写器,它们将mmap()共享一个文件支持的多个共享(即指定MAP_SHARED)大页面。将这些大页面清零(例如memset(ptr,0,size))可能会提前使页面出错。 ...

c++ c linux shared-memory huge-pages
1个回答
0
投票

关于mlock(2)

© www.soinside.com 2019 - 2024. All rights reserved.