diff options
Diffstat (limited to 'fs/file.c')
-rw-r--r-- | fs/file.c | 34 |
1 files changed, 14 insertions, 20 deletions
@@ -125,7 +125,8 @@ static void free_fdtable_rcu(struct rcu_head *rcu) | |||
125 | kmem_cache_free(files_cachep, fdt->free_files); | 125 | kmem_cache_free(files_cachep, fdt->free_files); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (fdt->max_fdset <= __FD_SETSIZE && fdt->max_fds <= NR_OPEN_DEFAULT) { | 128 | if (fdt->max_fdset <= EMBEDDED_FD_SET_SIZE && |
129 | fdt->max_fds <= NR_OPEN_DEFAULT) { | ||
129 | /* | 130 | /* |
130 | * The fdtable was embedded | 131 | * The fdtable was embedded |
131 | */ | 132 | */ |
@@ -155,8 +156,9 @@ static void free_fdtable_rcu(struct rcu_head *rcu) | |||
155 | 156 | ||
156 | void free_fdtable(struct fdtable *fdt) | 157 | void free_fdtable(struct fdtable *fdt) |
157 | { | 158 | { |
158 | if (fdt->free_files || fdt->max_fdset > __FD_SETSIZE || | 159 | if (fdt->free_files || |
159 | fdt->max_fds > NR_OPEN_DEFAULT) | 160 | fdt->max_fdset > EMBEDDED_FD_SET_SIZE || |
161 | fdt->max_fds > NR_OPEN_DEFAULT) | ||
160 | call_rcu(&fdt->rcu, free_fdtable_rcu); | 162 | call_rcu(&fdt->rcu, free_fdtable_rcu); |
161 | } | 163 | } |
162 | 164 | ||
@@ -199,7 +201,6 @@ static void copy_fdtable(struct fdtable *nfdt, struct fdtable *fdt) | |||
199 | (nfdt->max_fds - fdt->max_fds) * | 201 | (nfdt->max_fds - fdt->max_fds) * |
200 | sizeof(struct file *)); | 202 | sizeof(struct file *)); |
201 | } | 203 | } |
202 | nfdt->next_fd = fdt->next_fd; | ||
203 | } | 204 | } |
204 | 205 | ||
205 | /* | 206 | /* |
@@ -220,11 +221,9 @@ fd_set * alloc_fdset(int num) | |||
220 | 221 | ||
221 | void free_fdset(fd_set *array, int num) | 222 | void free_fdset(fd_set *array, int num) |
222 | { | 223 | { |
223 | int size = num / 8; | 224 | if (num <= EMBEDDED_FD_SET_SIZE) /* Don't free an embedded fdset */ |
224 | |||
225 | if (num <= __FD_SETSIZE) /* Don't free an embedded fdset */ | ||
226 | return; | 225 | return; |
227 | else if (size <= PAGE_SIZE) | 226 | else if (num <= 8 * PAGE_SIZE) |
228 | kfree(array); | 227 | kfree(array); |
229 | else | 228 | else |
230 | vfree(array); | 229 | vfree(array); |
@@ -237,22 +236,17 @@ static struct fdtable *alloc_fdtable(int nr) | |||
237 | fd_set *new_openset = NULL, *new_execset = NULL; | 236 | fd_set *new_openset = NULL, *new_execset = NULL; |
238 | struct file **new_fds; | 237 | struct file **new_fds; |
239 | 238 | ||
240 | fdt = kmalloc(sizeof(*fdt), GFP_KERNEL); | 239 | fdt = kzalloc(sizeof(*fdt), GFP_KERNEL); |
241 | if (!fdt) | 240 | if (!fdt) |
242 | goto out; | 241 | goto out; |
243 | memset(fdt, 0, sizeof(*fdt)); | ||
244 | 242 | ||
245 | nfds = __FD_SETSIZE; | 243 | nfds = 8 * L1_CACHE_BYTES; |
246 | /* Expand to the max in easy steps */ | 244 | /* Expand to the max in easy steps */ |
247 | do { | 245 | while (nfds <= nr) { |
248 | if (nfds < (PAGE_SIZE * 8)) | 246 | nfds = nfds * 2; |
249 | nfds = PAGE_SIZE * 8; | 247 | if (nfds > NR_OPEN) |
250 | else { | 248 | nfds = NR_OPEN; |
251 | nfds = nfds * 2; | 249 | } |
252 | if (nfds > NR_OPEN) | ||
253 | nfds = NR_OPEN; | ||
254 | } | ||
255 | } while (nfds <= nr); | ||
256 | 250 | ||
257 | new_openset = alloc_fdset(nfds); | 251 | new_openset = alloc_fdset(nfds); |
258 | new_execset = alloc_fdset(nfds); | 252 | new_execset = alloc_fdset(nfds); |