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.
  • 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
                    • 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)

                      ericcarroll@cosocial.caE This user is from outside of this forum
                      ericcarroll@cosocial.caE This user is from outside of this forum
                      ericcarroll@cosocial.ca
                      wrote last edited by
                      #43

                      @petrillic
                      Ok that was cool.

                      I never heard of the TI Apple II/Lisp chip Explorer before. Wow. I wonder if any survived...

                      I knew someone who was a Lisp die hard, worked on Symbolics workstations. Quite the war stories. Lisp afficionados are the hardest of the hard core.
                      @glyph @mcc

                      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

                        catfish_man@mastodon.socialC This user is from outside of this forum
                        catfish_man@mastodon.socialC This user is from outside of this forum
                        catfish_man@mastodon.social
                        wrote last edited by
                        #44

                        @mcc one of my very favorite papers! https://web.cs.umass.edu/publication/docs/2004/UM-CS-2004-016.pdf

                        1 Reply 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.

                          erincandescent@akko.erincandescent.netE This user is from outside of this forum
                          erincandescent@akko.erincandescent.netE This user is from outside of this forum
                          erincandescent@akko.erincandescent.net
                          wrote last edited by
                          #45

                          @artemist @kasperd @mcc yes but using MAP_FIXED in practice when you’re not the dynamic linker is fraught with perils like “there’s malloc block there and so i can’t use that address” or worse “there was a malloc block there and i just yeeted it out of existence” and things like “the OS has ASLR’d libc over where I wanted to map my ting”

                          what is practical is asking for a big block and suballocating within it.

                          mcc@mastodon.socialM r@glauca.spaceR 2 Replies Last reply
                          0
                          • erincandescent@akko.erincandescent.netE erincandescent@akko.erincandescent.net

                            @artemist @kasperd @mcc yes but using MAP_FIXED in practice when you’re not the dynamic linker is fraught with perils like “there’s malloc block there and so i can’t use that address” or worse “there was a malloc block there and i just yeeted it out of existence” and things like “the OS has ASLR’d libc over where I wanted to map my ting”

                            what is practical is asking for a big block and suballocating within it.

                            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
                            #46

                            @erincandescent @artemist @kasperd but what if i need to grow the block later 😞 😞 😞 😞

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

                              @erincandescent @artemist @kasperd but what if i need to grow the block later 😞 😞 😞 😞

                              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
                              #47

                              @mcc @erincandescent @kasperd don't. allocate 1TiB of memory as PROT_NONE (or on windows MEM_RESERVE). if you're on a 64-bit system it works fine, chrome does that (though i expect most of that is guard pages)

                              1 Reply Last reply
                              0
                              • erincandescent@akko.erincandescent.netE erincandescent@akko.erincandescent.net

                                @artemist @kasperd @mcc yes but using MAP_FIXED in practice when you’re not the dynamic linker is fraught with perils like “there’s malloc block there and so i can’t use that address” or worse “there was a malloc block there and i just yeeted it out of existence” and things like “the OS has ASLR’d libc over where I wanted to map my ting”

                                what is practical is asking for a big block and suballocating within it.

                                r@glauca.spaceR This user is from outside of this forum
                                r@glauca.spaceR This user is from outside of this forum
                                r@glauca.space
                                wrote last edited by
                                #48

                                @erincandescent @mcc @artemist @kasperd there are definitely ways to make this work on linux specifically (e.g. non-PIE statically-linked stub which blocks out the address space you want to reserve before loading into a more "normal" environment)

                                WINE has a.... poorly-documented and apparently not required "preloader" which does something vaguely of this nature

                                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 😞

                                  kasperd@westergaard.socialK This user is from outside of this forum
                                  kasperd@westergaard.socialK This user is from outside of this forum
                                  kasperd@westergaard.social
                                  wrote last edited by
                                  #49

                                  I know nothing about Windows APIs. Most of the code I have done using this was on Linux. And even on Linux I am not entirely sure about the details surrounding accounting of committed memory.

                                  1 Reply Last reply
                                  1
                                  0
                                  • R relay@relay.infosec.exchange shared this topic
                                  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