From: Miklos Szeredi Date: Fri, 23 Jun 2006 09:05:10 +0000 (-0700) Subject: [PATCH] locks: don't do unnecessary allocations X-Git-Tag: v2.6.18-rc1~1081^2~77 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39005d022ad221b76dc2de0ac62ef475a796433b;p=platform%2Fkernel%2Flinux-3.10.git [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: Miklos Szeredi Cc: Trond Myklebust Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/fs/locks.c b/fs/locks.c index c5ac6b4..2344f24 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -794,7 +794,8 @@ out: static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request, struct file_lock *conflock) { 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 *right = NULL; struct file_lock **before; @@ -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, * 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(); - new_fl2 = locks_alloc_lock(); + if (!(request->fl_flags & FL_ACCESS) && + (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(); if (request->fl_type != F_UNLCK) {