5 ms·
The kernel doesn't necessarily know how much physical memory is installed. It doesn't need to. It only needs to know how much physical memory it can use, and wh
by marcan_42 6y ago
The kernel doesn't necessarily know how much physical memory is installed. It doesn't need to. It only needs to know how much physical memory it can use, and where it lives in physical address space. On PCs, that is provided by the firmware at boot time via the e820 map (or via a UEFI method these days, and there is also the multiboot standard which GRUB will use to pass the info along to the booted kernel).
Therefore, there is no portable way to obtain that information that is guaranteed to work, because some platforms might not even provide it at all. Only if the kernel has/needs drivers that interact with the physical memory controller directly, or gets platform metadata such as via DMI, is this information readily available.
- wmf 6y agoHow much memory is reserved by UEFI and why? I would hope it's a negligible amount.
- dooglius 6y agoIf you have certain GPUs, it can be multiple gigs stolen as that's set aside for video memory
- gpderetta 6y agoDo you mean phisical address space or actual physical memory?
- dooglius 6y agoActual physical memory. I actually have a hack in order to reclaim and use some of this on my laptop.
- josephg 6y agoHow can you tell how much video memory is allocated & reserved by UEFI? I’d love to read more about this (and the hacks you used to get around it).
- dooglius 6y agoI just noticed the difference between what the manufacturer advertised and what the BIOS provided. Maybe I'll do a write-up of what I did at some point, but it's highly non-portable, and somewhat unsafe. Generally, the BIOS is supposed to allow the amount of video memory taken to be set along with other BIOS options, but there's no option in mine for whatever reason.
- monocasa 6y agoPhysical memory for integrated GPUs to use as VRAM.
- pjc50 6y agoIndeed. Also: what if you're inside virtualisation? The platform probably shouldn't tell you that there is more memory than allocated to your VM. Building systems that rely on looking round the curtain to the hardware has a habit of breaking when new hardware appears that does something surprising.
- JoeAltmaier 6y agoThat would be, all kernels. They all program the physical memory controller to suit their needs. They would all know how much memory is actually provisioned. Its a matter of a uniform way of exposing this information.
- cesarb 6y ago> That would be, all kernels. They all program the physical memory controller to suit their needs. None of the operating system kernels I know of (including Linux, all the BSDs, and Microsoft Windows) program the physical memory controller; it's always done by the platform firmware while running from ROM or cache-as-RAM, before the operating system kernel is loaded into RAM.
- JoeAltmaier 6y agoLinux: https://www.kernel.org/doc/html/latest/driver-api/memory-devices/index.html https://www.kernel.org/doc/html/latest/driver-api/memory-dev... Windows is harder to find (not open source) but issue tracking indicates it has one: https://www.intel.com/content/www/us/en/support/articles/000023446/software/chipset-software.html https://www.intel.com/content/www/us/en/support/articles/000... Of course the bootloaders all set up RAM. They have to, to load the operating system. Then the OS sets it up again, to suit itself.
- cesarb 6y agoAccording to https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/memory/Kconfig?h=v5.9 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin... these drivers are only used in some embedded systems. I looked at the kernel configuration for the distribution I'm using (/boot/config-`uname -r`), and CONFIG_MEMORY is not set, so none of these drivers are even available. That is: at least for desktop Linux, the firmware (not the bootloader) is the only one which sets up the physical memory controller (and actually, the only one which knows how to set up the physical memory controller; according to https://en.wikipedia.org/wiki/Coreboot#Initializing_DRAM https://en.wikipedia.org/wiki/Coreboot#Initializing_DRAM there's no public information on how to do so for modern desktop platforms).