changeset 1394:059f13d577bb HEAD

Use separate index alignment from memory alignment. We don't use pointers in index file so required alignmentation comes pretty much from sizeof(off_t).
author Timo Sirainen <tss@iki.fi>
date Sun, 27 Apr 2003 03:59:43 +0300
parents c0d6ab3ee2d0
children b7fa9a51611b
files configure.in src/lib-index/mail-index-data.c src/lib-index/mail-index-open.c src/lib-index/mail-index-update.c src/lib-index/mail-index.h
diffstat 5 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sun Apr 27 03:58:12 2003 +0300
+++ b/configure.in	Sun Apr 27 03:59:43 2003 +0300
@@ -49,10 +49,15 @@
 	preferred_off_t_bits=64)
 
 AC_ARG_WITH(mem-align,
-[  --with-mem-align=BYTES  Set the memory alignment (default: sizeof(off_t))],
+[  --with-mem-align=BYTES  Set the memory alignment (default: 8)],
 	mem_align=$withval,
 	mem_align=8)
 
+AC_ARG_WITH(index-align,
+[  --with-index-align=BYTES  Set the index file alignment (default: detect)],
+	index_align=$withval,
+	index_align=0)
+
 AC_ARG_WITH(passwd,
 [  --with-passwd           Build with /etc/passwd support (default)],
 	if test x$withval = xno; then
@@ -226,9 +231,6 @@
 	AC_DEFINE(IOLOOP_SELECT,, Implement I/O loop with select())
 ])
 
-dnl * memory alignment
-AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
-
 dnl * OS specific options
 case "$host_os" in
 	hpux*)
@@ -391,11 +393,6 @@
   AC_DEFINE_UNQUOTED(OFF_T_MAX, $offt_max, Maximum value of off_t)
 ])
 
-dnl currently we break if off_t is smaller than mem_align
-if test $offt_bits = 32 -a $mem_align = 8; then
-  mem_align=4
-fi
-
 AC_DEFINE_UNQUOTED(PRIuUOFF_T, "$uofft_fmt", printf() format for uoff_t)
 
 dnl * make sure size_t isn't signed. we'd probably work fine with it, but
@@ -479,6 +476,18 @@
   AC_DEFINE(HAVE_SOCKLEN_T,, Define to 'int' if you don't have socklen_t)
 fi
 
+dnl * memory alignment
+if test "$index_align" = "0"; then
+  if test $offt_bits = 64; then
+    index_align=8
+  else
+    index_align=4
+  fi
+fi
+
+AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
+AC_DEFINE_UNQUOTED(INDEX_ALIGN_SIZE, $index_align, Required index alignment)
+
 dnl * find random source
 AC_MSG_CHECKING([for /dev/urandom])
 if test -c /dev/urandom; then
--- a/src/lib-index/mail-index-data.c	Sun Apr 27 03:58:12 2003 +0300
+++ b/src/lib-index/mail-index-data.c	Sun Apr 27 03:59:43 2003 +0300
@@ -449,7 +449,7 @@
 {
 	uoff_t offset;
 
-	i_assert((size & (MEM_ALIGN_SIZE-1)) == 0);
+	i_assert((size & (INDEX_ALIGN_SIZE-1)) == 0);
 	i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
 	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header)))
@@ -550,7 +550,7 @@
 		return NULL;
 	}
 
