perf data: Increase RLIMIT_NOFILE limit when open too many files in perf_data__create...
authorYang Jihong <yangjihong1@huawei.com>
Fri, 13 Oct 2023 07:59:45 +0000 (07:59 +0000)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 20 Oct 2023 06:38:27 +0000 (23:38 -0700)
commitc4a852635eddcf4130a93e687bc7b120b19fd1b7
treee8a8dbbd5cd44b6ceddf40480b56016585a8cf38
parent3f8b6e5b11192dacb721d2d28ea4589917f5e822
perf data: Increase RLIMIT_NOFILE limit when open too many files in perf_data__create_dir()

If using parallel threads to collect data, perf record needs at least 6 fds
per CPU. (one for sys_perf_event_open, four for pipe msg and ack of the
pipe, see record__thread_data_open_pipes(), and one for open perf.data.XXX)
For an environment with more than 100 cores, if perf record uses both
`-a` and `--threads` options, it is easy to exceed the upper limit of the
file descriptor number, when we run out of them try to increase the limits.

Before:
  $ ulimit -n
  1024
  $ lscpu | grep 'On-line CPU(s)'
  On-line CPU(s) list:                0-159
  $ perf record --threads -a sleep 1
  Failed to create data directory: Too many open files

After:
  $ ulimit -n
  1024
  $ lscpu | grep 'On-line CPU(s)'
  On-line CPU(s) list:                0-159
  $ perf record --threads -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.394 MB perf.data (1576 samples) ]

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20231013075945.698874-1-yangjihong1@huawei.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/data.c