Results 1 to 9 of 9
Hi,
I'm looking for a consistent way to determine the available kernel memory. I found the 'free -l' and the cat /proc/meminfo commands, but they don't work on all linux ...
- 07-07-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Kernel memory determination
Hi,
I'm looking for a consistent way to determine the available kernel memory. I found the 'free -l' and the cat /proc/meminfo commands, but they don't work on all linux kernels/distributions. For instance, on the small version of the Wind River Linux distribution, the free command is not available. Is there a consistent method of determining the kernel memory (physically mapped one-to-one) across architectures, distributions, and kernels?
Additionally, I'd like a global variable that could reliably be used to determine the value. This would be used for OS aware debugging software. If we could look up a symbol to get the value, it would allow us to automatically determine it without requesting input from the user. We could also lookup a routine name that calculates it, execute the routine, and read the value from a register. Any other ideas would also be welcome.
Thanks,
Chris
- 07-08-2010 #2
try this i-scream libstatgrab homepage
- 07-08-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
Thanks. Unfortunately, it uses meminfo to get all it's information. Also, I need a procedure that I can run on any Linux OS without needing to install new utilities.
- 07-08-2010 #4Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
How about the sysinfo() function? This appears to be implemented across architectures/distributions, and I believe the return structure is standard. Does anyone know of any potential pitfalls? For instance, is the structure always fully populated by all distributions?
- 07-09-2010 #5
that library claims to run on any 2.2/2.4/2.6 kernel linux distro
based on the man page for sysinfo, it looks like it has what you need anyway, i would seriously doubt that it is distro dependent, it should only be kernel dependent and work on 2.4/2.6 kernels
- 07-09-2010 #6Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
I agree. Thanks for the input.
The only thing I worry about is that it won't be included in a distribution. Is that a concern? Is it always included, even on small footprint versions of Linux?
- 07-09-2010 #7
seems to be part of libc and glibc, so it should be there, you will probably have to write a small program to make the call though
- 07-09-2010 #8
I do have one problem with this method
there is no way to see cached memory, you can only see free and buffered memory, and since cache memory is only used by disk cache and is technically free, you will be missing this
Code:#include <sys/sysinfo.h> #include <stdio.h> int main(int argc, char **argv) { struct sysinfo info; int error; error = sysinfo(&info); if (error != 0) { printf("Error: %d\n", error); return error; } printf("Total Memory: %ld\n", info.totalram); printf("Free Memory: %ld\n", info.freeram); printf("Shared Memory: %ld\n", info.sharedram); printf("Buffered Memory: %ld\n", info.bufferram); printf("Total High Memory: %ld\n", info.totalhigh); printf("Free High Memory: %ld\n", info.freehigh); return 0; }
- 07-09-2010 #9Just Joined!
- Join Date
- Jul 2010
- Posts
- 5
I'm really only interested in low memory utilized in a one-to-one mapping (no virtual use) by the kernel, so the cache memory is not a problem.


Reply With Quote
