On Windows the mmap offset is not aligned to the page size but to the
allocator granularity which is usually bigger than the page size. Add a new
internal function to the mmap compat code to get the proper offset alignment
size for each platform.
See the "dwFileOffsetLow" section for more details :
https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile
Change-Id: Ic26dc53862719892738a88b3dcea6a15901a0c94
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2107
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
size_t length; /* virtual mmap length */
};
size_t length; /* virtual mmap length */
};
-#ifdef __WIN32__
-#include <windows.h>
-
-/*
- * On windows the memory mapping offset must be aligned to the memory
- * allocator allocation granularity and not the page size.
- */
-static inline
-off_t get_page_aligned_offset(off_t offset, size_t page_size)
-{
- SYSTEM_INFO sysinfo;
-
- GetNativeSystemInfo(&sysinfo);
-
- return ALIGN_FLOOR(offset, sysinfo.dwAllocationGranularity);
-}
-#else
-off_t get_page_aligned_offset(off_t offset, size_t page_size)
+off_t get_page_aligned_offset(off_t offset, int log_level)
- return ALIGN_FLOOR(offset, page_size);
+ return ALIGN_FLOOR(offset, bt_mmap_get_offset_align_size(log_level));
static inline
struct mmap_align *mmap_align(size_t length, int prot,
static inline
struct mmap_align *mmap_align(size_t length, int prot,
if (!mma)
return MAP_FAILED;
mma->length = length;
if (!mma)
return MAP_FAILED;
mma->length = length;
- page_aligned_offset = get_page_aligned_offset(offset, page_size);
+ page_aligned_offset = get_page_aligned_offset(offset, log_level);
/*
* Page aligned length needs to contain the requested range.
* E.g., for a small range that fits within a single page, we might
/*
* Page aligned length needs to contain the requested range.
* E.g., for a small range that fits within a single page, we might
+BT_HIDDEN
+size_t bt_mmap_get_offset_align_size(int log_level)
+{
+ SYSTEM_INFO sysinfo;
+
+ GetNativeSystemInfo(&sysinfo);
+ BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level, BT_LOG_TAG,
+ "Allocator granularity is %lu.",
+ sysinfo.dwAllocationGranularity);
+
+ return sysinfo.dwAllocationGranularity;
+}
+
int bt_munmap(void *addr, size_t length);
int bt_munmap(void *addr, size_t length);
+/*
+ * On Windows the memory mapping offset must be aligned to the memory
+ * allocator allocation granularity and not the page size.
+ */
+size_t bt_mmap_get_offset_align_size(int log_level);
+
#else /* __MINGW32__ */
#include <sys/mman.h>
#else /* __MINGW32__ */
#include <sys/mman.h>
+#include "common/common.h"
static inline
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
static inline
void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
{
return munmap(addr, length);
}
{
return munmap(addr, length);
}
+
+/*
+ * On other platforms the memory mapping offset must be aligned to the
+ * page size.
+ */
+static inline
+size_t bt_mmap_get_offset_align_size(int log_level)
+{
+ return bt_common_get_page_size(log_level);
+}
#endif /* __MINGW32__ */
#ifndef MAP_ANONYMOUS
#endif /* __MINGW32__ */
#ifndef MAP_ANONYMOUS
map_requested_offset:
offset_in_mapping = offset %
map_requested_offset:
offset_in_mapping = offset %
- bt_common_get_page_size(ds_file->log_level);
+ bt_mmap_get_offset_align_size(ds_file->log_level);
ds_file->mmap_offset = offset - offset_in_mapping;
ds_file->request_offset = offset_in_mapping;
ds_file->mmap_offset = offset - offset_in_mapping;
ds_file->request_offset = offset_in_mapping;
bt_logging_level log_level)
{
int ret;
bt_logging_level log_level)
{
int ret;
- const size_t page_size = bt_common_get_page_size(log_level);
+ const size_t offset_align = bt_mmap_get_offset_align_size(log_level);
struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1);
if (!ds_file) {
struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1);
if (!ds_file) {
- ds_file->mmap_max_len = page_size * 2048;
+ ds_file->mmap_max_len = offset_align * 2048;