Skip to contentSkip to conversation

get_empty_filp tweaks, inline epoll_init_file()

PATCH In review Benjamin LaHaise 2 participants 3 messages Jan 24, 2006 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 get_empty_filp tweaks, inline epoll_init_file()

This patch eliminates a handful of cache references by keeping current in a register instead of reloading (helps x86) and avoiding the overhead of a function call. Inlining eventpoll_init_file() saves 24 bytes. Also reorder file initialization to make writes occur more sequentially.

fs/eventpoll.c +0 -9
index 4284cd3..e536e79 100644
@@ -451,15 +451,6 @@ static void ep_poll_safewake(struct poll
 }
 
 
-/* Used to initialize the epoll bits inside the "struct file" */
-void eventpoll_init_file(struct file *file)
-{
-
-	INIT_LIST_HEAD(&file->f_ep_links);
-	spin_lock_init(&file->f_ep_lock);
-}
-
-
 /*
  * This is called from eventpoll_release() to unlink files from the eventpoll
  * interface. We need to have this facility to cleanup correctly files that are
fs/file_table.c +6 -4
index 768b581..67c4106 100644
@@ -72,6 +72,7 @@ static inline void file_free(struct file
  */
 struct file *get_empty_filp(void)
 {
+	struct task_struct *tsk;
 	static int old_max;
 	struct file * f;
 
@@ -90,13 +91,14 @@ struct file *get_empty_filp(void)
 	if (security_file_alloc(f))
 		goto fail_sec;
 
-	eventpoll_init_file(f);
+	tsk = current;
+	INIT_LIST_HEAD(&f->f_u.fu_list);
 	atomic_set(&f->f_count, 1);
-	f->f_uid = current->fsuid;
-	f->f_gid = current->fsgid;
 	rwlock_init(&f->f_owner.lock);
+	f->f_uid = tsk->fsuid;
+	f->f_gid = tsk->fsgid;
+	eventpoll_init_file(f);
 	/* f->f_version: 0 */
-	INIT_LIST_HEAD(&f->f_u.fu_list);
 	return f;
 
 over:
include/linux/eventpoll.h +6 -2
index 1289f0e..1e4bdfc 100644
@@ -52,7 +52,12 @@ struct file;
 #ifdef CONFIG_EPOLL
 
 /* Used to initialize the epoll bits inside the "struct file" */
-void eventpoll_init_file(struct file *file);
+static inline void eventpoll_init_file(struct file *file)
+{
+	INIT_LIST_HEAD(&file->f_ep_links);
+	spin_lock_init(&file->f_ep_lock);
+}
+
 
 /* Used to release the epoll bits inside the "struct file" */
 void eventpoll_release_file(struct file *file);
@@ -85,7 +90,6 @@ static inline void eventpoll_release(str
 	eventpoll_release_file(file);
 }
 
-
 #else
 
 static inline void eventpoll_init_file(struct file *file) {}
#1 lore raw
Quoted 3 lines · Benjamin LaHaise

This patch eliminates a handful of cache references by keeping current
in a register instead of reloading (helps x86)

Are you sure it helps? I was checking that the other day and found that the compiler caches current quite competently.

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 3 lines · Benjamin LaHaise

This patch eliminates a handful of cache references by keeping current
in a register instead of reloading (helps x86)

Are you sure it helps? I was checking that the other day and found that the compiler caches current quite competently.

I was looking at the code on x86-64 where it reloads from %gs:0, but x86 reloads current too.

0xc015599b <get_empty_filp+105>:        mov    $0xfffff000,%eax
0xc01559a0 <get_empty_filp+110>:        and    %esp,%eax

- eax is current_thread_info()
0xc01559a2 <get_empty_filp+112>: mov (%eax),%edx
- dereference to get current
0xc01559a4 <get_empty_filp+114>: mov 0x174(%edx),%edx
- load current->fsuid
0xc01559aa <get_empty_filp+120>: mov %edx,0x48(%esi)
- store in file->f_uid
0xc01559ad <get_empty_filp+123>: mov (%eax),%eax
- reload current
0xc01559af <get_empty_filp+125>: mov 0x184(%eax),%eax
- load current->fsgid
0xc01559b5 <get_empty_filp+131>: mov %eax,0x4c(%esi)
- store in file->f_gid

-ben