This is the mail archive of the
mailing list for the Cygwin project.
Re: Return the correct value for sysconf(_SC_PAGESIZE)
On Tue, Nov 15, 2016 at 5:19 PM, Corinna Vinschen
> On Nov 15 16:47, Erik Bray wrote:
>> On Tue, Nov 15, 2016 at 3:58 PM, Corinna Vinschen
>> <email@example.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
FWIW the background here is that I'm working on porting psutil  to
Cygwin, and trying to accomplish as much as *possible* through the
POSIX interfaces without having to fall back on the Windows API. It's
actually a great exercise in what is and isn't possible with Cygwin :)
In this case I was trying to compute process memory usage from
/proc/<pid>/statm which gives values in page counts, so I need the
page size (the actual page size) to compute the values in bytes.