Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-12291

__wt_file_zero doesn't need to allocate and zero a buffer

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Source code

      Currently it allocates and zeros a scratch buffer of up to 1MB. Instead we should declare a global like _Alignas(4096) static char zeros[1024*1024]; and we will have a semi-magical zero buffer to use. This will have some nice properties:

      • There will be a single zero buffer for the whole process rather than one per call.
      • It will be in the .bss section (or other platforms' equivalent) so it won't take up any space in the binary.
      • At least on linux, when the virtual memory gets populated, it will all be backed by the single special "zero page", so it won't actually take up any physical memory. You could have an arbitrary amount of zero bytes for free using this trick.

      It is very important that it isn't declared const but is treated as-if it is and never written to, even with zeros. If it is declared const, it goes in .rodata rather than .bss and takes up space (I filed a gcc bug to do this as an optimization). If it is written to with zeros, it breaks the magic single-page backing.

            Assignee:
            backlog-server-storage-engines [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: