2005-04-17 05:20:36 +07: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 18:00:12 +07:00
|
|
|
#include <linux/types.h>
|
2008-04-24 18:44:08 +07:00
|
|
|
#include <linux/posix_types.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-24 18:44:08 +07:00
|
|
|
struct file;
|
2006-12-07 11:32:52 +07:00
|
|
|
|
2008-02-14 06:03:15 +07:00
|
|
|
extern void fput(struct file *);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-17 13:31:13 +07:00
|
|
|
struct file_operations;
|
|
|
|
struct vfsmount;
|
|
|
|
struct dentry;
|
2009-08-09 03:52:35 +07:00
|
|
|
struct path;
|
2016-11-21 08:28:12 +07:00
|
|
|
extern struct file *alloc_file(const struct path *, fmode_t mode,
|
2009-08-09 03:52:35 +07:00
|
|
|
const struct file_operations *fop);
|
2007-10-17 13:31:13 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
static inline void fput_light(struct file *file, int fput_needed)
|
|
|
|
{
|
2010-12-14 07:38:08 +07:00
|
|
|
if (fput_needed)
|
2005-04-17 05:20:36 +07:00
|
|
|
fput(file);
|
|
|
|
}
|
|
|
|
|
2012-08-28 06:55:01 +07:00
|
|
|
struct fd {
|
|
|
|
struct file *file;
|
2014-03-04 00:36:58 +07:00
|
|
|
unsigned int flags;
|
2012-08-28 06:55:01 +07:00
|
|
|
};
|
2014-03-04 00:36:58 +07:00
|
|
|
#define FDPUT_FPUT 1
|
|
|
|
#define FDPUT_POS_UNLOCK 2
|
2012-08-28 06:55:01 +07:00
|
|
|
|
|
|
|
static inline void fdput(struct fd fd)
|
|
|
|
{
|
2014-03-04 00:36:58 +07:00
|
|
|
if (fd.flags & FDPUT_FPUT)
|
2012-08-28 06:55:01 +07:00
|
|
|
fput(fd.file);
|
|
|
|
}
|
|
|
|
|
2008-02-14 06:03:15 +07:00
|
|
|
extern struct file *fget(unsigned int fd);
|
2014-03-05 02:54:22 +07:00
|
|
|
extern struct file *fget_raw(unsigned int fd);
|
|
|
|
extern unsigned long __fdget(unsigned int fd);
|
|
|
|
extern unsigned long __fdget_raw(unsigned int fd);
|
|
|
|
extern unsigned long __fdget_pos(unsigned int fd);
|
2016-04-21 04:08:21 +07:00
|
|
|
extern void __f_unlock_pos(struct file *);
|
2012-08-28 06:55:01 +07:00
|
|
|
|
2014-03-05 02:54:22 +07:00
|
|
|
static inline struct fd __to_fd(unsigned long v)
|
2012-08-28 06:55:01 +07:00
|
|
|
{
|
2014-03-05 02:54:22 +07:00
|
|
|
return (struct fd){(struct file *)(v & ~3),v & 3};
|
2012-08-28 06:55:01 +07:00
|
|
|
}
|
|
|
|
|
2014-03-05 02:54:22 +07:00
|
|
|
static inline struct fd fdget(unsigned int fd)
|
|
|
|
{
|
|
|
|
return __to_fd(__fdget(fd));
|
|
|
|
}
|
2012-08-28 23:52:22 +07:00
|
|
|
|
2012-08-28 06:55:01 +07:00
|
|
|
static inline struct fd fdget_raw(unsigned int fd)
|
|
|
|
{
|
2014-03-05 02:54:22 +07:00
|
|
|
return __to_fd(__fdget_raw(fd));
|
2012-08-28 06:55:01 +07:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:08:21 +07:00
|
|
|
static inline struct fd fdget_pos(int fd)
|
|
|
|
{
|
|
|
|
return __to_fd(__fdget_pos(fd));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void fdput_pos(struct fd f)
|
|
|
|
{
|
|
|
|
if (f.flags & FDPUT_POS_UNLOCK)
|
|
|
|
__f_unlock_pos(f.file);
|
|
|
|
fdput(f);
|
|
|
|
}
|
|
|
|
|
2012-08-21 22:48:11 +07:00
|
|
|
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
|
2012-08-21 23:11:46 +07:00
|
|
|
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
|
2008-02-14 06:03:15 +07:00
|
|
|
extern void set_close_on_exec(unsigned int fd, int flag);
|
2012-08-21 22:48:11 +07:00
|
|
|
extern bool get_close_on_exec(unsigned int fd);
|
2005-04-17 05:20:36 +07:00
|
|
|
extern void put_filp(struct file *);
|
2012-08-13 04:18:05 +07:00
|
|
|
extern int get_unused_fd_flags(unsigned flags);
|
2008-02-14 06:03:15 +07:00
|
|
|
extern void put_unused_fd(unsigned int fd);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-02-14 06:03:15 +07:00
|
|
|
extern void fd_install(unsigned int fd, struct file *file);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-06-24 12:56:45 +07:00
|
|
|
extern void flush_delayed_fput(void);
|
|
|
|
extern void __fput_sync(struct file *);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* __LINUX_FILE_H */
|