[07/13] proc: convert /proc/thread-self to _print_integer()
diff mbox series

Message ID 20180827231503.26899-7-adobriyan@gmail.com
State New, archived
Headers show
Series
  • [01/13] seq_file: rewrite seq_puts() in terms of seq_write()
Related show

Commit Message

Alexey Dobriyan Aug. 27, 2018, 11:14 p.m. UTC
Benchmark readlink("/proc/thread-self") 2^23 times:

	9.447948508 seconds time elapsed ( +-  0.06% )
	7.846435274 seconds time elapsed ( +-  0.07% )

	-17%
---
 fs/proc/thread_self.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/fs/proc/thread_self.c b/fs/proc/thread_self.c
index b905010ca9eb..03dd644d8ada 100644
--- a/fs/proc/thread_self.c
+++ b/fs/proc/thread_self.c
@@ -15,6 +15,7 @@  static const char *proc_thread_self_get_link(struct dentry *dentry,
 	struct pid_namespace *ns = proc_pid_ns(inode);
 	pid_t tgid = task_tgid_nr_ns(current, ns);
 	pid_t pid = task_pid_nr_ns(current, ns);
+	char buf[10 + 6 + 10], *p = buf + sizeof(buf);
 	char *name;
 
 	if (!pid)
@@ -22,7 +23,13 @@  static const char *proc_thread_self_get_link(struct dentry *dentry,
 	name = kmalloc(10 + 6 + 10 + 1, dentry ? GFP_KERNEL : GFP_ATOMIC);
 	if (unlikely(!name))
 		return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD);
-	sprintf(name, "%u/task/%u", tgid, pid);
+
+	p = _print_integer_u32(p, pid);
+	p = memcpy(p - 6, "/task/", 6);
+	p = _print_integer_u32(p, tgid);
+	memcpy(name, p, buf + sizeof(buf) - p);
+	name[buf + sizeof(buf) - p] = '\0';
+
 	set_delayed_call(done, kfree_link, name);
 	return name;
 }