struct ReadStream
 {
    int16       max_ios;
+   int16       io_combine_limit;
    int16       ios_in_progress;
    int16       queue_size;
    int16       max_pinned_buffers;
 
    /* This should only be called with a pending read. */
    Assert(stream->pending_read_nblocks > 0);
-   Assert(stream->pending_read_nblocks <= io_combine_limit);
+   Assert(stream->pending_read_nblocks <= stream->io_combine_limit);
 
    /* We had better not exceed the pin limit by starting this read. */
    Assert(stream->pinned_buffers + stream->pending_read_nblocks <=
        int16       buffer_index;
        void       *per_buffer_data;
 
-       if (stream->pending_read_nblocks == io_combine_limit)
+       if (stream->pending_read_nblocks == stream->io_combine_limit)
        {
            read_stream_start_pending_read(stream, suppress_advice);
            suppress_advice = false;
     * signaled end-of-stream, we start the read immediately.
     */
    if (stream->pending_read_nblocks > 0 &&
-       (stream->pending_read_nblocks == io_combine_limit ||
+       (stream->pending_read_nblocks == stream->io_combine_limit ||
         (stream->pending_read_nblocks == stream->distance &&
          stream->pinned_buffers == 0) ||
         stream->distance == 0) &&
    ReadStream *stream;
    size_t      size;
    int16       queue_size;
+   int16       queue_overflow;
    int         max_ios;
    int         strategy_pin_limit;
    uint32      max_pinned_buffers;
    /* Cap to INT16_MAX to avoid overflowing below */
    max_ios = Min(max_ios, PG_INT16_MAX);
 
+   /*
+    * If starting a multi-block I/O near the end of the queue, we might
+    * temporarily need extra space for overflowing buffers before they are
+    * moved to regular circular position.  This is the maximum extra space we
+    * could need.
+    */
+   queue_overflow = io_combine_limit - 1;
+
    /*
     * Choose the maximum number of buffers we're prepared to pin.  We try to
     * pin fewer if we can, though.  We add one so that we can make progress
     */
    max_pinned_buffers = (max_ios + 1) * io_combine_limit;
    max_pinned_buffers = Min(max_pinned_buffers,
-                            PG_INT16_MAX - io_combine_limit - 1);
+                            PG_INT16_MAX - queue_overflow - 1);
 
    /* Give the strategy a chance to limit the number of buffers we pin. */
    strategy_pin_limit = GetAccessStrategyPinLimit(strategy);
     * one big chunk.  Though we have queue_size buffers, we want to be able
     * to assume that all the buffers for a single read are contiguous (i.e.
     * don't wrap around halfway through), so we allow temporary overflows of
-    * up to the maximum possible read size by allocating an extra
-    * io_combine_limit - 1 elements.
+    * up to the maximum possible overflow size.
     */
    size = offsetof(ReadStream, buffers);
-   size += sizeof(Buffer) * (queue_size + io_combine_limit - 1);
+   size += sizeof(Buffer) * (queue_size + queue_overflow);
    size += sizeof(InProgressIO) * Max(1, max_ios);
    size += per_buffer_data_size * queue_size;
    size += MAXIMUM_ALIGNOF * 2;
    stream = (ReadStream *) palloc(size);
    memset(stream, 0, offsetof(ReadStream, buffers));
    stream->ios = (InProgressIO *)
-       MAXALIGN(&stream->buffers[queue_size + io_combine_limit - 1]);
+       MAXALIGN(&stream->buffers[queue_size + queue_overflow]);
    if (per_buffer_data_size > 0)
        stream->per_buffer_data = (void *)
            MAXALIGN(&stream->ios[Max(1, max_ios)]);
    if (max_ios == 0)
        max_ios = 1;
 
+   /*
+    * Capture stable values for these two GUC-derived numbers for the
+    * lifetime of this stream, so we don't have to worry about the GUCs
+    * changing underneath us beyond this point.
+    */
    stream->max_ios = max_ios;
+   stream->io_combine_limit = io_combine_limit;
+
    stream->per_buffer_data_size = per_buffer_data_size;
    stream->max_pinned_buffers = max_pinned_buffers;
    stream->queue_size = queue_size;
     * doing full io_combine_limit sized reads (behavior B).
     */
    if (flags & READ_STREAM_FULL)
-       stream->distance = Min(max_pinned_buffers, io_combine_limit);
+       stream->distance = Min(max_pinned_buffers, stream->io_combine_limit);
    else
        stream->distance = 1;
 
        else
        {
            /* No advice; move towards io_combine_limit (behavior B). */
-           if (stream->distance > io_combine_limit)
+           if (stream->distance > stream->io_combine_limit)
            {
                stream->distance--;
            }
            else
            {
                distance = stream->distance * 2;
-               distance = Min(distance, io_combine_limit);
+               distance = Min(distance, stream->io_combine_limit);
                distance = Min(distance, stream->max_pinned_buffers);
                stream->distance = distance;
            }