-	if ((pos % MEM_ALIGN_SIZE) != 0) {
+	if ((pos % INDEX_ALIGN_SIZE) != 0) {
 		index_data_set_corrupted(data, "Data position (%"PRIuUOFF_T") "
 					 "is not memory aligned for record %u",
 					 pos, index_rec->uid);
@@ -612,7 +612,7 @@
 			break;
 		}
 
-		if ((rec->full_field_size % MEM_ALIGN_SIZE) != 0) {
+		if ((rec->full_field_size % INDEX_ALIGN_SIZE) != 0) {
 			index_data_set_corrupted(data, "Field %d size %u "
 				"is not memory aligned for record %u",
 				(int)field, rec->full_field_size,
--- a/src/lib-index/mail-index-open.c	Sun Apr 27 03:58:12 2003 +0300
+++ b/src/lib-index/mail-index-open.c	Sun Apr 27 03:59:43 2003 +0300
@@ -199,7 +199,7 @@
 		hdr->compat_data[2] == sizeof(unsigned int) &&
 		hdr->compat_data[3] == sizeof(time_t) &&
 		hdr->compat_data[4] == sizeof(uoff_t) &&
-		hdr->compat_data[5] == MEM_ALIGN_SIZE;
+		hdr->compat_data[5] == INDEX_ALIGN_SIZE;
 }
 
 static int mail_index_init_file(struct mail_index *index,
@@ -235,7 +235,7 @@
 	hdr->compat_data[2] = sizeof(unsigned int);
 	hdr->compat_data[3] = sizeof(time_t);
 	hdr->compat_data[4] = sizeof(uoff_t);
-	hdr->compat_data[5] = MEM_ALIGN_SIZE;
+	hdr->compat_data[5] = INDEX_ALIGN_SIZE;
 	hdr->indexid = ioloop_time;
 
 	/* mark the index requiring rebuild - rebuild() removes this flag
--- a/src/lib-index/mail-index-update.c	Sun Apr 27 03:58:12 2003 +0300
+++ b/src/lib-index/mail-index-update.c	Sun Apr 27 03:59:43 2003 +0300
@@ -81,11 +81,11 @@
 
 		if (update->fields[i] != NULL) {
 			/* value was modified - use it */
-			field_min_size = MEM_ALIGN(update->field_sizes[i]);
+			field_min_size = INDEX_ALIGN(update->field_sizes[i]);
 			*min_size += SIZEOF_MAIL_INDEX_DATA + field_min_size;
 			*max_size += SIZEOF_MAIL_INDEX_DATA +
-				MEM_ALIGN(update->field_sizes[i] +
-					  update->field_extra_sizes[i]);
+				INDEX_ALIGN(update->field_sizes[i] +
+					    update->field_extra_sizes[i]);
 
 			if (!field_exists ||
 			    rec->full_field_size < field_min_size)
@@ -109,15 +109,15 @@
 {
 	size_t size;
 
-	size = MEM_ALIGN(base);
+	size = INDEX_ALIGN(base);
 	extra -= size - base;
-	if (*max_extra < MEM_ALIGN_SIZE || extra == 0)
+	if (*max_extra < INDEX_ALIGN_SIZE || extra == 0)
 		return size; /* no extra / extra went into alignment */
 
-	extra = MEM_ALIGN(extra);
+	extra = INDEX_ALIGN(extra);
 	if (extra > *max_extra) {
 		/* partial */
-		extra = *max_extra & ~(size_t)(MEM_ALIGN_SIZE-1);
+		extra = *max_extra & ~(size_t)(INDEX_ALIGN_SIZE-1);
 		i_assert(extra <= *max_extra);
 	}
 
@@ -168,7 +168,7 @@
 			/* the field doesn't exist, jump to next */
 			continue;
 		}
-		i_assert((full_field_size % MEM_ALIGN_SIZE) == 0);
+		i_assert((full_field_size % INDEX_ALIGN_SIZE) == 0);
 
 		destrec = buffer_append_space(buf, SIZEOF_MAIL_INDEX_DATA +
 					      full_field_size);
--- a/src/lib-index/mail-index.h	Sun Apr 27 03:58:12 2003 +0300
+++ b/src/lib-index/mail-index.h	Sun Apr 27 03:59:43 2003 +0300
@@ -118,7 +118,7 @@
 	   2 = sizeof(unsigned int),
 	   3 = sizeof(time_t),
 	   4 = sizeof(uoff_t),
-	   5 = MEM_ALIGN_SIZE */
+	   5 = INDEX_ALIGN_SIZE */
 
 	unsigned int indexid;
 	unsigned int sync_id; /* re-mmap() when changed, required only
@@ -176,11 +176,11 @@
 struct mail_index_data_record {
 	unsigned int field; /* enum mail_data_field */
 	unsigned int full_field_size;
-	char data[MEM_ALIGN_SIZE]; /* variable size */
+	char data[INDEX_ALIGN_SIZE]; /* variable size */
 };
 
 #define SIZEOF_MAIL_INDEX_DATA \
-	(sizeof(struct mail_index_data_record) - MEM_ALIGN_SIZE)
+	(sizeof(struct mail_index_data_record) - INDEX_ALIGN_SIZE)
 
 #define DATA_RECORD_SIZE(rec) \
         (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
@@ -348,7 +348,7 @@
 	void (*update_field)(struct mail_index_update *update,
 			     enum mail_data_field field,
 			     const char *value, size_t extra_space);
-	/* Just remember that full_field_size will be MEM_ALIGNed, so
+	/* Just remember that full_field_size will be INDEX_ALIGNed, so
 	   it may differer from the given size parameter. */
 	void (*update_field_raw)(struct mail_index_update *update,
 				 enum mail_data_field field,
@@ -591,4 +591,8 @@
 #define INDEX_IS_IN_MEMORY(index) \
 	((index)->anon_mmap)
 
+/* Returns alignmentation for given size */
+#define INDEX_ALIGN(size) \
+	(((size) + INDEX_ALIGN_SIZE-1) & ~((unsigned int) INDEX_ALIGN_SIZE-1))
+
 #endif