From: Dmitry Kurochkin Date: Thu, 28 Apr 2011 12:23:55 +0000 (+0400) Subject: Move max_size and n_disk_objects to specific SwapDirs, remove updateSize(). X-Git-Tag: take07~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a86ff82af850849bee7b2347fd99cb85fbb5547c;p=thirdparty%2Fsquid.git Move max_size and n_disk_objects to specific SwapDirs, remove updateSize(). --- diff --git a/src/SwapDir.cc b/src/SwapDir.cc index 251fc73717..913c4e673d 100644 --- a/src/SwapDir.cc +++ b/src/SwapDir.cc @@ -39,7 +39,7 @@ #include "ConfigOption.h" SwapDir::SwapDir(char const *aType): theType(aType), - cur_size (0), max_size(0), n_disk_objects(0), + max_size(0), path(NULL), index(-1), min_objsize(0), max_objsize (-1), repl(NULL), removals(0), scanned(0), cleanLog(NULL) diff --git a/src/SwapDir.h b/src/SwapDir.h index e0d77aa9c5..a92f7079a0 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -144,17 +144,11 @@ public: virtual uint64_t minSize() const; - virtual uint64_t currentSize() const { return cur_size; } - - virtual uint64_t currentCount() const { return n_disk_objects; } - virtual int64_t maxObjectSize() const { return max_objsize; } virtual void stat (StoreEntry &anEntry) const; virtual StoreSearch *search(String const url, HttpRequest *) = 0; - virtual void updateSize(int64_t size, int sign); - /* migrated from store_dir.cc */ bool objectSizeIsAcceptable(int64_t objsize) const; @@ -169,6 +163,8 @@ protected: void dumpOptions(StoreEntry * e) const; virtual ConfigOption *getOptionTree() const; + int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; } + private: bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring); void optionReadOnlyDump(StoreEntry * e) const; @@ -176,14 +172,10 @@ private: void optionObjectSizeDump(StoreEntry * e) const; char const *theType; -private: - uint64_t cur_size; ///< currently used space in the storage area - protected: uint64_t max_size; ///< maximum allocatable size of the storage area public: - uint64_t n_disk_objects; ///< total number of objects stored char *path; int index; /* This entry's index into the swapDirs array */ int64_t min_objsize; diff --git a/src/fs/coss/CossSwapDir.h b/src/fs/coss/CossSwapDir.h index 5e6b890184..1a74fcb9e1 100644 --- a/src/fs/coss/CossSwapDir.h +++ b/src/fs/coss/CossSwapDir.h @@ -50,6 +50,8 @@ public: virtual void parse (int index, char *path); virtual void reconfigure (int, char *); virtual void swappedOut(const StoreEntry &e); + virtual uint64_t currentSize() const { return cur_size; } + virtual uint64_t currentCount() const { return n_disk_objects; } /* internals */ virtual off_t storeCossFilenoToDiskOffset(sfileno); virtual sfileno storeCossDiskOffsetToFileno(off_t); @@ -77,6 +79,16 @@ public: CossMemBuf *createMemBuf(off_t start, sfileno curfn, int *collision); sfileno allocate(const StoreEntry * e, int which); void startMembuf(); + StoreEntry *addDiskRestore(const cache_key *const key, + int file_number, + uint64_t swap_file_sz, + time_t expires, + time_t timestamp, + time_t lastref, + time_t lastmod, + uint32_t refcount, + uint16_t flags, + int clean); private: void changeIO(DiskIOModule *module); @@ -89,6 +101,8 @@ private: const char *ioModule; mutable ConfigOptionVector *currentIOOptions; const char *stripe_path; + uint64_t cur_size; ///< currently used space in the storage area + uint64_t n_disk_objects; ///< total number of objects stored }; /// \ingroup COSS diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 2a075eb7cf..dd9c07111e 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -74,16 +74,6 @@ struct _RebuildState { static char *storeCossDirSwapLogFile(SwapDir *, const char *); static EVH storeCossRebuildFromSwapLog; -static StoreEntry *storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key, - int file_number, - uint64_t swap_file_sz, - time_t expires, - time_t timestamp, - time_t lastref, - time_t lastmod, - uint32_t refcount, - uint16_t flags, - int clean); static void storeCossDirRebuild(CossSwapDir * sd); static void storeCossDirCloseTmpSwapLog(CossSwapDir * sd); static FILE *storeCossDirOpenTmpSwapLog(CossSwapDir *, int *, int *); @@ -482,7 +472,7 @@ storeCossRebuildFromSwapLog(void *data) rb->counts.objcount++; - e = storeCossAddDiskRestore(rb->sd, s.key, + e = rb->sd->addDiskRestore(s.key, s.swap_filen, s.swap_file_sz, s.expires, @@ -501,8 +491,8 @@ storeCossRebuildFromSwapLog(void *data) /* Add a new object to the cache with empty memory copy and pointer to disk * use to rebuild store from disk. */ -static StoreEntry * -storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key, +StoreEntry * +CossSwapDir::addDiskRestore(const cache_key *const key, int file_number, uint64_t swap_file_sz, time_t expires, @@ -522,7 +512,7 @@ storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key, * already in use! */ e = new StoreEntry(); e->store_status = STORE_OK; - e->swap_dirn = SD->index; + e->swap_dirn = index; e->setMemStatus(NOT_IN_MEMORY); e->swap_status = SWAPOUT_DONE; e->swap_filen = file_number; @@ -539,9 +529,10 @@ storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key, EBIT_CLR(e->flags, KEY_PRIVATE); e->ping_status = PING_NONE; EBIT_CLR(e->flags, ENTRY_VALIDATED); - SD->updateSize(e->swap_file_sz, 1); + cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz); + ++n_disk_objects; e->hashInsert(key); /* do it after we clear KEY_PRIVATE */ - storeCossAdd(SD, e); + storeCossAdd(this, e); assert(e->swap_filen >= 0); return e; } @@ -1072,7 +1063,8 @@ CossSwapDir::reconfigure(int index, char *path) void CossSwapDir::swappedOut(const StoreEntry &e) { - updateSize(e.swap_file_sz, 1); + cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz); + ++n_disk_objects; } void @@ -1082,7 +1074,7 @@ CossSwapDir::dump(StoreEntry &entry)const dumpOptions(&entry); } -CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0), blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL) +CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0), blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL), cur_size(0), n_disk_objects(0) { membufs.head = NULL; membufs.tail = NULL; diff --git a/src/fs/coss/store_io_coss.cc b/src/fs/coss/store_io_coss.cc index 4be22ed9da..bb4c09db4e 100644 --- a/src/fs/coss/store_io_coss.cc +++ b/src/fs/coss/store_io_coss.cc @@ -133,8 +133,10 @@ void CossSwapDir::unlink(StoreEntry & e) { debugs(79, 3, "storeCossUnlink: offset " << e.swap_filen); - if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) - updateSize(e.swap_file_sz, -1); + if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) { + cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz); + --n_disk_objects; + } StoreFScoss::GetInstance().stats.unlink.ops++; StoreFScoss::GetInstance().stats.unlink.success++; storeCossRemove(this, &e); diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 35e1bc6baa..da36b6396c 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -246,7 +246,7 @@ UFSSwapDir::create() createSwapSubDirs(); } -UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)) +UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)), cur_size(0), n_disk_objects(0) { /* modulename is only set to disk modules that are built, by configure, * so the Find call should never return NULL here. @@ -717,7 +717,8 @@ UFSSwapDir::addDiskRestore(const cache_key * key, e->ping_status = PING_NONE; EBIT_CLR(e->flags, ENTRY_VALIDATED); mapBitSet(e->swap_filen); - updateSize(e->swap_file_sz, 1); + cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz); + ++n_disk_objects; e->hashInsert(key); /* do it after we clear KEY_PRIVATE */ replacementAdd (e); return e; @@ -1289,8 +1290,10 @@ UFSSwapDir::unlink(StoreEntry & e) { debugs(79, 3, "storeUfsUnlink: dirno " << index << ", fileno "<< std::setfill('0') << std::hex << std::uppercase << std::setw(8) << e.swap_filen); - if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) - updateSize(e.swap_file_sz, -1); + if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) { + cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz); + --n_disk_objects; + } replacementRemove(&e); mapBitReset(e.swap_filen); UFSSwapDir::unlinkFile(e.swap_filen); @@ -1369,7 +1372,8 @@ UFSSwapDir::sync() void UFSSwapDir::swappedOut(const StoreEntry &e) { - updateSize(e.swap_file_sz, 1); + cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz); + ++n_disk_objects; } StoreSearch * diff --git a/src/fs/ufs/ufscommon.h b/src/fs/ufs/ufscommon.h index dfa9235c81..883c99f9d4 100644 --- a/src/fs/ufs/ufscommon.h +++ b/src/fs/ufs/ufscommon.h @@ -77,6 +77,8 @@ public: virtual int callback(); virtual void sync(); virtual void swappedOut(const StoreEntry &e); + virtual uint64_t currentSize() const { return cur_size; } + virtual uint64_t currentCount() const { return n_disk_objects; } void unlinkFile(sfileno f); // move down when unlink is a virtual method @@ -136,7 +138,8 @@ private: void optionIODump(StoreEntry * e) const; mutable ConfigOptionVector *currentIOOptions; char const *ioType; - + uint64_t cur_size; ///< currently used space in the storage area + uint64_t n_disk_objects; ///< total number of objects stored }; #include "RefCount.h" diff --git a/src/store_dir.cc b/src/store_dir.cc index dd4390491d..4f414b3183 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -323,19 +323,6 @@ storeDirSwapLog(const StoreEntry * e, int op) dynamic_cast(INDEXSD(e->swap_dirn))->logEntry(*e, op); } -void -SwapDir::updateSize(int64_t size, int 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) - n_disk_objects++; - else if (sign < 0) - n_disk_objects--; -} - void StoreController::stat(StoreEntry &output) const {