I'm looking for a function to call from a C program that returns the number of free huge pages.
I've found functions to return the huge page size(s), lots of information on how to use pseudo file system entries, but no man page for a function that returns the same information you get from running:
cat /proc/meminfo | grep '^Huge'
Is there such a thing?
I tried lots of web searches, got lots of information on use of huge pages, but no information on how to write a program that makes a system call to get said information.
This
ccode will open the file/proc/meminfoand read the values.Here is output showing 2
Hugevalues extracted.Notice that the entire line of text is read from the file. The line buffer here is static but other efforts can modify to buffer the entire file or other approaches for reading file data.
Notice that the
sscanfreturns number of assignments made by the format specified. The format specified separates the values to match. For example the text "HugePages_Total" must match or no assignments are made.Good luck!
main.c