MDEV-7004 - Merge scalability fixes from 10.0-power

All callers of open_cached_file() use 2 characters prefix. Allocating memory for
such short string is an overkill. Store it on IO_CACHE structure instead.

All callers of open_cached_file() use mysql_tmpdir as dir. No need to allocate
memory for it since it is constant and available till server shutdown.

This reduces number of allocations from 31 to 27 per OLTP RO transaction.
This commit is contained in:
Sergey Vojtovich 2014-12-02 15:03:35 +04:00
parent 9e9f1da0d2
commit 974808772b
2 changed files with 12 additions and 9 deletions

View File

@ -473,7 +473,8 @@ typedef struct st_io_cache /* Used when cacheing files */
ulong disk_writes;
void* arg; /* for use by pre/post_read */
char *file_name; /* if used with 'open_cached_file' */
char *dir,*prefix;
const char *dir;
char prefix[3];
File file; /* file descriptor */
/*
seek_not_done is set by my_b_seek() to inform the upcoming read/write

View File

@ -61,9 +61,14 @@ my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
size_t cache_size, myf cache_myflags)
{
DBUG_ENTER("open_cached_file");
cache->dir= dir ? my_strdup(dir,MYF(cache_myflags & MY_WME)) : (char*) 0;
cache->prefix= (prefix ? my_strdup(prefix,MYF(cache_myflags & MY_WME)) :
(char*) 0);
cache->dir= dir;
if (prefix)
{
DBUG_ASSERT(strlen(prefix) == 2);
memcpy(cache->prefix, prefix, 3);
}
else
cache->prefix[0]= 0;
cache->file_name=0;
cache->buffer=0; /* Mark that not open */
if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
@ -71,8 +76,6 @@ my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
{
DBUG_RETURN(0);
}
my_free(cache->dir);
my_free(cache->prefix);
DBUG_RETURN(1);
}
@ -83,7 +86,8 @@ my_bool real_open_cached_file(IO_CACHE *cache)
char name_buff[FN_REFLEN];
int error=1;
DBUG_ENTER("real_open_cached_file");
if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix,
if ((cache->file=create_temp_file(name_buff, cache->dir,
cache->prefix[0] ? cache->prefix : 0,
(O_RDWR | O_BINARY | O_TRUNC |
O_TEMPORARY | O_SHORT_LIVED),
MYF(MY_WME))) >= 0)
@ -114,8 +118,6 @@ void close_cached_file(IO_CACHE *cache)
}
#endif
}
my_free(cache->dir);
my_free(cache->prefix);
}
DBUG_VOID_RETURN;
}