]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Change SwapDir::cur_size to bytes, make it private, use currentSize() instead.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Wed, 27 Apr 2011 13:57:13 +0000 (17:57 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Wed, 27 Apr 2011 13:57:13 +0000 (17:57 +0400)
src/SwapDir.cc
src/SwapDir.h
src/fs/coss/store_dir_coss.cc
src/fs/ufs/store_dir_ufs.cc
src/store_dir.cc

index 9460f7a6a138647eb6d44321b6f6f0790c7ba04b..8a6b71e58e3af74c8a08f084040c6d9eead90e01 100644 (file)
@@ -127,7 +127,7 @@ SwapDir::canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const
     if (flags.read_only)
         return false; // cannot write at all
 
-    if (cur_size > max_size)
+    if (currentSize() > max_size << 10)
         return false; // already overflowing
 
     /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
index f1bffe320f52c6ee708049466d867b1c331c9e35..3dc7b96fb0765b7986cc58fc51ec282c05c2ede1 100644 (file)
@@ -144,7 +144,7 @@ public:
 
     virtual uint64_t minSize() const;
 
-    virtual uint64_t currentSize() const { return cur_size << 10; }
+    virtual uint64_t currentSize() const { return cur_size; }
 
     virtual uint64_t currentCount() const { return n_disk_objects; }
 
@@ -173,9 +173,11 @@ private:
     void optionObjectSizeDump(StoreEntry * e) const;
     char const *theType;
 
+private:
+    uint64_t cur_size;        ///< currently used space in the storage area
+
 public:
-    // TODO: store cur_size and max_size in bytes
-    uint64_t cur_size;        ///< currently used space in the storage area in kiloBytes
+    // TODO: store max_size in bytes
     uint64_t max_size;        ///< maximum allocatable size of the storage area in kiloBytes
     uint64_t n_disk_objects;  ///< total number of objects stored
     char *path;
index cd5b99e10e9bcfc4e649b5144b1b4f6e8543008f..90b5c22a3087603fd763c404bdac257666b4942d 100644 (file)
@@ -49,7 +49,7 @@
 #include "StoreFScoss.h"
 #include "Parsing.h"
 #include "swap_log_op.h"
-//#include "SquidMath.h"
+#include "SquidMath.h"
 
 #define STORE_META_BUFSZ 4096
 
@@ -981,11 +981,12 @@ CossSwapDir::callback()
 void
 CossSwapDir::statfs(StoreEntry & sentry) const
 {
+    const double currentSizeInKB = currentSize() / 1024.0;
     storeAppendPrintf(&sentry, "\n");
     storeAppendPrintf(&sentry, "Maximum Size: %lu KB\n", max_size);
-    storeAppendPrintf(&sentry, "Current Size: %lu KB\n", cur_size);
+    storeAppendPrintf(&sentry, "Current Size: %.2f KB\n", currentSizeInKB);
     storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n",
-                      (100.0 * (double)cur_size / (double)max_size) );
+                      Math::doublePercent(currentSizeInKB, max_size) );
     storeAppendPrintf(&sentry, "Number of object collisions: %d\n", (int) numcollisions);
 #if 0
     /* is this applicable? I Hope not .. */
index b1928b33b7828ff463a707bdb66159dcdc08f351..7d4f8d80de8144200e42847ab7e4b9927db224de 100644 (file)
@@ -314,12 +314,13 @@ UFSSwapDir::statfs(StoreEntry & sentry) const
     int totl_in = 0;
     int free_in = 0;
     int x;
+    const double currentSizeInKB = currentSize() / 1024.0;
     storeAppendPrintf(&sentry, "First level subdirectories: %d\n", l1);
     storeAppendPrintf(&sentry, "Second level subdirectories: %d\n", l2);
     storeAppendPrintf(&sentry, "Maximum Size: %"PRIu64" KB\n", max_size);
-    storeAppendPrintf(&sentry, "Current Size: %"PRIu64" KB\n", cur_size);
+    storeAppendPrintf(&sentry, "Current Size: %.2f KB\n", currentSizeInKB);
     storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n",
-                      (double)(100.0 * cur_size) / (double)max_size);
+                      Math::doublePercent(currentSizeInKB, max_size));
     storeAppendPrintf(&sentry, "Filemap bits in use: %d of %d (%d%%)\n",
                       map->n_files_in_map, map->max_n_files,
                       Math::intPercent(map->n_files_in_map, map->max_n_files));
@@ -365,7 +366,7 @@ UFSSwapDir::maintain()
 
     RemovalPurgeWalker *walker;
 
-    double f = (double) (cur_size - minSize()) / (max_size - minSize());
+    double f = (double) (currentSize() / 1024.0 - minSize()) / (max_size - minSize());
 
     f = f < 0.0 ? 0.0 : f > 1.0 ? 1.0 : f;
 
@@ -382,7 +383,7 @@ UFSSwapDir::maintain()
     walker = repl->PurgeInit(repl, max_scan);
 
     while (1) {
-        if (cur_size < minSize())
+        if (currentSize() < minSize() << 10)
             break;
 
         if (removed >= max_remove)
index 5386d02f1363af7d9926eaac19f87874e812574b..398345d55ba642dc944f6c3b73ba023d30899cd8 100644 (file)
@@ -236,7 +236,7 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
 static int
 storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
 {
-    ssize_t most_free = 0, cur_free;
+    uint64_t most_free = 0;
     ssize_t least_objsize = -1;
     int least_load = INT_MAX;
     int load;
@@ -263,7 +263,7 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
         if (load > least_load)
             continue;
 
-        cur_free = SD->max_size - SD->cur_size;
+        const uint64_t cur_free = (SD->max_size << 10) - SD->currentSize();
 
         /* If the load is equal, then look in more details */
         if (load == least_load) {
@@ -332,8 +332,8 @@ StoreController::updateSize(int64_t size, int sign)
 void
 SwapDir::updateSize(int64_t size, int sign)
 {
-    int64_t blks = (size + fs.blksize - 1) / fs.blksize;
-    int64_t k = ((blks * fs.blksize) >> 10) * sign;
+    const int64_t blks = (size + fs.blksize - 1) / fs.blksize;
+    const int64_t k = blks * fs.blksize * sign;
     cur_size += k;
 
     if (sign > 0)
@@ -400,12 +400,12 @@ StoreController::maxObjectSize() const
 void
 SwapDir::diskFull()
 {
-    if (cur_size >= max_size)
+    if (currentSize() >= max_size << 10)
         return;
 
-    max_size = cur_size;
+    max_size = currentSize() >> 10;
 
-    debugs(20, 1, "WARNING: Shrinking cache_dir #" << index << " to " << cur_size << " KB");
+    debugs(20, 1, "WARNING: Shrinking cache_dir #" << index << " to " << currentSize() / 1024.0 << " KB");
 }
 
 void