Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. Do you ever daydream about the incredibly wild optimizations a garbage collector could do if it had the direct control over virtual memory layout an operating system does

Do you ever daydream about the incredibly wild optimizations a garbage collector could do if it had the direct control over virtual memory layout an operating system does

Scheduled Pinned Locked Moved Uncategorized
49 Posts 23 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mcc@mastodon.socialM mcc@mastodon.social

    Do you ever daydream about the incredibly wild optimizations a garbage collector could do if it had the direct control over virtual memory layout an operating system does

    joe@f.duriansoftware.comJ This user is from outside of this forum
    joe@f.duriansoftware.comJ This user is from outside of this forum
    joe@f.duriansoftware.com
    wrote last edited by
    #23

    @mcc i recently saw this, which i thought was a clever use of only userspace-level control over virtual memory layout https://github.com/plasma-umass/Mesh

    dysfun@social.treehouse.systemsD 1 Reply Last reply
    0
    • driusan@doomscroller.socialD driusan@doomscroller.social
      @glyph@mastodon.social @mcc@mastodon.social That's just called shell scripting.
      mcc@mastodon.socialM This user is from outside of this forum
      mcc@mastodon.socialM This user is from outside of this forum
      mcc@mastodon.social
      wrote last edited by
      #24

      @driusan @glyph what if shell scripting were good

      1 Reply Last reply
      0
      • joe@f.duriansoftware.comJ joe@f.duriansoftware.com

        @mcc i recently saw this, which i thought was a clever use of only userspace-level control over virtual memory layout https://github.com/plasma-umass/Mesh

        dysfun@social.treehouse.systemsD This user is from outside of this forum
        dysfun@social.treehouse.systemsD This user is from outside of this forum
        dysfun@social.treehouse.systems
        wrote last edited by
        #25

        @joe @mcc it's going to make a mess of your page tables though. i wouldn't actually deploy it.

        joe@f.duriansoftware.comJ 1 Reply Last reply
        0
        • mcc@mastodon.socialM mcc@mastodon.social

          @glyph One thing I wonder is if we'd even need protected memory in that world. Per se. Or if we could throw out process protected memory and use the protected memory capabilities of the CPU for something entirely other

          glyph@mastodon.socialG This user is from outside of this forum
          glyph@mastodon.socialG This user is from outside of this forum
          glyph@mastodon.social
          wrote last edited by
          #26

          @mcc on the one hand, in principle, of course not! you can validate everything once at the garbage collector level, put the GC in the kerrnel, use formal methods or whatever and bob's your uncle, everything would be so fast!

          on the other hand, in practice, I have been in the room (usually at PyCon) where garbage collector bugs are being diagnosed and fixed, and from that experience, "no, this must never happen"

          mcc@mastodon.socialM 1 Reply Last reply
          0
          • glyph@mastodon.socialG glyph@mastodon.social

            @mcc on the one hand, in principle, of course not! you can validate everything once at the garbage collector level, put the GC in the kerrnel, use formal methods or whatever and bob's your uncle, everything would be so fast!

            on the other hand, in practice, I have been in the room (usually at PyCon) where garbage collector bugs are being diagnosed and fixed, and from that experience, "no, this must never happen"

            mcc@mastodon.socialM This user is from outside of this forum
            mcc@mastodon.socialM This user is from outside of this forum
            mcc@mastodon.social
            wrote last edited by
            #27

            @glyph I've been thinking a lot in recent years about the unikernel environment

            petrillic@hachyderm.ioP 1 Reply Last reply
            0
            • dysfun@social.treehouse.systemsD dysfun@social.treehouse.systems

              @joe @mcc it's going to make a mess of your page tables though. i wouldn't actually deploy it.

              joe@f.duriansoftware.comJ This user is from outside of this forum
              joe@f.duriansoftware.comJ This user is from outside of this forum
              joe@f.duriansoftware.com
              wrote last edited by
              #28

              @dysfun @mcc yeah that was my thinking too, that seems to be the ultimate fate of most clever page table trickery (see also attempts to implement calloc() by mapping zeroed pages)

              1 Reply Last reply
              0
              • mcc@mastodon.socialM mcc@mastodon.social

                @glyph I've been thinking a lot in recent years about the unikernel environment

                petrillic@hachyderm.ioP This user is from outside of this forum
                petrillic@hachyderm.ioP This user is from outside of this forum
                petrillic@hachyderm.io
                wrote last edited by
                #29

                @mcc @glyph isn't this really the story of things like the Smalltalk and Lisp machines?

                mcc@mastodon.socialM popeyeotaku@speedlines.stctp.zoneP 2 Replies Last reply
                0
                • petrillic@hachyderm.ioP petrillic@hachyderm.io

                  @mcc @glyph isn't this really the story of things like the Smalltalk and Lisp machines?

                  mcc@mastodon.socialM This user is from outside of this forum
                  mcc@mastodon.socialM This user is from outside of this forum
                  mcc@mastodon.social
                  wrote last edited by
                  #30

                  @petrillic @glyph I once got to see Dave Ungar using his laptop. It was a life-changing experience

                  petrillic@hachyderm.ioP 1 Reply Last reply
                  0
                  • mcc@mastodon.socialM mcc@mastodon.social

                    @petrillic @glyph I once got to see Dave Ungar using his laptop. It was a life-changing experience

                    petrillic@hachyderm.ioP This user is from outside of this forum
                    petrillic@hachyderm.ioP This user is from outside of this forum
                    petrillic@hachyderm.io
                    wrote last edited by
                    #31

                    @mcc @glyph :wistful sigh: Self.

                    glyph@mastodon.socialG 1 Reply Last reply
                    0
                    • petrillic@hachyderm.ioP petrillic@hachyderm.io

                      @mcc @glyph :wistful sigh: Self.

                      glyph@mastodon.socialG This user is from outside of this forum
                      glyph@mastodon.socialG This user is from outside of this forum
                      glyph@mastodon.social
                      wrote last edited by
                      #32

                      @mcc @petrillic I am aware *that* Genera sort of petered out, but I still don't really understand *why* it did. It was too expensive for the hardware of the day, but probably *less* too-expensive than, say, NeXTSTEP, which famously endured despite a worse start. Has anyone written a history of Symbolics? I wonder if there are good reasons for this.

                      petrillic@hachyderm.ioP 1 Reply Last reply
                      0
                      • glyph@mastodon.socialG glyph@mastodon.social

                        @mcc @petrillic I am aware *that* Genera sort of petered out, but I still don't really understand *why* it did. It was too expensive for the hardware of the day, but probably *less* too-expensive than, say, NeXTSTEP, which famously endured despite a worse start. Has anyone written a history of Symbolics? I wonder if there are good reasons for this.

                        petrillic@hachyderm.ioP This user is from outside of this forum
                        petrillic@hachyderm.ioP This user is from outside of this forum
                        petrillic@hachyderm.io
                        wrote last edited by
                        #33

                        @glyph @mcc Asianometry did a video on the whole boom and bust of the industry. It was part of the AI winter that happened.

                        - YouTube

                        Auf YouTube findest du die angesagtesten Videos und Tracks. Außerdem kannst du eigene Inhalte hochladen und mit Freunden oder gleich der ganzen Welt teilen.

                        favicon

                        (www.youtube.com)

                        glyph@mastodon.socialG ericcarroll@cosocial.caE 2 Replies Last reply
                        0
                        • petrillic@hachyderm.ioP petrillic@hachyderm.io

                          @glyph @mcc Asianometry did a video on the whole boom and bust of the industry. It was part of the AI winter that happened.

                          - YouTube

                          Auf YouTube findest du die angesagtesten Videos und Tracks. Außerdem kannst du eigene Inhalte hochladen und mit Freunden oder gleich der ganzen Welt teilen.

                          favicon

                          (www.youtube.com)

                          glyph@mastodon.socialG This user is from outside of this forum
                          glyph@mastodon.socialG This user is from outside of this forum
                          glyph@mastodon.social
                          wrote last edited by
                          #34

                          @petrillic @mcc what promising technology will this one destroy, I wonder

                          1 Reply Last reply
                          0
                          • mcc@mastodon.socialM mcc@mastodon.social

                            Do you ever daydream about the incredibly wild optimizations a garbage collector could do if it had the direct control over virtual memory layout an operating system does

                            aeva@mastodon.gamedev.placeA This user is from outside of this forum
                            aeva@mastodon.gamedev.placeA This user is from outside of this forum
                            aeva@mastodon.gamedev.place
                            wrote last edited by
                            #35

                            @mcc now I am

                            1 Reply Last reply
                            0
                            • petrillic@hachyderm.ioP petrillic@hachyderm.io

                              @mcc @glyph isn't this really the story of things like the Smalltalk and Lisp machines?

                              popeyeotaku@speedlines.stctp.zoneP This user is from outside of this forum
                              popeyeotaku@speedlines.stctp.zoneP This user is from outside of this forum
                              popeyeotaku@speedlines.stctp.zone
                              wrote last edited by
                              #36

                              @petrillic @mcc @glyph have I ever mentioned on here my insane plot to get Smalltalk-80 running on a C64 with GeoRAM? (I swear it's somehow possible, every few months I go back to work on it a little more -- last time I got stuck on optimizing a modulo operation in the method dispatcher)

                              1 Reply Last reply
                              0
                              • kasperd@westergaard.socialK kasperd@westergaard.social

                                You can use MAP_FIXED to get a range on a specific address. The address you specify that way does get rounded down to a multiple of the page size, but other than that it's used as is.

                                A zero value for address has a special meaning, so if you absolutely want to map at address 0 you need to ask for address 1 rounded down. Though some kernels won't permit that in the default configuration.

                                You can ask for more memory ahead of time. I am pretty sure the kernel only allocates the physical memory on the first write. However things get a little tricky with respect to over-commitment and such. As I understand it, the kernel will refuse the allocation if there is no way it could ever give you all of that memory. But I think the default is that when there is any doubt the kernel will let the allocation go through and kill the process later if it doesn't have memory after all. (I am not saying that's a good default.)

                                There is also the possibility of allocating a memory range with no permissions and then use mprotect to make parts of the range read and writable later. In that case it would make sense to me if the kernel only updates the count of committed memory once you make it writable, I don't know if that's actually what happens, but it should be easy to test.

                                I have used the approach of using mmap to allocate a range with no read or write permissions and then make a small range in the middle read-write with mprotect. My reason for using it has been to have guard pages around certain buffers as a security measure. It provides an extra layer of protection against buffer overflow vulnerabilities.

                                For some advanced use cases it can make sense to map a range with no privileges and later change the protection of the range from within a SIGSEGV handler when that address is accessed.

                                knowprose@mastodon.socialK This user is from outside of this forum
                                knowprose@mastodon.socialK This user is from outside of this forum
                                knowprose@mastodon.social
                                wrote last edited by
                                #37

                                @kasperd @mcc I have done this. I endorse. 🙃

                                1 Reply Last reply
                                0
                                • mcc@mastodon.socialM mcc@mastodon.social

                                  @kasperd Thank you, this is not something I have read up on and is a great basis for future research. Here's an important question: Do *both* Linux mmap and the Windows equivalents offer these capabilities? Because my use cases invariably need to target both 😞

                                  knowprose@mastodon.socialK This user is from outside of this forum
                                  knowprose@mastodon.socialK This user is from outside of this forum
                                  knowprose@mastodon.social
                                  wrote last edited by
                                  #38

                                  @mcc @kasperd it's at best, awkward. I managed a cross-platform project with wxwidgets some time ago, and had to kluge my own stuff.

                                  The abstraction layers are...

                                  1 Reply Last reply
                                  0
                                  • mcc@mastodon.socialM mcc@mastodon.social

                                    @kasperd Thank you, this is not something I have read up on and is a great basis for future research. Here's an important question: Do *both* Linux mmap and the Windows equivalents offer these capabilities? Because my use cases invariably need to target both 😞

                                    aeva@mastodon.gamedev.placeA This user is from outside of this forum
                                    aeva@mastodon.gamedev.placeA This user is from outside of this forum
                                    aeva@mastodon.gamedev.place
                                    wrote last edited by
                                    #39

                                    @mcc @kasperd I thiiiiink the Windows equivalent is VirtualAlloc https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc

                                    I'm a bit rusty on this, but I'm pretty sure you should be able to ask for an arbitrarily large virtual address space up front and change the page mapping on the fly.

                                    aeva@mastodon.gamedev.placeA 1 Reply Last reply
                                    0
                                    • aeva@mastodon.gamedev.placeA aeva@mastodon.gamedev.place

                                      @mcc @kasperd I thiiiiink the Windows equivalent is VirtualAlloc https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc

                                      I'm a bit rusty on this, but I'm pretty sure you should be able to ask for an arbitrarily large virtual address space up front and change the page mapping on the fly.

                                      aeva@mastodon.gamedev.placeA This user is from outside of this forum
                                      aeva@mastodon.gamedev.placeA This user is from outside of this forum
                                      aeva@mastodon.gamedev.place
                                      wrote last edited by
                                      #40

                                      @mcc @kasperd I think the main snags would be that you might also need to provide some kind of allocator to subdivide pages below the allowed granularity, and I have no idea what kind of overhead this would impose over non-virtual allocations.

                                      1 Reply Last reply
                                      0
                                      • kasperd@westergaard.socialK kasperd@westergaard.social

                                        You can use MAP_FIXED to get a range on a specific address. The address you specify that way does get rounded down to a multiple of the page size, but other than that it's used as is.

                                        A zero value for address has a special meaning, so if you absolutely want to map at address 0 you need to ask for address 1 rounded down. Though some kernels won't permit that in the default configuration.

                                        You can ask for more memory ahead of time. I am pretty sure the kernel only allocates the physical memory on the first write. However things get a little tricky with respect to over-commitment and such. As I understand it, the kernel will refuse the allocation if there is no way it could ever give you all of that memory. But I think the default is that when there is any doubt the kernel will let the allocation go through and kill the process later if it doesn't have memory after all. (I am not saying that's a good default.)

                                        There is also the possibility of allocating a memory range with no permissions and then use mprotect to make parts of the range read and writable later. In that case it would make sense to me if the kernel only updates the count of committed memory once you make it writable, I don't know if that's actually what happens, but it should be easy to test.

                                        I have used the approach of using mmap to allocate a range with no read or write permissions and then make a small range in the middle read-write with mprotect. My reason for using it has been to have guard pages around certain buffers as a security measure. It provides an extra layer of protection against buffer overflow vulnerabilities.

                                        For some advanced use cases it can make sense to map a range with no privileges and later change the protection of the range from within a SIGSEGV handler when that address is accessed.

                                        artemist@social.mildlyfunctional.gayA This user is from outside of this forum
                                        artemist@social.mildlyfunctional.gayA This user is from outside of this forum
                                        artemist@social.mildlyfunctional.gay
                                        wrote last edited by
                                        #41

                                        @kasperd @mcc not just is it possible to use MAP_FIXED, it is often required. ELF files can specify fixed addresses for loading, and executables do so unless they're specifically compiled for PIE. All binaries will want various pieces of memory mapped from both the file and anonymous backings in specific offsets from each other, so the linker will map a PROT_NONE mapping to reserve parts of the virtual address space then map parts of the file and memory on top of the shadowed mapping.

                                        leah@icu.weew.oooL erincandescent@akko.erincandescent.netE 2 Replies Last reply
                                        0
                                        • artemist@social.mildlyfunctional.gayA artemist@social.mildlyfunctional.gay

                                          @kasperd @mcc not just is it possible to use MAP_FIXED, it is often required. ELF files can specify fixed addresses for loading, and executables do so unless they're specifically compiled for PIE. All binaries will want various pieces of memory mapped from both the file and anonymous backings in specific offsets from each other, so the linker will map a PROT_NONE mapping to reserve parts of the virtual address space then map parts of the file and memory on top of the shadowed mapping.

                                          leah@icu.weew.oooL This user is from outside of this forum
                                          leah@icu.weew.oooL This user is from outside of this forum
                                          leah@icu.weew.ooo
                                          wrote last edited by
                                          #42

                                          @artemist @kasperd @mcc i love the fediverse, sometime you just stumble across something - as a noob when it comes to any memory management that close to the kernel this was such an interesting thread to read. thanks ^^

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups