Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf/5912~1
Choose a base ref
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf/5912
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Aug 4, 2025

  1. Optimize LISTEN/NOTIFY signaling with a lock-free atomic state machine

    This commit introduces a powerful pattern for modernizing inter-process
    communication by refactoring the LISTEN/NOTIFY subsystem to use a
    lock-free, atomic finite state machine (FSM). This directly addresses
    the historical lack of safe, efficient state synchronization primitives.
    
    Previously, if multiple transactions sent notifications concurrently,
    each would unconditionally attempt to signal all listening backends.
    This resulted in a storm of superfluous signals to listeners that were
    already pending a wakeup, causing unnecessary system call overhead.
    
    By introducing an atomic per-backend state (IDLE, SIGNALLED, PROCESSING)
    in shared memory and manipulated via compare-and-swap (CAS), this
    inefficiency is eliminated. A notifier can now atomically transition a
    listener's state from IDLE to SIGNALLED, ensuring that only the first
    notifier for a given idle listener dispatches a wakeup. The FSM also
    robustly handles race conditions where new notifications arrive while a
    listener is PROCESSING, guaranteeing no work is ever missed.
    
    This FSM pattern is a generalizable solution for managing concurrency in
    PostgreSQL. By modeling inter-process interactions as explicit state
    transitions, we can build more robust and performant subsystems. This
    commit demonstrates the pattern's effectiveness within async.c, and by
    cleanly solving the state management problem first, it enables a
    subsequent, trivial optimization of the wakeup mechanism itself.
    joelonsql authored and Commitfest Bot committed Aug 4, 2025
    Configuration menu
    Copy the full SHA
    a54954c View commit details
    Browse the repository at this point in the history
  2. Optimize LISTEN/NOTIFY wakeup by replacing signal with direct SetLatch

    Building upon the robust atomic state machine introduced in the previous
    commit, this change completes the modernization of NOTIFY IPC by
    replacing its wakeup mechanism. With inter-process state now managed
    reliably, the heavyweight SIGUSR1 signal is no longer necessary and is
    replaced with a much more efficient, direct "poke."
    
    The async.c notifier now replaces its call to SendProcSignal with a
    direct call to SetLatch on the target backend's procLatch. This is a
    significant optimization because WaitLatch, which listeners already use
    for blocking, is underpinned by the modern WaitEventSet abstraction
    (kqueue, epoll, etc.). We now leverage this existing, highly efficient
    infrastructure for the wakeup, completely bypassing the kill() syscall
    and the SIGUSR1 signal handler for all NOTIFY events.
    
    This demonstrates a powerful, two-step migration pattern:
    
    1. First, solve a subsystem's state synchronization problem with a
       lock-free, atomic FSM to eliminate redundant signaling.
    
    2. Then, with state management handled, make the wakeup itself cheaper
       by replacing the expensive signal with a direct SetLatch.
    
    This staged approach allows us to modernize subsystems incrementally and
    safely. By applying this pattern to async.c, we prove its viability and
    simplicity, creating a clear template for other parts of the system to
    follow in moving towards a more performant, signal-free IPC model.
    joelonsql authored and Commitfest Bot committed Aug 4, 2025
    Configuration menu
    Copy the full SHA
    b8f1647 View commit details
    Browse the repository at this point in the history
  3. [CF 5912] Optimize LISTEN/NOTIFY

    This branch was automatically generated by a robot using patches from an
    email thread registered at:
    
    https://commitfest.postgresql.org/patch/5912
    
    The branch will be overwritten each time a new patch version is posted to
    the thread, and also periodically to check for bitrot caused by changes
    on the master branch.
    
    Patch(es): https://www.postgresql.org/message-id/[email protected]
    Author(s): Joel Jacobson
    Commitfest Bot committed Aug 4, 2025
    Configuration menu
    Copy the full SHA
    9783317 View commit details
    Browse the repository at this point in the history
Loading