diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index cd2174eea4998dd13aabbce7ee5990dbac379726..50600a979dfd3f119bf67fd5d704b57c51e2564e 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4259,12 +4259,17 @@ bool LLAppViewer::initCache()
 	// initialize the new disk cache using saved settings
 	const std::string cache_dir_name = gSavedSettings.getString("DiskCacheDirName");
 
+	const U32 MB = 1024 * 1024;
+    const U64 MIN_CACHE_SIZE = 256 * MB;
+	const U64 MAX_CACHE_SIZE = 9984ll * MB;
+    const U64 setting_cache_total_size = (U64)gSavedSettings.getU32("CacheSize") * MB;
+    const U64 cache_total_size = llclamp(setting_cache_total_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
+    const F64 disk_cache_percent = gSavedSettings.getF32("DiskCachePercentOfTotal");
+    const F64 texture_cache_percent = 100.0 - disk_cache_percent;
+
     // note that the maximum size of this cache is defined as a percentage of the 
     // total cache size - the 'CacheSize' pref - for all caches. 
-    const unsigned int cache_total_size_mb = gSavedSettings.getU32("CacheSize");
-    const double disk_cache_percent = gSavedSettings.getF32("DiskCachePercentOfTotal");
-    const unsigned int disk_cache_mb = cache_total_size_mb * disk_cache_percent / 100;
-    const uintmax_t disk_cache_bytes = disk_cache_mb * 1024 * 1024;
+    const U32 disk_cache_size = cache_total_size * disk_cache_percent / 100;
 	const bool enable_cache_debug_info = gSavedSettings.getBOOL("EnableDiskCacheDebugInfo");
 
 	bool texture_cache_mismatch = false;
@@ -4315,7 +4320,7 @@ bool LLAppViewer::initCache()
 	}
 
 	const std::string cache_dir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, cache_dir_name);
-	LLDiskCache::initParamSingleton(cache_dir, disk_cache_bytes, enable_cache_debug_info);
+    LLDiskCache::initParamSingleton(cache_dir, disk_cache_size, enable_cache_debug_info);
 
 	if (!read_only)
 	{
@@ -4338,22 +4343,14 @@ bool LLAppViewer::initCache()
 	LLSplashScreen::update(LLTrans::getString("StartupInitializingTextureCache"));
 
 	// Init the texture cache
-	// Allocate 80% of the cache size for textures
-	const S32 MB = 1024 * 1024;
-	const S64 MIN_CACHE_SIZE = 256 * MB;
-	const S64 MAX_CACHE_SIZE = 9984ll * MB;
-
-	S64 cache_size = (S64)(gSavedSettings.getU32("CacheSize")) * MB;
-	cache_size = llclamp(cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
+    // Allocate the remaining percent which is not allocated to the disk cache
+    const U32 texture_cache_size = cache_total_size * texture_cache_percent / 100;
 
-	S64 texture_cache_size = cache_size;
-
-	S64 extra = LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, texture_cache_mismatch);
-	texture_cache_size -= extra;
+    LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, texture_cache_mismatch);
 
 	LLVOCache::getInstance()->initCache(LL_PATH_CACHE, gSavedSettings.getU32("CacheNumberOfRegionsForObjects"), getObjectCacheVersion());
 
-		return true;
+    return true;
 }
 
 void LLAppViewer::addOnIdleCallback(const boost::function<void()>& cb)
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index d4fc6f3de28d9e88147b4fab81659cbbcd96499e..9403e73b87474eaa774a87c8a1fd9e0c0c41eb91 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -1042,7 +1042,8 @@ void LLTextureCache::setReadOnly(BOOL read_only)
 	mReadOnly = read_only ;
 }
 
-//called in the main thread.
+// Called in the main thread.
+// Returns the unused amount of max_size if any
 S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL texture_cache_mismatch)
 {
 	llassert_always(getPending() == 0) ; //should not start accessing the texture cache before initialized.