This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Return the correct value for sysconf(_SC_PAGESIZE)


On Nov 15 16:47, Erik Bray wrote:
> On Tue, Nov 15, 2016 at 3:58 PM, Corinna Vinschen
> <corinna-cygwin@cygwin.com> wrote:
> > On Nov 15 14:51, Erik Bray wrote:
> >> Greetings,
> >>
> >> Currently sysconf(_SC_PAGESIZE) returns the value of
> >> wincap.allocation_granularity()--a change I *think* had to have been
> >> made by mistake in
> >> https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=commit;f=winsup/cygwin/sysconf.cc;h=177dc6c7f6d0608ef6540fd997d9b444e324cae2
> >>
> >> There's no obvious reason, anyways, that this value should be returned
> >> and not the actual page size.
> >
> > That's no accident, but a deliberate decision.  Originally we used the
> > page size at this point, but that's long ago.  This has been discussed
> > on the cygwin-developers mailing list years ago.  The problem is the
> > POSIX assumption that the allocation granularity equals the page size.
> > The only working solution which does not break assumptions is to return
> > the allocation granularity as page size.
> 
> Okay, sorry for suggesting otherwise.  When I looked at that commit it
> seemed like a there was a lot of mass renaming going on, so I thought
> it might have been an accident.  I didn't see the threads where this
> was discussed.
> 
> I see the reason for the change now, but the fact remains
> sysconf(_SC_PAGESIZE) cannot, then, be relied on to make any
> memory-related calculations from page counts.

What do you mean?  If you call sysconf(_SC_PHYS_PAGES) or
sysconf(_SC_AVPHYS_PAGES) you get the number of pages in _SC_PAGESIZE
chunks so all is good.

> Is there a different
> (posix-compliant) way to get the actual page size, or at least maybe
> it could be somewhere in /proc?

There is no good reason to use the non-POSIXy page size.  It doesn't
help you in the least for any pagesize-related functionality.  Mmap
as well as malloc and friends only work with _SC_PAGESIZE sized pages.

It sounds as if you're looking for a solution for which there's no
problem...


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]