Help porting Linux app - getting Free Memory and Real Memory

Rod Person rodperson at rodperson.com
Fri Mar 29 13:08:12 UTC 2013


On 03/28/13 23:28, Peter Jeremy wrote:
> 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.

First, thanks for you reply.  I can't speak to this and only say that he
read the Linux proc system for the Free Memory and Cache memory values.
Adds them together and that become the value used for free memory.  My
little hack does seem to stop these warning though. I just want to make
sure it correct in thinking and if possible use some standard way of
calculating these values.

>> 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'.

 man 3 sysctl, list them as integer that is why I did this.


Rod


More information about the freebsd-hackers mailing list