2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Wrapper functions for accessing the file_struct fd array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_FILE_H
|
|
|
|
#define __LINUX_FILE_H
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
[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>
2006-03-23 11:00:12 +00:00
|
|
|
#include <linux/types.h>
|
2008-04-24 11:44:08 +00:00
|
|
|
#include <linux/posix_types.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-24 11:44:08 +00:00
|
|
|
struct file;
|
2006-12-07 04:32:52 +00:00
|
|
|
|
2008-02-13 23:03:15 +00:00
|
|
|
extern void fput(struct file *);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-17 06:31:13 +00:00
|
|
|
struct file_operations;
|
|
|
|
struct vfsmount;
|
|
|
|
struct dentry;
|
2009-08-08 20:52:35 +00:00
|
|
|
struct path;
|
|
|
|
extern struct file *alloc_file(struct path *, fmode_t mode,
|
|
|
|
const struct file_operations *fop);
|
2007-10-17 06:31:13 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline void fput_light(struct file *file, int fput_needed)
|
|
|
|
{
|
2010-12-14 00:38:08 +00:00
|
|
|
if (fput_needed)
|
2005-04-16 22:20:36 +00:00
|
|
|
fput(file);
|
|
|
|
}
|
|
|
|
|
2012-08-27 23:55:01 +00:00
|
|
|
struct fd {
|
|
|
|
struct file *file;
|
|
|
|
int need_put;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void fdput(struct fd fd)
|
|
|
|
{
|
|
|
|
if (fd.need_put)
|
|
|
|
fput(fd.file);
|
|
|
|
}
|
|
|
|
|
2008-02-13 23:03:15 +00:00
|
|
|
extern struct file *fget(unsigned int fd);
|
|
|
|
extern struct file *fget_light(unsigned int fd, int *fput_needed);
|
2012-08-27 23:55:01 +00:00
|
|
|
|
|
|
|
static inline struct fd fdget(unsigned int fd)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
struct file *f = fget_light(fd, &b);
|
|
|
|
return (struct fd){f,b};
|
|
|
|
}
|
|
|
|
|
2012-08-28 16:52:22 +00:00
|
|
|
extern struct file *fget_raw(unsigned int fd);
|
|
|
|
extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
|
|
|
|
|
2012-08-27 23:55:01 +00:00
|
|
|
static inline struct fd fdget_raw(unsigned int fd)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
struct file *f = fget_raw_light(fd, &b);
|
|
|
|
return (struct fd){f,b};
|
|
|
|
}
|
|
|
|
|
2012-08-21 15:48:11 +00:00
|
|
|
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
|
2012-08-21 16:11:46 +00:00
|
|
|
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
|
2008-02-13 23:03:15 +00:00
|
|
|
extern void set_close_on_exec(unsigned int fd, int flag);
|
2012-08-21 15:48:11 +00:00
|
|
|
extern bool get_close_on_exec(unsigned int fd);
|
2005-04-16 22:20:36 +00:00
|
|
|
extern void put_filp(struct file *);
|
2012-08-12 21:18:05 +00:00
|
|
|
extern int get_unused_fd_flags(unsigned flags);
|
|
|
|
#define get_unused_fd() get_unused_fd_flags(0)
|
2008-02-13 23:03:15 +00:00
|
|
|
extern void put_unused_fd(unsigned int fd);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-13 23:03:15 +00:00
|
|
|
extern void fd_install(unsigned int fd, struct file *file);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-06-24 05:56:45 +00:00
|
|
|
extern void flush_delayed_fput(void);
|
|
|
|
extern void __fput_sync(struct file *);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* __LINUX_FILE_H */
|