Skip to content

Commit 1ee0d09

Browse files
committed
MDEV-32228 speedup opening tablespaces on Windows
is_file_on_ssd() is more expensive than it should be. It caches the results by volume name, but still calls GetVolumePathName() every time, which, as procmon shows, opens multiple directories in filesystem hierarchy (db directory, datadir, and all ancestors) The fix is to cache SSD status by volume serial ID, which is cheap to retrieve with GetFileInformationByHandleEx()
1 parent 89a493d commit 1ee0d09

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

storage/innobase/os/os0file.cc

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7358,36 +7358,40 @@ static bool is_volume_on_ssd(const char *volume_mount_point)
73587358
}
73597359

73607360
#include <unordered_map>
7361-
static bool is_file_on_ssd(char *file_path)
7361+
static bool is_path_on_ssd(char *file_path)
73627362
{
7363-
/* Cache of volume_path => volume_info, protected by rwlock.*/
7364-
static std::unordered_map<std::string, bool> cache;
7365-
static SRWLOCK lock= SRWLOCK_INIT;
7366-
73677363
/* Preset result, in case something fails, e.g we're on network drive.*/
73687364
char volume_path[MAX_PATH];
73697365
if (!GetVolumePathName(file_path, volume_path, array_elements(volume_path)))
73707366
return false;
7367+
return is_volume_on_ssd(volume_path);
7368+
}
7369+
7370+
static bool is_file_on_ssd(HANDLE handle, char *file_path)
7371+
{
7372+
ULONGLONG volume_serial_number;
7373+
FILE_ID_INFO info;
7374+
if(!GetFileInformationByHandleEx(handle, FileIdInfo, &info, sizeof(info)))
7375+
return false;
7376+
volume_serial_number= info.VolumeSerialNumber;
73717377

7372-
/* Try cached volume info first.*/
7373-
std::string volume_path_str(volume_path);
7378+
static std::unordered_map<ULONGLONG, bool> cache;
7379+
static SRWLOCK lock= SRWLOCK_INIT;
73747380
bool found;
73757381
bool result;
73767382
AcquireSRWLockShared(&lock);
7377-
auto e= cache.find(volume_path_str);
7383+
auto e= cache.find(volume_serial_number);
73787384
if ((found= e != cache.end()))
73797385
result= e->second;
73807386
ReleaseSRWLockShared(&lock);
7381-
7382-
if (found)
7383-
return result;
7384-
7385-
result= is_volume_on_ssd(volume_path);
7386-
7387-
/* Update cache */
7388-
AcquireSRWLockExclusive(&lock);
7389-
cache[volume_path_str]= result;
7390-
ReleaseSRWLockExclusive(&lock);
7387+
if (!found)
7388+
{
7389+
result= is_path_on_ssd(file_path);
7390+
/* Update cache */
7391+
AcquireSRWLockExclusive(&lock);
7392+
cache[volume_serial_number]= result;
7393+
ReleaseSRWLockExclusive(&lock);
7394+
}
73917395
return result;
73927396
}
73937397

@@ -7427,7 +7431,7 @@ void fil_node_t::find_metadata(os_file_t file
74277431
space->atomic_write_supported = space->purpose == FIL_TYPE_TEMPORARY
74287432
|| space->purpose == FIL_TYPE_IMPORT;
74297433
#ifdef _WIN32
7430-
on_ssd = is_file_on_ssd(name);
7434+
on_ssd = is_file_on_ssd(file, name);
74317435
FILE_STORAGE_INFO info;
74327436
if (GetFileInformationByHandleEx(
74337437
file, FileStorageInfo, &info, sizeof(info))) {

0 commit comments

Comments
 (0)