summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-01-28 13:14:48 -0500
committerDan Pasette <dan@mongodb.com>2014-03-09 11:27:35 -0400
commitc7436cd7fc8d2e7d891bcba6cd2d897b98b0fbcf (patch)
tree6ad0d3ad7a49ffdabdb90ab1b4ee22f523cbfc58
parent801d87f5c8d66d5f5a462c5e0daae67e6b848976 (diff)
downloadmongo-c7436cd7fc8d2e7d891bcba6cd2d897b98b0fbcf.tar.gz
Do not zero-fill newly allocated files on Windows
On Windows platforms code was added to zero-fill each newly allocated data file in order to work around Windows KB http://support.microsoft.com/kb/2731284. The KB only applies for Windows 7 and Windows 2008 Server installations, so there is no need to do it on each and every system. This fix restricts the zeroing-out code to only versions, which have had the bug. It will not check whether the hot fix has been installed.
-rw-r--r--src/mongo/util/file_allocator.cpp10
-rw-r--r--src/mongo/util/processinfo.h14
-rw-r--r--src/mongo/util/processinfo_win32.cpp11
3 files changed, 33 insertions, 2 deletions
diff --git a/src/mongo/util/file_allocator.cpp b/src/mongo/util/file_allocator.cpp
index e59bce6934b..7876744f7d5 100644
--- a/src/mongo/util/file_allocator.cpp
+++ b/src/mongo/util/file_allocator.cpp
@@ -39,6 +39,7 @@
#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/paths.h"
+#include "mongo/util/processinfo.h"
#include "mongo/util/time_support.h"
#include "mongo/util/timer.h"
@@ -186,6 +187,15 @@ namespace mongo {
size - 1 == lseek(fd, size - 1, SEEK_SET) );
uassert( 10442 , str::stream() << "Unable to allocate new file of size " << size << ' ' << errnoWithDescription(),
1 == write(fd, "", 1) );
+
+ // File expansion is completed here. Do not do the zeroing out on OS-es where there
+ // is no risk of triggering allocation-related bugs such as
+ // http://support.microsoft.com/kb/2731284.
+ //
+ if (!ProcessInfo::isDataFileZeroingNeeded()) {
+ return;
+ }
+
lseek(fd, 0, SEEK_SET);
const long z = 256 * 1024;
diff --git a/src/mongo/util/processinfo.h b/src/mongo/util/processinfo.h
index 8e9044d39e4..03fcdd85993 100644
--- a/src/mongo/util/processinfo.h
+++ b/src/mongo/util/processinfo.h
@@ -92,6 +92,11 @@ namespace mongo {
bool hasNumaEnabled() const { return sysInfo().hasNuma; }
/**
+ * Determine if file zeroing is necessary for newly allocated data files.
+ */
+ static bool isDataFileZeroingNeeded() { return systemInfo->fileZeroNeeded; }
+
+ /**
* Get extra system stats
*/
void appendSystemDetails( BSONObjBuilder& details ) const {
@@ -145,12 +150,19 @@ namespace mongo {
string cpuArch;
bool hasNuma;
BSONObj _extraStats;
+
+ // This is an OS specific value, which determines whether files should be zero-filled
+ // at allocation time in order to avoid Microsoft KB 2731284.
+ //
+ bool fileZeroNeeded;
+
SystemInfo() :
addrSize( 0 ),
memSize( 0 ),
numCores( 0 ),
pageSize( 0 ),
- hasNuma( false ) {
+ hasNuma( false ),
+ fileZeroNeeded (false) {
// populate SystemInfo during construction
collectSystemInfo();
}
diff --git a/src/mongo/util/processinfo_win32.cpp b/src/mongo/util/processinfo_win32.cpp
index 3f42eb12698..d6f88e88a59 100644
--- a/src/mongo/util/processinfo_win32.cpp
+++ b/src/mongo/util/processinfo_win32.cpp
@@ -100,7 +100,7 @@ namespace mongo {
void ProcessInfo::SystemInfo::collectSystemInfo() {
BSONObjBuilder bExtra;
stringstream verstr;
- OSVERSIONINFOEX osvi; // os version
+ OSVERSIONINFOEX osvi; // os version
MEMORYSTATUSEX mse; // memory stats
SYSTEM_INFO ntsysinfo; //system stats
@@ -142,6 +142,15 @@ namespace mongo {
osName += "Windows 7";
else
osName += "Windows Server 2008 R2";
+
+ // Windows 6.1 is either Windows 7 or Windows 2008 R2. There is no SP2 for
+ // either of these two operating systems, but the check will hold if one
+ // were released. This code assumes that SP2 will include fix for
+ // http://support.microsoft.com/kb/2731284.
+ //
+ if ((osvi.wServicePackMajor >= 0) && (osvi.wServicePackMajor < 2)) {
+ fileZeroNeeded = true;
+ }
break;
case 0:
if ( osvi.wProductType == VER_NT_WORKSTATION )