Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3371467rdh; Mon, 27 Nov 2023 12:26:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGC+pzPi4DTbSh1Wa/vqWImwgNYaL8vrmvLTnhGaYlnakn38CEMOlIPVYj5qSph+7ivuxF2 X-Received: by 2002:a05:6a20:9385:b0:18c:19ab:d2e5 with SMTP id x5-20020a056a20938500b0018c19abd2e5mr11561327pzh.33.1701116817682; Mon, 27 Nov 2023 12:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701116817; cv=none; d=google.com; s=arc-20160816; b=btFQsEM5BmdOzgLaGjIILOqprYh4EABQ5AizkCWOfCOReBtP0JoGILq2d8qJjZll3m j6GeFuHVLLFcFcyH2tX1VgM1rHaVzaFGpRxKgQ6unlmd3O4ksT+xSguZTklElVSelFeb /ubzQkBXKSnc3Jkwn9JT0JuOd2X4O53JsWAUbPLd4rjA1x5ScmJcZ/4QVikm9oqIDGgF jQ9WsS+tA+SnuSNuWMvqHizfhagAo22e3OMN0wY9ORQwEmk9XXZvu9W9zm1ytEdi+YJz VJJBlnbZD3Wc7Y0Dz7781aZ+Huo+2KS5urMiOSGOshz+7rbJA+AhcnSxy0iz1gql0c1a lLew== 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 :dkim-signature; bh=dNtbW7bb1joRBd02cZwF5zPKpcLSt2ynX6nmeWUG++o=; fh=ZP5rkIgi+sgQyvA0Nb5diyJQn/QILptIgBv8r67XkSs=; b=ZePYino0e6Ubpojcn7yknXCYtNZ/0KGz/n0T9LqWDGW0QXWQP+EJSdGVULrdO0NOCq wQdB2QPsMKNZIFoelebSHo+c7FZWq8hcF6Rowq5S1OpMcYw3pDte765o3ZBu6TERm40h V1g2BB0yHOFKQgCTMzOsrNfiLOCCLWGAooPftjVAk5OIJapLAgrbf3tCFsDrno6hqCDF dN1jlTv0CW55QqT96q7fwqQHSXNI1KN9fWE6v/Zp2lYwXjpOZQBI+AaiRIZDsaHk92yn 8hhujj8v/gcMuS3lB7BsHFwtpYvwovaydNBdgTbiObmPm320MYWdClA+hBEXS4shvHnE 4m0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="v2u4G/Ni"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id 8-20020a631448000000b00578b9fb24f6si10340739pgu.616.2023.11.27.12.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 12:26:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="v2u4G/Ni"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7C18C82492A8; Mon, 27 Nov 2023 12:26:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231767AbjK0U0j (ORCPT + 99 others); Mon, 27 Nov 2023 15:26:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjK0U0h (ORCPT ); Mon, 27 Nov 2023 15:26:37 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE67CD4D for ; Mon, 27 Nov 2023 12:26:43 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-50aa698b384so13984e87.0 for ; Mon, 27 Nov 2023 12:26:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701116802; x=1701721602; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dNtbW7bb1joRBd02cZwF5zPKpcLSt2ynX6nmeWUG++o=; b=v2u4G/NikjoCRNKLXT7gRsYoU/kJ2LI4RxhcCkFKP6AyoYIIZHUueQToNBIinzlOmP lN3xbMLJRPjngBLVSAbLZrnc0S1GmL/PPxfl/7J5QVNSK4S1xd6IcYGscb5/Br/VWeC8 encknEOx/j4fcHsxKJmiNX5D1gZA6gg/ZpAw3D7T3kMzB+0GhcAYO1+UtJ30aRV/MFWx iVBClxyZ3DhH2IG6y7b61MUBgRs4MGevC9eEiQcoWzwbeoIrdQsrBOKFmz4UGkVwFea4 1D5hSBzZTBZpA4BeDu5GVaHVmqRCJPPGxuj9/yo8hoIxi/TNXfMw1PsJirm/pPvGpe66 8tpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701116802; x=1701721602; 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=dNtbW7bb1joRBd02cZwF5zPKpcLSt2ynX6nmeWUG++o=; b=vd6tYmO1AXB+tsC957ClQfyWMubhauN59NKHtsSOHL2T1Qwn6KcyiGh03HqPK2Rdp8 L2vVJnlNr2TDk2tWIK60bHuAzenP+XjGEuRWLI+HLbCZu+/Q6l2b2jRAFmSuHpd/6l6o b3QigLDD+XDZZ9ByCtEEcHYTMEikUZkO/XGsbS28ZO+8JirqdUrnDAeMTm9o1gxA7SA7 YSXmncfMsyE+SNmXM7ZCy3yyPZK/4Kse/eVljbm5CAZsg8aDN/Zu7k5N5RByaUFh8PrG QoojA57Vh8oROQL+1249b2wXb1n6DOG9sgvtBpolYQlq30ITyepT/X27fE2qHzEn+qh7 V7nQ== X-Gm-Message-State: AOJu0YwN85yfUTa+SUz9conRgS2lLJ9RXSkRSJKKz6YiyV1BQCfOFDrD FPRpa6obg+/ZefAFhMfO+W6me5hR72rl4S52LT9Klw== X-Received: by 2002:a05:6512:1585:b0:50a:519d:5a8a with SMTP id bp5-20020a056512158500b0050a519d5a8amr327946lfb.5.1701116802002; Mon, 27 Nov 2023 12:26:42 -0800 (PST) MIME-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> <20231102175735.2272696-7-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 27 Nov 2023 12:26:29 -0800 Message-ID: Subject: Re: [PATCH v4 06/53] tools api fs: Switch filename__read_str to use io.h To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Mon, 27 Nov 2023 12:26:54 -0800 (PST) On Sun, Nov 5, 2023 at 7:53=E2=80=AFPM Namhyung Kim w= rote: > > On Thu, Nov 2, 2023 at 10:58=E2=80=AFAM Ian Rogers w= rote: > > > > filename__read_str has its own string reading code that allocates > > memory before reading into it. The memory allocated is sized at BUFSIZ > > that is 8kb. Most strings are short and so most of this 8kb is > > wasted. > > > > Refactor io__getline so that the newline character can be configurable > > and ignored in the case of filename__read_str. > > > > Code like build_caches_for_cpu in perf's header.c will read many > > strings and hold them in a data structure, in this case multiple > > strings per cache level per CPU. Using io.h's io__getline avoids the > > wasted memory as strings are temporarily read into a buffer on the > > stack before being copied to a buffer that grows 128 bytes at a time > > and is never sized larger than the string. > > > > For a 16 hyperthread system the memory consumption of "perf record > > true" is reduced by 180kb, primarily through saving memory when > > reading the cache information. > > > > Signed-off-by: Ian Rogers > > --- > > [SNIP] > > diff --git a/tools/lib/api/io.h b/tools/lib/api/io.h > > index a77b74c5fb65..50d33e14fb56 100644 > > --- a/tools/lib/api/io.h > > +++ b/tools/lib/api/io.h > > @@ -141,7 +141,7 @@ static inline int io__get_dec(struct io *io, __u64 = *dec) > > } > > > > /* Read up to and including the first newline following the pattern of= getline. */ > > You may want to update the comment as well. > > > -static inline ssize_t io__getline(struct io *io, char **line_out, size= _t *line_len_out) > > +static inline ssize_t io__getline_nl(struct io *io, char **line_out, s= ize_t *line_len_out, int nl) > > How about io__getdelim() similar to POSIX? Thanks done for v5. Ian > Thanks, > Namhyung > > > > { > > char buf[128]; > > int buf_pos =3D 0; > > @@ -151,7 +151,7 @@ static inline ssize_t io__getline(struct io *io, ch= ar **line_out, size_t *line_l > > > > /* TODO: reuse previously allocated memory. */ > > free(*line_out); > > - while (ch !=3D '\n') { > > + while (ch !=3D nl) { > > ch =3D io__get_char(io); > > > > if (ch < 0) > > @@ -184,4 +184,9 @@ static inline ssize_t io__getline(struct io *io, ch= ar **line_out, size_t *line_l > > return -ENOMEM; > > } > > > > +static inline ssize_t io__getline(struct io *io, char **line_out, size= _t *line_len_out) > > +{ > > + return io__getline_nl(io, line_out, line_len_out, /*nl=3D*/'\n'= ); > > +} > > + > > #endif /* __API_IO__ */ > > -- > > 2.42.0.869.gea05f2083d-goog > > >