From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B3C4D1F44D for ; Thu, 4 Apr 2024 20:03:30 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=bX9OeuRv; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=Ah2CEtg/; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 65EE583CB7; Thu, 4 Apr 2024 20:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1712260999; bh=CEY6jopwuv6XmZt9F6gRP+6aE7ghKvZbiSeamenr0GQ=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=bX9OeuRv2BUdICWL/PxoBUK7gW0RPVjfw0roVnsXBePu1WLw2+man1TD6U9n93Ywx cYOD8wcUL8etkLijFO6p/d+H8dtDnsgxRXVEDEFUci2zCZu+HThaMM/unmd0A+y7sY gDrMZC04Dtwz49+md7XqcV0X1zDHuTqVzyoQhdek= Received: from s.wfbtzhsv.outbound-mail.sendgrid.net (s.wfbtzhsv.outbound-mail.sendgrid.net [159.183.224.104]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 6C19A83CB5 for ; Thu, 4 Apr 2024 20:03:16 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=Ah2CEtg/; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=DLr0jdlecvxvHDl++Xf1UMdkHICvpAQYNIQBNQV7Vho=; b=Ah2CEtg/wEA55qOdZrm9Hc0coVVFmCs2DiI2uYnpvHXBKNOKrobYB08kc9vrA8SHhHUs WhQEiBSFgrfTo+RPpfmkmzjyeFFx5xtBy8q7mpF7cCtO+iHaFTIWRQfrGAk2vPg7nl70LH 2wUI174pUqAD0pFv6zH3K5GUj20hhW5ht5HU133j7QJxVlMEZOuSRG7c7RUZsiPtdj5Efm GpTWX87CKI78eaWAnEAyq6mWZTKpZqA7UcpNYU+A7TVZkxSdb9YPVmN5lxD4Wxnffloj2S l1LudNGApud2I1pqTDW7zncw1emDuaH05k25O6Yx5iC71R3horke8WWoTCxvfAcw== Received: by recvd-6fc499775c-pshrz with SMTP id recvd-6fc499775c-pshrz-1-660F0783-12 2024-04-04 20:03:15.505245932 +0000 UTC m=+1465398.276658804 Received: from herokuapp.com (unknown) by geopod-ismtpd-28 (SG) with ESMTP id iSMmk0ebTv2DvbGLnLYQfg for ; Thu, 04 Apr 2024 20:03:15.491 +0000 (UTC) Date: Thu, 04 Apr 2024 20:03:15 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20351 X-Redmine-Issue-Author: eightbitraptor X-Redmine-Issue-Priority: Normal X-Redmine-Sender: eightbitraptor X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 94037 X-SG-EID: =?us-ascii?Q?u001=2E9VAa+KF84+ACjWkSb8mcy8gS+fYyyXFRcDVQpXgr7nDVEZYc6+Pq9ajFu?= =?us-ascii?Q?WmefySeLz3zn3rchgcytbyt4srfHH8FuYLgsYRD?= =?us-ascii?Q?3WTVvJnqa+pjLp+YiWWS7sJrBg1gctizUeqpfvf?= =?us-ascii?Q?ISKOaSypdtHZ72XS0W3+38kZ1ABsa54+0x8q4pF?= =?us-ascii?Q?fFbdeYA1WP2pkk7ol7tgNWEmCs5tWZea2FAWs6A?= =?us-ascii?Q?F=2FZVb7cihHYrpPhNG22e8rf0UshLp6WYGmsTM6k?= =?us-ascii?Q?tCP0E051t8CidzkwoIdfjjTjBkFS49LoJMTn=2Frs?= =?us-ascii?Q?Sxqr8ZCA=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: YTZASR6LW6R2UMZCSTSOYVHO7EHAHG4W X-Message-ID-Hash: YTZASR6LW6R2UMZCSTSOYVHO7EHAHG4W X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:117442] [Ruby master Feature#20351] Optionally extract common GC routines into a DSO List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "eightbitraptor (Matthew Valentine-House) via ruby-core" Cc: "eightbitraptor (Matthew Valentine-House)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20351 has been updated by eightbitraptor (Matthew Valentine-House). Based on feedback from @katei and @nobu we have changed our approach to this project. An updated PR can be found here: [[GH #10456]](https://github.com/ruby/ruby/pull/10456) Instead of building the Ruby GC as a shared object in order to override it using `LD_LIBRARY_PATH`/`LD_PRELOAD` et al, and after experimenting with some alternative approaches we have decided to use an approach based around the `dlopen` wrappers provided in `dln.c`. This provides several benefits that our existing implementation does not. - It does not require integration of another shared object into the build system. As pointed out by @katei, this is a complex and error-prone task, with added complexity implications for committers building and testing new features on Ruby, as well as an explosion of new CI tasks required to test all variants. - It doesn't expose the GC as a shared object, with the potentially misleading consequence of users assuming they can link against the Ruby GC independently; as they currently can with `libruby` - It runs on more platforms than our initial approach which was targeted specifically at Linux and MacOS. The use of existing functionality in `dln.c` should allow development of this feature on any platform that supports C extensions. The approach taken here is as follows: - Enable this feature by configuring with `--with-shared-gc` - When enabled, Ruby will check for the presence of the environment variable `RUBY_GC_LIBRARY_PATH` - If that path exists and points to a valid shared object - Open the shared object (using `dln_open`), and map the `Init_GC` function to a function map - call `Init_GC` as part of `rb_objspace_alloc` when initialising the GC - If that path does not point to a valid shared object - Degrade gracefully to initialising the existing Ruby objspace and GC When Ruby is configured without the `--with-shared-gc` flag, no extra code is compiled and so existing behaviour is maintained without any performance penalty. Enabling this feature, but not populating `RUBY_GC_LIBRARY_PATH` will incur a small performance penalty due to the overhead of using `getenv` to check for the environment variable. The use of `dln.c` rather than using `dlopen` directly, should enable this feature to be supported on all platforms that support loading shared libraries, rather than the initial implementation, which explicitly only supported Linux and MacOS. ---------------------------------------- Feature #20351: Optionally extract common GC routines into a DSO https://bugs.ruby-lang.org/issues/20351#change-107823 * Author: eightbitraptor (Matthew Valentine-House) * Status: Open ---------------------------------------- [Github PR#10302](https://github.com/ruby/ruby/pull/10302) **NOTE: This proposal does not change the default build of Ruby, and therefore should NOT cause performance degradation for Ruby built in the usual way** Our long term goal is to standardise Ruby's GC interface, allowing alternative GC implementations to be used. This will be acheived by optionally building Ruby's GC as a shared object; enabling it to be replaced at runtime using using `LD_LIBRARY_PATH`. eg: ``` LD_LIBRARY_PATH=/custom_gc_location ruby script.rb ``` This ticket proposes the first step towards this goal. A new experimental build option, `--enable-shared-gc`, that will compile and link a module into the built `ruby` binary as a shared object - `miniruby` will remain statically linked to the existing GC in all cases. Similar methods of replacing functionality relied on by Ruby have precedent. `jemalloc` uses `LD_PRELOAD` to replace `glibc` provided `malloc` and `free` at runtime. Although this project will be the first time a technique such as this has been used to replace core Ruby functionality. This flag will be marked as experimental & **disabled by default**. [The PR linked from this ticket](https://github.com/ruby/ruby/pull/10302) implements the new build flag, along with the absolute minimum code required to test it's implementation (a single debug function). The implementation of the new build flag is based on the existing implementation of `--enable-shared` and behaves as follows: - `--enable-shared --enable-shared-gc` This will build both `libruby` and `librubygc` as shared objects. `ruby` will link dynamically to both `libruby` and `librubygc`. - `--disable-shared --enable-shared-gc` This will build `librubygc` as a shared object, and build `libruby` as a static object. `libruby` will link dynamically to `librubygc` and `ruby` will be statically linked to `libruby`. - `--disable-shared-gc` **This will be the default**, and when this case is true the build behaviour will be exactly the same as it is currently. ie. the existing Ruby GC will be built and linked statically into either `ruby` or `libruby.so` depending on the state of `--enable-shared`. We are aware that there will be a small performance penalty from moving the GC logic into a shared object, but this is an opt-in configuration turned on at build time intended to be used by experienced users. Still, we anticipate that, even with this configuration turned on, this penalty will be negligible compared the the benefit that being able to use high performance GC algorithms will provide. This performance penalty is also the reason that **this feature will be disabled by default**. There will be no performance impact for anyone compiling Ruby in the usual manner, without explicitly enabling this feature. We have discussed this proposal with @matz who has approved our work on this project - having a clear abstraction between the VM and the GC will enable us to iterate faster on improvements to Ruby's existing GC. ## Motivation In the long term we want to provide the ability to override the current Ruby GC implementation in order to: * Experiment with modern high-performance GC implementations, such as Immix, G1, LXR etc. * Easily split-test changes to the GC, or the GC tuning, in production without having to rebuild Ruby * Easily use debug builds of the GC to help identify production problems and bottlenecks without having to rebuild Ruby * Encourage the academic memory management research community to consider Ruby for their research (the current work on [MMTk & Ruby](https://github.com/mmtk/mmtk-ruby) is a good example of this). ## Future work The initial implementation of the shared GC module in this PR is deliberately small, and exists only for testing the build system integration. The next steps are to identify boundaries between the GC and the VM and begin to extract common functionality into this GC wrapper module to serve as the foundation of our GC interface. ## Who's working on this - @eightbitraptor - @tenderlovemaking - @peterzhu2118 - @eileencodes -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/