|
|
Log in / Subscribe / Register

Revisiting mshare

By Jonathan Corbet
May 13, 2026

LSFMM+BPF
Linux can share memory between processes, but each process (almost always) has its own set of page tables. In situations where vast numbers of processes are sharing a memory region, the combined size of the page tables can exceed that of the shared memory itself. There has, thus, long been an interest in enabling unrelated processes to share page tables referring to shared memory. Anthony Yznaga is the latest developer to try to push this idea (known as "mshare") forward; he described the status of that work in a memory-management-track discussion at the 2026 Linux Storage, Filesystem, Memory Management, and BPF Summit (LSFMM+BPF).

[Anthony Yznaga] This is not the first (or second) time that page-table sharing has made it onto the LSFMM+BPF agenda; it was most recently discussed in 2024, when Khalid Aziz updated the group on the proposal. Aziz has since retired, and Yznaga has picked up the work.

The overall shape of this patch series has not changed; sharing starts when a process creates a shared memory region by creating a file in a special msharefs filesystem. That region is created along with its own mm_struct structure, which is used to manage the page tables for the region. Each sharing process can then attach to this region by opening and mapping the msharefs file, resulting in the creation of a special virtual memory area (a "window VMA") representing that region in the process's address space. Page faults and other memory-management operations, upon encountering the window VMA, follow the pointer to the special mm_struct and operate on the page tables there.

At least, that is how things looked in 2024, and again in 2025 when Yznaga posted an updated version of the patch set. In the session, though, he let it be known that, while the implementation of mshare is substantially the same, the API has switched back to system-call form, as had been the case with earlier versions. Back then, a single mshare() system call had been proposed; now there is a whole set of them. The shared region is now created with mshare_create():

    int mshare_create(unsigned int flags);

This call will return a file descriptor representing the new region; the only supported flags value is O_CLOEXEC. The size of the region must subsequently be set with an ftruncate() call. A call to mshare_attach() will map the shared region into the calling process's address space:

    int mshare_attach(int fd, unsigned int offset, unsigned int size,
    		      void *addr, unsigned int flags);

(Note that Yznaga did not show the types of the parameters on his slide, so I have filled in something plausible). There is an mshare_map() to do the equivalent of an mmap() call, setting up backing store for the addresses within the shared region. There are various other calls, including mshare_advise() and mshare_protect(), to control the management of this region. Yznaga did not go into details about how other processes find and attach to this region.

The ownership model of the shared region has changed somewhat, in that the process calling mshare_create() is the owner for the life of the process; when that process exits or closes the file descriptor, the region disappears and mappings in other processes are removed. This change, he said, simplifies control-group accounting, makes the lifetime of the region clear, and provides a target for the out-of-memory killer should things reach that point.

Yznaga concluded with a summary of problems he is working on now. Page-table walking is a big challenge he said, especially getting the locking between the window VMAs and the mshare region's VMA correct. The resident-set-size statistics for mshare-using processes are wrong; the information for the shared region is stored in the special mm_struct and not exposed anywhere. The current design requires the process that created the region to stick around; there would be value in some sort of ownership-transfer mechanism so that the creator could hand the region off and exit.

He is also looking for more potential use cases for this feature. Jason Gunthorpe mentioned high-performance-computing processes that need to share resources, so it would be good to show that this feature can work for that use case. Another participant mentioned the Android Zygote process, which serves as the parent for all apps in the system. There is quite a bit of sharing between those processes, and thus potential benefit from mshare, but any changes made by a process to the region should not be visible to other attached processes, so it would be necessary to unshare page tables in that case.

Another participant asked how TLB flushing is handled in the shared region. There is, Yznaga answered, a linked list of all processes sharing the region; when a TLB flush happens, that list is traversed and each process is flushed individually. Gunthorpe observed that this list sounded a lot like an MMU notifier; Yznaga said that he had tried using notifiers, but they did not work in that case.

Matthew Wilcox noted that allowing each process to map the shared region at a different virtual address increases the complexity of the feature; perhaps requiring the region to be mapped at the same address everywhere would be a useful simplification? The response in the room made it clear that this was not a popular idea. The session ended with Wilcox suggesting that, once the feature finally lands, it will be possible to remove the page-table sharing implemented by the hugetlbfs subsystem, which is currently the only way to get this kind of sharing on Linux systems.

Index entries for this article
KernelMemory management/Page-table sharing
ConferenceStorage, Filesystem, Memory-Management and BPF Summit/2026


to post comments

Different VAs?

Posted May 13, 2026 14:06 UTC (Wed) by IAmLiterallyABee (subscriber, #144892) [Link] (1 responses)

How can they share page tables if the memory is mapped at different virtual addresses? The offset into the table determines the address. Are they only sharing OS structures and not the architectural page tables?

Different VAs?

Posted May 13, 2026 14:18 UTC (Wed) by corbet (editor, #1) [Link]

The shared region has to have PMD alignment, so the offsets will be the same even though the base address differs.

Alias mappings

Posted May 14, 2026 13:39 UTC (Thu) by fw (subscriber, #26023) [Link]

I wonder if this allows to create alias mappings that are still copy-on-write and compatible with fork. This would allow transparent coloring of pointers without hardware support for address masking. This would be quite interesting to malloc implementations because it can help with determining allocation metadata efficiently during deallocation.

Ownership

Posted May 18, 2026 13:05 UTC (Mon) by claudex (subscriber, #92510) [Link] (1 responses)

> when that process exits or closes the file descriptor, the region disappears and mappings in other processes are removed.

What happen if another process is accessing the region while the owner process close it ? And does it mean that the non owner process should make a check that the region is still existing before each access (with some kind of lock?) ?

Ownership

Posted May 18, 2026 16:02 UTC (Mon) by daroc (editor, #160859) [Link]

I wasn't present for that talk, but as I understand it, this is the point of flushing the TLB when the page tables change: either the other process accesses the page before the TLB is flushed (and the address is present in the TLB), and the access succeeds, or it accesses the page after the TLB is flushed, and has to walk the page tables. The updated page tables will show that the area isn't mapped, and the process will get a segmentation fault, just as it would for any other inaccessible memory. If application authors don't want to get segmentation faults, they should ensure their programs don't do that, using whatever technique they'd like (locking, static verification, etc.).


Copyright © 2026, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds