diff options
author | unknown <marko@hundin.mysql.fi> | 2005-06-27 17:04:57 +0300 |
---|---|---|
committer | unknown <marko@hundin.mysql.fi> | 2005-06-27 17:04:57 +0300 |
commit | 1b9e735012e4687ecbc28070c1bcd4ca9cf3d5f0 (patch) | |
tree | a7a00b4e2ad6dd6e0c65489e27cfac46b4bda0e3 /innobase/os | |
parent | dca8f40ceceac58e2237064e67a471c5b035d742 (diff) | |
download | mariadb-git-1b9e735012e4687ecbc28070c1bcd4ca9cf3d5f0.tar.gz |
InnoDB: Optimize the extension of files. This will greatly speed
up CREATE TABLE in innodb_file_per_table=1 mode.
innobase/fil/fil0fil.c:
fil_extend_space_to_desired_size(): Do not allocate or initialize
more memory than is necessary. Write at most one megabyte at a time.
innobase/include/os0file.h:
os_file_set_size(): Corrected the synopsis
innobase/os/os0file.c:
os_file_set_size(): Corrected the synopsis and some comments.
s/offset/current_size; s/low/desired_size/;
Do not allocate or initialize more memory than is necessary.
Write at most one megabyte at a time.
Diffstat (limited to 'innobase/os')
-rw-r--r-- | innobase/os/os0file.c | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 15f5bf40e51..25123c47cb8 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -1642,7 +1642,7 @@ os_file_get_size_as_iblonglong( } /*************************************************************************** -Sets a file size. This function can be used to extend or truncate a file. */ +Write the specified number of zeros to a newly created file. */ ibool os_file_set_size( @@ -1655,47 +1655,39 @@ os_file_set_size( size */ ulint size_high)/* in: most significant 32 bits of size */ { - ib_longlong offset; - ib_longlong low; - ulint n_bytes; + ib_longlong current_size; + ib_longlong desired_size; ibool ret; byte* buf; byte* buf2; - ulint i; + ulint buf_size; ut_a(size == (size & 0xFFFFFFFF)); - /* We use a very big 8 MB buffer in writing because Linux may be - extremely slow in fsync on 1 MB writes */ + current_size = 0; + desired_size = (ib_longlong)size + (((ib_longlong)size_high) << 32); - buf2 = ut_malloc(UNIV_PAGE_SIZE * 513); + /* Write up to 1 megabyte at a time. */ + buf_size = ut_min(UNIV_PAGE_SIZE * 64, desired_size); + buf2 = ut_malloc(buf_size + UNIV_PAGE_SIZE); /* Align the buffer for possible raw i/o */ buf = ut_align(buf2, UNIV_PAGE_SIZE); /* Write buffer full of zeros */ - for (i = 0; i < UNIV_PAGE_SIZE * 512; i++) { - buf[i] = '\0'; - } - - offset = 0; - low = (ib_longlong)size + (((ib_longlong)size_high) << 32); + memset(buf, 0, buf_size); - if (low >= (ib_longlong)(100 * 1024 * 1024)) { + if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) { fprintf(stderr, "InnoDB: Progress in MB:"); } - while (offset < low) { - if (low - offset < UNIV_PAGE_SIZE * 512) { - n_bytes = (ulint)(low - offset); - } else { - n_bytes = UNIV_PAGE_SIZE * 512; - } - + while (current_size < desired_size) { + ulint n_bytes = ut_min(buf_size, + (ulint) (desired_size - current_size)); ret = os_file_write(name, file, buf, - (ulint)(offset & 0xFFFFFFFF), - (ulint)(offset >> 32), + (ulint)(current_size & 0xFFFFFFFF), + (ulint)(current_size >> 32), n_bytes); if (!ret) { ut_free(buf2); @@ -1703,18 +1695,18 @@ os_file_set_size( } /* Print about progress for each 100 MB written */ - if ((offset + n_bytes) / (ib_longlong)(100 * 1024 * 1024) - != offset / (ib_longlong)(100 * 1024 * 1024)) { + if ((current_size + n_bytes) / (ib_longlong)(100 * 1024 * 1024) + != current_size / (ib_longlong)(100 * 1024 * 1024)) { fprintf(stderr, " %lu00", - (ulong) ((offset + n_bytes) + (ulong) ((current_size + n_bytes) / (ib_longlong)(100 * 1024 * 1024))); } - offset += n_bytes; + current_size += n_bytes; } - if (low >= (ib_longlong)(100 * 1024 * 1024)) { + if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) { fprintf(stderr, "\n"); } |