aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_worker.c
diff options
context:
space:
mode:
authorLars Ellenberg <lars@linbit.com>2014-04-28 12:43:29 -0400
committerJens Axboe <axboe@fb.com>2014-04-30 15:46:55 -0400
commitf9c78128f833ae3057884ca219259c8ae5db8898 (patch)
tree8b8daca4fb5153211289b98b012dc648aacff2d3 /drivers/block/drbd/drbd_worker.c
parente4d7d6f4d36daff6aad84f96e48debde8e6ed09e (diff)
drbd: always implicitly close last epoch when idle
Once our sender thread needs to wait_for_work(), and actually needs to schedule(), just before we do that, we already check if it is useful to implicitly close the last epoch. The condition was too strict: only implicitly close the epoch, if there have been no new (write) requests at all. The assumption was that if there were new requests, they would always be communicated one way or another, and would send necessary epoch separating barriers explicitly. This is not always true, e.g. when becoming diskless, or while explicitly starting a full resync. The last communicated epoch could stay open for a long time, locking down corresponding activity log extents. It is safe to always implicitly send that last barrier, as soon as we determin that there cannot be more requests in the last communicated epoch, even if there have been (uncommunicated) new requests in new epochs meanwhile. Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/block/drbd/drbd_worker.c')
-rw-r--r--drivers/block/drbd/drbd_worker.c48
1 files changed, 15 insertions, 33 deletions
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
index 34dde10fae48..d8f57b6305cd 100644
--- a/drivers/block/drbd/drbd_worker.c
+++ b/drivers/block/drbd/drbd_worker.c
@@ -1799,34 +1799,6 @@ void drbd_start_resync(struct drbd_device *device, enum drbd_conns side)
1799 mutex_unlock(device->state_mutex); 1799 mutex_unlock(device->state_mutex);
1800} 1800}
1801 1801
1802/* If the resource already closed the current epoch, but we did not
1803 * (because we have not yet seen new requests), we should send the
1804 * corresponding barrier now. Must be checked within the same spinlock
1805 * that is used to check for new requests. */
1806static bool need_to_send_barrier(struct drbd_connection *connection)
1807{
1808 if (!connection->send.seen_any_write_yet)
1809 return false;
1810
1811 /* Skip barriers that do not contain any writes.
1812 * This may happen during AHEAD mode. */
1813 if (!connection->send.current_epoch_writes)
1814 return false;
1815
1816 /* ->req_lock is held when requests are queued on
1817 * connection->sender_work, and put into ->transfer_log.
1818 * It is also held when ->current_tle_nr is increased.
1819 * So either there are already new requests queued,
1820 * and corresponding barriers will be send there.
1821 * Or nothing new is queued yet, so the difference will be 1.
1822 */
1823 if (atomic_read(&connection->current_tle_nr) !=
1824 connection->send.current_epoch_nr + 1)
1825 return false;
1826
1827 return true;
1828}
1829
1830static bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list) 1802static bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list)
1831{ 1803{
1832 spin_lock_irq(&queue->q_lock); 1804 spin_lock_irq(&queue->q_lock);
@@ -1885,12 +1857,22 @@ static void wait_for_work(struct drbd_connection *connection, struct list_head *
1885 spin_unlock_irq(&connection->resource->req_lock); 1857 spin_unlock_irq(&connection->resource->req_lock);
1886 break; 1858 break;
1887 } 1859 }
1888 send_barrier = need_to_send_barrier(connection); 1860
1861 /* We found nothing new to do, no to-be-communicated request,
1862 * no other work item. We may still need to close the last
1863 * epoch. Next incoming request epoch will be connection ->
1864 * current transfer log epoch number. If that is different
1865 * from the epoch of the last request we communicated, it is
1866 * safe to send the epoch separating barrier now.
1867 */
1868 send_barrier =
1869 atomic_read(&connection->current_tle_nr) !=
1870 connection->send.current_epoch_nr;
1889 spin_unlock_irq(&connection->resource->req_lock); 1871 spin_unlock_irq(&connection->resource->req_lock);
1890 if (send_barrier) { 1872
1891 drbd_send_barrier(connection); 1873 if (send_barrier)
1892 connection->send.current_epoch_nr++; 1874 maybe_send_barrier(connection,
1893 } 1875 connection->send.current_epoch_nr + 1);
1894 schedule(); 1876 schedule();
1895 /* may be woken up for other things but new work, too, 1877 /* may be woken up for other things but new work, too,
1896 * e.g. if the current epoch got closed. 1878 * e.g. if the current epoch got closed.