Looks like I am at it again. This time I'm writing a application level sector cache. Here's what I've got:
I have a USB thumb drive in which the raw device is opened for read/write. I have requested the kernel use an exclusive lock on the device and the no cache flag is specified. The cache table is 256 sectors. So for 512 byte sectors, the data size of the cache is 128KB. The search algorithm is linear so it starts at the top of the cache (most recently referenced sectors) and ends at the bottom. The actual cache algorithm that I have in place searches the cache table. If there is a hit, then that entry is brought up to the top while the other entries that are between the original position of the found entry and the top entry are pushed down one spot. If there is no hit, it's a write, and the table is full, then the entry with the lowest sequence number is removed from the list, unless it's towards the top end. In that case, the bottom entry is excised from the table instead.
What do you guys think about this? Is there a better way?
I have a USB thumb drive in which the raw device is opened for read/write. I have requested the kernel use an exclusive lock on the device and the no cache flag is specified. The cache table is 256 sectors. So for 512 byte sectors, the data size of the cache is 128KB. The search algorithm is linear so it starts at the top of the cache (most recently referenced sectors) and ends at the bottom. The actual cache algorithm that I have in place searches the cache table. If there is a hit, then that entry is brought up to the top while the other entries that are between the original position of the found entry and the top entry are pushed down one spot. If there is no hit, it's a write, and the table is full, then the entry with the lowest sequence number is removed from the list, unless it's towards the top end. In that case, the bottom entry is excised from the table instead.
What do you guys think about this? Is there a better way?