From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 29 13:08:12 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7C37553C for ; Fri, 29 Mar 2013 13:08:12 +0000 (UTC) (envelope-from rodperson@rodperson.com) Received: from www6.pairlite.com (www6.pairlite.com [64.130.10.16]) by mx1.freebsd.org (Postfix) with ESMTP id 5C90E1EC for ; Fri, 29 Mar 2013 13:08:12 +0000 (UTC) Received: from [192.168.1.10] (c-71-60-224-178.hsd1.pa.comcast.net [71.60.224.178]) by www6.pairlite.com (Postfix) with ESMTPSA id 0DE0267AEE; Fri, 29 Mar 2013 09:08:07 -0400 (EDT) Message-ID: <51559228.5020302@rodperson.com> Date: Fri, 29 Mar 2013 09:07:52 -0400 From: Rod Person User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Peter Jeremy Subject: Re: Help porting Linux app - getting Free Memory and Real Memory References: <5156316F.9050202@rodperson.com> <20130329032845.GG81066@server.rulingia.com> In-Reply-To: <20130329032845.GG81066@server.rulingia.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Fri, 29 Mar 2013 13:14:20 +0000 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 13:08:12 -0000 On 03/28/13 23:28, Peter Jeremy wrote: > 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. 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