Hi,
Doh - bewing beat me to it! Hmm - post it anyway...
MDM wrote:Hey, so I got some questions for you all (I searched through the wiki/forums, didn't find any topics like this, so sorry if I missed something and am duplicating topic subjects). So I know a little bit about normal HD driver algorithms, but I don't know much about reading/writing to SSD, or RAID controllers, and what algorithms are the most efficient for them. It seems since SSD doesn't have any moveable parts, FCFS would be best, but I would like to make sure...
Internally SSD works on large blocks (e.g. maybe 1 MiB blocks). For example, if you write 4096 bytes then the SSD might (internally) read 1 MiB, modify the 4096 bytes within it, then write the entire 1 MiB back. For maximum performance you might want to cache blocks in RAM (e.g. only ever read large blocks), and combine writes that effect the same "large block" into a single write (e.g. if someone wants to write 4096 bytes at offset 0 and someone else wants to write 4096 bytes at offset 0x8000, then you update the data in your cache and write the entire large block (rather than doing 2 separate/smaller writes).
Also, most modern OS's have I/O priorities. Taking this into account you'd want a list of pending read/write requests. You'd find the highest priority request in the list, work out which large block/s are needed for the highest priority request, then find any other pending requests in the list that effect the same large block, then combine all of those requests so that you only do 1 read (if necessary) and 1 write to satisfy all of the requests.
Of course there's still cases where you'd want to do "partial block" reads/writes. For example, if there's very little chance that reading a full block will help you avoid future reads from that block (maybe your cache is tiny due to lack of free RAM) and the bottleneck is USB bandwidth; then reading/writing a partial block might be better.
MDM wrote:Also what about RAID? What type of algorithms are best for RAID controllers, as well? Does the best RAID algorithm change depending on what hard drives are in the RAID array? Specifically, what about an SSD and a hard disk used in a RAID array? What about RAID's with disks of different sizes? (Sorry for all the questions relating to this...).
For software RAID you end up with a layer of software that sends read/write requests to the disk drivers themselves; and the disk drivers work the same as they would without RAID (and different drivers may use different algorithms to suit different device types). For hardware RAID the RAID controller sorts it out - you just pretend it's a single device (even though it's not). In this case you might want to attempt to do "large blocks" if any of the devices are SSD, and you'd might want to attempt to limit head movement if any of the devices are hard disks (which means that for a mixture of hard disks and SSD you might want to attempt to do both). It'd also depend on the RAID controller - maybe the RAID controller has it's own caching, and maybe the RAID controller supports NCQ ("Native Command Queue", where the controller can decide to do things in a different order to improve performance).
MDM wrote:Also, just a misc question... So when I turn my computer on it searches for the bootsector (0x7c00) (or does it search for bootsector on first partion...?) on my hard disk, if it finds a bootable bootsector, it loads it, which then loads the bootloader, which (depending on which bootloader you have...) reads the partion-table, and then asks the end user which partion you want to load, when you load the said partion, it loads another bootloader for that specific partion/OS on that partion. How does it know where that bootloader is/what size it is. Is their a localized bootsector for partions as well as a global bootsector? How would it find that bootsector?
For "PC BIOS" systems; when you turn the computer on the BIOS searches for a bootable device. Usually there's a search order that can be controlled by BIOS settings (e.g. "first floppy, then first CD, then first hard drive"). For different types of devices the BIOS does different things.
For floppy disks and hard disks (and USB devices that look like a disk to the BIOS) the BIOS loads the first sector (usually 512 bytes) from the device at 0x00007C00 and jumps to it. That's all the BIOS does. The first sector might contain a partition table and a piece of code to find a bootable partition (a partition marked as "active" in the partition table), load the first sector from the bootable partition and jump to it. It's possible to partition a floppy drive or have a hard drive that isn't partitioned - the BIOS doesn't know/care (but most OSs expect floppies to have no partitions and expect hard drives to be partitioned).
For CD-ROMs the BIOS searches for a special table (the "boot catalogue") on the CD, which tells the BIOS if the CD is bootable and how to boot it. There's 3 options here. The entry in the boot catalogue might tell the BIOS to emulate a floppy disk (and tell the BIOS where a floppy image is on the CD); or the boot catalogue might tell the BIOS to emulate a hard disk (and tell the BIOS where a hard disk image is on the CD). In both these case it ends up being like a real floppy/hard disk (BIOS modifies it's "disk services" functions to make the image on the CD look like a real floppy/hard drive; then loads the first 512 bytes from the emulated floppy/hard disk and jumps to it). The other options is "no emulation". In this case the BIOS loads "n" sectors from somewhere on the CD and then jumps to it; where the number of sectors, the starting sector and the address to load them are all determined from the entry in the boot catalogue. In theory this allows you to have a huge boot loader (e.g. 400 KiB) and you can ask the BIOS to load it at 0x00001000 or anywhere else that is sane for real mode code (instead of 0x00007C00). In practice some BIOSs are buggy and it's better to use 0x00007C00 as the load address (and only load 1 sector if you can). For "no emulation" CD boot, you can use the BIOS disk services to read (2048 byte) sectors from the CD; and if the boot loader needs to load more files from CD it can (but the boot loader should probably have code to support the CD's file system, e.g. ISO9660).
For network boot, the BIOS starts code in the network card's ROM. The network card's ROM broadcasts a (slightly special) request for DHCP info, and hopefully a server returns a (slightly special) DHCP info packet containing the normal information (IP address, subnet mask, etc) with some additional/extra information (the IP address for a TFTP server and a file name to download from that TFTP server). Then the network card's ROM contacts the TFTP server and tries to download the file into memory at 0x00007C00, and then jumps to this file. In this case the boot loader (that was downloaded and jumped to) can use a special API provided by the network card's ROM to access network services (including downloading more files if necessary). There are some variations on this that are only supported in some cases (e.g. some network cards might allow files to be downloaded by normal FTP or HTTP); and it's possible for the "network card's ROM" to actually be normal code (e.g. booted from a disk) that is pretending to be a network card's ROM (but actually isn't). For this to work you need a DHCP server that supports it (and you need to configure it so the correct computers start the correct file, which can be a little tricky if different computers boot different files as you need to rely on ethernet MAC addresses) and you need a TFTP server somewhere too (not necessarily on the same computer as the DHCP server).
Cheers,
Brendan