linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Morten Hustveit <mortehu@ping.uio.no>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] fcntl: Add the F_READAHEAD command
Date: Thu, 25 Nov 2010 10:54:37 +0100	[thread overview]
Message-ID: <20101125095437.GA3409@ping.uio.no> (raw)

Allow userland applications to control the read-ahead per file descriptor.

For example, this interface can be used to adjust read sizes in applications
using sendfile() to serve many streams from disk.

The implementation is based on sys_readahead() and sys_fadvise64().

The same interface was added to FreeBSD in 2009.

Signed-off-by: Morten Hustveit <mortehu@ping.uio.no>
--- 
diff --git a/fs/fcntl.c b/fs/fcntl.c
index ecc8b39..19a8a46 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -340,6 +340,31 @@ static int f_getown_ex(struct file *filp, unsigned long arg)
 	return ret;
 }
 
+static int f_readahead(struct file *filp, unsigned long arg)
+{
+	struct address_space *mapping;
+
+	mapping = filp->f_mapping;
+	if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage)
+		return -EINVAL;
+
+	if (mapping->a_ops->get_xip_mem)
+		return 0;
+
+	if (arg) {
+		filp->f_ra.ra_pages = (arg + PAGE_SIZE - 1) >> PAGE_SHIFT;
+		spin_lock(&filp->f_lock);
+		filp->f_mode &= ~FMODE_RANDOM;
+		spin_unlock(&filp->f_lock);
+	} else {
+		spin_lock(&filp->f_lock);
+		filp->f_mode |= FMODE_RANDOM;
+		spin_unlock(&filp->f_lock);
+	}
+
+	return 0;
+}
+
 static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
 		struct file *filp)
 {
@@ -420,6 +445,9 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
 	case F_GETPIPE_SZ:
 		err = pipe_fcntl(filp, cmd, arg);
 		break;
+	case F_READAHEAD:
+		err = f_readahead(filp, arg);
+		break;
 	default:
 		break;
 	}
diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h
index afc00af..69d8e4d 100644
--- a/include/linux/fcntl.h
+++ b/include/linux/fcntl.h
@@ -28,6 +28,11 @@
 #define F_GETPIPE_SZ	(F_LINUX_SPECIFIC_BASE + 8)
 
 /*
+ * Set read-ahead buffer size
+ */
+#define F_READAHEAD	(F_LINUX_SPECIFIC_BASE + 9)
+
+/*
  * Types of directory notifications that may be requested.
  */
 #define DN_ACCESS	0x00000001	/* File accessed */

             reply	other threads:[~2010-11-25 10:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-25  9:54 Morten Hustveit [this message]
2010-11-25 18:08 ` [PATCH] fcntl: Add the F_READAHEAD command Andreas Dilger
2010-11-26  0:36   ` [PATCH v2] " Morten Hustveit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101125095437.GA3409@ping.uio.no \
    --to=mortehu@ping.uio.no \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).