diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2006-03-23 06:00:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-23 10:38:09 -0500 |
commit | 0c9e63fd38a2fb2181668a0cdd622a3c23cfd567 (patch) | |
tree | 8fdb91603347b1da2e83a095ebcaab44b2c3c237 /include/linux/file.h | |
parent | d8733c2956968a01394a4d2a9e97a8b431a78776 (diff) |
[PATCH] Shrinks sizeof(files_struct) and better layout
1) Reduce the size of (struct fdtable) to exactly 64 bytes on 32bits
platforms, lowering kmalloc() allocated space by 50%.
2) Reduce the size of (files_struct), using a special 32 bits (or
64bits) embedded_fd_set, instead of a 1024 bits fd_set for the
close_on_exec_init and open_fds_init fields. This save some ram (248
bytes per task) as most tasks dont open more than 32 files. D-Cache
footprint for such tasks is also reduced to the minimum.
3) Reduce size of allocated fdset. Currently two full pages are
allocated, that is 32768 bits on x86 for example, and way too much. The
minimum is now L1_CACHE_BYTES.
UP and SMP should benefit from this patch, because most tasks will touch
only one cache line when open()/close() stdin/stdout/stderr (0/1/2),
(next_fd, close_on_exec_init, open_fds_init, fd_array[0 .. 2] being in the
same cache line)
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/file.h')
-rw-r--r-- | include/linux/file.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/include/linux/file.h b/include/linux/file.h index 9901b850f2e4..9f7c2513866f 100644 --- a/include/linux/file.h +++ b/include/linux/file.h | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/compiler.h> | 10 | #include <linux/compiler.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/rcupdate.h> | 12 | #include <linux/rcupdate.h> |
13 | #include <linux/types.h> | ||
13 | 14 | ||
14 | /* | 15 | /* |
15 | * The default fd array needs to be at least BITS_PER_LONG, | 16 | * The default fd array needs to be at least BITS_PER_LONG, |
@@ -17,10 +18,22 @@ | |||
17 | */ | 18 | */ |
18 | #define NR_OPEN_DEFAULT BITS_PER_LONG | 19 | #define NR_OPEN_DEFAULT BITS_PER_LONG |
19 | 20 | ||
21 | /* | ||
22 | * The embedded_fd_set is a small fd_set, | ||
23 | * suitable for most tasks (which open <= BITS_PER_LONG files) | ||
24 | */ | ||
25 | struct embedded_fd_set { | ||
26 | unsigned long fds_bits[1]; | ||
27 | }; | ||
28 | |||
29 | /* | ||
30 | * More than this number of fds: we use a separately allocated fd_set | ||
31 | */ | ||
32 | #define EMBEDDED_FD_SET_SIZE (BITS_PER_BYTE * sizeof(struct embedded_fd_set)) | ||
33 | |||
20 | struct fdtable { | 34 | struct fdtable { |
21 | unsigned int max_fds; | 35 | unsigned int max_fds; |
22 | int max_fdset; | 36 | int max_fdset; |
23 | int next_fd; | ||
24 | struct file ** fd; /* current fd array */ | 37 | struct file ** fd; /* current fd array */ |
25 | fd_set *close_on_exec; | 38 | fd_set *close_on_exec; |
26 | fd_set *open_fds; | 39 | fd_set *open_fds; |
@@ -33,13 +46,20 @@ struct fdtable { | |||
33 | * Open file table structure | 46 | * Open file table structure |
34 | */ | 47 | */ |
35 | struct files_struct { | 48 | struct files_struct { |
49 | /* | ||
50 | * read mostly part | ||
51 | */ | ||
36 | atomic_t count; | 52 | atomic_t count; |
37 | struct fdtable *fdt; | 53 | struct fdtable *fdt; |
38 | struct fdtable fdtab; | 54 | struct fdtable fdtab; |
39 | fd_set close_on_exec_init; | 55 | /* |
40 | fd_set open_fds_init; | 56 | * written part on a separate cache line in SMP |
57 | */ | ||
58 | spinlock_t file_lock ____cacheline_aligned_in_smp; | ||
59 | int next_fd; | ||
60 | struct embedded_fd_set close_on_exec_init; | ||
61 | struct embedded_fd_set open_fds_init; | ||
41 | struct file * fd_array[NR_OPEN_DEFAULT]; | 62 | struct file * fd_array[NR_OPEN_DEFAULT]; |
42 | spinlock_t file_lock; /* Protects concurrent writers. Nests inside tsk->alloc_lock */ | ||
43 | }; | 63 | }; |
44 | 64 | ||
45 | #define files_fdtable(files) (rcu_dereference((files)->fdt)) | 65 | #define files_fdtable(files) (rcu_dereference((files)->fdt)) |