Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Mar 2013 14:28:45 +1100
From:      Peter Jeremy <peter@rulingia.com>
To:        Rod Person <rodperson@rodperson.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Help porting Linux app - getting Free Memory and Real Memory
Message-ID:  <20130329032845.GG81066@server.rulingia.com>
In-Reply-To: <5156316F.9050202@rodperson.com>
References:  <5156316F.9050202@rodperson.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <rodperson@rodperson.com> 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130329032845.GG81066>