Are unlink
, fsync
, and rename
the only ones that are by definition atomic?
Edit: atomic means that an operation either succeeds and has an effect or has fails and has no effect; an operation must not fail and have an effect.
clearly if the kernel panics, the program can't handle the error of the operation failing but it must consider in this case that it did fail
Atomic operations are often used in the kernel, the primary component of most operating systems. However, most computer hardware, compilers and libraries also provide varying levels of atomic operations. In loading and storing, computer hardware carries out writing and reading to a word-sized memory.
Atomic operations are sequences of instructions that guarantee atomic accesses and updates of shared single word variables. This means that atomic operations cannot protect accesses to complex data structures in the way that locks can, but they provide a very efficient way of serializing access to a single word.
Edit: atomic means that an operation either succeeds and has an effect or has fails and has no effect; an operation must not fail and have an effect. clearly if the kernel panics, the program can't handle the error of the operation failing but it must consider in this case that it did fail Show activity on this post.
mv, link, symlink, mkdir and some ways of opening files are atomic. Show activity on this post. I'm not sure fsync (2) is atomic; if a file has 100 megabytes dirty in the buffer cache, it'll take several seconds to write that data out, and the kernel may crash while the transfer to disk is in progress.
Here's an article listing some atomic file operations:
http://rcrowley.org/2010/01/06/things-unix-can-do-atomically.html
mv
, link
, symlink
, mkdir
and some ways of opening files are atomic.
I'm not sure fsync(2)
is atomic; if a file has 100 megabytes dirty in the buffer cache, it'll take several seconds to write that data out, and the kernel may crash while the transfer to disk is in progress. Perhaps the DMA engine on board can only handle 4-megabyte writes. Perhaps there is no DMA support, and the CPU must schedule every write via 512 byte blocks.
What do you mean by 'atomic'?
mkdir
is probably 'atomic', either the directory exists on disk and is linked in to a parent directory, or the directory data structure isn't yet linked into a parent directory, and is therefore unreachable --> doesn't exist.
Same might go for mount(2)
: it would be hard to find a mount(2)
half-way complete, and if it fails, the entire mount fails: either the filesystem is mounted, or it isn't.
umount(2)
is funny, it can be done lazily, but once it is unmounted, it cannot be used for open(2)
or creat(2)
calls.
So, I guess it comes down to, what do you mean by 'atomic'? :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With