Skip to content
Snippets Groups Projects
  • Alexander Turenko's avatar
    d6cf327f
    test: stabilize flaky fiber memory leak detection · d6cf327f
    Alexander Turenko authored
    After #4736 regression fix (in fact it just reverts the new logic in
    small) it is possible again that a fiber's region may hold a memory for
    a while, but release it eventually. When the used memory exceeds 128 KiB
    threshold, fiber_gc() puts 'garbage' slabs back to slab_cache and
    subtracts them from region_used() metric. But until this point those
    slabs are accounted in region_used() and so in fiber.info() metrics.
    
    This commit fixes flakiness of test cases of the following kind:
    
     | fiber.info()[fiber.self().id()].memory.used -- should be zero
     | <...workload...>
     | fiber.info()[fiber.self().id()].memory.used -- should be zero
    
    The problem is that the first `<...>.memory.used` value may be non-zero.
    It depends of previous tests that were executed on this tarantool
    instance.
    
    The obvious way to solve it would be print differences between
    `<...>.memory.used` values before and after a workload instead of
    absolute values. This however does not work, because a first slab in a
    region can be almost used at the point where a test case starts and a
    next slab will be acquired from a slab_cache. This means that the
    previous slab will become a 'garbage' and will not be collected until
    128 KiB threshold will exceed: the latter `<...>.memory.used` check will
    return a bigger value than the former one. However, if the threshold
    will be reached during the workload, the latter check may show lesser
    value than the former one. In short, the test case would be unstable
    after this change.
    
    It is resolved by restarting of a tarantool instance before such test
    cases to ensure that there are no 'garbage' slabs in a current fiber's
    region.
    
    Note: This works only if a test case reserves only one slab at the
    moment: otherwise some memory may be hold after the case (and so a
    memory check after a workload will fail). However it seems that our
    cases are small enough to don't trigger this situation.
    
    Call of region_free() would be enough, but we have no Lua API for it.
    
    Fixes #4750.
    d6cf327f
    History
    test: stabilize flaky fiber memory leak detection
    Alexander Turenko authored
    After #4736 regression fix (in fact it just reverts the new logic in
    small) it is possible again that a fiber's region may hold a memory for
    a while, but release it eventually. When the used memory exceeds 128 KiB
    threshold, fiber_gc() puts 'garbage' slabs back to slab_cache and
    subtracts them from region_used() metric. But until this point those
    slabs are accounted in region_used() and so in fiber.info() metrics.
    
    This commit fixes flakiness of test cases of the following kind:
    
     | fiber.info()[fiber.self().id()].memory.used -- should be zero
     | <...workload...>
     | fiber.info()[fiber.self().id()].memory.used -- should be zero
    
    The problem is that the first `<...>.memory.used` value may be non-zero.
    It depends of previous tests that were executed on this tarantool
    instance.
    
    The obvious way to solve it would be print differences between
    `<...>.memory.used` values before and after a workload instead of
    absolute values. This however does not work, because a first slab in a
    region can be almost used at the point where a test case starts and a
    next slab will be acquired from a slab_cache. This means that the
    previous slab will become a 'garbage' and will not be collected until
    128 KiB threshold will exceed: the latter `<...>.memory.used` check will
    return a bigger value than the former one. However, if the threshold
    will be reached during the workload, the latter check may show lesser
    value than the former one. In short, the test case would be unstable
    after this change.
    
    It is resolved by restarting of a tarantool instance before such test
    cases to ensure that there are no 'garbage' slabs in a current fiber's
    region.
    
    Note: This works only if a test case reserves only one slab at the
    moment: otherwise some memory may be hold after the case (and so a
    memory check after a workload will fail). However it seems that our
    cases are small enough to don't trigger this situation.
    
    Call of region_free() would be enough, but we have no Lua API for it.
    
    Fixes #4750.