Unusable areas in the memory map.
Posted: Sat Mar 24, 2012 9:43 pm
So I almost finished my memory detection code. Needs some polishing, some finishing touches, more comments. As suggested, I'm managing overlapping free and non free areas in various combinations - merging adjacent free areas, splitting a free area into two smaller areas, if an unusable area is in the middle of it, shrinking/truncating a free area, if a non free area partially overlaps it. And my question is about those unusable areas. Is it necessary to keep track of them? Currently I extract only the usable ram areas. Though keeping track of unusable areas should not be hard to implement having current functionality. I mean I understand perfectly clear why I need to know usable ram areas and not write to areas, that are not free for use. But what would I use the non free areas for? Do I really need to know where they are, if I can't use them? Because it seems that I know where certain devices are mapped. I could use vga text mode memory as an example. It's location is standardized, it is always at the same address. Or so I think. It's memory is not available for use in the sense, that you can't allocate an area that it uses, for other purposes, but the kernel's vga text mode driver uses it for it's own good. While it does not have it's memory zone marked as unusable, it assumes the area is meant to manipulate the text on screen. Then, AFAIK there are devices that can be mapped by kernel to areas it chooses. Correct me if I'm wrong, but PCI would be one case of that. But I thought, that the kernel could allocate an area of known usable ram for that. So again, i can't see the purpose of tracking unusable ram areas. Then there's the simple matter, that it's logical, that areas, that are not mapped as usable, are unusable. And perhaps the kernel could track which device uses which area (like the PCI) of memory by tracking those areas in the memory map - marking them as unusable, but again, I think that the addresses for memory mapped devices are either assumed (IOW hard coded), and don't need to be tracked, or allocated by means of memory management. And maybe it is because some areas are marked as "reclaimable"? This is the only reason I can think of right now. And I read http://forum.osdev.org/viewtopic.php?f= ... 01#p140080 and http://wiki.osdev.org/Memory_Map_(x86) , which are mostly the same, but still. These two pages don't seem to make it clearer for me. I also tried searching the net, but either there is little to no such information, or Google just can't find it, or I was using the wrong keywords. Oh, and the stuff about PCI in this Brendan's post http://forum.osdev.org/viewtopic.php?f= ... ap#p206397 indicates that memory mapped PCI devices' memory ranges should in fact be marked as unusable ram? If so, is it possible to do it the way I mentioned, which I'd prefer, at least with the current knowledge, or are there some sort of barriers for that, maybe some sort of reason, why the other way is better?