if (copy_to_user(info, &val, sizeof(struct sysinfo)))
return -EFAULT;
return 0;
}
sysinfo()系统调用最终由上面的函数给出内核的统计值。
其中,do_sysinfo()函数的实现也在同一文件中,其定义的部分内容如下:
[kernel/timer.c: sysinfo()->do_sysinfo()]
/**
* do_sysinfo - fill in sysinfo struct
* @info: pointer to buffer to fill
*/
int do_sysinfo(struct sysinfo *info)
{
...
si_meminfo(info);
...
bitcount = 0;
mem_unit = info->mem_unit;
while (mem_unit > 1) {
bitcount++;
mem_unit >>= 1;
sav_total = mem_total;
mem_total <<= 1;
if (mem_total < sav_total)
goto out;
}
/*
* If mem_total did not overflow, multiply all memory values by
* info->mem_unit and set it to 1. This leaves things compatible
* with 2.2.x, and also retains compatibility with earlier 2.4.x
* kernels...
*/