Skip to contentSkip to conversation

don't allow sys_readahead() on files opened with O_DIRECT

PATCH RESEND In review Jan Blunck 3 participants 4 messages Aug 23, 2005 – Aug 25, 2005

Subsystems (2)
lore
Share & tools
lore

Jan Blunck

author
#0 lore raw

PATCH RESEND 1/1 don't allow sys_readahead() on files opened with O_DIRECT

IMO sys_readahead() doesn't make sense if the file is opened with O_DIRECT, because the page cache is stuffed but never used. Therefore this patch changes that by letting the call return with -EINVAL.

 mm/filemap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)
mm/filemap.c +2 -1
Index: experimental-jb/mm/filemap.c
===================================================================
@@ -1111,7 +1111,8 @@ static ssize_t
 do_readahead(struct address_space *mapping, struct file *filp,
 	     unsigned long index, unsigned long nr)
 {
-	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage)
+	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage
+	    || (filp->f_flags & O_DIRECT))
 		return -EINVAL;
 
 	force_page_cache_readahead(mapping, filp, index,
#1 lore raw
Quoted 5 lines · Jan Blunck

IMO sys_readahead() doesn't make sense if the file is opened with O_DIRECT, because the page cache is stuffed but never used. Therefore this patch changes that by letting the call return with -EINVAL.

a) It doesn't hurt, it's just a bit of a silly thing to do.

b) posix_fadvise(POSIX_FADV_WILLNEED) should get the same treatment (and it's the preferred way of doing readahead).

c) O_DIRECT fd's should, as much as possible, offer the same ABI as buffered fd's.

d) The patch could break existing apps.

author
#2 lore raw
Quoted 2 lines · Andrew Morton

a) It doesn't hurt, it's just a bit of a silly thing to do.

IMO it may hurt the performance.

Quoted 3 lines

b) posix_fadvise(POSIX_FADV_WILLNEED) should get the same treatment (and it's the preferred way of doing readahead).

Yes, of course.

Quoted 3 lines

c) O_DIRECT fd's should, as much as possible, offer the same ABI as buffered fd's.

Hmm, with XIP fd's we agreed on the following behavior: fadvise() and madvise() just return without reading anything to the page cache. Since XIP fd's are similar to O_DIRECT fd's their behavior should be similar, too. If we don't honor the advises we might also ignore the syscall. At least redhat's readahead is using them.

Maybe we should agree on one behavior that makes sense. And I don't see any point in filling the page cache when it is not needed.

Quoted 2 lines

d) The patch could break existing apps.

Since it could break applications that are already (some kind of) broken that shouldn't be a problem.

So you think it is better to read nothing to the page cache and return zero instead? This seems like "lying" to the user-space :)

#3 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton
Quoted 4 lines

IMO sys_readahead() doesn't make sense if the file is opened with O_DIRECT, because the page cache is stuffed but never used. Therefore this patch changes that by letting the call return with -EINVAL.

a) It doesn't hurt, it's just a bit of a silly thing to do.

For ocfs that only allows either direct or buffered I/O on a single inode at a given time it hurts. It messes up the synchronization protocol to be exact..