Commit 95e861db authored by Eric Dumazet's avatar Eric Dumazet Committed by Linus Torvalds

[PATCH] reorder struct files_struct

The file_lock spinlock sits close to mostly read fields of 'struct
files_struct'

In SMP (and NUMA) environments, each time a thread wants to open or close
a file, it has to acquire the spinlock, thus invalidating the cache line
containing this spinlock on other CPUS.  So other threads doing
read()/write()/...  calls that use RCU to access the file table are going
to ask further memory (possibly NUMA) transactions to read again this
memory line.

Move the spinlock to another cache line, so that concurrent threads can
share the cache line containing 'count' and 'fdt' fields.

It's worth up to 9% on a microbenchmark using a 4-thread 2-package x86
machine.  See
http://marc.theaimsgroup.com/?l=linux-kernel&m=112680448713342&w=2Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d6c7ac08
...@@ -33,13 +33,13 @@ struct fdtable { ...@@ -33,13 +33,13 @@ struct fdtable {
* Open file table structure * Open file table structure
*/ */
struct files_struct { struct files_struct {
atomic_t count; atomic_t count;
spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */
struct fdtable *fdt; struct fdtable *fdt;
struct fdtable fdtab; struct fdtable fdtab;
fd_set close_on_exec_init; fd_set close_on_exec_init;
fd_set open_fds_init; fd_set open_fds_init;
struct file * fd_array[NR_OPEN_DEFAULT]; struct file * fd_array[NR_OPEN_DEFAULT];
spinlock_t file_lock; /* Protects concurrent writers. Nests inside tsk->alloc_lock */
}; };
#define files_fdtable(files) (rcu_dereference((files)->fdt)) #define files_fdtable(files) (rcu_dereference((files)->fdt))
......
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