Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1556093lqa; Mon, 29 Apr 2024 11:46:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEJJ05WnmArwmxJQXary6GkBt0C3m7wsrk2Ny314LkDqBqvRKBtWoFPPbXNDc7TH3/a524wvB9w10vZqFiEEw27OnEa6Sx3r+2cJBs1A== X-Google-Smtp-Source: AGHT+IFw2cTmj19iCzb3kLzaS0FaTuBMQkSy0qXn/JM76wYPB/a3Giv4wxeoRIAmi5KWDBdQwyDb X-Received: by 2002:a05:6a20:55a0:b0:1ad:ab1:9a03 with SMTP id kk32-20020a056a2055a000b001ad0ab19a03mr9865523pzb.25.1714416395365; Mon, 29 Apr 2024 11:46:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714416395; cv=pass; d=google.com; s=arc-20160816; b=OEMexTIOyJTND7MszZTbY2cW47W7Bv898I65s9treVCf63rr8bQRzGV6ZZiTaxD3bD DVe0D2Q/oQMULsgc7EzMAUXgpGo7RlJ7opeZmwrQPA28Lvq+vNnvUyiMTk8BLtLfTx6P JiboXJNpS9vI1UT04rWcuK/U9PI2RhqIwcVoNEpGl397+K1NKBMQXkYz4Ez0sKEmvn4O bldfkIUdPG/FqjTCWx2OsnUGsFfGfXtBwY3ff37Im2pptlwG3dTtb63sGamSz9AunRWQ SGCejcRPIGjvKNzKMXIom6k61q2rRP1pxaBdIkBZJrRoXh1KTNvyWs27qAM4L0W5U/f0 ZLAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=oSCw02zU0xlj3oJMiPK9ug/zZBXgwAdEBami/HcNOOo=; fh=6ILwRysSY8hCNrjr73ajWTmmVeJ6uT8/cW0g7w5yflQ=; b=IEtd/gtnmK0P19l5A2ToGdC1OxzJunfzNKwDosjqei4Z12PxU91pWDI6geNUWd2Cam KrpeqriPaYaOQoyOMpkwIKDEWoIkOWJ+LMgyU5E6zIa/pPpoiw1ovIXij9qiY+ik8aOk DK98oznqOx2yU75YnJEhOAmPKp+Y7h6xI5UjHFHDPA5GnW+rPwrHeHxbwlmzxV4vojlI hIgMfivS1jOwaaW9ex4Sc8Er/+InXUFcSpLlokImI7iMMcqNALEHMu8dYv+rEjFAiikz OfP4cONzWeMRG26t+I36x2S6hbMKQySlPOOCdTfFOP2yQi45b39SL+hTzXoe7b4qI4Gw hYSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="AtcLxt/l"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-162846-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bf24-20020a656d18000000b006151a42da7dsi942375pgb.482.2024.04.29.11.46.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 11:46:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162846-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="AtcLxt/l"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-162846-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162846-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EF70F28402A for ; Mon, 29 Apr 2024 18:46:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE77613AA41; Mon, 29 Apr 2024 18:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AtcLxt/l" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E0E313AA2C for ; Mon, 29 Apr 2024 18:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714416386; cv=none; b=oopXAv2INeAWKy0amf6LPUDja4h3rvIFKOCPtLaGPK7LF8ZL4X7dQp61mUZm/7LxY94LFGDv8IkPfGvZTqD/mpmDtmhaXhJu/yA1fUc37rtgTHgeTgC2xDoOaX+FJp/DL20awuLzqmSLZS/91Gls/gHSs7mGTDv+UHrWRh7qWbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714416386; c=relaxed/simple; bh=6uTTt0xsMfuVzjMKqkCH0gjwhFQ2avhuuVM4OafhzkE=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=m4dJyMoWL3HqQjvWc71CuhmmGXQV4/bb4dCHIId3AkoaC5QsoYjbT5cNyaVS25x1K2jy1actwHf8x5oRAvL4c9dCUi0YqXxZCn/SmDpzzphIhs21h9YQ41H9/44hagQk7861/VyMzlJTTZdqfingnY+KKmR7BedXbi4bJyPF/FU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AtcLxt/l; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ddaf165a8d9so7849682276.1 for ; Mon, 29 Apr 2024 11:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714416384; x=1715021184; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=oSCw02zU0xlj3oJMiPK9ug/zZBXgwAdEBami/HcNOOo=; b=AtcLxt/l6jGuxgHNeS9Q9UH71zxzDm9U2mkRwP0lCSRQKtllRY5U/Ie5k0RNQRUUgX F5Fu7M7jn11J3kmNuwywItaNQnnnvA/5CTMiHGXTkGNfpkPOsgLs43vOlUKNnREqeazz 6NWmcb4JnM4J8cVHMsoHQ/7dxDGWw3P90x5Mi2IylwwhL7H4CxNI1a/H1PdSwUJcxt3b 1gvWebJehVolFWdZjfjYzZQz37i+XId+IlLhKS5fbLOQ+HHmvQx3Un1efbUd9j2yzKXq 0fKBAjKQ5r+wg1QP/FHeqmp69wHOacc9ih6RnXOZuu/S1SD8xtaaqZKp7msfaEAeFeN2 XPQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714416384; x=1715021184; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oSCw02zU0xlj3oJMiPK9ug/zZBXgwAdEBami/HcNOOo=; b=c9BiO6SheFFPmE+GtCJhtARFqARyyE9JVbtOsf+UsQjqSl2Ux0zi1rTOphVl05lKwy VTIReq0IO10TJi9YRPnkQJlKw0Z4OTlOe5DMgbp4GAeaHVS0VH2RTGXx/dtH65FF2gOM iK5VAoiT/Q1yAHjjpHU/UYL4ZpQ/Cpqr5zJngUemW+sXqeZWkc7Xb2SyTq0un0XPAruM bu+35mxgmA/xMEmHfKTP2denCDnfztSyJAXLCGH+pS+SIXNe4PilrMoi0ZTQLGDfk0JK sOekicbMlNLtZ4p11NNGG0LVngKMEyddqKtjV/ebCTwQzFSVtkwNlMcWxVWWNUihPsKL aIzQ== X-Forwarded-Encrypted: i=1; AJvYcCVrDOE8MAtb9u5ARlrORGYR1GJwIhtVO+AkJOTkzQ6j46vsxkMlv3dgFgCALcapOVhWb7HKaaIvQfSCxmewUgTCSVK0b0TUM7JH6979 X-Gm-Message-State: AOJu0Yzh0KULe7Pst0keuaG5Wit+zUMDqTcuKp8Lnmm+CLH2i8rU9JfT zCDpi8kIhRrdOUmYSmrhAvRjDSJ4Fr02Kpeo73f5bftp6ZMRyAtr9N5VJNEfwQ6UZM2hPLYkv7F CCb2czQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:c137:aa10:25e1:8f1e]) (user=irogers job=sendgmr) by 2002:a05:6902:1106:b0:dcc:8be2:7cb0 with SMTP id o6-20020a056902110600b00dcc8be27cb0mr1236562ybu.0.1714416384297; Mon, 29 Apr 2024 11:46:24 -0700 (PDT) Date: Mon, 29 Apr 2024 11:46:07 -0700 Message-Id: <20240429184614.1224041-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [PATCH v5 0/7] dso/dsos memory savings and clean up From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Athira Rajeev , Colin Ian King , nabijaczleweli@nabijaczleweli.xyz, Leo Yan , Song Liu , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Yanteng Si , Sun Haiyong , Changbin Du , Andi Kleen , Thomas Richter , Masami Hiramatsu , Dima Kogan , zhaimingbing , Paran Lee , Li Dong , Tiezhu Yang , Yang Jihong , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 7 more patches from: https://lore.kernel.org/lkml/20240202061532.1939474-1-irogers@google.com/ a near half year old adventure in trying to lower perf's dynamic memory use. Bits like the memory overhead of opendir are on the sidelines for now, too much fighting over how distributions/C-libraries present getdents. These changes are more good old fashioned replace an rb-tree with a sorted array and add reference count tracking. The changes migrate dsos code, the collection of dso structs, more into the dsos.c/dsos.h files. As with maps and threads, this is done so the internals can be changed - replacing a linked list (for fast iteration) and an rb-tree (for fast finds) with a lazily sorted array. The complexity of operations remain roughly the same, although iterating an array is likely faster than iterating a linked list, the memory usage is at least reduced by half. As fixing the memory usage necessitates changing operations like find, modify these operations so that they increment the reference count to avoid races like a find in dsos and a remove. Similarly tighten up lock usage so that operations working on dsos state hold the appropriate lock. Note, since this series is partially applied in the perf-tools-next tree currently some memory leaks have been introduced. v5. Rebase, adding use of accessors to dso as necessary. Previous versions were all rebases or dropping merged patches. Ian Rogers (7): perf dsos: Switch backing storage to array from rbtree/list perf dsos: Remove __dsos__addnew perf dsos: Remove __dsos__findnew_link_by_longname_id perf dsos: Switch hand code to bsearch perf dso: Add reference count checking and accessor functions perf dso: Reference counting related fixes perf dso: Use container_of to avoid a pointer in dso_data tools/perf/builtin-annotate.c | 6 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-buildid-list.c | 18 +- tools/perf/builtin-inject.c | 71 ++- tools/perf/builtin-kallsyms.c | 2 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-report.c | 6 +- tools/perf/builtin-script.c | 8 +- tools/perf/builtin-top.c | 4 +- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/code-reading.c | 8 +- tools/perf/tests/dso-data.c | 67 ++- tools/perf/tests/hists_common.c | 6 +- tools/perf/tests/hists_cumulate.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/maps.c | 4 +- tools/perf/tests/symbols.c | 8 +- tools/perf/tests/vmlinux-kallsyms.c | 6 +- tools/perf/ui/browsers/annotate.c | 6 +- tools/perf/ui/browsers/hists.c | 8 +- tools/perf/ui/browsers/map.c | 4 +- tools/perf/util/annotate-data.c | 16 +- tools/perf/util/annotate.c | 17 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/block-info.c | 2 +- tools/perf/util/bpf-event.c | 8 +- tools/perf/util/build-id.c | 38 +- tools/perf/util/callchain.c | 2 +- tools/perf/util/data-convert-json.c | 2 +- tools/perf/util/db-export.c | 6 +- tools/perf/util/disasm.c | 40 +- tools/perf/util/dlfilter.c | 12 +- tools/perf/util/dso.c | 429 ++++++++------- tools/perf/util/dso.h | 500 ++++++++++++++++-- tools/perf/util/dsos.c | 286 +++++----- tools/perf/util/dsos.h | 18 +- tools/perf/util/event.c | 8 +- tools/perf/util/header.c | 8 +- tools/perf/util/hist.c | 4 +- tools/perf/util/intel-pt.c | 22 +- tools/perf/util/machine.c | 50 +- tools/perf/util/map.c | 78 +-- tools/perf/util/maps.c | 14 +- tools/perf/util/print_insn.c | 2 +- tools/perf/util/probe-event.c | 25 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 21 +- tools/perf/util/sort.c | 19 +- tools/perf/util/srcline.c | 65 +-- tools/perf/util/symbol-elf.c | 145 +++-- tools/perf/util/symbol-minimal.c | 4 +- tools/perf/util/symbol.c | 186 +++---- tools/perf/util/symbol_fprintf.c | 4 +- tools/perf/util/synthetic-events.c | 24 +- tools/perf/util/thread.c | 4 +- tools/perf/util/unwind-libunwind-local.c | 18 +- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/vdso.c | 8 +- 58 files changed, 1409 insertions(+), 932 deletions(-) -- 2.44.0.769.g3c40516874-goog