Help porting Linux app - getting Free Memory and Real Memory

Peter Jeremy peter at rulingia.com
Fri Mar 29 03:29:09 UTC 2013


On 2013-Mar-29 20:27:27 -0400, Rod Person <rodperson at 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] = top_level;
>    mib[1] = next_level;
>    len = sizeof(ctlvalue);
>
>    sysctl(mib, 2, &ctlvalue, &len, NULL, 0);   
>   
>    return ctlvalue;
>}
>
>
>int main(void){
>    int realmem = getSysCtl(CTL_HW, HW_REALMEM);
>    int usermem = 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.

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20130329/74951722/attachment.sig>


More information about the freebsd-hackers mailing list