From: Eric Dumazet <dada1@cosmosbay.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [RFC, PATCH] avoid some atomics in open()/close() for monothreaded processes
Date: Wed, 22 Mar 2006 07:23:34 +0100 [thread overview]
Message-ID: <4420ED66.5060703@cosmosbay.com> (raw)
In-Reply-To: <4420DB55.60803@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 812 bytes --]
Goal : Avoid some locking/unlocking 'struct files_struct'->file_lock for mono
threaded processes.
We define files_multithreaded() function .
static inline int files_multithreaded(const struct files_struct *files)
{
return sizeof(files->file_lock) > 0 && atomic_read(&files->count) > 1;
}
On plain UP kernel (not preemptable nor spinlock debug), this function is a
const 0, so that gcc can wipe out some code.
On preemptible or SMP, or spinlock debug kernels, the result is true only if
the ref count is greater than 1 (multi threaded process or /proc/{pid}/fd is
under investigation by another task)
This patch increases kernel size but pros are worth the cons, as said Linus
himself, we should increase performance of mono-threaded tasks....
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: files_multithreaded.patch --]
[-- Type: text/plain, Size: 1790 bytes --]
--- a/include/linux/file.h 2006-03-22 06:23:02.000000000 +0100
+++ b/include/linux/file.h 2006-03-22 07:11:08.000000000 +0100
@@ -42,6 +42,11 @@
spinlock_t file_lock; /* Protects concurrent writers. Nests inside tsk->alloc_lock */
};
+static inline int files_multithreaded(const struct files_struct *files)
+{
+ return sizeof(files->file_lock) > 0 && atomic_read(&files->count) > 1;
+}
+
#define files_fdtable(files) (rcu_dereference((files)->fdt))
extern void FASTCALL(__fput(struct file *));
--- a/fs/open.c.orig 2006-03-22 06:24:34.000000000 +0100
+++ b/fs/open.c 2006-03-22 06:30:54.000000000 +0100
@@ -1050,11 +1050,17 @@
{
struct files_struct *files = current->files;
struct fdtable *fdt;
- spin_lock(&files->file_lock);
+ int fl_locked = 0;
+
+ if (files_multithreaded(files)) {
+ spin_lock(&files->file_lock);
+ fl_locked = 1;
+ }
fdt = files_fdtable(files);
BUG_ON(fdt->fd[fd] != NULL);
rcu_assign_pointer(fdt->fd[fd], file);
- spin_unlock(&files->file_lock);
+ if (fl_locked)
+ spin_unlock(&files->file_lock);
}
EXPORT_SYMBOL(fd_install);
@@ -1147,8 +1153,12 @@
struct file * filp;
struct files_struct *files = current->files;
struct fdtable *fdt;
+ int fl_locked = 0;
- spin_lock(&files->file_lock);
+ if (files_multithreaded(files)) {
+ spin_lock(&files->file_lock);
+ fl_locked = 1;
+ }
fdt = files_fdtable(files);
if (fd >= fdt->max_fds)
goto out_unlock;
@@ -1158,11 +1168,13 @@
rcu_assign_pointer(fdt->fd[fd], NULL);
FD_CLR(fd, fdt->close_on_exec);
__put_unused_fd(files, fd);
- spin_unlock(&files->file_lock);
+ if (fl_locked)
+ spin_unlock(&files->file_lock);
return filp_close(filp, files);
out_unlock:
- spin_unlock(&files->file_lock);
+ if (fl_locked)
+ spin_unlock(&files->file_lock);
return -EBADF;
}
next prev parent reply other threads:[~2006-03-22 6:23 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-12 2:04 More than 8 CPUs detected and CONFIG_X86_PC cannot handle it on 2.6.16-rc6 Krzysztof Oledzki
2006-03-12 5:03 ` Andrew Morton
2006-03-12 11:04 ` Krzysztof Oledzki
2006-03-12 11:25 ` Andrew Morton
2006-03-12 13:05 ` Krzysztof Oledzki
2006-03-12 15:35 ` Venkatesh Pallipadi
2006-03-12 21:13 ` Krzysztof Oledzki
2006-03-12 22:30 ` Andrew Morton
2006-03-13 19:36 ` Ashok Raj
2006-03-13 19:51 ` Andrew Morton
2006-03-13 20:05 ` Ashok Raj
2006-03-13 22:22 ` Andrew Morton
2006-03-13 23:04 ` Ashok Raj
2006-03-15 5:44 ` Nathan Lynch
2006-03-15 6:18 ` Shaohua Li
2006-03-15 7:31 ` Andrew Morton
2006-03-15 9:37 ` [PATCH] No need to protect current->group_info in sys_getgroups(), in_group_p() and in_egroup_p() Eric Dumazet
2006-03-20 19:09 ` [PATCH] Use unsigned int types for a faster bsearch Eric Dumazet
2006-03-22 5:06 ` [PATCH] Use __read_mostly on some hot fs variables Eric Dumazet
2006-03-22 5:15 ` Nick Piggin
2006-03-22 6:23 ` Eric Dumazet [this message]
2006-03-22 6:41 ` [RFC, PATCH] avoid some atomics in open()/close() for monothreaded processes Andrew Morton
2006-03-22 6:59 ` Eric Dumazet
2006-03-22 7:03 ` Andrew Morton
2006-03-15 18:09 ` More than 8 CPUs detected and CONFIG_X86_PC cannot handle it on 2.6.16-rc6 Ashok Raj
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=4420ED66.5060703@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=akpm@osdl.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