Skip to content

Commit a58fc4a

Browse files
committed
Bug 1645052 - Do not store number of bytes written to the cache in preferences, r=valentin,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D88488
1 parent 836481e commit a58fc4a

File tree

4 files changed

+17
-53
lines changed

4 files changed

+17
-53
lines changed

netwerk/cache2/CacheIndex.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define kMinUnwrittenChanges 300
2525
#define kMinDumpInterval 20000 // in milliseconds
2626
#define kMaxBufSize 16384
27-
#define kIndexVersion 0x00000009
27+
#define kIndexVersion 0x0000000A
2828
#define kUpdateIndexStartDelay 50000 // in milliseconds
2929
#define kTelemetryReportBytesLimit (2U * 1024U * 1024U * 1024U) // 2GB
3030

@@ -305,9 +305,6 @@ nsresult CacheIndex::InitInternal(nsIFile* aCacheDirectory) {
305305

306306
mStartTime = TimeStamp::NowLoRes();
307307

308-
mTotalBytesWritten = CacheObserver::CacheAmountWritten();
309-
mTotalBytesWritten <<= 10;
310-
311308
ReadIndexFromDisk();
312309

313310
return NS_OK;
@@ -425,8 +422,6 @@ nsresult CacheIndex::Shutdown() {
425422

426423
bool sanitize = CacheObserver::ClearCacheOnShutdown();
427424

428-
CacheObserver::SetCacheAmountWritten(index->mTotalBytesWritten >> 10);
429-
430425
LOG(
431426
("CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, "
432427
"dontMarkIndexClean=%d, sanitize=%d]",
@@ -1718,6 +1713,10 @@ void CacheIndex::WriteIndexToDisk() {
17181713
// dirty flag
17191714
NetworkEndian::writeUint32(mRWBuf + mRWBufPos, 1);
17201715
mRWBufPos += sizeof(uint32_t);
1716+
// amount of data written to the cache
1717+
NetworkEndian::writeUint32(mRWBuf + mRWBufPos,
1718+
static_cast<uint32_t>(mTotalBytesWritten >> 10));
1719+
mRWBufPos += sizeof(uint32_t);
17211720

17221721
mSkipEntries = 0;
17231722
}
@@ -2199,6 +2198,11 @@ void CacheIndex::ParseRecords() {
21992198
}
22002199
}
22012200
pos += sizeof(uint32_t);
2201+
2202+
uint64_t dataWritten = NetworkEndian::readUint32(mRWBuf + pos);
2203+
pos += sizeof(uint32_t);
2204+
dataWritten <<= 10;
2205+
mTotalBytesWritten += dataWritten;
22022206
}
22032207

22042208
uint32_t hashOffset = pos;
@@ -3888,17 +3892,9 @@ void CacheIndex::UpdateTotalBytesWritten(uint32_t aBytesWritten) {
38883892
index->mState == READY && !index->mIndexNeedsUpdate &&
38893893
!index->mShuttingDown) {
38903894
index->DoTelemetryReport();
3891-
38923895
index->mTotalBytesWritten = 0;
3893-
CacheObserver::SetCacheAmountWritten(0);
38943896
return;
38953897
}
3896-
3897-
uint64_t writtenKB = index->mTotalBytesWritten >> 10;
3898-
// Store number of written kilobytes to prefs after writing at least 10MB.
3899-
if ((writtenKB - CacheObserver::CacheAmountWritten()) > (10 * 1024)) {
3900-
CacheObserver::SetCacheAmountWritten(writtenKB);
3901-
}
39023898
}
39033899

39043900
void CacheIndex::DoTelemetryReport() {

netwerk/cache2/CacheIndex.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ typedef struct {
5858
// journal and start update process whenever this flag is set during index
5959
// parsing.
6060
uint32_t mIsDirty;
61+
62+
// The amount of data written to the cache. When it reaches
63+
// kTelemetryReportBytesLimit a telemetry report is sent and the counter is
64+
// reset.
65+
uint32_t mKBWritten;
6166
} CacheIndexHeader;
6267

6368
static_assert(sizeof(CacheIndexHeader::mVersion) +
6469
sizeof(CacheIndexHeader::mTimeStamp) +
65-
sizeof(CacheIndexHeader::mIsDirty) ==
70+
sizeof(CacheIndexHeader::mIsDirty) +
71+
sizeof(CacheIndexHeader::mKBWritten) ==
6672
sizeof(CacheIndexHeader),
6773
"Unexpected sizeof(CacheIndexHeader)!");
6874

netwerk/cache2/CacheObserver.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ bool CacheObserver::sHashStatsReported = kDefaultHashStatsReported;
4444
Atomic<PRIntervalTime> CacheObserver::sShutdownDemandedTime(
4545
PR_INTERVAL_NO_TIMEOUT);
4646

47-
static uint32_t const kDefaultCacheAmountWritten = 0;
48-
Atomic<uint32_t, Relaxed> CacheObserver::sCacheAmountWritten(
49-
kDefaultCacheAmountWritten);
50-
5147
NS_IMPL_ISUPPORTS(CacheObserver, nsIObserver, nsISupportsWeakReference)
5248

5349
// static
@@ -97,10 +93,6 @@ void CacheObserver::AttachToPreferences() {
9793
0.01F, std::min(1440.0F, mozilla::Preferences::GetFloat(
9894
"browser.cache.frecency_half_life_hours",
9995
kDefaultHalfLifeHours)));
100-
101-
mozilla::Preferences::AddAtomicUintVarCache(
102-
&sCacheAmountWritten, "browser.cache.disk.amount_written",
103-
kDefaultCacheAmountWritten);
10496
}
10597

10698
// static
@@ -194,29 +186,6 @@ void CacheObserver::StoreHashStatsReported() {
194186
sHashStatsReported);
195187
}
196188

