kboot: Parse memory usage
To properly size segments, we have to know how much memory we have in the system, as well as how much this process can allocate. Due to our inability to overcommit, we need to know how much memory is available. commit_limit is the grand total allowed. committed_as is the current memory used. mem_avail is what Linux tells us is available. Find these from /proc/meminfo. We'll use them later to allocate the biggest possible segment sizes, but for now print the raw numbers. Sponsored by: Netflix Reviewed by: kevans (earlier version) Differential Revision: https://reviews.freebsd.org/D38267
This commit is contained in:
parent
2e1edd04eb
commit
7da605ec03
@ -50,6 +50,45 @@ static void kboot_zfs_probe(void);
|
||||
|
||||
extern int command_fdt_internal(int argc, char *argv[]);
|
||||
|
||||
static uint64_t commit_limit;
|
||||
static uint64_t committed_as;
|
||||
static uint64_t mem_avail;
|
||||
|
||||
static void
|
||||
memory_limits(void)
|
||||
{
|
||||
int fd;
|
||||
char buf[128];
|
||||
|
||||
/*
|
||||
* To properly size the slabs, we need to find how much memory we can
|
||||
* commit to using. commit_limit is the max, while commited_as is the
|
||||
* current total. We can use these later to allocate the largetst amount
|
||||
* of memory possible so we can support larger ram disks than we could
|
||||
* by using fixed segment sizes. We also grab the memory available so
|
||||
* we don't use more than 49% of that.
|
||||
*/
|
||||
fd = open("host:/proc/meminfo", O_RDONLY);
|
||||
if (fd != -1) {
|
||||
while (fgetstr(buf, sizeof(buf), fd) > 0) {
|
||||
if (strncmp(buf, "MemAvailable:", 13) == 0) {
|
||||
mem_avail = strtoll(buf + 13, NULL, 0);
|
||||
mem_avail <<= 10; /* Units are kB */
|
||||
} else if (strncmp(buf, "CommitLimit:", 12) == 0) {
|
||||
commit_limit = strtoll(buf + 13, NULL, 0);
|
||||
commit_limit <<= 10; /* Units are kB */
|
||||
} else if (strncmp(buf, "Committed_AS:", 13) == 0) {
|
||||
committed_as = strtoll(buf + 14, NULL, 0);
|
||||
committed_as <<= 10; /* Units are kB */
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Commit limit: %lld Committed bytes %lld Available %lld\n",
|
||||
(long long)commit_limit, (long long)committed_as,
|
||||
(long long)mem_avail);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* NB: getdev should likely be identical to this most places, except maybe
|
||||
* we should move to storing the length of the platform devdesc.
|
||||
@ -217,6 +256,8 @@ main(int argc, const char **argv)
|
||||
setenv("LINES", "24", 1);
|
||||
setenv("usefdt", "1", 1);
|
||||
|
||||
memory_limits();
|
||||
|
||||
/*
|
||||
* Find acpi, if it exists
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user