Enlarging a Sparse File

231 Views Asked by At

I am designing a filesystem based queue and it impacts performance to scan the queue to compute its size when it is very large. I was looking for a way to count the task completions from many different processes. One idea I had was to create a "completions" file that each process opens in append mode and contributes one byte. The size of the file would then be the number of completions, which means the OS is effectively managing all the counter locking for me.

I was wondering if there would be a way to do this without writing any bytes at all using sparse files. I could call ftruncate with size = size + 1, but this would very obviously lead to many race conditions. I was wondering if there was a way to write one byte in append mode and have the byte never materialize.

Thanks for your suggestions!

0

There are 0 best solutions below