Skip to content
Permalink
Browse files

BFS: Make the log-flusher thread persistent.

Previously, a new log-flush thread was created every time there was
an idle transaction. Now we just release a semaphore for an
already-existing thread.

Change-Id: If788dbe17ef8e069ce12aa7b778626d051cce2d0
  • Loading branch information...
waddlesplash committed Jul 27, 2019
1 parent 1bb1999 commit 14b62ae4dafb0bed95849aedef783268aa278a66
Showing with 27 additions and 9 deletions.
  1. +23 −8 src/add-ons/kernel/file_systems/bfs/Journal.cpp
  2. +4 −1 src/add-ons/kernel/file_systems/bfs/Journal.h
@@ -409,6 +409,12 @@ Journal::Journal(Volume* volume)
{ {
recursive_lock_init(&fLock, "bfs journal"); recursive_lock_init(&fLock, "bfs journal");
mutex_init(&fEntriesLock, "bfs journal entries"); mutex_init(&fEntriesLock, "bfs journal entries");

fLogFlusherSem = create_sem(0, "bfs log flusher");
fLogFlusher = spawn_kernel_thread(&Journal::_LogFlusher, "bfs log flusher",
B_NORMAL_PRIORITY, this);
if (fLogFlusher > 0)
resume_thread(fLogFlusher);
} }




@@ -418,6 +424,11 @@ Journal::~Journal()


recursive_lock_destroy(&fLock); recursive_lock_destroy(&fLock);
mutex_destroy(&fEntriesLock); mutex_destroy(&fEntriesLock);

sem_id logFlusher = fLogFlusherSem;
fLogFlusherSem = -1;
delete_sem(logFlusher);
wait_for_thread(fLogFlusher, NULL);
} }




@@ -685,20 +696,24 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void* _logEntry)
/*static*/ void /*static*/ void
Journal::_TransactionIdle(int32 transactionID, int32 event, void* _journal) Journal::_TransactionIdle(int32 transactionID, int32 event, void* _journal)
{ {
// The current transaction seems to be idle - flush it. We can't do this // The current transaction seems to be idle - flush it. (We can't do this
// in this thread, as flushing the log can produce new transaction events. // in this thread, as flushing the log can produce new transaction events.)
thread_id id = spawn_kernel_thread(&Journal::_FlushLog, "bfs log flusher", Journal* journal = (Journal*)_journal;
B_NORMAL_PRIORITY, _journal); release_sem(journal->fLogFlusherSem);
if (id > 0)
resume_thread(id);
} }




/*static*/ status_t /*static*/ status_t
Journal::_FlushLog(void* _journal) Journal::_LogFlusher(void* _journal)
{ {
Journal* journal = (Journal*)_journal; Journal* journal = (Journal*)_journal;
return journal->_FlushLog(false, false); while (journal->fLogFlusherSem >= 0) {
if (acquire_sem(journal->fLogFlusherSem) != B_OK)
continue;

journal->_FlushLog(false, false);
}
return B_OK;
} }




@@ -60,7 +60,7 @@ class Journal {
int32 event, void* _logEntry); int32 event, void* _logEntry);
static void _TransactionIdle(int32 transactionID, int32 event, static void _TransactionIdle(int32 transactionID, int32 event,
void* _journal); void* _journal);
static status_t _FlushLog(void* _journal); static status_t _LogFlusher(void* _journal);


private: private:
Volume* fVolume; Volume* fVolume;
@@ -76,6 +76,9 @@ class Journal {
int32 fTransactionID; int32 fTransactionID;
bool fHasSubtransaction; bool fHasSubtransaction;
bool fSeparateSubTransactions; bool fSeparateSubTransactions;

thread_id fLogFlusher;
sem_id fLogFlusherSem;
}; };




0 comments on commit 14b62ae

Please sign in to comment.
You can’t perform that action at this time.