Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2945505lqp; Mon, 25 Mar 2024 14:03:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/GP7YkaKZaSzoTNAjEI13RG+GGw24geLPF6PzfUk0tMMQgPRnfsSov/4iCpBLeXddotcwuH0X0mOeXFV1C7R+N4pGeZo91nu+RT62Pg== X-Google-Smtp-Source: AGHT+IF4Xt/xP7daXZUyYbdofXzaEcdmHG/AL7oxV77YPP5OuQ8KJuAANfJFdJx8vWmYzbNKZJZv X-Received: by 2002:a50:8e16:0:b0:56b:a092:b6eb with SMTP id 22-20020a508e16000000b0056ba092b6ebmr6562790edw.35.1711400628157; Mon, 25 Mar 2024 14:03:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711400628; cv=pass; d=google.com; s=arc-20160816; b=k+wRhEe5ZhuEa0261YIOu9XJX5wf7RidiYcnAUIUfGnJ5/TVtpXJKklipyu1qEoOPP 13rxvqWmxmjlshTUnt9/O8I+Ya4ODYs9F7D+r4WYqd/mIMfavNjdOserJvCBHZ2cPoMT h49Cs52tDCQTvzo7vnoK80YO5wpa7sXMf/ZXDE4KMJMaX7OdWOILDgClopH//WueEr73 Atyqw1MKUs9FDmNjwq2FdsIrkRuiDhDUQXGW0X0eK5bJrpKNCHE6hFH6TeWHPOhzY6+q 4i6WQIGnaLymM/1lMxq+8QDjNoMLi6h7r1MMwaYjZYa6QmlVYKC+VKUTtBvuLi0LAJKX YYWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=iZOI+hPW8RmYPNaW33K5gzZDR3NImStcasjV31kXcvg=; fh=647LUOthhJXgq3j1vjANIuo6MT6boz4Db9pnK1ERxW0=; b=JWp8ioLH1n7viOV9u2blSiQ95o2EGNbziF9iYPUTpPLbgM0SAidlVFtGUOtPO9RVia skf57hRGBiP20oZjMdXodJH61UgbaqQhDaK+nBWd+v+WxNVtxRv83KWlFlDSoionI0Ba rEH/U9oELrTCf9jfNlhorhbw6WTeDREYw82a7S1Ln3ctucKwNGqtEN/lDtVpuD2En7ic EOaRyWTZRm+fPs6ZMAkzg1ZOiGEtAmrjM+K3sdkR/y73hxJLSgM7pZxJzq3QWvzedWfv hds2mB50SQ820PjnW2RVZLf75kgNonMddIR1WvoYxdxe0Yg3xpI+LaeoQqF1g/Do4uCs 6g9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-118006-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118006-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x11-20020a056402414b00b0056989b7e356si2942807eda.150.2024.03.25.14.03.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:03:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118006-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-118006-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118006-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B680B1F31D68 for ; Mon, 25 Mar 2024 21:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2FE65EE64; Mon, 25 Mar 2024 21:03:36 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 3DDDD54902; Mon, 25 Mar 2024 21:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400615; cv=none; b=DgfAPax6y91k/OOKZVCwH6YfBIK5H7PEam7TzILebyirCQwnL4m+GSQULcf7Erc/rrq/A4tz2pVbn/wl21cP7C+T6E5wc9+N2aQMqQdE82kEVTNcVjYGtpBtx9GZP3iqlNHQgIGh1MCzng1vm8t5UmeQgxNt/pLNOgrT6zlIJa8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400615; c=relaxed/simple; bh=ssgHvQ3R3Mpu8R/TTz7+YkBqBn4TOTRhLYISdOqAxPE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BYyMrf45it92zel0gnM+OTMQ5+iHG98B6KFaQmDoR+N679P7McmaCnaa12LTpbdPyfgcvzG89ewG4RoSrZPoO04OJv49KH932FCooKtWARiMCmHn76bXdtpFU1N6inExX2S5wT08zanG5R71x85KSCJwZrR+RBJbb9X6Huvz2eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cf2d73a183so3678421a12.1; Mon, 25 Mar 2024 14:03:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400613; x=1712005413; 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=iZOI+hPW8RmYPNaW33K5gzZDR3NImStcasjV31kXcvg=; b=NOZ0+ZTacgZSn6b4Rpuo0kwXk8NFAHNa33FguomKL6pbXHp+0KUOAnaBS/QtdNAI+C XQumGJ7UBX+wWQN5Zq1IN/c/QvisKBluCnHHkQCQ/2blixNXGrWlAcN8nwM6uo2L6e2y 6Ypt3GZ8/2NKOqA+zG2IlFZ3DH61mqFt1GAJA36Eu5pPBkXSyZJI+IuR1S46uhIqz1PK sKGswnZ/M2uHOGfpPO6JGBMr6zM6UpknU3vTVVejVuBs/sTFhoE4b5zbdB8/aBHmd5g5 C0VpLIZNnQ+x352SzT9S/p8Pm8IX7jUM5wDzjIqrR2bPgXW/lmOZIld7jgzdTlcVXnTc 7m4w== X-Forwarded-Encrypted: i=1; AJvYcCUyeYm2PCCplHVMgeo61hjneOAMTaXF1utLfcedOpK/xyYPNt9W7pgcFelgYmzSW6rQk9Amb79YQ3FkMWaTn8Z5RBdbHl0OwHSJuO9h6Pe78sIFF2HHDM1HrMPrdGkZJaokUpsWq8FfbHPTINKPPDE2HGHejHWmILTOPGEKM1+VMVFEBA== X-Gm-Message-State: AOJu0Yxqt0RqCzX9gMpm22iHrQUNgHzErRsWGqbetytHAkhphoRO/yD2 2nz3zAqIHRJrERBdQj+2sN7m7/otmtdD1ZUqkDiYdJ2Il7712OX7yUC/JXaf92lflMnuZmVr4Cl BXelw/ZO8EBUsrGVxPqgBJcwa05g= X-Received: by 2002:a17:90a:f40b:b0:2a0:4e60:ba46 with SMTP id ch11-20020a17090af40b00b002a04e60ba46mr10982726pjb.16.1711400613373; Mon, 25 Mar 2024 14:03:33 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> In-Reply-To: <20240321160300.1635121-1-irogers@google.com> From: Namhyung Kim Date: Mon, 25 Mar 2024 14:03:22 -0700 Message-ID: Subject: Re: [PATCH v2 00/13] dso/dsos memory savings and clean up To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , =?UTF-8?Q?Ahelenia_Ziemia=C5=84ska?= , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Ian, On Thu, Mar 21, 2024 at 9:03=E2=80=AFAM Ian Rogers wro= te: > > 13 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 reduce 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. > > Here are some questions (with answers) that I am expecting from reviewers= : > > - Why not refactor dso with accessors first and then do the other things= ? > > My ambition with this change was to lower memory overhead not to > particularly clean up and fix dso. Fixing the memory overhead, by > refactoring and changing the internals, showed that locking discipline > and reference counting discipline was lacking. The later changes try > to fix these as a service to the community while I am changing the > code and to also ensure that code is correct (more correct than it was > wrt locking and reference counting than before the patches). > > Reordering the patches to do the refactoring first will be a giant > pain. It will merge conflict with every other patch in the series and > is basically a request to reimplement everything from square 1. The > only thing I'd have in my favor would be how the code should look at > the end of the series, and reordering patches doesn't change the > eventual outcome of applying the patches. Note also, were I to send > the memory saving patches and then a week later send the API clean up > and reference counting fix patches the patches would be merged in the > order they are here. I've done my best, I know you may consider that > I'm adding to your reviewing overhead but I've also got to think about > the overhead to me. > > - Please break apart this change... > > The first changes are moving things, but when a broken API is spotted > like the missing get on dsos__find I put it in a change to move the > function and to add the missed get. Could this be two changes? Yes, it > could. Does moving code materially change the behavior of the tool? > No. I've done it in one patch to minimize churn and to some extent for > my sanity. Such changes are less than 100 lines of code and all > independently tested. > > - The logic in dso around short, long name and id with sorting is weird > > Yes, I've tried to make it less weird while retaining the existing > behavior. It would be easy to make a series of patches just cleaning > it up but I came here to save memory not change the dso API. > > - Move the fixes in the 12th patch earlier. > > This is possible but then impossible to test with reference count > checking. This does mean there are broken reference counts before the > patch is applied, but this is generally already the case. Yes, some > hypothetical person may decide to fork midway through this patch > series and my order would mean they wouldn't have a fix. I've done my > best while working within the bounds of my time and trying to avoid > churn. > > v2. Rebases on top of tmp.perf-tools-next resolving merge conflicts. > > Ian Rogers (13): > perf dso: Reorder variables to save space in struct dso > perf dsos: Attempt to better abstract dsos internals > perf dsos: Tidy reference counting and locking > perf dsos: Add dsos__for_each_dso > perf dso: Move dso functions out of dsos > perf dsos: Switch more loops to dsos__for_each_dso > 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 Acked-by: Namhyung Kim Thanks, Namhyung > > tools/perf/builtin-annotate.c | 8 +- > tools/perf/builtin-buildid-cache.c | 2 +- > tools/perf/builtin-buildid-list.c | 18 +- > tools/perf/builtin-inject.c | 96 +-- > tools/perf/builtin-kallsyms.c | 2 +- > tools/perf/builtin-mem.c | 4 +- > tools/perf/builtin-record.c | 2 +- > 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 | 14 +- > tools/perf/util/annotate.c | 47 +- > 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 | 136 ++--- > tools/perf/util/build-id.h | 2 - > tools/perf/util/callchain.c | 2 +- > tools/perf/util/data-convert-json.c | 2 +- > tools/perf/util/db-export.c | 6 +- > tools/perf/util/dlfilter.c | 12 +- > tools/perf/util/dso.c | 472 +++++++++------ > tools/perf/util/dso.h | 554 +++++++++++++++--- > tools/perf/util/dsos.c | 529 +++++++++++------ > tools/perf/util/dsos.h | 40 +- > 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 | 192 ++---- > tools/perf/util/machine.h | 2 + > tools/perf/util/map.c | 82 ++- > tools/perf/util/maps.c | 14 +- > 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/session.c | 21 + > tools/perf/util/session.h | 2 + > 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 | 56 +- > 61 files changed, 1817 insertions(+), 1220 deletions(-) > > -- > 2.44.0.396.g6e790dbe36-goog >