Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/cache: move the bulk of allocations off the Go heap #523

Merged
merged 6 commits into from
Feb 12, 2020

Commits on Feb 12, 2020

  1. internal/cache: move the bulk of allocations off the Go heap

    Use C malloc/free for the bulk of cache allocations. This required
    elevating `cache.Value` to a public citizen of the cache package. A
    distinction is made between manually managed memory and automatically
    managed memory. Weak handles can only be made from values stored in
    automatically managed memory. Note that weak handles are only used for
    the index, filter, and range-del blocks, so the number of weak handles
    is O(num-tables).
    
    A finalizer is set on `*allocCache` and `*Cache` in order to ensure that
    any outstanding manually allocated memory is released when these objects
    are collected.
    
    When `invariants` are enabled, finalizers are also set on `*Value` and
    sstable iterators to ensure that we're not leaking manually managed
    memory.
    
    Fixes #11
    petermattis committed Feb 12, 2020
    Configuration menu
    Copy the full SHA
    b880bab View commit details
    Browse the repository at this point in the history
  2. internal/cache: optimize allocation of manual Values

    For manual Values, allocate the `Value` at the start of the backing
    buffer. For large block caches, the number of Values can reach 500k-1m
    or higher, and consume a significant fraction of the total allocated
    objects in the Go heap.
    petermattis committed Feb 12, 2020
    Configuration menu
    Copy the full SHA
    e8986be View commit details
    Browse the repository at this point in the history
  3. internal/cache: optimize allocation of entry objects

    Each entry in the cache has an associated `entry` struct. For large
    block caches, the number of entries can reach 500k-1m or higher, and
    consume a significant fraction of the total allocated objects in the Go
    heap. For manually managed values, the lifetime of the associated
    `entry` is known and the `*entry` never escapes outside of the cache
    package. This allows us to manually manage the memory for these entries,
    which are the majority of entries in the cache.
    petermattis committed Feb 12, 2020
    Configuration menu
    Copy the full SHA
    1bdb288 View commit details
    Browse the repository at this point in the history
  4. ci: add no-invariants test configuration

    The "invariants" build tag causes different code paths to be
    utilized. Add a no-invariants test configuration for testing the
    invariant-less code paths.
    
    Change the race builds to not specify the "invariants" tags as doing so
    causes them to frequently flake on the CI machines. This appears to be
    due to the size of the machines (RAM available) and not something more
    serious.
    petermattis committed Feb 12, 2020
    Configuration menu
    Copy the full SHA
    73078fc View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    c1fa89c View commit details
    Browse the repository at this point in the history
  6. internal/cache: add robinHoodMap

    Add `robinHoodMap` which is a hash map implemented using Robin Hood
    hashing. `robinHoodMap` is specialized to use `key` and `*entry` as the
    key and value for the map respectively. The memory for the backing array
    is manually allocated. This lowers GC pressure by moving the allocated
    memory out of the Go heap, and by moving all of `*entry` pointers out of
    the Go heap.
    
    Use `robinHoodMap` for both the `shard.blocks` and `shard.files` maps.
    
    Old is Go-map, new is RobinHood-map.
    
    name              old time/op  new time/op  delta
    MapInsert-16       144ns ± 5%   101ns ± 8%  -29.88%  (p=0.000 n=10+9)
    MapLookupHit-16    137ns ± 1%    47ns ± 1%  -65.58%  (p=0.000 n=8+10)
    MapLookupMiss-16  89.9ns ± 4%  48.6ns ± 3%  -45.95%  (p=0.000 n=10+9)
    petermattis committed Feb 12, 2020
    Configuration menu
    Copy the full SHA
    0f2704f View commit details
    Browse the repository at this point in the history