From: Ken Brown <kbrown@cornell.edu>
To: cygwin-developers@cygwin.com
Subject: Re: page_size vs allocation_granularity
Date: Wed, 22 Jul 2020 12:42:31 -0400 [thread overview]
Message-ID: <3e8c9ae9-cfa7-f4db-d243-dc9593b252e9@cornell.edu> (raw)
In-Reply-To: <20200722083327.GR16360@calimero.vinschen.de>
On 7/22/2020 4:33 AM, Corinna Vinschen wrote:
> On Jul 21 18:40, Ken Brown via Cygwin-developers wrote:
>> Hi Corinna,
>>
>> I'm curious about the design decision that causes sysconf(_SC_PAGESIZE) to
>> return wincap.allocation_granularity() rather than wincap.page_size().
>> Changing this would improve Linux compatibility, I think, but maybe it would
>> have some bad consequences that I'm not aware of.
>
> It was a long and hard process to move from 4K to 64K pagesize, with
> lots of loaded discussions. The Cygwin mailing list archives will
> show a lot of this in the 200X years.
>
> It was the only way to make mmap 99% POSIX-conformant. Consider, for
> instance this:
>
> pagesize = sysconf(_SC_PAGESIZE);
> addr = mmap (NULL, pagesize, PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> addr2 = mmap (addr + pagesize, pagesize, PROT_READ | PROT_WRITE,
> MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>
> On Windows, this fails with pagesize = 4K, but it works with pagesize =
> 64K, because of that idiotic Windows allocation granularity. Almost
> all POSIX expectations are automagically fixed by using the granularity
> as pagesize in a POSIX sense.
>
> There's only one problem left: While you can only allocate usefully in
> 64K steps, the size of the memory area allocated for a file is only 4K
> aligned, thus leaving the remainder of the 64K block unmapped.
>
> This problem could be fixed back in 32 bit times by adding the
> AT_ROUND_TO_PAGE mapping. Very unfortunately, the 64 bit Windows
> designer decided to keep the braindead 64K allocation granularity
> but to drop the AT_ROUND_TO_PAGE flag, thus removing the only chance
> to make this single situation POSIX-compatible as well.
>
>> I'm asking because in my recent fooling around with php, I noticed that
>> Yaakov had to apply the following Cygwin-specific patch to avoid a crash:
>
> It would be nice to learn what kind of crash that was.
Here's a better reference than the one I gave in my previous reply, which
actually explains what's going on:
https://sourceware.org/pipermail/cygwin/2017-May/232562.html
> If php reads or writes in the remainder of the block constituting EOF,
> or tries to change page protection, shit happens. Every time, a process
> stabs into the EOF block following the last valid 4K block, it results
> in a STATUS_ACCESS_VIOLATION which in turn calls
> mmap_is_attached_or_noreserve(). While this situation can be
> recognized, I don't see a way to fix this from the processes POV.
So that's exactly what happens when php maps a file whose size is a multiple of
4K but not a multiple of 64K. It expects that there is a zero-filled region
beyond EOF that it can safely read from.
Ken
next prev parent reply other threads:[~2020-07-22 16:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-21 22:40 Ken Brown
2020-07-22 8:33 ` Corinna Vinschen
2020-07-22 8:47 ` Corinna Vinschen
2020-07-22 11:36 ` Ken Brown
2020-07-22 16:42 ` Ken Brown [this message]
2020-07-22 18:35 ` Ken Brown
2020-07-22 18:48 ` Corinna Vinschen
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=3e8c9ae9-cfa7-f4db-d243-dc9593b252e9@cornell.edu \
--to=kbrown@cornell.edu \
--cc=cygwin-developers@cygwin.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).