Free RAM Space Relevance and Maximum RAM

Hi All,

Below code I am using to fetch Free RAM Space but for few of the servers its fetching negative result.I am wondering how free space can be in negative.

(if (exists wmi) then (((((it as integer/1024)-(((size of ram)/(1024*1024)))-12)) as string & " MB") of (string values of selects “MaxCapacity from Win32_PhysicalMemoryArray where Use=‘3’” of wmi)) as string else (“N/A”))

There are inspectors for RAM you can use directly and more efficiently for this.

You can put the following in the fixlet debugger to see those inspectors:

properties whose(it as string as lowercase contains "ram")

This will give you the raw free ram:

free amount of ram

I would recommend starting with the raw value in a property before trying to convert it into something like MB. I also strongly recommend having the raw and unparsed values for use in things like WebReports or Session Relevance. Don’t only have a parsed and easily human readable result that has to be reparsed for other uses later.

In the relevance you provide above, there is a -12 in there, which could make the returned result negative in some cases.

This should give you a more human readable output:

(if (0<(it / (1024*1024*1024*1024))) then (it / (1024*1024*1024*1024)) as string & " TB" else if (0<(it / (1024*1024*1024))) then (it / (1024*1024*1024)) as string & " GB" else if (0<(it / (1024*1024))) then (it / (1024*1024)) as string & " MB" else if (0<(it / (1024))) then (it / (1024)) as string & " KB" else (it as string & " B")) of (free amount of ram)

Hi All,

can anyone Please help me,how exactly the below code is working and fetching result

if (exists wmi) then (((it as integer/1024) as string & " MB") of (string values of selects “MaxCapacity from Win32_PhysicalMemoryArray where Use=‘3’” of wmi)) else (“N/A”)

Thanks in advance

That code is using WMI to get info about Win32_PhysicalMemoryArray in Windows.

See the raw results using this query:

selects "* from Win32_PhysicalMemoryArray" of wmi

The query you provided is using Use='3' to filter out the potential for multiple results of different types. It is also only returning MaxCapacity instead of all possible values.

Ideally, you would get the raw values this way:

unique values of string values of selects "MaxCapacity from Win32_PhysicalMemoryArray where Use='3'" of wmis

I’m actually not certain what this value represents. it doesn’t seem to match my actual free memory or total memory.

It might be the maximum amount of RAM my system can handle in KB.

From the Microsoft Reference:

Maximum memory size (in bytes) installable for this particular memory array. If the size is unknown, the property is given a value of 0 (zero).

But also:

Qualifiers: MappingStrings ("SMBIOS|Type 16|Maximum Capacity") , Units ("kilobytes")

This means this info is available in SMBIOS in addition to WMI. BigFix has a native SMBIOS inspector which is faster, more efficient, and more cross platform than using WMI. In general, any info you can get from SMBIOS you should get from there instead of from WMI whenever possible.

This means, the following would be the best possible option to get this raw data:

unique values of (it as integer) of (it as string) of values "maximum_capacity" of structures "physical_memory_array" of smbios

This would provide a more human readable parsed result:

(if (0<(it / (1024*1024*1024*1024))) then (it / (1024*1024*1024*1024)) as string & " TB" else if (0<(it / (1024*1024*1024))) then (it / (1024*1024*1024)) as string & " GB" else if (0<(it / (1024*1024))) then (it / (1024*1024)) as string & " MB" else if (0<(it / (1024))) then (it / (1024)) as string & " KB" else (it as string & " B")) of (it * 1024) of unique values of (it as integer) of (it as string) of values "maximum_capacity" of structures "physical_memory_array" of smbios

References:

Thanks Jgstew for your response.

Code which you have mentioned above shows Available RAM but I am confused between Available RAM and Free RAM’
please see below screenshot :-

The number you’re interested in is, “Available RAM” – that is the RAM that is available for application use.

Available RAM is made up of a combination of the Cached and Free RAM. Cached RAM is immediately freeable where as Free RAM is literally unitilized.

1 Like

Free memory can not be allocated right??

Available = Cached + Free - (something)

Available is a combination of cached and free, both cached and free are immediately available for use by an application.

can you please explain me -(somethings) because I am really not clear

2 Likes

Available RAM is a combination of Cached RAM and Free RAM but the OS reserves some of it for some reason that I’m not entirely clear on.

So if you have:
Cached RAM: 1150MB
Free RAM: 101MB

Your Available RAM should be right around ~1200 MB (Cached + Free - x)

2 Likes

actually the above code brings the Maximum Capacity from PhysicalMemoryArray.My concern here,Is this Maximum RAM which can be installed on this machine??

Yes, I did actually say that buried in my reply here:

I’m fairly sure that is what that is.

I was pointing out that this is a better way to get that same info:

unique values of (it as integer) of (it as string) of values "maximum_capacity" of structures "physical_memory_array" of smbios
1 Like

It isn’t all that clear in general.

What do you really want to know? Do you want to know how much memory is immediately available to any application?

We used to call the amount of “unused” RAM “free”, but Microsoft has muddied the water a bit and now calls this “available” RAM instead of “free”.

“free” RAM is effectively RAM not being used at all for anything. You actually WANT this value to be low because it means the RAM is being used either for programs or for caching or for other things.

The more RAM can be used for caching, the better your system performance will be, BUT this caching is able to be dumped instantly as soon as a program or the OS needs it, so it is considered “Available”:

“Available” RAM is what we used to call “free” RAM. This is the actual amount of RAM that is not being used by executing programs on your system. If you want to know how much RAM isn’t technically being used, this is the value to look at.

There is probably some Microsoft article somewhere that explains this better.

This situation is actually even more confusing on Win10 and Mac OS X because of RAM compression which causes even more RAM to be “Available” than is actually “Available”.

Short answer: It is confusing.

1 Like

Thanks Jgstew. This information was really helpful :smile:

1 Like