You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
Just want to say you have an excellent job on nitch, But as you probably already know, there are different versions on how used memory should be displayed, I did notice on nitch that it takes TotalMem - AvailableMem to get UsedMem. I just wanted to make you aware of the formula that htop uses and which has derived from a write up on Kernel.org https://www.kernel.org/doc/Documentation/filesystems/proc.txt
basically htop originally used MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable + Shmem
Then some patches made it in the kernel changed the way SharedMem and Cached are calculated, I haven't personally read the patch notes https://lore.kernel.org/lkml/[email protected]/
but it basically comes down to Shmem being part of cache so the accepted formula and the one htop uses is
MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable
I have implemented this is my fetch program written Pascal
// Get Memory and usagefunctionGetRamUsage(): string;
var
strTmp, strMemTotal, strMemFree, strShmem, strBuffers, strCached,
strSRclaimable: string;
intMemUsage, intTotalMem: single;
slMemInfo: TStringList;
begin
Result := 'Error';
// Set the name of the file that will be read
slMemInfo := TStringList.Create;
try
slMemInfo.LoadFromFile('/proc/meminfo');
try// Process MemTotal
strTmp := slMemInfo.Strings[0];
strMemTotal := Trim(ExtractString(strTmp, 'MemTotal:', 'kB'));
// Process MemFree
strTmp := slMemInfo.Strings[1];
strMemFree := Trim(ExtractString(strTmp, 'MemFree:', 'kB'));
// Process Buffers
strTmp := slMemInfo.Strings[3];
strBuffers := Trim(ExtractString(strTmp, 'Buffers:', 'kB'));
// Process Cached
strTmp := slMemInfo.Strings[4];
strCached := Trim(ExtractString(strTmp, 'Cached:', 'kB'));
// Process Shmem
strTmp := slMemInfo.Strings[20];
strShmem := Trim(ExtractString(strTmp, 'Shmem:', 'kB'));
// Process SReclaimable
strTmp := slMemInfo.Strings[25];
strSRclaimable := Trim(ExtractString(strTmp, 'SReclaimable:', 'kB'));
// Calc Mem Total
intTotalMem := StrToFloat(strMemTotal);
// Calc Mem Usage
intMemUsage := (intTotalMem - StrToFloat(strMemFree) - StrToFloat(strBuffers) -
StrToFloat(strCached) - StrToFloat(strSRclaimable));
finally
slMemInfo.Free;
end;
except
on E: EInOutError do
writeln('File handling error occurred. Details: ', E.Message);
end;
Result := Format('%.2fGB / %.2fGB', [intMemUsage / (1024 * 1024), intTotalMem / (1024 * 1024)]);
end;
I am not saying you should change your formula, just making you aware of the accepted formula used at htop, everyone seems to have a different opinion on this particular topic, and it goes into a lot more discussion at kernel.org and htop github, hope this helps, if not disregard and deleted the topic.
fyi,
programs like btop uses the same formula as nitch, but they are aware of htop and the kernel.org discription aristocratos/btop#161
The text was updated successfully, but these errors were encountered:
Hi,
Just want to say you have an excellent job on nitch, But as you probably already know, there are different versions on how used memory should be displayed, I did notice on nitch that it takes TotalMem - AvailableMem to get UsedMem. I just wanted to make you aware of the formula that htop uses and which has derived from a write up on Kernel.org
https://www.kernel.org/doc/Documentation/filesystems/proc.txt
basically htop originally used MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable + Shmem
Then some patches made it in the kernel changed the way SharedMem and Cached are calculated, I haven't personally read the patch notes https://lore.kernel.org/lkml/[email protected]/
but it basically comes down to Shmem being part of cache so the accepted formula and the one htop uses is
MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable
I have implemented this is my fetch program written Pascal
I am not saying you should change your formula, just making you aware of the accepted formula used at htop, everyone seems to have a different opinion on this particular topic, and it goes into a lot more discussion at kernel.org and htop github, hope this helps, if not disregard and deleted the topic.
fyi,
programs like btop uses the same formula as nitch, but they are aware of htop and the kernel.org discription
aristocratos/btop#161
The text was updated successfully, but these errors were encountered: