Commit 39005d02 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

[PATCH] locks: don't do unnecessary allocations

posix_lock_file() always allocates new locks in advance, even if it's easy to
determine that no allocations will be needed.

Optimize these cases:

 - FL_ACCESS flag is set

 - Unlocking the whole range
Signed-off-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0d9a490a
...@@ -794,7 +794,8 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) ...@@ -794,7 +794,8 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request, struct file_lock *conflock) static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
{ {
struct file_lock *fl; struct file_lock *fl;
struct file_lock *new_fl, *new_fl2; struct file_lock *new_fl = NULL;
struct file_lock *new_fl2 = NULL;
struct file_lock *left = NULL; struct file_lock *left = NULL;
struct file_lock *right = NULL; struct file_lock *right = NULL;
struct file_lock **before; struct file_lock **before;
...@@ -803,9 +804,15 @@ static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request ...@@ -803,9 +804,15 @@ static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request
/* /*
* We may need two file_lock structures for this operation, * We may need two file_lock structures for this operation,
* so we get them in advance to avoid races. * so we get them in advance to avoid races.
*
* In some cases we can be sure, that no new locks will be needed
*/ */
new_fl = locks_alloc_lock(); if (!(request->fl_flags & FL_ACCESS) &&
new_fl2 = locks_alloc_lock(); (request->fl_type != F_UNLCK ||
request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
new_fl = locks_alloc_lock();
new_fl2 = locks_alloc_lock();
}
lock_kernel(); lock_kernel();
if (request->fl_type != F_UNLCK) { if (request->fl_type != F_UNLCK) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment