]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed StoreEntry::mayStartSwapOut() logic to handle terminated swapouts.
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 22 Jul 2013 17:04:00 +0000 (11:04 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Mon, 22 Jul 2013 17:04:00 +0000 (11:04 -0600)
StoreEntry::mayStartSwapOut() should return true if a swapout can start. If
swapout was started earlier but then terminated for some reason (setting sio
to nil), the method should not return true. Checking swap_status ==
SWAPOUT_DONE does not work reliably because the status may be reset to
SWAPOUT_NONE in some cases (and the check was too late anyway). Checking
decision == swPossible does not work at all because while swapout start was
possible at some point, it is no longer possible after we started swapping
out.

Added MemObject::SwapOut::swStarted to detect started swapouts reliably.

src/MemObject.h
src/store_swapout.cc

index 36d3390c3d5af6b6225476b6b9757d4c7fad7630..79232f8fab0c0eee060973cd63142a1d5d1059b0 100644 (file)
@@ -133,7 +133,7 @@ public:
         StoreIOState::Pointer sio;
 
         /// Decision states for StoreEntry::swapoutPossible() and related code.
-        typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1 } Decision;
+        typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
         Decision decision; ///< current decision state
     };
 
index 581a6db08ae200d50bc0778f17929dcdb77397ff..f77fab1aaa8816001ae6835bef83cf7a372198b8 100644 (file)
@@ -69,6 +69,7 @@ storeSwapOutStart(StoreEntry * e)
            e->swap_dirn << ", fileno " << std::hex << std::setw(8) << std::setfill('0') <<
            std::uppercase << e->swap_filen);
     e->swap_status = SWAPOUT_WRITING;
+    mem->swapout.decision = MemObject::SwapOut::swStarted;
     /* If we start swapping out objects with OutOfBand Metadata,
      * then this code needs changing
      */
@@ -372,18 +373,12 @@ StoreEntry::mayStartSwapOut()
     assert(mem_obj);
     MemObject::SwapOut::Decision &decision = mem_obj->swapout.decision;
 
-    // if we decided that swapout is not possible, do not repeat same checks
+    // if we decided that starting is not possible, do not repeat same checks
     if (decision == MemObject::SwapOut::swImpossible) {
         debugs(20, 3, HERE << " already rejected");
         return false;
     }
 
-    // if we decided that swapout is possible, do not repeat same checks
-    if (decision == MemObject::SwapOut::swPossible) {
-        debugs(20, 3,  HERE << "already allowed");
-        return true;
-    }
-
     // if we swapped out already, do not start over
     if (swap_status == SWAPOUT_DONE) {
         debugs(20, 3,  HERE << "already did");
@@ -391,6 +386,19 @@ StoreEntry::mayStartSwapOut()
         return false;
     }
 
+    // if we stared swapping out already, do not start over
+    if (decision == MemObject::SwapOut::swStarted) {
+        debugs(20, 3, "already started");
+        decision = MemObject::SwapOut::swImpossible;
+        return false;
+    }
+
+    // if we decided that swapout is possible, do not repeat same checks
+    if (decision == MemObject::SwapOut::swPossible) {
+        debugs(20, 3, "already allowed");
+        return true;
+    }
+
     if (!checkCachable()) {
         debugs(20, 3,  HERE << "not cachable");
         decision = MemObject::SwapOut::swImpossible;