In short, how's file system communicate with block device?
CodePudding user response:
I don't know much about block sizes. I think the block size of the filesystem for ext4 (Linux) is 4KB which is logical considering the modern processor's page size (4KB). Now I think the block size (minimal addressable unit) of modern SSDs is either 256KB or 4MB depending on the disk. This is probably due to several factors (memory throughput, cost vs performance, etc).
In short, how's file system communicate with block device?
The filesystem doesn't communicate with block devices, the OS does. On x86, the OS sets up the registers of the PCI DMA host controller known as AHCI (https://www.intel.com/content/www/us/en/io/serial-ata/serial-ata-ahci-spec-rev1-3-1.html). The OS triggers read/write cycles to/from RAM in blocks of 256KB/4MB. It probably holds structures of the filesystem that it loads at boot. It thus knows already where the different files are (it has a cache). It will load the part of the filesystem it needs, read/write the file, then rewrite modifications on disk in big blocks.
Also, the AHCI triggers MSI interrupts on command completion. Basically, the OS triggers DMA read/write cycles on behalf of user mode processes. It will then put these processes on the wait-for-IO queue. On interrupt, it will put back the process on the run queue and put the address of the disk data in the corresponding register for the read() or write() call.