Octocontrabass wrote:
rdos wrote:
particularly when most discs use 512 bytes per sector.
Almost all modern disks use 4096 bytes per physical sector. They may offer a compatibility mode with 512-byte logical sectors, but you should only write whole 4096-byte physical sectors. This is especially important for SSDs, where write amplification caused by partial physical sector writes will shorten the drive's lifespan.
Right, and this would make the user space interface a lot simpler. Instead of needing to update bitmaps with written sectors, the page table dirty bit can be used for writing back whole 4096 areas.
The user space file part entry would then look like:
Code:
struct FilePartEntry
{
int64 position;
int32 size;
int32 base;
};
A 4k page could contain up 256 such entries to be able to buffer up to 256 parts of the file. This 4k page can then be made read only so it cannot be modified by user space.
Using the dirty and accessed bits a "second chance" algorithm can be developed for removing unused parts of the file. Every time a read has taken place the counter is increased, and a write might increase it with two (or more). When an untouched part is found, the counter is decreased, and if it is zero, the part is removed from the mapping. The replacement algorithm can be run with each part miss and regularly (like once a second). Write back of file contents can be checked at the same time.
Another mapping will map current state of the file, like current size, allocated size, attributes & name. This mapping will also be read only to user space.
I will need two new syscalls:
- Request to cache a new part of the file (position + desired size as parameters)
- Request to change the file size