• Tom Lane's avatar
    Clean up handling of anonymous mmap'd shared-memory segment. · 15fc5e15
    Tom Lane authored
    Fix detaching of the mmap'd segment to have its own on_shmem_exit callback,
    rather than piggybacking on the one for detaching from the SysV segment.
    That was confusing, and given the distance between the two attach calls,
    it was trouble waiting to happen.
    
    Make the detaching calls idempotent by clearing AnonymousShmem to show
    we've already unmapped.  I spent quite a bit of time yesterday trying
    to find a path that would allow the munmap()'s to be done twice, and
    while I did not succeed, it seems silly that there's even a question.
    
    Make the #ifdef logic less confusing by separating "do we want to use
    anonymous shmem" from EXEC_BACKEND.  Even though there's no current
    scenario where those conditions are different, it is not helpful for
    different places in the same file to be testing EXEC_BACKEND for what
    are fundamentally different reasons.
    
    Don't do on_exit_reset() in StartBackgroundWorker().  At best that's
    useless (InitPostmasterChild would have done it already) and at worst
    it could zap some callback that's unrelated to shared memory.
    
    Improve comments, and simplify the huge_pages enablement logic slightly.
    
    Back-patch to 9.4 where hugepage support was introduced.
    Arguably this should go into 9.3 as well, but the code looks
    significantly different there, and I doubt it's worth the
    trouble of adapting the patch given I can't show a live bug.
    15fc5e15
bgworker.c 28.9 KB