Closed infeo closed 1 year ago
To recycle the data buffer of Chunks, a synchronization mechanism is needed which ensures:
This would add another layer of complexity, hence, for now we decided to keep it simple and just synchronize threads on methods in CleartextFileChannel
.
In PR https://github.com/cryptomator/cryptofs/pull/125, the class
BufferPool
was introduced to reduce buffer allocations and reuse already allocated buffers for de- and encryption. The affected buffers are part of "Chunk" records, which represent a contigous memory area in a file.A buffer is recylced, when:
ChunkCache
: https://github.com/cryptomator/cryptofs/blob/ec170e76a75dc3188e32576a5b3326a2404f74fd/src/main/java/org/cryptomator/cryptofs/fh/ChunkCache.java#L47-L54The third point (recycle on eviction) causes a severe bug. Imagine the following scenario:
Low hit rate -> High number of cache evictions -> High recylce rate. But only because a chunk is evicted does not imply, the thread reading on the chunk has finished its operation. If the recycled buffer is selected to be filled again, the (still not finished) thread is reading wrong content.