Commit 1084e540 authored by unknown's avatar unknown

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.
parent e00981bb
...@@ -3400,9 +3400,9 @@ fil_extend_space_to_desired_size( ...@@ -3400,9 +3400,9 @@ fil_extend_space_to_desired_size(
fil_space_t* space; fil_space_t* space;
byte* buf2; byte* buf2;
byte* buf; byte* buf;
ulint buf_size;
ulint start_page_no; ulint start_page_no;
ulint file_start_page_no; ulint file_start_page_no;
ulint n_pages;
ulint offset_high; ulint offset_high;
ulint offset_low; ulint offset_low;
ibool success = TRUE; ibool success = TRUE;
...@@ -3427,22 +3427,20 @@ fil_extend_space_to_desired_size( ...@@ -3427,22 +3427,20 @@ fil_extend_space_to_desired_size(
fil_node_prepare_for_io(node, system, space); fil_node_prepare_for_io(node, system, space);
/* Extend 1 MB at a time */
buf2 = mem_alloc(1024 * 1024 + UNIV_PAGE_SIZE);
buf = ut_align(buf2, UNIV_PAGE_SIZE);
memset(buf, '\0', 1024 * 1024);
start_page_no = space->size; start_page_no = space->size;
file_start_page_no = space->size - node->size; file_start_page_no = space->size - node->size;
while (start_page_no < size_after_extend) { /* Extend at most 64 pages at a time */
n_pages = size_after_extend - start_page_no; buf_size = ut_min(64, size_after_extend - start_page_no)
* UNIV_PAGE_SIZE;
buf2 = mem_alloc(buf_size + UNIV_PAGE_SIZE);
buf = ut_align(buf2, UNIV_PAGE_SIZE);
if (n_pages > (1024 * 1024) / UNIV_PAGE_SIZE) { memset(buf, 0, buf_size);
n_pages = (1024 * 1024) / UNIV_PAGE_SIZE;
} while (start_page_no < size_after_extend) {
ulint n_pages = ut_min(buf_size / UNIV_PAGE_SIZE,
size_after_extend - start_page_no);
offset_high = (start_page_no - file_start_page_no) offset_high = (start_page_no - file_start_page_no)
/ (4096 * ((1024 * 1024) / UNIV_PAGE_SIZE)); / (4096 * ((1024 * 1024) / UNIV_PAGE_SIZE));
......
...@@ -368,7 +368,7 @@ os_file_get_size_as_iblonglong( ...@@ -368,7 +368,7 @@ os_file_get_size_as_iblonglong(
/* out: size in bytes, -1 if error */ /* out: size in bytes, -1 if error */
os_file_t file); /* in: handle to a file */ os_file_t file); /* in: handle to a file */
/*************************************************************************** /***************************************************************************
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 ibool
os_file_set_size( os_file_set_size(
......
...@@ -1642,7 +1642,7 @@ os_file_get_size_as_iblonglong( ...@@ -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 ibool
os_file_set_size( os_file_set_size(
...@@ -1655,47 +1655,39 @@ os_file_set_size( ...@@ -1655,47 +1655,39 @@ os_file_set_size(
size */ size */
ulint size_high)/* in: most significant 32 bits of size */ ulint size_high)/* in: most significant 32 bits of size */
{ {
ib_longlong offset; ib_longlong current_size;
ib_longlong low; ib_longlong desired_size;
ulint n_bytes;
ibool ret; ibool ret;
byte* buf; byte* buf;
byte* buf2; byte* buf2;
ulint i; ulint buf_size;
ut_a(size == (size & 0xFFFFFFFF)); ut_a(size == (size & 0xFFFFFFFF));
/* We use a very big 8 MB buffer in writing because Linux may be current_size = 0;
extremely slow in fsync on 1 MB writes */ 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 */ /* Align the buffer for possible raw i/o */
buf = ut_align(buf2, UNIV_PAGE_SIZE); buf = ut_align(buf2, UNIV_PAGE_SIZE);
/* Write buffer full of zeros */ /* Write buffer full of zeros */
for (i = 0; i < UNIV_PAGE_SIZE * 512; i++) { memset(buf, 0, buf_size);
buf[i] = '\0';
}
offset = 0;
low = (ib_longlong)size + (((ib_longlong)size_high) << 32);
if (low >= (ib_longlong)(100 * 1024 * 1024)) { if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) {
fprintf(stderr, "InnoDB: Progress in MB:"); fprintf(stderr, "InnoDB: Progress in MB:");
} }
while (offset < low) { while (current_size < desired_size) {
if (low - offset < UNIV_PAGE_SIZE * 512) { ulint n_bytes = ut_min(buf_size,
n_bytes = (ulint)(low - offset); (ulint) (desired_size - current_size));
} else {
n_bytes = UNIV_PAGE_SIZE * 512;
}
ret = os_file_write(name, file, buf, ret = os_file_write(name, file, buf,
(ulint)(offset & 0xFFFFFFFF), (ulint)(current_size & 0xFFFFFFFF),
(ulint)(offset >> 32), (ulint)(current_size >> 32),
n_bytes); n_bytes);
if (!ret) { if (!ret) {
ut_free(buf2); ut_free(buf2);
...@@ -1703,18 +1695,18 @@ os_file_set_size( ...@@ -1703,18 +1695,18 @@ os_file_set_size(
} }
/* Print about progress for each 100 MB written */ /* Print about progress for each 100 MB written */
if ((offset + n_bytes) / (ib_longlong)(100 * 1024 * 1024) if ((current_size + n_bytes) / (ib_longlong)(100 * 1024 * 1024)
!= offset / (ib_longlong)(100 * 1024 * 1024)) { != current_size / (ib_longlong)(100 * 1024 * 1024)) {
fprintf(stderr, " %lu00", fprintf(stderr, " %lu00",
(ulong) ((offset + n_bytes) (ulong) ((current_size + n_bytes)
/ (ib_longlong)(100 * 1024 * 1024))); / (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"); fprintf(stderr, "\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment