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 2015/05/17 16:07:21 UTC
svn commit: r1679859 -
/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
Author: stefan2
Date: Sun May 17 14:07:21 2015
New Revision: 1679859
URL: http://svn.apache.org/r1679859
Log:
On the 1.10-cache-improvements branch:
Instead of carefully limiting the key sizes and checking those limits,
make all length fields in entry_t and entry_key_t SIZE_Ts. This saves
a number of down-/shortening casts as well as key-length limiter code.
The limit for what item size we will actually cache stays in place.
On the downside, we each entry bucket (entry_group_t) can hold only 7
entries now - down from 10 in /trunk. This is due to added fields to
and enlarging fields in the entry_t struct.
This practically undoes r1679679 and r1679687.
* subversion/libsvn_subr/cache-membuffer.c
(entry_key_t): Extend KEY_LEN to size_t and reorder members to give them
natural alignment.
(entry_t): Extend item SIZE element to size_t.
(membuffer_cache_set_internal,
membuffer_cache_set_partial_internal): Remove obsolete shortening casts.
(combine_long_key,
svn_cache__create_membuffer_cache): Use size_t with all lengths. Drop key
length limiter code and conversions.
Modified:
subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
Modified: subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c?rev=1679859&r1=1679858&r2=1679859&view=diff
==============================================================================
--- subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c Sun May 17 14:07:21 2015
@@ -207,15 +207,15 @@ typedef struct entry_key_t
/* 16 byte finger print of the full key. */
apr_uint64_t fingerprint[2];
+ /* Length of the full key. This value is aligned to ITEM_ALIGNMENT to
+ * make sure the subsequent item content is properly aligned. If 0,
+ * PREFIX_KEY is implied to be != NO_INDEX. */
+ apr_size_t key_len;
+
/* Unique index of the shared key prefix, i.e. it's index within the
* prefix pool (see prefix_pool_t). NO_INDEX if the key prefix is not
* shared, otherwise KEY_LEN==0 is implied. */
apr_uint32_t prefix_idx;
-
- /* Length of the full key. This value is aligned to ITEM_ALIGNMENT to
- * make sure the subsequent item content is properly aligned. If 0,
- * PREFIX_KEY is implied to be != NO_INDEX. */
- apr_uint32_t key_len;
} entry_key_t;
/* A full key, i.e. the combination of the cache's key prefix with some
@@ -553,7 +553,7 @@ typedef struct entry_t
* above ensures that there will be no overflows.
* Only valid for used entries.
*/
- apr_uint32_t size;
+ apr_size_t size;
/* Number of (read) hits for this entry. Will be reset upon write.
* Only valid for used entries.
@@ -2218,7 +2218,7 @@ membuffer_cache_set_internal(svn_membuff
* negative value.
*/
cache->data_used += (apr_uint64_t)size - entry->size;
- entry->size = (apr_uint32_t) size;
+ entry->size = size;
entry->priority = priority;
#ifdef SVN_DEBUG_CACHE_MEMBUFFER
@@ -2251,7 +2251,7 @@ membuffer_cache_set_internal(svn_membuff
* the serialized item's (future) position within data buffer.
*/
entry = find_entry(cache, group_index, to_find, TRUE);
- entry->size = (apr_uint32_t) size;
+ entry->size = size;
entry->offset = level->current_data;
entry->priority = priority;
@@ -2677,7 +2677,7 @@ membuffer_cache_set_partial_internal(svn
/* Write the new entry.
*/
entry = find_entry(cache, group_index, to_find, TRUE);
- entry->size = (apr_uint32_t) (item_size + key_len);
+ entry->size = item_size + key_len;
entry->offset = cache->l1.current_data;
if (key_len)
@@ -2801,32 +2801,14 @@ combine_long_key(svn_membuffer_cache_t *
{
apr_uint32_t *digest_buffer;
char *key_copy;
- apr_uint32_t prefix_len = cache->prefix.entry_key.key_len;
- apr_uint32_t aligned_key_len;
+ apr_size_t prefix_len = cache->prefix.entry_key.key_len;
+ apr_size_t aligned_key_len;
/* handle variable-length keys */
if (key_len == APR_HASH_KEY_STRING)
key_len = strlen((const char *) key);
- /* Paranoia: Ridiculously long keys.
- *
- * We can't cache combined keys of 4GB and longer anyways. So, putting
- * a cap on them just above the maximum cachable value keeps them still
- * non-cachable but allows us to cast to u32.
- */
- assert(MAX_ITEM_SIZE < APR_UINT32_MAX);
- if (APR_UINT32_MAX - prefix_len <= key_len)
- {
- /* Non-cachable. Cap values. No data alignment needed. */
- key_len = APR_UINT32_MAX - prefix_len;
- aligned_key_len = APR_UINT32_MAX - prefix_len;
- }
- else
- {
- /* Cast is safe.
- * Key and item may be cachable, so item alignment is necessary. */
- aligned_key_len = ALIGN_VALUE((apr_uint32_t)key_len);
- }
+ aligned_key_len = ALIGN_VALUE(key_len);
/* Combine keys. */
svn_membuf__ensure(&cache->combined_key.full_key,
@@ -3361,19 +3343,6 @@ svn_cache__create_membuffer_cache(svn_ca
prefix_orig_len = strlen(prefix) + 1;
prefix_len = ALIGN_VALUE(prefix_orig_len);
- assert(MAX_ITEM_SIZE < APR_UINT32_MAX);
- if (prefix_len > MAX_ITEM_SIZE)
- {
- /* We should never ever get here but the above check makes the cast
- * to u32 further down safe. We may also catch missing parameter
- * initializations here. */
- return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
- "Cache prefix length of %" APR_UINT64_T_FMT
- " exceeds maximum of %" APR_UINT64_T_FMT
- " bytes\n", (apr_uint64_t)prefix_len,
- (apr_uint64_t)MAX_ITEM_SIZE);
- }
-
svn_membuf__create(&cache->prefix.full_key, prefix_len, result_pool);
memcpy((char *)cache->prefix.full_key.data, prefix, prefix_orig_len);
memset((char *)cache->prefix.full_key.data + prefix_orig_len, 0,
@@ -3387,7 +3356,7 @@ svn_cache__create_membuffer_cache(svn_ca
scratch_pool));
memcpy(cache->prefix.entry_key.fingerprint, checksum->digest,
sizeof(cache->prefix.entry_key.fingerprint));
- cache->prefix.entry_key.key_len = (apr_uint32_t)prefix_len;
+ cache->prefix.entry_key.key_len = prefix_len;
/* Fix-length keys of up to 16 bytes may be handled without storing the
* full key separately for each item. */