Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 018CFC7EE2E for ; Thu, 25 May 2023 07:13:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238941AbjEYHNp (ORCPT ); Thu, 25 May 2023 03:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238957AbjEYHMp (ORCPT ); Thu, 25 May 2023 03:12:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F2510D3 for ; Thu, 25 May 2023 00:12:30 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba83fed50e1so592887276.1 for ; Thu, 25 May 2023 00:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684998750; x=1687590750; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=OOlx2WRh+JFuq5y5J1qgtXH5kcli3Ek1O+02SLEhl6g=; b=kmXVsTge4xmX+270y+4v3x5uW1+11ox1yW+hi9yEMgQn9sO0CHfD+VwreYbdFONYoN LjcOzr176iehQTRWpLbTvBtKPzDvkKPOHMOe5UJli8zL7Q/4efTzSwUWVeoLxMGAGIL5 52U1NI/uaGB+bmjAvbSlPl1I+T4m4aHFhvV1yeGgJzmXFBme6m9WwsXSRMKvyohQDQdH cRhImkqUfXu2cmZJRZ+7FtGsPaqchPbL/I0+x+Yxy7oWeIg2ikFVuyIm6Vf3Y9N+ZFFY A573FB21aZOIgWnAoW2z8qnTLF+RMR9aL76pKKyKZht6Sn0y9c3r/kQMunTjTkCfFftM I/Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684998750; x=1687590750; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OOlx2WRh+JFuq5y5J1qgtXH5kcli3Ek1O+02SLEhl6g=; b=ggJsskLvgwVPJz27ZZJr0uutuwSy3g2GqBFkJqQWDjmf3nj41byTWk5ga4V8gohBD8 wpueblyiILsQHXqgVHymTuDAfbc1VwTkX9CJv9SFIysjrYbC5/cFLhopy/CqgVQyYHDP pRByyMgLUlGTEYQZ0nFs7DIOaO9GWvogEEFCiujAQm7jtQGicVWZSSisMjSgEB1yDTN2 DiPQ6c++BucOpgriQXivSVd+XJjbzIpuPwggx9q3FqgVo7MIjrzsNdqwZ5viHa/BKbsM A7CAqEEaSwyrnjFlxUSY6CggF5LndP+vxmuPRow2zxK9M+6ntHMyutKWOd9AWhEiTL5x zkjw== X-Gm-Message-State: AC+VfDyITIbsXsP8sdCLxnk0sFhzuAv50Z4vlPJF6cQlzZm7Y+8ojk3c VE6yu7SbwkhzPVAM8KUflw67gqOJdybu X-Google-Smtp-Source: ACHHUZ5IKhWTV/gXJDXr9pJVclWxuWbfOiaxQn3UH+XZ67yumdh7Bo9yq4vReN/76WBymOEj6XPPtLGWFSZY X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:6584:0:b0:ba8:381b:f764 with SMTP id z126-20020a256584000000b00ba8381bf764mr1455616ybb.3.1684998750427; Thu, 25 May 2023 00:12:30 -0700 (PDT) Date: Thu, 25 May 2023 00:11:31 -0700 In-Reply-To: <20230525071133.2066610-1-irogers@google.com> Message-Id: <20230525071133.2066610-15-irogers@google.com> Mime-Version: 1.0 References: <20230525071133.2066610-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v1 14/16] tools api fs: Dynamically allocate cgroupfs mount point cache From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , "Masami Hiramatsu (Google)" , "Steven Rostedt (Google)" , Ross Zwisler , Leo Yan , Tiezhu Yang , Yang Jihong , Andi Kleen , Kan Liang , Ravi Bangoria , Sean Christopherson , K Prateek Nayak , Paolo Bonzini , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Move the cgroupfs_cache_entry 4128 byte array out of .bss. Signed-off-by: Ian Rogers --- tools/lib/api/fs/cgroup.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/lib/api/fs/cgroup.c b/tools/lib/api/fs/cgroup.c index 1573dae4259d..250629a09423 100644 --- a/tools/lib/api/fs/cgroup.c +++ b/tools/lib/api/fs/cgroup.c @@ -14,7 +14,7 @@ struct cgroupfs_cache_entry { }; /* just cache last used one */ -static struct cgroupfs_cache_entry cached; +static struct cgroupfs_cache_entry *cached; int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) { @@ -24,9 +24,9 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) char *p, *path; char mountpoint[PATH_MAX]; - if (!strcmp(cached.subsys, subsys)) { - if (strlen(cached.mountpoint) < maxlen) { - strcpy(buf, cached.mountpoint); + if (cached && !strcmp(cached->subsys, subsys)) { + if (strlen(cached->mountpoint) < maxlen) { + strcpy(buf, cached->mountpoint); return 0; } return -1; @@ -91,8 +91,13 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys) free(line); fclose(fp); - strncpy(cached.subsys, subsys, sizeof(cached.subsys) - 1); - strcpy(cached.mountpoint, mountpoint); + if (!cached) + cached = calloc(1, sizeof(*cached)); + + if (cached) { + strncpy(cached->subsys, subsys, sizeof(cached->subsys) - 1); + strcpy(cached->mountpoint, mountpoint); + } if (mountpoint[0] && strlen(mountpoint) < maxlen) { strcpy(buf, mountpoint); -- 2.40.1.698.g37aff9b760-goog