BIBS
BIBS

Reputation: 414

Reasons for direct_io failure

I want to know under what circumstances a direct I/O transfer will fail?

I have following three sub-queries for that. As per "Understanding Linux kernel" book..

  1. Linux offers a simple way to bypass the page cache: direct I/O transfers. In each I/O direct transfer, the kernel programs the disk controller to transfer the data directly from/to pages belonging to the User Mode address space of a self-caching application.

-- So to explain failure one needs to check whether application has self caching feature or not? Not sure how that can be done.

2.Furthermore the book says "When a self-caching application wishes to directly access a file, it opens the file specifying the O_DIRECT flag . While servicing the open( ) system call, the dentry_open( ) function checks whether the direct_IO method is implemented for the address_space object of the file being opened, and returns an error code in the opposite case".

-- Apart from this any other reason that can explain direct I/O failure ?

3.Will this command "dd if=/dev/zero of=myfile bs=1M count=1 oflag=direct" ever fail in linux (assuming ample disk space available) ?

Upvotes: 2

Views: 1696

Answers (2)

Anon
Anon

Reputation: 7154

There are many reasons why direct I/O can go on to fail.

So to explain failure one needs to check whether application has self caching feature or not?

You can't do this externally - you have the either deduce this from the source code or watching how the program used resources as it ran (binary disassembly I guess). This is more a property of how the program does its work rather than a "turn this feature on in a call". It would be a dangerous assumption to think all programs that use O_DIRECT have self caching (probabilistically I'd say it's more likely but you don't know for sure).

  1. There are strict requirements for using O_DIRECT and they are mentioned in the man page of open (see the O_DIRECT section of NOTES).
  2. With modern kernels the area being operated on must be aligned to, and its size must be a multiple of, the disk's block size. Failure to do this correctly may even result in silent fallback to buffered I/O.
  3. Yes, for example trying to use it on a filesystem (such as tmpfs) doesn't support O_DIRECT. I suppose it could also fail if the path down to the disk returns failures for some reason (e.g. disk is dying and is returning the error much sooner in comparison to what happens with writeback).

Upvotes: 0

lqs
lqs

Reputation: 1454

The underlying filesystem and block device must support O_DIRECT flag. This command will fail because tmpfs doesn't support O_DIRECT.

dd if=/dev/zero of=/dev/shm/test bs=1M count=1 oflag=direct

The write size must be the multiply of the block size of underlying driver. This command will fail because 123 is not multiply of 512:

dd if=/dev/zero of=myfile bs=123 count=1 oflag=direct

Upvotes: 1

Related Questions