[10/13] proc: convert readdir /proc to _print_integer()
diff mbox series

Message ID 20180827231503.26899-10-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:15 p.m. UTC
Benchmark readdir("/proc") 2^13 times with 2K processes in a pid
namespace:

	850.3750 us per readdir
	786.5625

	-7.5%

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
 fs/proc/base.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 79d2f7d72ad1..33f444721965 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3223,16 +3223,15 @@  int proc_pid_readdir(struct file *file, struct dir_context *ctx)
 	for (iter = next_tgid(ns, iter);
 	     iter.task;
 	     iter.tgid += 1, iter = next_tgid(ns, iter)) {
-		char name[10 + 1];
-		unsigned int len;
+		char name[10], *p = name + sizeof(name);
 
 		cond_resched();
 		if (!has_pid_permissions(ns, iter.task, HIDEPID_INVISIBLE))
 			continue;
 
-		len = snprintf(name, sizeof(name), "%u", iter.tgid);
+		p = _print_integer_u32(p, iter.tgid);
 		ctx->pos = iter.tgid + TGID_OFFSET;
-		if (!proc_fill_cache(file, ctx, name, len,
+		if (!proc_fill_cache(file, ctx, p, name + sizeof(name) - p,
 				     proc_pid_instantiate, iter.task, NULL)) {
 			put_task_struct(iter.task);
 			return 0;