Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp811710rdb; Thu, 19 Oct 2023 23:00:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5oQQOKanqJe9g4hIWItQ1niJtRg9EUlG+5Yc50VhEUjKqNGqqrpMtn+et3qze2rSsWcF5 X-Received: by 2002:a17:90a:1995:b0:27d:1d1f:1551 with SMTP id 21-20020a17090a199500b0027d1d1f1551mr968615pji.29.1697781647066; Thu, 19 Oct 2023 23:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697781647; cv=none; d=google.com; s=arc-20160816; b=JYKSGhUU+x3IduszfOyEUkTeAZ8Sdw2wmqIdbvmdAKa2hhpMNo25fV9maBRW/GNlxz xjk3GJhbO6sza93THF4zh32f9/V9AdzfPKrsrTB2im42lXeSkh5elIsl3bHCJpBTzm6k zRj2yKltXE/88bpm7oPjzr+/vy1m2RVT7TLpGf8JPGbEEN4m3QzhIHi6cvXb9wIuR5dA L7N+3YLzBfhMhM9HPfWmsyl2/RDNIGMXPraeYEZGHA+yYe9miKuad83zJFDgNIc/e3G3 TJOmaofFj5+Yrgk0FAiZULot55xId+A9UODRV51Ump0n8HeIrg+1A0hn0rDUOGUyrSae SFvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=8Er4QJ0+hHbRoucfmh72w5cKgy6BQrvTcGpa++Q1yKk=; fh=5oP/1UXqGTJCn9EhtPaD4mnUJdzyrxl2TCHfeacTi9c=; b=i+zNz8dE+BTkGYzQqYUHepzv+MM293YWrGGVzHZpB2DUsEIrXdBLfd+1hnLg6fGfnb aDu/McoKU/6pN39jeNGGG67ubzXo7wKvqkY/SNftTyH1G6X8kb+OnOuKdtoxo35Lcykt Y/WUUsxnK5oKwO5uD30YAjHFN6CDGw5k8IR5RDeddh5T7WuENoRHH2VGuGnHpxGyp4uI g5eY5/kgFcG338jccJ8zsGMo3B07d39BhSk8Z0aSiSelx6pmcD8WSVhLN7XGhcak/3Lh TT9/nC0GqXc7PlJFEZr5Fdoc0dPBlwN27JzXo2yXv/UMnkNdmzByz7Es+eLbqqxptU/l 2pAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p20-20020a17090ad31400b0027d37d5dff9si1224960pju.56.2023.10.19.23.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 23:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 66E3C807E938; Thu, 19 Oct 2023 23:00:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346919AbjJTF7o convert rfc822-to-8bit (ORCPT + 99 others); Fri, 20 Oct 2023 01:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235599AbjJTF7m (ORCPT ); Fri, 20 Oct 2023 01:59:42 -0400 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B399AD41; Thu, 19 Oct 2023 22:59:37 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-27db9fdec16so415131a91.2; Thu, 19 Oct 2023 22:59:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697781577; x=1698386377; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8QW6mQLWJHq+LWYoj7TKuXQ4crGYlNNS1CC7z5LwBXk=; b=MXU2UDaUYQBFyDXhnZddGiK6P/oYzprSYY0cu2RuYNUx2OTDSgjTFvLVWY59SZmIqn VzqEdJToMaHKUWjAapPd8uzPHHFSPYBFgsziWtHecf7YBGI90UuqOM86HHxHSk2T0PVK YpOqwjvcAv1ok/T4xSPi1QGhIFIFEgb4UF2KKP1sidSIGty491+hg7Gh+8+l2zNSWmPB fYUo8XXZvdhTLMNB4AIG8mbLhnhcGnX9pUDbqZspKoA6ZJPQjP6aH9rpkoAo1zxix8W+ WlBtolNCxct3CIdim3TFaa2w2qjW+9LlmatZdZpGJPLUrenpzUQYKCpE5pVUDAmdE9Sd yvwA== X-Gm-Message-State: AOJu0YxX/X9y2cENxmuHaeSTvQj79rjE+Rum43K7CkUZLcsMUrSZIqiU gAOmyLNkxwGtK1+GvtKm2q/dRY+uKGdbF8wsXWwyLaq+ X-Received: by 2002:a17:90a:19c5:b0:27c:eb7f:cd00 with SMTP id 5-20020a17090a19c500b0027ceb7fcd00mr891990pjj.22.1697781577025; Thu, 19 Oct 2023 22:59:37 -0700 (PDT) MIME-Version: 1.0 References: <20231013075945.698874-1-yangjihong1@huawei.com> In-Reply-To: <20231013075945.698874-1-yangjihong1@huawei.com> From: Namhyung Kim Date: Thu, 19 Oct 2023 22:59:25 -0700 Message-ID: Subject: Re: [PATCH] perf data: Increase RLIMIT_NOFILE limit when open too many files in perf_data__create_dir() To: Yang Jihong Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 23:00:12 -0700 (PDT) Hello, On Fri, Oct 13, 2023 at 1:01 AM Yang Jihong wrote: > > 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) Yep, probably one more for the dummy event. > 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 > --- > tools/perf/util/data.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c > index fc16299c915f..098f9e3bb2e7 100644 > --- a/tools/perf/util/data.c > +++ b/tools/perf/util/data.c > @@ -17,6 +17,7 @@ > #include "util.h" // rm_rf_perf_data() > #include "debug.h" > #include "header.h" > +#include "evsel.h" > #include > > static void close_dir(struct perf_data_file *files, int nr) > @@ -35,6 +36,7 @@ void perf_data__close_dir(struct perf_data *data) > > int perf_data__create_dir(struct perf_data *data, int nr) > { > + enum rlimit_action set_rlimit = NO_CHANGE; > struct perf_data_file *files = NULL; > int i, ret; > > @@ -54,11 +56,21 @@ int perf_data__create_dir(struct perf_data *data, int nr) > goto out_err; > } > > +retry_open: > ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); > if (ret < 0) { > + /* > + * If using parallel threads to collect data, > + * perf record needs at least 6 fds per CPU. > + * When we run out of them try to increase the limits. > + */ > + if (errno == EMFILE && evsel__increase_rlimit(&set_rlimit)) It seems weird that we have this helper with evsel prefix and it does nothing with evsel. But it's a separate concern, so Acked-by: Namhyung Kim Thanks, Namhyung > + goto retry_open; > + > ret = -errno; > goto out_err; > } > + set_rlimit = NO_CHANGE; > > file->fd = ret; > } > -- > 2.34.1 >