← Back to team overview

maria-developers team mailing list archive

accelerating CREATE TABLE

 

Hi,

I made a patch to accelerate CREATE TABLE on the innodb plugin.
To zero table spaces, I used fallocate instead of normal writes and sync.
I compared MariaDB 5.5 trunk and the patched one by our own application,
which creates > 1000 tables in series, with ext4 filesystem on Ubuntu 12.04.
Results are shown below.

Original MariaDB 5.5 trunk: 64.9 seconds (5 times avg.)
Patched MariaDB 5.5 trunk: 36.0 seconds (5 times avg.)

Any comments or suggestions?

Thanks,
Toshikuni Fukaya
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: toshikuni-fukaya@xxxxxxxxxxxx-20130122005501-\
#   vc9xqiogy02xfmoe
# target_branch: file:///home/fukaya/mariadb/maria/trunk/
# testament_sha1: 5da3bd435589381472f4c9aa60d14aa006c46bab
# timestamp: 2013-01-22 10:14:57 +0900
# base_revision_id: wlad@xxxxxxxxxxxxxxxx-20130118174907-\
#   pn27v90e4xkqzfi3
# 
# Begin patch
=== modified file 'config.h.cmake'
--- config.h.cmake	2012-07-31 17:29:07 +0000
+++ config.h.cmake	2013-01-22 00:55:01 +0000
@@ -214,6 +214,7 @@
 #cmakedefine HAVE_POLL 1
 #cmakedefine HAVE_PORT_CREATE 1
 #cmakedefine HAVE_POSIX_FALLOCATE 1
+#cmakedefine HAVE_FALLOCATE 1
 #cmakedefine HAVE_PREAD 1
 #cmakedefine HAVE_PAUSE_INSTRUCTION 1
 #cmakedefine HAVE_FAKE_PAUSE_INSTRUCTION 1

=== modified file 'configure.cmake'
--- configure.cmake	2012-08-15 06:34:18 +0000
+++ configure.cmake	2013-01-22 00:55:01 +0000
@@ -398,6 +398,7 @@
 CHECK_FUNCTION_EXISTS (poll HAVE_POLL)
 CHECK_FUNCTION_EXISTS (port_create HAVE_PORT_CREATE)
 CHECK_FUNCTION_EXISTS (posix_fallocate HAVE_POSIX_FALLOCATE)
+CHECK_FUNCTION_EXISTS (fallocate HAVE_FALLOCATE)
 CHECK_FUNCTION_EXISTS (pread HAVE_PREAD)
 CHECK_FUNCTION_EXISTS (pthread_attr_create HAVE_PTHREAD_ATTR_CREATE)
 CHECK_FUNCTION_EXISTS (pthread_attr_getstacksize HAVE_PTHREAD_ATTR_GETSTACKSIZE)

=== modified file 'storage/innobase/fil/fil0fil.c'
--- storage/innobase/fil/fil0fil.c	2012-09-20 12:44:33 +0000
+++ storage/innobase/fil/fil0fil.c	2013-01-22 00:55:01 +0000
@@ -3961,6 +3961,7 @@
 	ulint		offset_low;
 	ulint		page_size;
 	ibool		success		= TRUE;
+	ibool		fallenback	= TRUE;
 
 	fil_mutex_enter_and_prepare_for_io(space_id);
 
@@ -3989,6 +3990,31 @@
 	start_page_no = space->size;
 	file_start_page_no = space->size - node->size;
 
+#ifdef HAVE_FALLOCATE
+	{
+		ulint n_pages = size_after_extend - start_page_no;
+		if(fallocate(node->handle, 0, node->size * page_size,
+			     n_pages * page_size) == 0) {
+			node->size += n_pages;
+			space->size += n_pages;
+			os_has_said_disk_full = FALSE;
+			fallenback = FALSE;
+			goto extend_after;
+		} else if (errno != ENOSYS && errno != EOPNOTSUPP) {
+			n_pages = ((ulint)
+				   (os_file_get_size_as_iblonglong(
+					   node->handle)
+				    / page_size)) - node->size;
+
+			node->size += n_pages;
+			space->size += n_pages;
+			fallenback = FALSE;
+			goto extend_after;
+		}
+		/* fall back if filesystem does not support fallocate */
+	}
+#endif
+
 	/* Extend at most 64 pages at a time */
 	buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
 	buf2 = mem_alloc(buf_size + page_size);
@@ -4041,7 +4067,8 @@
 
 	mem_free(buf2);
 
-	fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
+extend_after:
+	fil_node_complete_io(node, fil_system, fallenback ? OS_FILE_WRITE : OS_FILE_READ);
 
 	*actual_size = space->size;
 

=== modified file 'storage/innobase/os/os0file.c'
--- storage/innobase/os/os0file.c	2013-01-15 18:13:32 +0000
+++ storage/innobase/os/os0file.c	2013-01-22 00:55:01 +0000
@@ -1970,6 +1970,15 @@
 	current_size = 0;
 	desired_size = (ib_int64_t)size + (((ib_int64_t)size_high) << 32);
 
+#ifdef HAVE_FALLOCATE
+	if (fallocate(file, 0, 0, desired_size) == 0) {
+		return (TRUE);
+	} else if (errno != ENOSYS && errno != EOPNOTSUPP) {
+		goto error_handling;
+	}
+	/* fall back if filesystem does not support fallocate */
+#endif
+
 	/* Write up to 1 megabyte at a time. */
 	buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE))
 		* UNIV_PAGE_SIZE;

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWQGVEWoABCNfgGAwe3////9t
3+C////6YAh86b5tNQABZs+wAA0rQXAkoplM0amnpqehqeoaekMnpD1MmmgABoGj1NAHGjJkYRiA
YTQYBNBoGTJoyZDCAxFNPVNkh6jQBpoAHpABkaNAAAAAJEimKn6p+RTaYKb1Gk8iek09TTTJoDTQ
aaAAaA2qmoT0aNGpsmgIYBMnqBhANAaZGmg0wJJAQACAmT0miaankptJ6j1AZlHqaAD1PKaQTxhs
kpNBQJN9UEMbBsaY+qFDTGgbY3gMGHdD+3nC/0QxkaNrWTuZ0k9jRn1WXoplgiRzV10ibQQy/WiC
h4Cx0xAIJxRCSBICGFkDlTVUNNUEpCmL2twWfbe7Ixhi9B3/pcSdlP4pSx/DUG2GQG22NjYWGlW/
PQ0fmm+zNMgzRK7NRRREFzCHPSSqoiqip1fOKaYbZGwpPxlsv8Lryte6vnAbCwjpIVmNaD6r/tIc
aulaGodKfdsVFvzu9jUoM67arVjGQF92Nu4MQ5cumvc7vDEuebukAjQ7XYCcwl5IyVQypNC9f5YW
fYjZiPFGXe15ZnTibi9z5ysCZebe84ci0V1hMHgpaxfIKgKBcQqYDxYFp7qFcJ35boT6LzVgnBbd
fJKO4NupsZ+0J41kWFCgrfCcnKUlwMxUwF9TSBtX2KDGMuJjBZmE5PvAoyhiFeUAmewBxlA8nef3
XAmsIcSh4JwmseEKisIg6Iwm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