From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: Some experience with the igc branch Date: Wed, 25 Dec 2024 13:50:37 +0100 Message-ID: References: <87o713wwsi.fsf@telefonica.net> <87ldw7fwet.fsf@protonmail.com> <87a5cnfj8t.fsf@protonmail.com> <86seqe4j4f.fsf@gnu.org> <87ttaucub8.fsf@protonmail.com> <87pllicrpi.fsf@protonmail.com> <864j2u442i.fsf@gnu.org> <87ldw6as5f.fsf@protonmail.com> <86o7112rnq.fsf@gnu.org> <867c7p2nz4.fsf@gnu.org> <861pxx2lh7.fsf@gnu.org> <86ldw40xbo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28643"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: pipcet@protonmail.com, ofv@wanadoo.es, emacs-devel@gnu.org, eller.helmut@gmail.com, acorallo@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 25 13:51:07 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tQQqx-0007Hm-EI for ged-emacs-devel@m.gmane-mx.org; Wed, 25 Dec 2024 13:51:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQQqc-0006mo-IT; Wed, 25 Dec 2024 07:50:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQQqa-0006mV-Jn for emacs-devel@gnu.org; Wed, 25 Dec 2024 07:50:44 -0500 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tQQqY-0004hD-KJ; Wed, 25 Dec 2024 07:50:44 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-aaedd529ba1so327193266b.1; Wed, 25 Dec 2024 04:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735131039; x=1735735839; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=goEtA6x6kNfxItL15E0ZaUvDnFyBjhW+rq3CQwSD3i0=; b=fAAjGDVOCmbwu64KTNQ/+cuEOYRM6hk4Pls0NVdLbXpjcnXI4NOUHIOepyY4USz0gb twRYa59DSbhjuiE/CWrdg7wtpK4NwFZ8lju4MhH+DZ4W0LtkWrnL0JI33At88LHEVjc7 O6rsj3aCV0qGnTdJioE1FEoB/p4eoUlrwrRyptwW2CEwsPV2HLLfl0yJB3opFpHMcFxv lTY1YNMlnXZvVHz4WUptDIbTnBJVxDiIylQtl+aHkC++oMf11j7l64tWQK0kIcei3fp3 H1dgcTYWgqlxIzWWMJByhgcD2qluUiQv93XpLEhzfXvBcMnHInD5Ved9Xo96x1EwsE0A f9sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735131039; x=1735735839; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=goEtA6x6kNfxItL15E0ZaUvDnFyBjhW+r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smtp-Source: AGHT+IHwKqj4+7ZVIx/PqhWvotXBwRUghbzSVN8up+VAHUQ8I33lfGxrXR7Lkl6gNupYuKwecMpS0A== X-Received: by 2002:a05:6402:210f:b0:5d0:cfad:f71 with SMTP id 4fb4d7f45d1cf-5d81de1c921mr46386705a12.32.1735131039267; Wed, 25 Dec 2024 04:50:39 -0800 (PST) Original-Received: from pro2 (p200300e0b73d6f00401d1c7c2fc22e2d.dip0.t-ipconnect.de. [2003:e0:b73d:6f00:401d:1c7c:2fc2:2e2d]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e89641asm789553266b.55.2024.12.25.04.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Dec 2024 04:50:38 -0800 (PST) In-Reply-To: <86ldw40xbo.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 25 Dec 2024 14:19:23 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327083 Archived-At: Eli Zaretskii writes: >> From: Gerd M=C3=B6llmann >> Cc: pipcet@protonmail.com, ofv@wanadoo.es, emacs-devel@gnu.org, >> eller.helmut@gmail.com, acorallo@gnu.org >> Date: Wed, 25 Dec 2024 05:56:26 +0100 >>=20 >> Eli Zaretskii writes: >>=20 >> >> The SIGPROF handler does two things: (1) get the current backtrace, >> >> which does not trip on memory barriers, and (2) build a summary, i.e. >> >> count same backtraces using a hash table. (2) trips on memory barrier= s. >> > >> > Can you elaborate on (2) and why it trips? I guess I'm missing >> > something because I don't understand which code in record_backtrace >> > does trip on memory barriers and why. >>=20 >> Ok, (2) begins as shown below. >>=20 >> static void >> record_backtrace (struct profiler_log *plog, EMACS_INT count) >> { >> log_t *log =3D plog->log; >> get_backtrace (log->trace, log->depth); >> --- (2) begins after this line ------------------------------- >> EMACS_UINT hash =3D trace_hash (log->trace, log->depth); >>=20 >> The SIGPROF can have interrupted Emacs at any point, both the MPS thread >> and all others. MPS may have been doing arbitrary stuff when >> interrupted, and Emacs threads too. Memory barriers may be on >> unpredictable segments of memory, as they usually are, as part of MPS' >> GC implementation. Do you agree with this picture? >>=20 >> Elsewhere I tried to explain why I think this works up to the line >> marked (2) above. Now enter trace_hash. Current implementation: >>=20 >> static EMACS_UINT >> trace_hash (Lisp_Object *trace, int depth) >> { >> EMACS_UINT hash =3D 0; >> for (int i =3D 0; i < depth; i++) >> { >> Lisp_Object f =3D trace[i]; >> EMACS_UINT hash1; >> #ifdef HAVE_MPS >> hash1 =3D (CLOSUREP (f) ? igc_hash (AREF (f, CLOSURE_CODE)) : ig= c_hash (f)); >> ^^^^^^^^ ^^^^^^^^ ^^^^ >>=20 >> The constructs I marked with ^^^ all access the memory of F. F is a >> vectorlike, it's memory is managed by MPS in an MPS pool that uses >> memory barriers, so the memory of F can currently be behind a barrier. >> It doesn't have to, but it can. >>=20 >> When we access F's memory and it is behind a barrier, the result is a >> nested SIgSEGV while handling SIGPROF. > > Two followup questions: > > . how is accessing F different from accessing the specpdl stack? F's memory is allocated from an MPS pool via alloc_impl in igc.c. Most objects are allocated from a pool that uses barriers (I think except PVEC_THREAD). The specpdl stacks are mallocs (see grow_specpdl_allocation), and uses as a roots. There are currently no barriers on roots. > . how does this work with the current GC, where F could have been > collected and its memory freed? I think when we find F in a specpdl stack, GC should have seen it and marked it too in mark_specpdl. So it wouldn't be freed. (Same for igc, where the stacks are roots, and should have seen F in that way in scan_specdl.) > The first question is more important, from where I stand. Looking > forward beyond the point where we land igc on master, I wonder how > will be able to tell, for a random non-trivial change on the C level, > whether what it does can cause trouble with MPS? That is, how can a > mere mortal determine whether a given data structure in igc Emacs can > or cannot be safely touched when MPS happens to do its thing, whether > synchronously or asynchronously? We must have some reasonably > practical way of telling this, or else we will be breaking Emacs high > and low. > >> More code accessing memory that is potentially behind a barrier follows >> in record_backtrace. > > Which code is that? (It's a serious question: I tried to identify > that code, but couldn't. I'm probably missing something.) The example I saw, with ^^^^ marking the call sites: static void record_backtrace (struct profiler_log *plog, EMACS_INT count) { log_t *log =3D plog->log; get_backtrace (log->trace, log->depth); EMACS_UINT hash =3D trace_hash (log->trace, log->depth); int hidx =3D log_hash_index (log, hash); int idx =3D log->index[hidx]; while (idx >=3D 0) { if (log->hash[idx] =3D=3D hash && trace_equal (log->trace, get_key_vector (log, idx), log->depth)) ^^^^^^^^^^^ static bool trace_equal (Lisp_Object *bt1, Lisp_Object *bt2, int depth) { for (int i =3D 0; i < depth; i++) if (!BASE_EQ (bt1[i], bt2[i]) && NILP (Ffunction_equal (bt1[i], bt2[i])= )) ^^^^^^^^^^^^^^^ DEFUN ("function-equal", Ffunction_equal, Sfunction_equal, 2, 2, 0, doc: /* Return non-nil if F1 and F2 come from the same source. Used to determine if different closures are just different instances of the same lambda expression, or are really unrelated function. */) (Lisp_Object f1, Lisp_Object f2) { bool res; if (EQ (f1, f2)) res =3D true; else if (CLOSUREP (f1) && CLOSUREP (f2)) ^^^^^^^^ ^^^^^^^^ res =3D EQ (AREF (f1, CLOSURE_CODE), AREF (f2, CLOSURE_CODE)); ^^^^ ^^^^ Didn't look further than that, though.