X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fstore_dir.cc;h=5303ce3864a149e322098c380c7c9c79c1a99a6e;hb=f7f3304a49c07e7874e9fae279a1e0111e88d2f9;hp=833457e855a3f090fbb9491b3f309c64f6390384;hpb=cc34568dd6d1a7fa78a4db8927f9d21437d84bbb;p=thirdparty%2Fsquid.git diff --git a/src/store_dir.cc b/src/store_dir.cc index 833457e855..5303ce3864 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -33,7 +33,7 @@ * */ -#include "squid.h" +#include "squid-old.h" #include "Store.h" #include "MemObject.h" #include "MemStore.h" @@ -75,7 +75,7 @@ static STDIRSELECT storeDirSelectSwapDirLeastLoad; int StoreController::store_dirs_rebuilding = 1; StoreController::StoreController() : swapDir (new StoreHashIndex()) - , memStore(NULL) + , memStore(NULL) {} StoreController::~StoreController() @@ -92,7 +92,7 @@ STDIRSELECT *storeDirSelectSwapDir = storeDirSelectSwapDirLeastLoad; void StoreController::init() { - if (UsingSmp() && IamWorkerProcess()) { + if (Config.memShared && IamWorkerProcess()) { memStore = new MemStore; memStore->init(); } @@ -116,7 +116,7 @@ StoreController::createOneStore(Store &aStore) * The following is a workaround for create store directories sequentially * when running on native Windows port. */ -#ifndef _SQUID_MSWIN_ +#if !_SQUID_MSWIN_ if (fork()) return; @@ -125,7 +125,7 @@ StoreController::createOneStore(Store &aStore) aStore.create(); -#ifndef _SQUID_MSWIN_ +#if !_SQUID_MSWIN_ exit(0); @@ -137,13 +137,13 @@ StoreController::create() { swapDir->create(); -#ifndef _SQUID_MSWIN_ +#if !_SQUID_MSWIN_ pid_t pid; do { int status; -#ifdef _SQUID_NEXT_ +#if _SQUID_NEXT_ pid = wait3(&status, WNOHANG, NULL); #else @@ -179,7 +179,10 @@ SwapDir::objectSizeIsAcceptable(int64_t objsize) const return false; // Else, make sure that the object size will fit. - return min_objsize <= objsize && max_objsize > objsize; + if (max_objsize == -1 && min_objsize <= objsize) + return true; + else + return min_objsize <= objsize && max_objsize > objsize; } @@ -324,16 +327,23 @@ storeDirSwapLog(const StoreEntry * e, int op) } void -SwapDir::updateSize(int64_t size, int sign) +StoreController::getStats(StoreInfoStats &stats) const { - 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--; + if (memStore) + memStore->getStats(stats); + else { + // move this code to a non-shared memory cache class when we have it + stats.mem.shared = false; + stats.mem.capacity = Config.memMaxSize; + stats.mem.size = mem_node::StoreMemSize(); + stats.mem.count = hot_obj_count; + } + + swapDir->getStats(stats); + + // low-level info not specific to memory or disk cache + stats.store_entry_count = StoreEntry::inUseCount(); + stats.mem_object_count = MemObject::inUseCount(); } void @@ -678,7 +688,7 @@ StoreController::reference(StoreEntry &e) /* Notify the fs that we're referencing this object again */ if (e.swap_dirn > -1) - e.store()->reference(e); + swapDir->reference(e); // Notify the memory cache that we're referencing this object again if (memStore && e.mem_status == IN_MEMORY) @@ -691,23 +701,27 @@ StoreController::reference(StoreEntry &e) } } -void +bool StoreController::dereference(StoreEntry & e) { + bool keepInStoreTable = true; // keep if there are no objections + /* Notify the fs that we're not referencing this object any more */ if (e.swap_filen > -1) - e.store()->dereference(e); + keepInStoreTable = swapDir->dereference(e) && keepInStoreTable; // Notify the memory cache that we're not referencing this object any more if (memStore && e.mem_status == IN_MEMORY) - memStore->dereference(e); + keepInStoreTable = memStore->dereference(e) && keepInStoreTable; // TODO: move this code to a non-shared memory cache class when we have it if (e.mem_obj) { if (mem_policy->Dereferenced) mem_policy->Dereferenced(mem_policy, &e, &e.mem_obj->repl); } + + return keepInStoreTable; } StoreEntry * @@ -727,7 +741,8 @@ StoreController::get(const cache_key *key) } } - // TODO: this disk iteration is misplaced; move to StoreHashIndex + // TODO: this disk iteration is misplaced; move to StoreHashIndex when + // the global store_table is no longer used for in-transit objects. if (const int cacheDirs = Config.cacheSwap.n_configured) { // ask each cache_dir until the entry is found; use static starting // point to avoid asking the same subset of disks more often @@ -741,14 +756,14 @@ StoreController::get(const cache_key *key) if (StoreEntry *e = sd->get(key)) { debugs(20, 3, HERE << "cache_dir " << idx << - " got cached entry: " << *e); + " got cached entry: " << *e); return e; } } } debugs(20, 4, HERE << "none of " << Config.cacheSwap.n_configured << - " cache_dirs have " << storeKeyText(key)); + " cache_dirs have " << storeKeyText(key)); return NULL; } @@ -767,15 +782,13 @@ StoreController::handleIdleEntry(StoreEntry &e) // leave keepInLocalMemory false; memStore maintains its own cache } else { keepInLocalMemory = e.memoryCachable() && // entry is in good shape and - // the local memory cache is not overflowing - (mem_node::InUseCount() <= store_pages_max); + // the local memory cache is not overflowing + (mem_node::InUseCount() <= store_pages_max); } - dereference(e); - - // XXX: Rock store specific: Since each SwapDir controls its index, - // unlocked entries should not stay in the global store_table. - if (fileno >= 0) { + // An idle, unlocked entry that belongs to a SwapDir which controls + // its own index, should not stay in the global store_table. + if (!dereference(e)) { debugs(20, 5, HERE << "destroying unlocked entry: " << &e << ' ' << e); destroyStoreEntry(static_cast(&e)); return; @@ -871,7 +884,7 @@ StoreHashIndex::init() /* Calculate size of hash table (maximum currently 64k buckets). */ /* this is very bogus, its specific to the any Store maintaining an * in-core index, not global */ - size_t buckets = ((Store::Root().maxSize() + Config.memMaxSize) >> 10) / Config.Store.avgObjectSize; + size_t buckets = (Store::Root().maxSize() + Config.memMaxSize) / Config.Store.avgObjectSize; debugs(20, 1, "Swap maxSize " << (Store::Root().maxSize() >> 10) << " + " << ( Config.memMaxSize >> 10) << " KB, estimated " << buckets << " objects"); buckets /= Config.Store.objectsPerBucket; @@ -880,7 +893,8 @@ StoreHashIndex::init() * moment it remains at approximately 24 hours. */ store_hash_buckets = storeKeyHashBuckets(buckets); debugs(20, 1, "Using " << store_hash_buckets << " Store buckets"); - debugs(20, 1, "Max Mem size: " << ( Config.memMaxSize >> 10) << " KB"); + debugs(20, 1, "Max Mem size: " << ( Config.memMaxSize >> 10) << " KB" << + (Config.memShared ? " [shared]" : "")); debugs(20, 1, "Max Swap size: " << (Store::Root().maxSize() >> 10) << " KB"); store_table = hash_create(storeKeyHashCmp, @@ -971,6 +985,22 @@ StoreHashIndex::maxObjectSize() const return result; } +void +StoreHashIndex::getStats(StoreInfoStats &stats) const +{ + // accumulate per-disk cache stats + for (int i = 0; i < Config.cacheSwap.n_configured; i++) { + StoreInfoStats dirStats; + store(i)->getStats(dirStats); + stats += dirStats; + } + + // common to all disks + stats.swap.open_disk_fd = store_open_disk_fd; + + // memory cache stats are collected in StoreController::getStats(), for now +} + void StoreHashIndex::stat(StoreEntry & output) const { @@ -985,12 +1015,16 @@ StoreHashIndex::stat(StoreEntry & output) const } void -StoreHashIndex::reference(StoreEntry&) -{} +StoreHashIndex::reference(StoreEntry &e) +{ + e.store()->reference(e); +} -void -StoreHashIndex::dereference(StoreEntry&) -{} +bool +StoreHashIndex::dereference(StoreEntry &e) +{ + return e.store()->dereference(e); +} void StoreHashIndex::maintain()