• F
    The GPDB Vmem is the lowest layer of memory allocator that supports higher... · 42ca3506
    Foyzur Rahman 提交于
        The GPDB Vmem is the lowest layer of memory allocator that supports higher allocators such as AllocSet. This layer (mostly defined in memprot.c) is in charge of actually calling malloc/realloc/free to allocate/reallocate/free memory. In this process this layer is also in charge of reserving "virtual" memory or Vmem, which is a GPDB specific shared memory counter to track per-segment combined allocations across all the GPDB processes under Vmem umbrella. The Vmem counter is managed by a separate module Vmem_Tracker, and the memprot functions (such as gp_malloc, gp_free2 and gp_realloc) call the APIs provided by VmemTracker.
    
        Previously the memprot allocators (gp_alloc/gp_realloc/gp_free) were only allocating/freeing memory but were not adding any additional metadata in the header (and there was no header) to track the size of allocations. Therefore, there was no gp_free as freeing memory requires the size of the free to adjust Vmem counter inside VmemTracker. This was patched by explicitly passing size info in gp_free2.
    
        In this PR we do the following:
    
        * We add allocation size in Vmem header (along with checksums which are only available in debug build to detect header and footer boundary, and buffer overruns).
    
        * We remove size information from the block header of AllocSet.
    
        * We rename gp_free2 to gp_free as the second parameter (size information) is now obtained from the header and therefore no longer necessary
    
        * We modify all the consumers of memprot.c APIs to use the new APIs
    
        * We add unit tests to test the metadata and the correctness of the new Vmem allocators
    
        This is the first step to integrate external modules and third party allocations with Vmem. A long running issue in GPDB is its inability to track allocations by external components including libraries such as ORCA. Therefore, the central Vmem counter is often way off from the underlying allocations, and this may run the system out of memory. By maintaining the size information in the Vmem header, we now have a self-contained allocator that can be exposed to external allocators such as GPOS allocators, without forcing them to manage size information separately.
    
        This fixes #117269929.
    Signed-off-by: NMarc Spehlmann <marc.spehlmann@gmail.com>
    42ca3506
palloc.h 7.5 KB