You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2016/01/04 16:11:08 UTC
svn commit: r1722887 -
/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
Author: stefan2
Date: Mon Jan 4 15:11:08 2016
New Revision: 1722887
URL: http://svn.apache.org/viewvc?rev=1722887&view=rev
Log:
Stop trying to align pointers in the cache-membuffer code, too, because
that is not portable.
* subversion/libsvn_subr/cache-membuffer.c
(ITEM_ALIGNMENT): Document that this is no longer an "absolute" alignment.
(ALIGN_POINTER,
secure_aligned_alloc): Drop. We can't do this.
(svn_cache__membuffer_cache_create): Don't align pointers but still
ensure that the data buffer sizes
and relative positions are multiples
of ITEM_ALIGNMENT.
(membuffer_cache_get_internal): No longer try to be better than standard
APR pointer alignment.
Modified:
subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1722887&r1=1722886&r2=1722887&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Mon Jan 4 15:11:08 2016
@@ -147,6 +147,10 @@
#endif
/* For more efficient copy operations, let's align all data items properly.
+ * Since we can't portably align pointers, this is rather the item size
+ * granularity which ensures *relative* alignment within the cache - still
+ * giving us decent copy speeds on most machines.
+ *
* Must be a power of 2.
*/
#define ITEM_ALIGNMENT 16
@@ -814,10 +818,6 @@ struct svn_membuffer_t
*/
#define ALIGN_VALUE(value) (((value) + ITEM_ALIGNMENT-1) & -ITEM_ALIGNMENT)
-/* Align POINTER value to the next ITEM_ALIGNMENT boundary.
- */
-#define ALIGN_POINTER(pointer) ((void*)ALIGN_VALUE((apr_size_t)(char*)(pointer)))
-
/* If locking is supported for CACHE, acquire a read lock for it.
*/
static svn_error_t *
@@ -1827,28 +1827,6 @@ ensure_data_insertable_l1(svn_membuffer_
* right answer. */
}
-/* Mimic apr_pcalloc in APR_POOL_DEBUG mode, i.e. handle failed allocations
- * (e.g. OOM) properly: Allocate at least SIZE bytes from POOL and zero
- * the content of the allocated memory if ZERO has been set. Return NULL
- * upon failed allocations.
- *
- * Also, satisfy our buffer alignment needs for performance reasons.
- */
-static void* secure_aligned_alloc(apr_pool_t *pool,
- apr_size_t size,
- svn_boolean_t zero)
-{
- void* memory = apr_palloc(pool, size + ITEM_ALIGNMENT);
- if (memory != NULL)
- {
- memory = ALIGN_POINTER(memory);
- if (zero)
- memset(memory, 0, size);
- }
-
- return memory;
-}
-
svn_error_t *
svn_cache__membuffer_cache_create(svn_membuffer_t **cache,
apr_size_t total_size,
@@ -2017,10 +1995,11 @@ svn_cache__membuffer_cache_create(svn_me
c[seg].l2.last = NO_INDEX;
c[seg].l2.next = NO_INDEX;
c[seg].l2.start_offset = c[seg].l1.size;
- c[seg].l2.size = data_size - c[seg].l1.size;
+ c[seg].l2.size = ALIGN_VALUE(data_size) - c[seg].l1.size;
c[seg].l2.current_data = c[seg].l2.start_offset;
- c[seg].data = secure_aligned_alloc(pool, (apr_size_t)data_size, FALSE);
+ /* This cast is safe because DATA_SIZE <= MAX_SEGMENT_SIZE. */
+ c[seg].data = apr_palloc(pool, (apr_size_t)ALIGN_VALUE(data_size));
c[seg].data_used = 0;
c[seg].max_entry_size = max_entry_size;
@@ -2409,7 +2388,7 @@ membuffer_cache_get_internal(svn_membuff
}
size = ALIGN_VALUE(entry->size) - entry->key.key_len;
- *buffer = ALIGN_POINTER(apr_palloc(result_pool, size + ITEM_ALIGNMENT-1));
+ *buffer = apr_palloc(result_pool, size);
memcpy(*buffer, cache->data + entry->offset + entry->key.key_len, size);
#ifdef SVN_DEBUG_CACHE_MEMBUFFER