summaryrefslogtreecommitdiff
path: root/innobase/os
diff options
context:
space:
mode:
authormarko@hundin.mysql.fi <>2005-06-27 17:04:57 +0300
committermarko@hundin.mysql.fi <>2005-06-27 17:04:57 +0300
commit8064ee217f481d3866dbaab62b237bed6b61864b (patch)
treea7a00b4e2ad6dd6e0c65489e27cfac46b4bda0e3 /innobase/os
parent87d681c7bb0151709f7236c2ebff44fa0d9330c5 (diff)
downloadmariadb-git-8064ee217f481d3866dbaab62b237bed6b61864b.tar.gz
InnoDB: Optimize the extension of files. This will greatly speed
up CREATE TABLE in innodb_file_per_table=1 mode.
Diffstat (limited to 'innobase/os')
-rw-r--r--innobase/os/os0file.c50
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");
}