9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Dan Cross <crossd@gmail.com>
To: 9fans <9fans@9fans.net>
Subject: Re: mmaping on plan9? (was Re: [9fans] venti /plan9port mmapped
Date: Sat, 14 Feb 2026 09:26:36 -0500	[thread overview]
Message-ID: <CAEoi9W5EYhWsZoYJABQotidQbZRYQXixCyyzq4+7Wo4UPS5YKg@mail.gmail.com> (raw)
In-Reply-To: <17710401560.A0E9fA4ec.5667@composer.9fans.topicbox.com>

On Sat, Feb 14, 2026 at 2:15 AM Alyssa M via 9fans <9fans@9fans.net> wrote:
> On Friday, February 13, 2026, at 1:36 AM, Dan Cross wrote:
> > Let me be blunt: the `mmap` interface, as specified in 4.2BSD
> > and implemented in a bunch of Unix and Unix-like systems, is
> > atrocious. Its roots come from a system that was radically
> > different in design than Unix, and its baroque design, with a
> > bunch of operations multiplexed onto a single call with 6 (!!)
> > arguments, two of which are bitmaps that interact in abstruse
> > ways and one of which can radically alter the semantics of
> > the call, really shows. I believe that it _is_ possible to do better.
>
> I'm definitely with you there.
>
> What I'm trying to do is explore whether the standard read/write
> calls with a different implementation could make mmap redundant
> by using the combination of demand paging and copy-on-write to
> defer or elide I/O. This is not mmap, and not really memory
> mapping in the conventional sense either. But I think it can do the
> things an mmap user is looking for (so long as they're not looking
> for frame buffers or shared memory.) A successful implementation
> will not be detectably different from the traditional read/write calls
> except with respect to deferred or elided I/O.

But as before, I don't see how you intend to make that work in a way
that is transparent to actual programmers. The semantics of read/write
and memory mapping files are just too different.

> The key ideas are that the read (and write!) system calls associate
> buffer pages with a snapshot of the file data involved (which is then
> demand loaded - deferred), and altering memory pages breaks that
> association, and associates the altered pages with the swap file.

Except they don't.

It sounds like you're thinking in terms of pages, I get that; but
read/write work in terms of byte buffers that have no obligation to be
byte aligned. Put another way, read and write relate the contents of a
"file" with an arbitrarily sized and aligned byte-buffer in memory,
but there is no obligation that those byte buffers have the properties
required to be a "page" in the virtual memory sense.

As in my earlier email, consider the case of a `read` into some long
buffer that is offset relative to a page boundary. For example,
assuming a 4KiB page:

    char *p = 0xffffffff00000000; // Starts at 4GiB.
    read(fd, p + 2, 0x1000*1024*128);

Here, a program is reading 512MiB of data into a buffer, but that
buffer doesn't start on a page boundary; so the contents of each
logical "page" read from the file are offset from the start of a page
a la the virtual memory system. Because of that, the system can't play
clever games with page mapping the read contents anymore: the virtual
memory hardware enforces the property that pages are _aligned_ to the
page size, and the destination of this read are not aligned to that
alignment requirement.

> Pages that are still associated with the file region they're being written
> to are not written (this is the eliding part). Fragments of pages are
> treated traditionally. The segment this happens in may be logically
> much larger even than the swap area - and not is pre-allocated, so
> pages are either allocated swap space on demand, or are associated
> with snapshots.

This still doesn't make any sense to me.  The _program_ has already
allocated the memory it reads into; how the system gets the data into
that memory in response to a read is sort of irrelevant.  In any
event, you still have to deal with the problem of destination buffers
that aren't page aligned, which is already going to make this
unworkable in the general case.  You could special-case requests for
page aligned reads, I guess, but there are a lot of corner cases: what
if I `malloc` a buffer, align a pointer to a page boundary at some
offset into the malloc'ed region, `read`, and then immediately `free`
the buffer?  Now `free` needs to know to tell the system that this
region was dealloc'ed; if it doesn't, then a subsequent `malloc`
covering part of it could cause a lot of IO for no good reason, as I
go to write bits of that memory and they're CoW faulted into the
process's address space.  `free` usually doesn't care; it's a
userspace library, and sure, some implementations do interact with the
system more than others, but now I'm essentially requiring that.

In short, I don't see how this decreases complexity; it seems to
objectively increase it.

> There's much more I could say, but I don't have it all working yet, and
> making it work at scale is probably another story.

Well, I wish you luck, and if you come up with something amazing, I'll
be the first to admit that I'm wrong.  But it sure seems like the
practicality of the idea is predicated on assumptions that don't hold
in the vast majority of cases.

Again, I think there's space for something like memory-mapped files in
the wider universe of systems design, but I'm afraid you'll find that
trying to make that thing `read` is not workable.

        - Dan C.

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Te8d7c6e48b5c075b-M399decded15386d15d15b6c7
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

  reply	other threads:[~2026-02-15  4:30 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-02 19:54 [9fans] venti /plan9port mmapped wb.kloke
2026-01-02 20:39 ` ori
2026-01-02 20:58   ` Bakul Shah via 9fans
2026-01-06 22:59     ` Ron Minnich
2026-01-07  4:27       ` Noam Preil
2026-01-07  6:15       ` Shawn Rutledge
2026-01-07 15:46         ` Persistent memory (was Re: [9fans] venti /plan9port mmapped) arnold
2026-01-07 16:11           ` Noam Preil
2026-01-07 17:26             ` Wes Kussmaul
2026-01-07  8:52       ` [9fans] venti /plan9port mmapped wb.kloke
2026-01-07 16:30         ` mmaping on plan9? (was " Bakul Shah via 9fans
2026-01-07 16:40           ` Noam Preil
2026-01-07 16:41           ` ori
2026-01-07 20:35             ` Bakul Shah via 9fans
2026-01-07 21:31               ` ron minnich
2026-01-08  7:56                 ` arnold
2026-01-08 10:31                 ` wb.kloke
2026-01-09  0:02                   ` ron minnich
2026-01-09  3:57                 ` Paul Lalonde
2026-01-09  5:10                   ` ron minnich
2026-01-09  5:18                     ` arnold
2026-01-09  6:06                       ` David Leimbach via 9fans
2026-01-09 17:13                         ` ron minnich
2026-01-09 17:39                         ` tlaronde
2026-01-09 19:48                           ` David Leimbach via 9fans
2026-02-05 21:30                             ` Alyssa M via 9fans
2026-02-08 14:18                               ` Ethan Azariah
2026-02-08 15:10                                 ` Alyssa M via 9fans
2026-02-08 20:43                                   ` Ethan Azariah
2026-02-09  1:35                                     ` ron minnich
2026-02-09 15:23                                       ` ron minnich
2026-02-09 17:13                                         ` Bakul Shah via 9fans
2026-02-09 21:38                                           ` ron minnich
2026-02-10 10:13                                         ` Alyssa M via 9fans
2026-02-11  1:43                                           ` Ron Minnich
2026-02-11  2:19                                           ` Bakul Shah via 9fans
2026-02-11  3:21                                           ` Ori Bernstein
2026-02-11 10:01                                             ` hiro
2026-02-12  1:36                                               ` Dan Cross
2026-02-12  5:39                                                 ` Alyssa M via 9fans
2026-02-12  9:08                                                   ` hiro via 9fans
2026-02-12 13:34                                                   ` Alyssa M via 9fans
2026-02-13 13:48                                                     ` hiro
2026-02-13 17:21                                                     ` ron minnich
2026-02-15 16:12                                                       ` Danny Wilkins via 9fans
2026-02-17  3:13                                                         ` Alyssa M via 9fans
2026-02-17 13:02                                                           ` Dan Cross
2026-02-17 16:00                                                             ` ron minnich
2026-02-17 16:39                                                               ` hiro
2026-02-17 16:56                                                             ` Bakul Shah via 9fans
2026-02-17 17:54                                                               ` hiro
2026-02-17 22:21                                                               ` Alyssa M via 9fans
2026-02-16  2:24                                                       ` Alyssa M via 9fans
2026-02-16  3:17                                                         ` Ori Bernstein
2026-02-16 10:55                                                           ` Frank D. Engel, Jr.
2026-02-16 13:49                                                             ` Ori Bernstein
2026-02-16 19:40                                                           ` Bakul Shah via 9fans
2026-02-16 19:43                                                             ` Bakul Shah via 9fans
2026-02-16  9:50                                                         ` tlaronde
2026-02-16 12:24                                                         ` hiro via 9fans
2026-02-16 12:33                                                         ` hiro via 9fans
2026-02-11 14:22                                             ` Dan Cross
2026-02-11 18:44                                               ` Ori Bernstein
2026-02-12  1:22                                                 ` Dan Cross
2026-02-12  4:26                                                   ` Ori Bernstein
2026-02-12  4:34                                                     ` Dan Cross
2026-02-12  3:12                                             ` Alyssa M via 9fans
2026-02-12  4:52                                               ` Dan Cross
2026-02-12  8:37                                                 ` Alyssa M via 9fans
2026-02-12 12:37                                                   ` hiro via 9fans
2026-02-13  1:36                                                   ` Dan Cross
2026-02-14  3:35                                                     ` Alyssa M via 9fans
2026-02-14 14:26                                                       ` Dan Cross [this message]
2026-02-15  4:34                                                   ` Bakul Shah via 9fans
2026-02-15 10:19                                                     ` hiro
2026-02-10 16:49                                         ` wb.kloke
2026-02-08 14:08                             ` Ethan Azariah
2026-01-07 21:40               ` ori
2026-01-07 16:52           ` ori
2026-01-07 17:37             ` wb.kloke
2026-01-07 17:46               ` Noam Preil
2026-01-07 17:56                 ` wb.kloke
2026-01-07 18:07                   ` Noam Preil
2026-01-07 18:58                     ` wb.kloke
2026-01-07 14:57       ` Thaddeus Woskowiak
2026-01-07 16:07         ` Wes Kussmaul
2026-01-07 16:22           ` Noam Preil
2026-01-07 17:31             ` Wes Kussmaul
2026-01-07 16:13         ` Noam Preil
2026-01-02 21:01   ` ori
2026-01-08 15:59     ` wb.kloke
2026-02-11 23:19       ` red

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEoi9W5EYhWsZoYJABQotidQbZRYQXixCyyzq4+7Wo4UPS5YKg@mail.gmail.com \
    --to=crossd@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).