*
*/
-#include "squid.h"
+#include "squid-old.h"
#include "Store.h"
#include "MemObject.h"
#include "MemStore.h"
int StoreController::store_dirs_rebuilding = 1;
StoreController::StoreController() : swapDir (new StoreHashIndex())
- , memStore(NULL)
+ , memStore(NULL)
{}
StoreController::~StoreController()
void
StoreController::init()
{
- if (UsingSmp() && IamWorkerProcess()) {
+ if (Config.memShared && IamWorkerProcess()) {
memStore = new MemStore;
memStore->init();
}
* 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;
aStore.create();
-#ifndef _SQUID_MSWIN_
+#if !_SQUID_MSWIN_
exit(0);
{
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
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;
}
}
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
/* 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)
}
}
-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 *
}
}
- // 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
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;
}
// 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<hash_link*>(&e));
return;
/* 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;
* 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,
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
{
}
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()