From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 29 03:29:09 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 12D08789 for ; Fri, 29 Mar 2013 03:29:09 +0000 (UTC) (envelope-from peter@rulingia.com) Received: from vps.rulingia.com (host-122-100-2-194.octopus.com.au [122.100.2.194]) by mx1.freebsd.org (Postfix) with ESMTP id 89D1B8BF for ; Fri, 29 Mar 2013 03:29:07 +0000 (UTC) Received: from server.rulingia.com (c220-239-237-213.belrs5.nsw.optusnet.com.au [220.239.237.213]) by vps.rulingia.com (8.14.5/8.14.5) with ESMTP id r2T3Svfs050009 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Mar 2013 14:28:58 +1100 (EST) (envelope-from peter@rulingia.com) X-Bogosity: Ham, spamicity=0.000000 Received: from server.rulingia.com (localhost.rulingia.com [127.0.0.1]) by server.rulingia.com (8.14.5/8.14.5) with ESMTP id r2T3Skh7042825 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 29 Mar 2013 14:28:46 +1100 (EST) (envelope-from peter@server.rulingia.com) Received: (from peter@localhost) by server.rulingia.com (8.14.5/8.14.5/Submit) id r2T3Sjr7042780; Fri, 29 Mar 2013 14:28:45 +1100 (EST) (envelope-from peter) Date: Fri, 29 Mar 2013 14:28:45 +1100 From: Peter Jeremy To: Rod Person Subject: Re: Help porting Linux app - getting Free Memory and Real Memory Message-ID: <20130329032845.GG81066@server.rulingia.com> References: <5156316F.9050202@rodperson.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WYTEVAkct0FjGQmd" Content-Disposition: inline In-Reply-To: <5156316F.9050202@rodperson.com> X-PGP-Key: http://www.rulingia.com/keys/peter.pgp User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2013 03:29:09 -0000 --WYTEVAkct0FjGQmd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2013-Mar-29 20:27:27 -0400, Rod Person wrote: >Everything is going we except that the program gives warnings that there >isn't enough free memory on the system to perform certain actions. That premise sounds suspiciously like the upstream author doesn't understand how Unix VM works. >int getSysCtl(int top_level, int next_level){ > int mib[2], ctlvalue; > size_t len; > > mib[0] =3D top_level; > mib[1] =3D next_level; > len =3D sizeof(ctlvalue); > > sysctl(mib, 2, &ctlvalue, &len, NULL, 0); =20 > =20 > return ctlvalue; >} > > >int main(void){ > int realmem =3D getSysCtl(CTL_HW, HW_REALMEM); > int usermem =3D getSysCtl(CTL_HW, HW_USERMEM); HW_REALMEM and HW_USERMEM return an unsigned long, not an int. That probably explains the nonsense value you are seeing in 'User Memory'. > printf("Total VM Memory: %i\n",vmsize.t_vm); > printf("Total Real Memory: %i\n",vmsize.t_rm); > printf("shared real memory: %i\n",vmsize.t_rmshr); > printf("active shared real memory: %i\n",vmsize.t_armshr); > printf("Total Free Memory pages: %i\n",vmsize.t_free); And these numbers are all in pages as you surmise. --=20 Peter Jeremy --WYTEVAkct0FjGQmd Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlFVCm0ACgkQ/opHv/APuIczIgCfW6kLSGbI7zmjJ7OfNmvdfzzr xzoAn0OiKx1nRg9okBvAFxcCqy6ms2C9 =t6ZM -----END PGP SIGNATURE----- --WYTEVAkct0FjGQmd--