Skip to content

Commit fe82a29

Browse files
authored
Remove FileSystemCacheSize setting (#7984)
1 parent 55fd220 commit fe82a29

File tree

3 files changed

+0
-200
lines changed

3 files changed

+0
-200
lines changed

builds/install/misc/firebird.conf

-28
Original file line numberDiff line numberDiff line change
@@ -287,34 +287,6 @@
287287
#UseFileSystemCache = true
288288

289289

290-
# ----------------------------
291-
# File system cache size
292-
#
293-
# This setting controls the maximum amount of RAM used by Windows file system
294-
# cache on a 64-bit Windows host. It has no effect for Unix hosts in this release yet.
295-
#
296-
# Note that the lowest number presently supported is 10%, and the highest number
297-
# is 95%; numbers outside these limits will apply a default value of 30%.
298-
#
299-
# If the cache size has already been selected when the engine starts, the host
300-
# setting will not be changed. Thus you may need to reboot the host for the
301-
# change of this setting to have effect.
302-
#
303-
# To leave host caching settings unchanged, set this parameter to 0. This is
304-
# the default parameter value.
305-
#
306-
# Security note
307-
# To adjust the setting, the engine needs the SeIncreaseQuotaPrivilege right.
308-
# Built-in service accounts and administrators have it by default. The installer
309-
# grants this right to the Firebird service account. If the engine fails to adjust
310-
# the cache size setting, it will log a warning message to the firebird.log and
311-
# continue.
312-
#
313-
# Type: integer, measured in % of total physical RAM
314-
#
315-
#FileSystemCacheSize = 0
316-
317-
318290
# ----------------------------
319291
# Remove protection against opening databases on NFS mounted volumes on
320292
# Linux/Unix and SMB/CIFS volumes on Windows.

src/common/config/config.h

-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ enum ConfigKey
154154
KEY_DATABASE_GROWTH_INCREMENT,
155155
KEY_TRACE_CONFIG,
156156
KEY_MAX_TRACELOG_SIZE,
157-
KEY_FILESYSTEM_CACHE_SIZE,
158157
KEY_PLUG_PROVIDERS,
159158
KEY_PLUG_AUTH_SERVER,
160159
KEY_PLUG_AUTH_CLIENT,
@@ -257,7 +256,6 @@ constexpr ConfigEntry entries[MAX_CONFIG_KEY] =
257256
{TYPE_INTEGER, "DatabaseGrowthIncrement", false, 128 * 1048576}, // bytes
258257
{TYPE_STRING, "AuditTraceConfigFile", true, ""}, // location of audit trace configuration file
259258
{TYPE_INTEGER, "MaxUserTraceLogSize", true, 10}, // maximum size of user session trace log
260-
{TYPE_INTEGER, "FileSystemCacheSize", true, 0}, // percent
261259
{TYPE_STRING, "Providers", false, "Remote, " CURRENT_ENGINE ", Loopback"},
262260
{TYPE_STRING, "AuthServer", false, "Srp256"},
263261
#ifdef WIN_NT
@@ -570,8 +568,6 @@ class Config : public RefCounted, public GlobalStorage
570568

571569
CONFIG_GET_PER_DB_INT(getDatabaseGrowthIncrement, KEY_DATABASE_GROWTH_INCREMENT);
572570

573-
CONFIG_GET_GLOBAL_KEY(FB_UINT64, getFileSystemCacheSize, KEY_FILESYSTEM_CACHE_SIZE, getInt);
574-
575571
CONFIG_GET_GLOBAL_STR(getAuditTraceConfigFile, KEY_TRACE_CONFIG);
576572

577573
CONFIG_GET_GLOBAL_KEY(FB_UINT64, getMaxUserTraceLogSize, KEY_MAX_TRACELOG_SIZE, getInt);

src/jrd/os/win32/winnt.cpp

-168
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ static bool maybeCloseFile(HANDLE&);
109109
static jrd_file* seek_file(jrd_file*, BufferDesc*, OVERLAPPED*);
110110
static jrd_file* setup_file(Database*, const Firebird::PathName&, HANDLE, bool, bool);
111111
static bool nt_error(const TEXT*, const jrd_file*, ISC_STATUS, FbStatusVector* const);
112-
static void adjustFileSystemCacheSize();
113-
114-
struct AdjustFsCache
115-
{
116-
static void init() { adjustFileSystemCacheSize(); }
117-
};
118-
119-
static InitMutex<AdjustFsCache> adjustFsCacheOnce("AdjustFsCacheOnce");
120112

121113
inline static DWORD getShareFlags(const bool shared_access, bool temporary = false)
122114
{
@@ -192,8 +184,6 @@ jrd_file* PIO_create(thread_db* tdbb, const Firebird::PathName& string,
192184
* Create a new database file.
193185
*
194186
**************************************/
195-
adjustFsCacheOnce.init();
196-
197187
Database* const dbb = tdbb->getDatabase();
198188

199189
const TEXT* file_name = string.c_str();
@@ -515,8 +505,6 @@ jrd_file* PIO_open(thread_db* tdbb,
515505
bool readOnly = false;
516506
const bool shareMode = dbb->dbb_config->getServerMode() != MODE_SUPER;
517507

518-
adjustFsCacheOnce.init();
519-
520508
HANDLE desc = CreateFile(ptr,
521509
GENERIC_READ | GENERIC_WRITE,
522510
getShareFlags(shareMode),
@@ -954,159 +942,3 @@ static bool nt_error(const TEXT* string,
954942

955943
return false;
956944
}
957-
958-
// These are defined in Windows Server 2008 SDK
959-
#ifndef FILE_CACHE_FLAGS_DEFINED
960-
#define FILE_CACHE_MAX_HARD_ENABLE 0x00000001
961-
#define FILE_CACHE_MAX_HARD_DISABLE 0x00000002
962-
#define FILE_CACHE_MIN_HARD_ENABLE 0x00000004
963-
#define FILE_CACHE_MIN_HARD_DISABLE 0x00000008
964-
#endif // FILE_CACHE_FLAGS_DEFINED
965-
966-
BOOL SetPrivilege(
967-
HANDLE hToken, // access token handle
968-
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
969-
BOOL bEnablePrivilege) // to enable or disable privilege
970-
{
971-
TOKEN_PRIVILEGES tp;
972-
LUID luid;
973-
974-
if (!LookupPrivilegeValue(
975-
NULL, // lookup privilege on local system
976-
lpszPrivilege, // privilege to lookup
977-
&luid)) // receives LUID of privilege
978-
{
979-
// gds__log("LookupPrivilegeValue error: %u", GetLastError() );
980-
return FALSE;
981-
}
982-
983-
tp.PrivilegeCount = 1;
984-
tp.Privileges[0].Luid = luid;
985-
if (bEnablePrivilege)
986-
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
987-
else
988-
tp.Privileges[0].Attributes = 0;
989-
990-
// Enable or disable the privilege
991-
992-
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
993-
(PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL))
994-
{
995-
//gds__log("AdjustTokenPrivileges error: %u", GetLastError() );
996-
return FALSE;
997-
}
998-
999-
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
1000-
{
1001-
//gds__log("The token does not have the specified privilege");
1002-
return FALSE;
1003-
}
1004-
1005-
return TRUE;
1006-
}
1007-
1008-
static void adjustFileSystemCacheSize()
1009-
{
1010-
int percent = Config::getFileSystemCacheSize();
1011-
1012-
// firebird.conf asks to do nothing
1013-
if (percent == 0)
1014-
return;
1015-
1016-
// Ensure that the setting has a sensible value
1017-
if (percent > 95 || percent < 10)
1018-
{
1019-
gds__log("Incorrect FileSystemCacheSize setting %d. Using default (30 percent).", percent);
1020-
percent = 30;
1021-
}
1022-
1023-
HMODULE hmodKernel32 = GetModuleHandle("kernel32.dll");
1024-
1025-
// This one requires 64-bit XP or Windows Server 2003 SP1
1026-
typedef BOOL (WINAPI *PFnSetSystemFileCacheSize)(SIZE_T, SIZE_T, DWORD);
1027-
1028-
typedef BOOL (WINAPI *PFnGetSystemFileCacheSize)(PSIZE_T, PSIZE_T, PDWORD);
1029-
1030-
// This one needs any NT, but load it dynamically anyways just in case
1031-
typedef BOOL (WINAPI *PFnGlobalMemoryStatusEx)(LPMEMORYSTATUSEX);
1032-
1033-
PFnSetSystemFileCacheSize pfnSetSystemFileCacheSize =
1034-
(PFnSetSystemFileCacheSize) GetProcAddress(hmodKernel32, "SetSystemFileCacheSize");
1035-
PFnGetSystemFileCacheSize pfnGetSystemFileCacheSize =
1036-
(PFnGetSystemFileCacheSize) GetProcAddress(hmodKernel32, "GetSystemFileCacheSize");
1037-
PFnGlobalMemoryStatusEx pfnGlobalMemoryStatusEx =
1038-
(PFnGlobalMemoryStatusEx) GetProcAddress(hmodKernel32, "GlobalMemoryStatusEx");
1039-
1040-
// If we got too old OS and functions are not there - do not bother
1041-
if (!pfnGetSystemFileCacheSize || !pfnSetSystemFileCacheSize || !pfnGlobalMemoryStatusEx)
1042-
return;
1043-
1044-
MEMORYSTATUSEX msex;
1045-
msex.dwLength = sizeof(msex);
1046-
1047-
// This should work
1048-
if (!pfnGlobalMemoryStatusEx(&msex))
1049-
system_call_failed::raise("GlobalMemoryStatusEx", GetLastError());
1050-
1051-
SIZE_T origMinimumFileCacheSize, origMaximumFileCacheSize;
1052-
DWORD origFlags;
1053-
1054-
BOOL result = pfnGetSystemFileCacheSize(&origMinimumFileCacheSize,
1055-
&origMaximumFileCacheSize, &origFlags);
1056-
1057-
if (!result)
1058-
{
1059-
const DWORD error = GetLastError();
1060-
#ifndef _WIN64
1061-
// This error is returned on 64-bit Windows when the file cache size
1062-
// overflows the ULONG limit restricted by the 32-bit Windows API.
1063-
// Let's avoid writing it into the log as it's not a critical failure.
1064-
if (error != ERROR_ARITHMETIC_OVERFLOW)
1065-
#endif
1066-
gds__log("GetSystemFileCacheSize error %d", error);
1067-
return;
1068-
}
1069-
1070-
// Somebody has already configured maximum cache size limit
1071-
// Hope it is a sensible one - do not bother to adjust it
1072-
if ((origFlags & FILE_CACHE_MAX_HARD_ENABLE) != 0)
1073-
return;
1074-
1075-
DWORDLONG maxMem = (msex.ullTotalPhys / 100) * percent;
1076-
1077-
#ifndef _WIN64
1078-
// If we are trying to set the limit so high that it doesn't fit
1079-
// in 32-bit API - leave settings alone and write a message to log file
1080-
if (maxMem > (SIZE_T)(-2))
1081-
{
1082-
gds__log("Could not use 32-bit SetSystemFileCacheSize API to set cache size limit to %I64d."
1083-
" Please use 64-bit engine or configure cache size limit externally", maxMem);
1084-
return;
1085-
}
1086-
#endif
1087-
1088-
HANDLE hToken;
1089-
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1090-
{
1091-
gds__log("OpenProcessToken error %d", GetLastError());
1092-
return;
1093-
}
1094-
1095-
if (SetPrivilege(hToken, "SeIncreaseQuotaPrivilege", TRUE))
1096-
{
1097-
result = pfnSetSystemFileCacheSize(0, maxMem, FILE_CACHE_MAX_HARD_ENABLE);
1098-
const DWORD error = GetLastError();
1099-
SetPrivilege(hToken, "SeIncreaseQuotaPrivilege", FALSE);
1100-
1101-
if (!result)
1102-
{
1103-
// If we do not have enough permissions - silently ignore the error
1104-
gds__log("SetSystemFileCacheSize error %d. "
1105-
"The engine will continue to operate, but the system "
1106-
"performance may degrade significantly when working with "
1107-
"large databases", error);
1108-
}
1109-
}
1110-
1111-
CloseHandle(hToken);
1112-
}

0 commit comments

Comments
 (0)