Date: Tue, 25 Feb 2003 16:37:05 +1100 (EST) From: Bruce Evans <bde@zeta.org.au> To: Marcel Moolenaar <marcel@xcllnt.net> Cc: "M. Warner Losh" <imp@bsdimp.com>, <arch@FreeBSD.ORG> Subject: Re: Fw: Proposed new sysctl MIB nodes Message-ID: <20030225160527.W9462-100000@gamplex.bde.org> In-Reply-To: <20030225005912.GA1583@athlon.pn.xcllnt.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 24 Feb 2003, Marcel Moolenaar wrote: > On Mon, Feb 24, 2003 at 05:47:42PM -0700, M. Warner Losh wrote: > > > > From: Jason R Thorpe <thorpej@wasabisystems.com> > > > > I'd like to propose new HW_PHYSPAGES and HW_USERPAGES MIB nodes that > > return the same information, but in a 32-bit page count, instead. The > > implementation is left as an exercise to the reader. I just want to get > > consensus on the names, so that I can tell the GCC people about it, and > > have it work on all the BSD platforms (as their current sysctl code does). > > What's the reason to not use a 64-bit entity whether it represents > bytes or pages? Under FreeBSD, the sysctl return an unsigned long, so they already return a 64-bit entity on machines which happen to have 64-bit longs. Under NetBSD, the sysctls return a 32-bit signed int, so they only already return 64 non-overflowing bits on machines which happen to have 65-bit ints. This gives the following pedantic wrongness for always using a 64-bit entity for bytes: On machines with 32-bit longs: Returning a 64-bit entity would mainly be a micropessimization. On machines with 64-bit longs: A 64-bit entity is already returned under FreeBSD. This is already incompatible with NetBSD, but correctly-written applications shouldn't notice -- they should read scalar values into a union or something (yes, this is messy to code; there is no portable way to convert the size returned by sysctl to a type, and the correct type is not even documented in sysctl(3) (it says that HW.PHYSMEM returns an "integer" and doesn't say that an "integer" can have almost any size). On machines with >64-bit longs: Returning a 64-bit entity would be a regression on machines with more than 2^64 bytes of memory :-). > Or to be more presice, an integral entity that can be used to cast > to from a pointer without data loss? That would be more bogus than returning a plain u_long, since u_long was the largest scalar type, but the size needed to count main memory is unrelated to the number of bits in a pointer. In practice, u_long is the same as uintptr_t on most machines, but that doesn't make it right for counting main memory since all of main memory might not be mappable (e.g., on i386's with PAE support). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030225160527.W9462-100000>