2 * DEBUG: section 47 Store Directory Routines
7 #include "ConfigOption.h"
8 #include "DiskIO/DiskIOModule.h"
9 #include "DiskIO/DiskIOStrategy.h"
10 #include "DiskIO/ReadRequest.h"
11 #include "DiskIO/WriteRequest.h"
12 #include "fs/rock/RockSwapDir.h"
13 #include "fs/rock/RockIoState.h"
14 #include "fs/rock/RockIoRequests.h"
15 #include "fs/rock/RockRebuild.h"
17 #include "ipc/mem/Pages.h"
18 #include "MemObject.h"
20 #include "SquidConfig.h"
21 #include "SquidMath.h"
31 const int64_t Rock::SwapDir::HeaderSize
= 16*1024;
33 Rock::SwapDir::SwapDir(): ::SwapDir("rock"),
34 slotSize(HeaderSize
), filePath(NULL
), map(NULL
), io(NULL
),
39 Rock::SwapDir::~SwapDir()
47 Rock::SwapDir::search(String
const url
, HttpRequest
*)
50 return NULL
; // XXX: implement
54 Rock::SwapDir::get(String
const key
, STOREGETCLIENT cb
, void *data
)
56 ::SwapDir::get(key
, cb
, data
);
59 // called when Squid core needs a StoreEntry with a given key
61 Rock::SwapDir::get(const cache_key
*key
)
63 if (!map
|| !theFile
|| !theFile
->canRead())
67 const Ipc::StoreMapAnchor
*const slot
= map
->openForReading(key
, filen
);
71 const Ipc::StoreMapAnchor::Basics
&basics
= slot
->basics
;
73 // create a brand new store entry and initialize it with stored basics
74 StoreEntry
*e
= new StoreEntry();
77 e
->swap_filen
= filen
;
78 e
->swap_file_sz
= basics
.swap_file_sz
;
79 e
->lastref
= basics
.lastref
;
80 e
->timestamp
= basics
.timestamp
;
81 e
->expires
= basics
.expires
;
82 e
->lastmod
= basics
.lastmod
;
83 e
->refcount
= basics
.refcount
;
84 e
->flags
= basics
.flags
;
85 e
->store_status
= STORE_OK
;
86 e
->setMemStatus(NOT_IN_MEMORY
);
87 e
->swap_status
= SWAPOUT_DONE
;
88 e
->ping_status
= PING_NONE
;
89 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
90 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
91 EBIT_CLR(e
->flags
, KEY_PRIVATE
);
92 EBIT_SET(e
->flags
, ENTRY_VALIDATED
);
97 // the disk entry remains open for reading, protected from modifications
100 void Rock::SwapDir::disconnect(StoreEntry
&e
)
102 assert(e
.swap_dirn
== index
);
103 assert(e
.swap_filen
>= 0);
104 // cannot have SWAPOUT_NONE entry with swap_filen >= 0
105 assert(e
.swap_status
!= SWAPOUT_NONE
);
107 // do not rely on e.swap_status here because there is an async delay
108 // before it switches from SWAPOUT_WRITING to SWAPOUT_DONE.
110 // since e has swap_filen, its slot is locked for either reading or writing
111 map
->abortIo(e
.swap_filen
);
114 e
.swap_status
= SWAPOUT_NONE
;
118 Rock::SwapDir::currentSize() const
120 const uint64_t spaceSize
= !freeSlots
?
121 maxSize() : (slotSize
* freeSlots
->size());
122 // everything that is not free is in use
123 return maxSize() - spaceSize
;
127 Rock::SwapDir::currentCount() const
129 return map
? map
->entryCount() : 0;
132 /// In SMP mode only the disker process reports stats to avoid
133 /// counting the same stats by multiple processes.
135 Rock::SwapDir::doReportStat() const
137 return ::SwapDir::doReportStat() && (!UsingSmp() || IamDiskProcess());
141 Rock::SwapDir::swappedOut(const StoreEntry
&)
143 // stats are not stored but computed when needed
147 Rock::SwapDir::entryLimitAllowed() const
149 const int64_t eLimitLo
= map
? map
->entryLimit() : 0; // dynamic shrinking unsupported
150 const int64_t eWanted
= (maxSize() - HeaderSize
)/slotSize
;
151 return min(max(eLimitLo
, eWanted
), entryLimitHigh());
154 // TODO: encapsulate as a tool; identical to CossSwapDir::create()
156 Rock::SwapDir::create()
161 if (UsingSmp() && !IamDiskProcess()) {
162 debugs (47,3, HERE
<< "disker will create in " << path
);
166 debugs (47,3, HERE
<< "creating in " << path
);
169 if (::stat(path
, &swap_sb
) < 0) {
170 debugs (47, DBG_IMPORTANT
, "Creating Rock db directory: " << path
);
171 const int res
= mkdir(path
, 0700);
173 createError("mkdir");
176 const int swap
= open(filePath
, O_WRONLY
|O_CREAT
|O_TRUNC
|O_BINARY
, 0600);
178 createError("create");
180 #if SLOWLY_FILL_WITH_ZEROS
182 Must(maxSize() % sizeof(block
) == 0);
183 memset(block
, '\0', sizeof(block
));
185 for (off_t offset
= 0; offset
< maxSize(); offset
+= sizeof(block
)) {
186 if (write(swap
, block
, sizeof(block
)) != sizeof(block
))
187 createError("write");
190 if (ftruncate(swap
, maxSize()) != 0)
191 createError("truncate");
193 char header
[HeaderSize
];
194 memset(header
, '\0', sizeof(header
));
195 if (write(swap
, header
, sizeof(header
)) != sizeof(header
))
196 createError("write");
202 // report Rock DB creation error and exit
204 Rock::SwapDir::createError(const char *const msg
) {
205 debugs(47, DBG_CRITICAL
, "ERROR: Failed to initialize Rock Store db in " <<
206 filePath
<< "; " << msg
<< " error: " << xstrerror());
207 fatal("Rock Store db creation error");
211 Rock::SwapDir::init()
215 // XXX: SwapDirs aren't refcounted. We make IORequestor calls, which
216 // are refcounted. We up our count once to avoid implicit delete's.
219 freeSlots
= shm_old(Ipc::Mem::PageStack
)(freeSlotsPath());
222 map
= new DirMap(inodeMapPath());
225 const char *ioModule
= needsDiskStrand() ? "IpcIo" : "Blocking";
226 if (DiskIOModule
*m
= DiskIOModule::Find(ioModule
)) {
227 debugs(47,2, HERE
<< "Using DiskIO module: " << ioModule
);
228 io
= m
->createStrategy();
231 debugs(47, DBG_CRITICAL
, "FATAL: Rock store is missing DiskIO module: " <<
233 fatal("Rock Store missing a required DiskIO module");
236 theFile
= io
->newFile(filePath
);
237 theFile
->configure(fileConfig
);
238 theFile
->open(O_RDWR
, 0644, this);
240 // Increment early. Otherwise, if one SwapDir finishes rebuild before
241 // others start, storeRebuildComplete() will think the rebuild is over!
242 // TODO: move store_dirs_rebuilding hack to store modules that need it.
243 ++StoreController::store_dirs_rebuilding
;
247 Rock::SwapDir::needsDiskStrand() const
249 const bool wontEvenWorkWithoutDisker
= Config
.workers
> 1;
250 const bool wouldWorkBetterWithDisker
= DiskIOModule::Find("IpcIo");
251 return InDaemonMode() && (wontEvenWorkWithoutDisker
||
252 wouldWorkBetterWithDisker
);
256 Rock::SwapDir::parse(int anIndex
, char *aPath
)
260 path
= xstrdup(aPath
);
262 // cache store is located at path/db
264 fname
.append("/rock");
265 filePath
= xstrdup(fname
.termedBuf());
270 // Current openForWriting() code overwrites the old slot if needed
271 // and possible, so proactively removing old slots is probably useless.
272 assert(!repl
); // repl = createRemovalPolicy(Config.replPolicy);
278 Rock::SwapDir::reconfigure()
282 // TODO: can we reconfigure the replacement policy (repl)?
286 /// parse maximum db disk size
288 Rock::SwapDir::parseSize(const bool reconfiguring
)
290 const int i
= GetInteger();
292 fatal("negative Rock cache_dir size value");
293 const uint64_t new_max_size
=
294 static_cast<uint64_t>(i
) << 20; // MBytes to Bytes
296 max_size
= new_max_size
;
297 else if (new_max_size
!= max_size
) {
298 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' size "
299 "cannot be changed dynamically, value left unchanged (" <<
300 (max_size
>> 20) << " MB)");
305 Rock::SwapDir::getOptionTree() const
307 ConfigOptionVector
*vector
= dynamic_cast<ConfigOptionVector
*>(::SwapDir::getOptionTree());
309 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseSizeOption
, &SwapDir::dumpSizeOption
));
310 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseTimeOption
, &SwapDir::dumpTimeOption
));
311 vector
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::parseRateOption
, &SwapDir::dumpRateOption
));
316 Rock::SwapDir::allowOptionReconfigure(const char *const option
) const
318 return strcmp(option
, "slot-size") != 0 &&
319 ::SwapDir::allowOptionReconfigure(option
);
322 /// parses time-specific options; mimics ::SwapDir::optionObjectSizeParse()
324 Rock::SwapDir::parseTimeOption(char const *option
, const char *value
, int reconfiguring
)
326 // TODO: ::SwapDir or, better, Config should provide time-parsing routines,
327 // including time unit handling. Same for size and rate.
329 time_msec_t
*storedTime
;
330 if (strcmp(option
, "swap-timeout") == 0)
331 storedTime
= &fileConfig
.ioTimeout
;
338 // TODO: handle time units and detect parsing errors better
339 const int64_t parsedValue
= strtoll(value
, NULL
, 10);
340 if (parsedValue
< 0) {
341 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << parsedValue
);
345 const time_msec_t newTime
= static_cast<time_msec_t
>(parsedValue
);
348 *storedTime
= newTime
;
349 else if (*storedTime
!= newTime
) {
350 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
351 << " cannot be changed dynamically, value left unchanged: " <<
358 /// reports time-specific options; mimics ::SwapDir::optionObjectSizeDump()
360 Rock::SwapDir::dumpTimeOption(StoreEntry
* e
) const
362 if (fileConfig
.ioTimeout
)
363 storeAppendPrintf(e
, " swap-timeout=%" PRId64
,
364 static_cast<int64_t>(fileConfig
.ioTimeout
));
367 /// parses rate-specific options; mimics ::SwapDir::optionObjectSizeParse()
369 Rock::SwapDir::parseRateOption(char const *option
, const char *value
, int isaReconfig
)
372 if (strcmp(option
, "max-swap-rate") == 0)
373 storedRate
= &fileConfig
.ioRate
;
380 // TODO: handle time units and detect parsing errors better
381 const int64_t parsedValue
= strtoll(value
, NULL
, 10);
382 if (parsedValue
< 0) {
383 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << parsedValue
);
387 const int newRate
= static_cast<int>(parsedValue
);
390 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must not be negative but is: " << newRate
);
395 *storedRate
= newRate
;
396 else if (*storedRate
!= newRate
) {
397 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
398 << " cannot be changed dynamically, value left unchanged: " <<
405 /// reports rate-specific options; mimics ::SwapDir::optionObjectSizeDump()
407 Rock::SwapDir::dumpRateOption(StoreEntry
* e
) const
409 if (fileConfig
.ioRate
>= 0)
410 storeAppendPrintf(e
, " max-swap-rate=%d", fileConfig
.ioRate
);
413 /// parses size-specific options; mimics ::SwapDir::optionObjectSizeParse()
415 Rock::SwapDir::parseSizeOption(char const *option
, const char *value
, int reconfiguring
)
417 uint64_t *storedSize
;
418 if (strcmp(option
, "slot-size") == 0)
419 storedSize
= &slotSize
;
426 // TODO: handle size units and detect parsing errors better
427 const uint64_t newSize
= strtoll(value
, NULL
, 10);
429 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must be positive; got: " << newSize
);
433 if (newSize
<= sizeof(DbCellHeader
)) {
434 debugs(3, DBG_CRITICAL
, "FATAL: cache_dir " << path
<< ' ' << option
<< " must exceed " << sizeof(DbCellHeader
) << "; got: " << newSize
);
439 *storedSize
= newSize
;
440 else if (*storedSize
!= newSize
) {
441 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir " << path
<< ' ' << option
442 << " cannot be changed dynamically, value left unchanged: " <<
449 /// reports size-specific options; mimics ::SwapDir::optionObjectSizeDump()
451 Rock::SwapDir::dumpSizeOption(StoreEntry
* e
) const
453 storeAppendPrintf(e
, " slot-size=%" PRId64
, slotSize
);
456 /// check the results of the configuration; only level-0 debugging works here
458 Rock::SwapDir::validateOptions()
461 fatal("Rock store requires a positive slot-size");
463 const int64_t maxSizeRoundingWaste
= 1024 * 1024; // size is configured in MB
464 const int64_t slotSizeRoundingWaste
= slotSize
;
465 const int64_t maxRoundingWaste
=
466 max(maxSizeRoundingWaste
, slotSizeRoundingWaste
);
467 const int64_t usableDiskSize
= diskOffset(entryLimitAllowed());
468 const int64_t diskWasteSize
= maxSize() - usableDiskSize
;
469 Must(diskWasteSize
>= 0);
471 // warn if maximum db size is not reachable due to sfileno limit
472 if (entryLimitAllowed() == entryLimitHigh() &&
473 diskWasteSize
>= maxRoundingWaste
) {
474 debugs(47, DBG_CRITICAL
, "Rock store cache_dir[" << index
<< "] '" << path
<< "':");
475 debugs(47, DBG_CRITICAL
, "\tmaximum number of entries: " << entryLimitAllowed());
476 debugs(47, DBG_CRITICAL
, "\tdb slot size: " << slotSize
<< " Bytes");
477 debugs(47, DBG_CRITICAL
, "\tmaximum db size: " << maxSize() << " Bytes");
478 debugs(47, DBG_CRITICAL
, "\tusable db size: " << usableDiskSize
<< " Bytes");
479 debugs(47, DBG_CRITICAL
, "\tdisk space waste: " << diskWasteSize
<< " Bytes");
480 debugs(47, DBG_CRITICAL
, "WARNING: Rock store config wastes space.");
485 Rock::SwapDir::rebuild()
487 //++StoreController::store_dirs_rebuilding; // see Rock::SwapDir::init()
488 AsyncJob::Start(new Rebuild(this));
492 Rock::SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
494 if (!::SwapDir::canStore(e
, sizeof(DbCellHeader
)+diskSpaceNeeded
, load
))
497 if (!theFile
|| !theFile
->canWrite())
503 // Do not start I/O transaction if there are less than 10% free pages left.
504 // TODO: reserve page instead
505 if (needsDiskStrand() &&
506 Ipc::Mem::PageLevel(Ipc::Mem::PageId::ioPage
) >= 0.9 * Ipc::Mem::PageLimit(Ipc::Mem::PageId::ioPage
)) {
507 debugs(47, 5, HERE
<< "too few shared pages for IPC I/O left");
518 StoreIOState::Pointer
519 Rock::SwapDir::createStoreIO(StoreEntry
&e
, StoreIOState::STFNCB
*cbFile
, StoreIOState::STIOCB
*cbIo
, void *data
)
521 if (!theFile
|| theFile
->error()) {
522 debugs(47,4, HERE
<< theFile
);
527 Ipc::StoreMapAnchor
*const slot
=
528 map
->openForWriting(reinterpret_cast<const cache_key
*>(e
.key
), filen
);
530 debugs(47, 5, HERE
<< "map->add failed");
537 // XXX: We rely on our caller, storeSwapOutStart(), to set e.fileno.
538 // If that does not happen, the entry will not decrement the read level!
540 Rock::SwapDir::Pointer
self(this);
541 IoState
*sio
= new IoState(self
, &e
, cbFile
, cbIo
, data
);
543 sio
->swap_dirn
= index
;
544 sio
->swap_filen
= filen
;
545 sio
->writeableAnchor_
= slot
;
547 debugs(47,5, HERE
<< "dir " << index
<< " created new filen " <<
548 std::setfill('0') << std::hex
<< std::uppercase
<< std::setw(8) <<
549 sio
->swap_filen
<< std::dec
<< " starting at " <<
550 diskOffset(sio
->swap_filen
));
559 Rock::SwapDir::diskOffset(int filen
) const
562 return HeaderSize
+ slotSize
*filen
;
566 Rock::SwapDir::diskOffset(Ipc::Mem::PageId
&pageId
) const
569 return diskOffset(pageId
.number
- 1);
573 Rock::SwapDir::diskOffsetLimit() const
576 return diskOffset(map
->entryLimit());
580 Rock::SwapDir::entryMaxPayloadSize() const
582 return slotSize
- sizeof(DbCellHeader
);
586 Rock::SwapDir::entriesNeeded(const int64_t objSize
) const
588 return (objSize
+ entryMaxPayloadSize() - 1) / entryMaxPayloadSize();
592 Rock::SwapDir::useFreeSlot(Ipc::Mem::PageId
&pageId
)
594 if (freeSlots
->pop(pageId
)) {
595 debugs(47, 5, "got a previously free slot: " << pageId
);
599 // catch free slots delivered to noteFreeMapSlice()
600 assert(!waitingForPage
);
601 waitingForPage
= &pageId
;
602 if (map
->purgeOne()) {
603 assert(!waitingForPage
); // noteFreeMapSlice() should have cleared it
604 assert(pageId
.set());
605 debugs(47, 5, "got a previously busy slot: " << pageId
);
608 assert(waitingForPage
== &pageId
);
609 waitingForPage
= NULL
;
611 debugs(47, 3, "cannot get a slot; entries: " << map
->entryCount());
616 Rock::SwapDir::validSlotId(const SlotId slotId
) const
618 return 0 <= slotId
&& slotId
< entryLimitAllowed();
622 Rock::SwapDir::noteFreeMapSlice(const sfileno sliceId
)
624 Ipc::Mem::PageId pageId
;
625 pageId
.pool
= index
+1;
626 pageId
.number
= sliceId
+1;
627 if (waitingForPage
) {
628 *waitingForPage
= pageId
;
629 waitingForPage
= NULL
;
631 freeSlots
->push(pageId
);
635 // tries to open an old entry with swap_filen for reading
636 StoreIOState::Pointer
637 Rock::SwapDir::openStoreIO(StoreEntry
&e
, StoreIOState::STFNCB
*cbFile
, StoreIOState::STIOCB
*cbIo
, void *data
)
639 if (!theFile
|| theFile
->error()) {
640 debugs(47,4, HERE
<< theFile
);
644 if (e
.swap_filen
< 0) {
645 debugs(47,4, HERE
<< e
);
649 // Do not start I/O transaction if there are less than 10% free pages left.
650 // TODO: reserve page instead
651 if (needsDiskStrand() &&
652 Ipc::Mem::PageLevel(Ipc::Mem::PageId::ioPage
) >= 0.9 * Ipc::Mem::PageLimit(Ipc::Mem::PageId::ioPage
)) {
653 debugs(47, 5, HERE
<< "too few shared pages for IPC I/O left");
657 // The are two ways an entry can get swap_filen: our get() locked it for
658 // reading or our storeSwapOutStart() locked it for writing. Peeking at our
659 // locked entry is safe, but no support for reading a filling entry.
660 const Ipc::StoreMapAnchor
*slot
= map
->peekAtReader(e
.swap_filen
);
662 return NULL
; // we were writing afterall
664 Rock::SwapDir::Pointer
self(this);
665 IoState
*sio
= new IoState(self
, &e
, cbFile
, cbIo
, data
);
667 sio
->swap_dirn
= index
;
668 sio
->swap_filen
= e
.swap_filen
;
669 sio
->readableAnchor_
= slot
;
672 debugs(47,5, HERE
<< "dir " << index
<< " has old filen: " <<
673 std::setfill('0') << std::hex
<< std::uppercase
<< std::setw(8) <<
676 assert(slot
->sameKey(static_cast<const cache_key
*>(e
.key
)));
677 assert(slot
->basics
.swap_file_sz
> 0);
678 assert(slot
->basics
.swap_file_sz
== e
.swap_file_sz
);
684 Rock::SwapDir::ioCompletedNotification()
687 fatalf("Rock cache_dir failed to initialize db file: %s", filePath
);
689 if (theFile
->error())
690 fatalf("Rock cache_dir at %s failed to open db file: %s", filePath
,
693 debugs(47, 2, "Rock cache_dir[" << index
<< "] limits: " <<
694 std::setw(12) << maxSize() << " disk bytes and " <<
695 std::setw(7) << map
->entryLimit() << " entries");
701 Rock::SwapDir::closeCompleted()
707 Rock::SwapDir::readCompleted(const char *buf
, int rlen
, int errflag
, RefCount
< ::ReadRequest
> r
)
709 ReadRequest
*request
= dynamic_cast<Rock::ReadRequest
*>(r
.getRaw());
711 IoState::Pointer sio
= request
->sio
;
713 if (errflag
== DISK_OK
&& rlen
> 0)
714 sio
->offset_
+= rlen
;
716 StoreIOState::STRCB
*callback
= sio
->read
.callback
;
718 sio
->read
.callback
= NULL
;
720 if (cbdataReferenceValidDone(sio
->read
.callback_data
, &cbdata
))
721 callback(cbdata
, r
->buf
, rlen
, sio
.getRaw());
725 Rock::SwapDir::writeCompleted(int errflag
, size_t rlen
, RefCount
< ::WriteRequest
> r
)
727 Rock::WriteRequest
*request
= dynamic_cast<Rock::WriteRequest
*>(r
.getRaw());
729 assert(request
->sio
!= NULL
);
730 IoState
&sio
= *request
->sio
;
732 // quit if somebody called IoState::close() while we were waiting
733 if (!sio
.stillWaiting()) {
734 debugs(79, 3, "ignoring closed entry " << sio
.swap_filen
);
738 if (errflag
== DISK_OK
) {
739 // do not increment sio.offset_ because we do it in sio->write()
740 if (request
->isLast
) {
741 // close, the entry gets the read lock
742 map
->closeForWriting(sio
.swap_filen
, true);
743 sio
.finishedWriting(errflag
);
746 writeError(sio
.swap_filen
);
747 sio
.finishedWriting(errflag
);
748 // and hope that Core will call disconnect() to close the map entry
753 Rock::SwapDir::writeError(const sfileno fileno
)
755 // Do not abortWriting here. The entry should keep the write lock
756 // instead of losing association with the store and confusing core.
757 map
->freeEntry(fileno
); // will mark as unusable, just in case
758 // All callers must also call IoState callback, to propagate the error.
762 Rock::SwapDir::full() const
764 return freeSlots
!= NULL
&& !freeSlots
->size();
767 // storeSwapOutFileClosed calls this nethod on DISK_NO_SPACE_LEFT,
768 // but it should not happen for us
770 Rock::SwapDir::diskFull()
772 debugs(20, DBG_IMPORTANT
, "BUG: No space left with rock cache_dir: " <<
776 /// purge while full(); it should be sufficient to purge just one
778 Rock::SwapDir::maintain()
780 // The Store calls this to free some db space, but there is nothing wrong
781 // with a full() db, except when db has to shrink after reconfigure, and
782 // we do not support shrinking yet (it would have to purge specific slots).
783 // TODO: Disable maintain() requests when they are pointless.
787 Rock::SwapDir::reference(StoreEntry
&e
)
789 debugs(47, 5, HERE
<< &e
<< ' ' << e
.swap_dirn
<< ' ' << e
.swap_filen
);
790 if (repl
&& repl
->Referenced
)
791 repl
->Referenced(repl
, &e
, &e
.repl
);
795 Rock::SwapDir::dereference(StoreEntry
&e
, bool)
797 debugs(47, 5, HERE
<< &e
<< ' ' << e
.swap_dirn
<< ' ' << e
.swap_filen
);
798 if (repl
&& repl
->Dereferenced
)
799 repl
->Dereferenced(repl
, &e
, &e
.repl
);
801 // no need to keep e in the global store_table for us; we have our own map
806 Rock::SwapDir::unlinkdUseful() const
808 // no entry-specific files to unlink
813 Rock::SwapDir::unlink(StoreEntry
&e
)
815 debugs(47, 5, HERE
<< e
);
817 map
->freeEntry(e
.swap_filen
);
822 Rock::SwapDir::trackReferences(StoreEntry
&e
)
824 debugs(47, 5, HERE
<< e
);
826 repl
->Add(repl
, &e
, &e
.repl
);
830 Rock::SwapDir::ignoreReferences(StoreEntry
&e
)
832 debugs(47, 5, HERE
<< e
);
834 repl
->Remove(repl
, &e
, &e
.repl
);
838 Rock::SwapDir::statfs(StoreEntry
&e
) const
840 storeAppendPrintf(&e
, "\n");
841 storeAppendPrintf(&e
, "Maximum Size: %" PRIu64
" KB\n", maxSize() >> 10);
842 storeAppendPrintf(&e
, "Current Size: %.2f KB %.2f%%\n",
843 currentSize() / 1024.0,
844 Math::doublePercent(currentSize(), maxSize()));
847 const int limit
= map
->entryLimit();
848 storeAppendPrintf(&e
, "Maximum entries: %9d\n", limit
);
850 const int entryCount
= map
->entryCount();
851 storeAppendPrintf(&e
, "Current entries: %9d %.2f%%\n",
852 entryCount
, (100.0 * entryCount
/ limit
));
854 const unsigned int slotsFree
= !freeSlots
? 0 : freeSlots
->size();
855 if (slotsFree
<= static_cast<const unsigned int>(limit
)) {
856 const int usedSlots
= limit
- static_cast<const int>(slotsFree
);
857 storeAppendPrintf(&e
, "Used slots: %9d %.2f%%\n",
858 usedSlots
, (100.0 * usedSlots
/ limit
));
860 if (limit
< 100) { // XXX: otherwise too expensive to count
861 Ipc::ReadWriteLockStats stats
;
862 map
->updateStats(stats
);
868 storeAppendPrintf(&e
, "Pending operations: %d out of %d\n",
869 store_open_disk_fd
, Config
.max_open_disk_fds
);
871 storeAppendPrintf(&e
, "Flags:");
874 storeAppendPrintf(&e
, " SELECTED");
877 storeAppendPrintf(&e
, " READ-ONLY");
879 storeAppendPrintf(&e
, "\n");
884 Rock::SwapDir::inodeMapPath() const {
885 static String inodesPath
;
887 inodesPath
.append("_inodes");
888 return inodesPath
.termedBuf();
892 Rock::SwapDir::freeSlotsPath() const {
893 static String spacesPath
;
895 spacesPath
.append("_spaces");
896 return spacesPath
.termedBuf();
901 RunnerRegistrationEntry(rrAfterConfig
, SwapDirRr
);
904 void Rock::SwapDirRr::create(const RunnerRegistry
&)
906 Must(mapOwners
.empty() && freeSlotsOwners
.empty());
907 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
908 if (const Rock::SwapDir
*const sd
= dynamic_cast<Rock::SwapDir
*>(INDEXSD(i
))) {
909 const int64_t capacity
= sd
->entryLimitAllowed();
911 SwapDir::DirMap::Owner
*const mapOwner
=
912 SwapDir::DirMap::Init(sd
->inodeMapPath(), capacity
);
913 mapOwners
.push_back(mapOwner
);
915 // XXX: remove pool id and counters from PageStack
916 Ipc::Mem::Owner
<Ipc::Mem::PageStack
> *const freeSlotsOwner
=
917 shm_new(Ipc::Mem::PageStack
)(sd
->freeSlotsPath(),
919 sizeof(DbCellHeader
));
920 freeSlotsOwners
.push_back(freeSlotsOwner
);
922 // XXX: add method to initialize PageStack with no free pages
924 Ipc::Mem::PageId pageId
;
925 if (!freeSlotsOwner
->object()->pop(pageId
))
932 Rock::SwapDirRr::~SwapDirRr()
934 for (size_t i
= 0; i
< mapOwners
.size(); ++i
) {
936 delete freeSlotsOwners
[i
];