forked from TencentOS/TencentOS-kernel
Merge pull request #311 from arafatms/tk4/0009-kabi-performance
Improve performance for unixbench test
This commit is contained in:
commit
90a466d964
|
|
@ -2232,10 +2232,12 @@ static void binder_deferred_fd_close(int fd)
|
|||
return;
|
||||
init_task_work(&twcb->twork, binder_do_fd_close);
|
||||
__close_fd_get_file(fd, &twcb->file);
|
||||
if (twcb->file)
|
||||
if (twcb->file) {
|
||||
filp_close(twcb->file, current->files);
|
||||
task_work_add(current, &twcb->twork, true);
|
||||
else
|
||||
} else {
|
||||
kfree(twcb);
|
||||
}
|
||||
}
|
||||
|
||||
static void binder_transaction_buffer_release(struct binder_proc *proc,
|
||||
|
|
|
|||
96
fs/file.c
96
fs/file.c
|
|
@ -642,7 +642,9 @@ out_unlock:
|
|||
EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
|
||||
|
||||
/*
|
||||
* variant of __close_fd that gets a ref on the file for later fput
|
||||
* variant of __close_fd that gets a ref on the file for later fput.
|
||||
* The caller must ensure that filp_close() called on the file, and then
|
||||
* an fput().
|
||||
*/
|
||||
int __close_fd_get_file(unsigned int fd, struct file **res)
|
||||
{
|
||||
|
|
@ -662,7 +664,7 @@ int __close_fd_get_file(unsigned int fd, struct file **res)
|
|||
spin_unlock(&files->file_lock);
|
||||
get_file(file);
|
||||
*res = file;
|
||||
return filp_close(file, files);
|
||||
return 0;
|
||||
|
||||
out_unlock:
|
||||
spin_unlock(&files->file_lock);
|
||||
|
|
@ -706,29 +708,79 @@ void do_close_on_exec(struct files_struct *files)
|
|||
spin_unlock(&files->file_lock);
|
||||
}
|
||||
|
||||
static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs)
|
||||
static inline struct file *__fget_files_rcu(struct files_struct *files,
|
||||
unsigned int fd, fmode_t mask, unsigned int refs)
|
||||
{
|
||||
for (;;) {
|
||||
struct file *file;
|
||||
struct fdtable *fdt = rcu_dereference_raw(files->fdt);
|
||||
struct file __rcu **fdentry;
|
||||
|
||||
if (unlikely(fd >= fdt->max_fds))
|
||||
return NULL;
|
||||
|
||||
fdentry = fdt->fd + array_index_nospec(fd, fdt->max_fds);
|
||||
file = rcu_dereference_raw(*fdentry);
|
||||
if (unlikely(!file))
|
||||
return NULL;
|
||||
|
||||
if (unlikely(file->f_mode & mask))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Ok, we have a file pointer. However, because we do
|
||||
* this all locklessly under RCU, we may be racing with
|
||||
* that file being closed.
|
||||
*
|
||||
* Such a race can take two forms:
|
||||
*
|
||||
* (a) the file ref already went down to zero,
|
||||
* and get_file_rcu_many() fails. Just try
|
||||
* again:
|
||||
*/
|
||||
if (unlikely(!get_file_rcu_many(file, refs)))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* (b) the file table entry has changed under us.
|
||||
* Note that we don't need to re-check the 'fdt->fd'
|
||||
* pointer having changed, because it always goes
|
||||
* hand-in-hand with 'fdt'.
|
||||
*
|
||||
* If so, we need to put our refs and try again.
|
||||
*/
|
||||
if (unlikely(rcu_dereference_raw(files->fdt) != fdt) ||
|
||||
unlikely(rcu_dereference_raw(*fdentry) != file)) {
|
||||
fput_many(file, refs);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ok, we have a ref to the file, and checked that it
|
||||
* still exists.
|
||||
*/
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
static struct file *__fget_files(struct files_struct *files, unsigned int fd,
|
||||
fmode_t mask, unsigned int refs)
|
||||
{
|
||||
struct files_struct *files = current->files;
|
||||
struct file *file;
|
||||
|
||||
rcu_read_lock();
|
||||
loop:
|
||||
file = fcheck_files(files, fd);
|
||||
if (file) {
|
||||
/* File object ref couldn't be taken.
|
||||
* dup2() atomicity guarantee is the reason
|
||||
* we loop to catch the new file (or NULL pointer)
|
||||
*/
|
||||
if (file->f_mode & mask)
|
||||
file = NULL;
|
||||
else if (!get_file_rcu_many(file, refs))
|
||||
goto loop;
|
||||
}
|
||||
file = __fget_files_rcu(files, fd, mask, refs);
|
||||
rcu_read_unlock();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
static inline struct file *__fget(unsigned int fd, fmode_t mask,
|
||||
unsigned int refs)
|
||||
{
|
||||
return __fget_files(current->files, fd, mask, refs);
|
||||
}
|
||||
|
||||
struct file *fget_many(unsigned int fd, unsigned int refs)
|
||||
{
|
||||
return __fget(fd, FMODE_PATH, refs);
|
||||
|
|
@ -746,6 +798,18 @@ struct file *fget_raw(unsigned int fd)
|
|||
}
|
||||
EXPORT_SYMBOL(fget_raw);
|
||||
|
||||
struct file *fget_task(struct task_struct *task, unsigned int fd)
|
||||
{
|
||||
struct file *file = NULL;
|
||||
|
||||
task_lock(task);
|
||||
if (task->files)
|
||||
file = __fget_files(task->files, fd, 0, 1);
|
||||
task_unlock(task);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lightweight file lookup - no refcnt increment if fd table isn't shared.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ extern void fput(struct file *);
|
|||
extern void fput_many(struct file *, unsigned int);
|
||||
|
||||
struct file_operations;
|
||||
struct task_struct;
|
||||
struct vfsmount;
|
||||
struct dentry;
|
||||
struct inode;
|
||||
|
|
@ -47,6 +48,7 @@ static inline void fdput(struct fd fd)
|
|||
extern struct file *fget(unsigned int fd);
|
||||
extern struct file *fget_many(unsigned int fd, unsigned int refs);
|
||||
extern struct file *fget_raw(unsigned int fd);
|
||||
extern struct file *fget_task(struct task_struct *task, 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);
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ static inline void *get_freepointer(struct kmem_cache *s, void *object)
|
|||
|
||||
static void prefetch_freepointer(const struct kmem_cache *s, void *object)
|
||||
{
|
||||
prefetch(object + s->offset);
|
||||
prefetchw(object + s->offset);
|
||||
}
|
||||
|
||||
static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)
|
||||
|
|
|
|||
|
|
@ -700,7 +700,8 @@ CONFIG_OPROFILE_EVENT_MULTIPLEX=y
|
|||
CONFIG_HAVE_OPROFILE=y
|
||||
CONFIG_OPROFILE_NMI_TIMER=y
|
||||
CONFIG_KPROBES=y
|
||||
# CONFIG_JUMP_LABEL is not set
|
||||
CONFIG_JUMP_LABEL=y
|
||||
# CONFIG_STATIC_KEYS_SELFTEST is not set
|
||||
CONFIG_OPTPROBES=y
|
||||
CONFIG_KPROBES_ON_FTRACE=y
|
||||
CONFIG_UPROBES=y
|
||||
|
|
@ -4995,7 +4996,7 @@ CONFIG_RCU_CPU_STALL_TIMEOUT=60
|
|||
# CONFIG_NOTIFIER_ERROR_INJECTION is not set
|
||||
CONFIG_FUNCTION_ERROR_INJECTION=y
|
||||
# CONFIG_FAULT_INJECTION is not set
|
||||
CONFIG_LATENCYTOP=y
|
||||
# CONFIG_LATENCYTOP is not set
|
||||
CONFIG_USER_STACKTRACE_SUPPORT=y
|
||||
CONFIG_NOP_TRACER=y
|
||||
CONFIG_HAVE_FUNCTION_TRACER=y
|
||||
|
|
|
|||
Loading…
Reference in New Issue