197-
// static
198-
void CacheObserver::SetCacheAmountWritten(uint32_t aCacheAmountWritten) {
199-
sCacheAmountWritten = aCacheAmountWritten;
200-
201-
if (!sSelf) {
202-
return;
203-
}
204-
205-
if (NS_IsMainThread()) {
206-
sSelf->StoreCacheAmountWritten();
207-
} else {
208-
nsCOMPtr<nsIRunnable> event =
209-
NewRunnableMethod("net::CacheObserver::StoreCacheAmountWritten",
210-
sSelf.get(), &CacheObserver::StoreCacheAmountWritten);
211-
NS_DispatchToMainThread(event);
212-
}
213-
}
214-
215-
void CacheObserver::StoreCacheAmountWritten() {
216-
mozilla::Preferences::SetInt("browser.cache.disk.amount_written",
217-
sCacheAmountWritten);
218-
}
219-
220189
// static
221190
void CacheObserver::ParentDirOverride(nsIFile** aDir) {
222191
if (NS_WARN_IF(!aDir)) return;

netwerk/cache2/CacheObserver.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ class CacheObserver : public nsIObserver, public nsSupportsWeakReference {
7979
static void SetCacheFSReported();
8080
static bool HashStatsReported() { return sHashStatsReported; }
8181
static void SetHashStatsReported();
82-
static uint32_t CacheAmountWritten() // result in kilobytes
83-
{
84-
return sCacheAmountWritten;
85-
}
86-
static void SetCacheAmountWritten(uint32_t); // parameter in kilobytes.
8782
static void ParentDirOverride(nsIFile** aDir);
8883

8984
static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk);
@@ -102,7 +97,6 @@ class CacheObserver : public nsIObserver, public nsSupportsWeakReference {
10297

10398
void StoreCacheFSReported();
10499
void StoreHashStatsReported();
105-
void StoreCacheAmountWritten();
106100
void AttachToPreferences();
107101

108102
static int32_t sAutoMemoryCacheCapacity;
@@ -111,7 +105,6 @@ class CacheObserver : public nsIObserver, public nsSupportsWeakReference {
111105
static bool sCacheFSReported;
112106
static bool sHashStatsReported;
113107
static Atomic<PRIntervalTime> sShutdownDemandedTime;
114-
static Atomic<uint32_t, Relaxed> sCacheAmountWritten;
115108

116109
// Non static properties, accessible via sSelf
117110
nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;

0 commit comments

Comments
 (0)