MK.
MK.

Reputation: 4027

writing a mmapped file using a huge page mapping

It is my understanding that currently, on linux, there is no way to mmap a file (either on xfs or ext4) and then write to it and also somehow use huge pages.

Is this correct or is this outdated information and there is a way to do so now?

Thanks.

Upvotes: 3

Views: 1498

Answers (1)

noname
noname

Reputation: 31

If you mmap a file with MAP_HUGETLB that is not from 'hugetlbfs', the mmap will fail. From ksys_mmap_pgoff()

if (!(flags & MAP_ANONYMOUS)) {
    ...
    if (unlikely(flags & MAP_HUGETLB && !is_file_hugepages(file)))
         goto out_fput;

is_file_hugepages() checks if the file ops is hugetlbfs_file_operations, which won't be true for e.g. ext4.

However, you might be able to use transparent huge pages. Currently (4.19 or so), you also have to use DAX (direct access, often used with nvdimms and persistent memory). I haven't done it yet, but that's from tracing through the code. Specifically, to get huge pages working, you'll at least need a huge-page-aligned address, which comes from thp_get_unmapped_area(), which bails out if you aren't using DAX:

 if (!IS_DAX(filp->f_mapping->host) || !IS_ENABLED(CONFIG_FS_DAX_PMD))
    goto out;

Upvotes: 1

Related Questions