diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/file.h | 28 | ||||
| -rw-r--r-- | include/linux/init_task.h | 10 |
2 files changed, 29 insertions, 9 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)) |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index dcfd2ecccb5d..92146f3b7423 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
| @@ -7,11 +7,10 @@ | |||
| 7 | #define INIT_FDTABLE \ | 7 | #define INIT_FDTABLE \ |
| 8 | { \ | 8 | { \ |
| 9 | .max_fds = NR_OPEN_DEFAULT, \ | 9 | .max_fds = NR_OPEN_DEFAULT, \ |
| 10 | .max_fdset = __FD_SETSIZE, \ | 10 | .max_fdset = EMBEDDED_FD_SET_SIZE, \ |
| 11 | .next_fd = 0, \ | ||
| 12 | .fd = &init_files.fd_array[0], \ | 11 | .fd = &init_files.fd_array[0], \ |
| 13 | .close_on_exec = &init_files.close_on_exec_init, \ | 12 | .close_on_exec = (fd_set *)&init_files.close_on_exec_init, \ |
| 14 | .open_fds = &init_files.open_fds_init, \ | 13 | .open_fds = (fd_set *)&init_files.open_fds_init, \ |
| 15 | .rcu = RCU_HEAD_INIT, \ | 14 | .rcu = RCU_HEAD_INIT, \ |
| 16 | .free_files = NULL, \ | 15 | .free_files = NULL, \ |
| 17 | .next = NULL, \ | 16 | .next = NULL, \ |
| @@ -20,9 +19,10 @@ | |||
| 20 | #define INIT_FILES \ | 19 | #define INIT_FILES \ |
| 21 | { \ | 20 | { \ |
| 22 | .count = ATOMIC_INIT(1), \ | 21 | .count = ATOMIC_INIT(1), \ |
| 23 | .file_lock = SPIN_LOCK_UNLOCKED, \ | ||
| 24 | .fdt = &init_files.fdtab, \ | 22 | .fdt = &init_files.fdtab, \ |
| 25 | .fdtab = INIT_FDTABLE, \ | 23 | .fdtab = INIT_FDTABLE, \ |
| 24 | .file_lock = SPIN_LOCK_UNLOCKED, \ | ||
| 25 | .next_fd = 0, \ | ||
| 26 | .close_on_exec_init = { { 0, } }, \ | 26 | .close_on_exec_init = { { 0, } }, \ |
| 27 | .open_fds_init = { { 0, } }, \ | 27 | .open_fds_init = { { 0, } }, \ |
| 28 | .fd_array = { NULL, } \ | 28 | .fd_array = { NULL, } \ |
