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 <[email protected]>
---
 fs/proc/base.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

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;
-- 
2.16.4

Reply via email to