Unnecessary limitation on munmap?

Mark Geisert mark@maxrnd.com
Sat Dec 21 22:15:23 GMT 2024


Hi Ken,

On 12/21/2024 1:42 PM, Ken Brown wrote:
> I'm wondering why munmap insists on operating with chunks of size 64k 
> instead of pages of size 4k.  In other words, what would go wrong if we 
> did the following:
> 
> --- a/winsup/cygwin/mm/mmap.cc
> +++ b/winsup/cygwin/mm/mmap.cc
> @@ -1143,7 +1143,7 @@ munmap (void *addr, size_t len)
>         set_errno (EINVAL);
>         return -1;
>       }
> -  const size_t pagesize = wincap.allocation_granularity ();
> +  const size_t pagesize = wincap.page_size ();
>     if (((uintptr_t) addr % pagesize) || !len)
>       {
>         set_errno (EINVAL);
> 
> I'm currently testing a build with this patch, and so far I haven't seen 
> any problems.  But maybe I don't know what to test.

I'm afraid I don't remember the circumstances, but the change from 4K 
pages to 64K was done somewhat recently.  In the last 2-3 years IIRC.

Maybe check the git history of mmap.cc for clues?  Some corner case of 
how Windows manages page protection wasn't allowing the desired POSIX 
and/or Linux behavior?
HTH,

..mark


More information about the Cygwin-developers mailing list