summaryrefslogtreecommitdiff
path: root/src/cache.c
Commit message (Collapse)AuthorAgeFilesLines
* cache: fix cache eviction using deallocated keyPatrick Steinhardt2019-05-241-2/+1
| | | | | | | | | | | | | | | When evicting cache entries, we first retrieve the object that is to be evicted, delete the object and then finally delete the key from the cache. In case where the cache eviction caused us to free the cached object, though, its key will point to invalid memory now when trying to remove it from the cache map. On my system, this causes us to not properly remove the key from the map, as its memory has been overwritten already and thus the key lookup it will fail and we cannot delete it. Fix this by only decrementing the refcount of the evictee after we have removed it from our cache map. Add a test that caused a segfault previous to that change.
* Merge pull request #4901 from pks-t/pks/uniform-map-apiEdward Thomson2019-02-221-31/+22
|\ | | | | High-level map APIs
| * cache: use iteration interface for cache evictionPatrick Steinhardt2019-02-151-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To relieve us from memory pressure, we may regularly call `cache_evict_entries` to remove some entries from it. Unfortunately, our cache does not support a least-recently-used mode or something similar, which is why we evict entries completeley at random right now. Thing is, this is only possible due to the map interfaces exposing the entry indices, and we intend to completely remove those to decouple map users from map implementations. As soon as that is done, we are unable to do this random eviction anymore. Convert this to make use of an iterator for now. Obviously, there is no random eviction possible like that anymore, but we'll always start by evicting from the beginning of the map. Due to hashing, one may hope that the selected buckets will be evicted at least in some way unpredictably. But more likely than not, this will not be the case. But let's see what happens and if any users complain about degraded performance. If so, we might come up with a different scheme than random removal, e.g. by using an LRU cache.
| * oidmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, one would use either `git_oidmap_insert` to insert key/value pairs into a map or `git_oidmap_put` to insert a key only. These function have historically been macros, which is why their syntax is kind of weird: instead of returning an error code directly, they instead have to be passed a pointer to where the return value shall be stored. This does not match libgit2's common idiom of directly returning error codes.Furthermore, `git_oidmap_put` is tightly coupled with implementation details of the map as it exposes the index of inserted entries. Introduce a new function `git_oidmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all trivial callers of `git_oidmap_insert` and `git_oidmap_put` to make use of it.
| * oidmap: introduce high-level getter for valuesPatrick Steinhardt2019-02-151-15/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The current way of looking up an entry from a map is tightly coupled with the map implementation, as one first has to look up the index of the key and then retrieve the associated value by using the index. As a caller, you usually do not care about any indices at all, though, so this is more complicated than really necessary. Furthermore, it invites for errors to happen if the correct error checking sequence is not being followed. Introduce a new high-level function `git_oidmap_get` that takes a map and a key and returns a pointer to the associated value if such a key exists. Otherwise, a `NULL` pointer is returned. Adjust all callers that can trivially be converted.
| * maps: use uniform lifecycle management functionsPatrick Steinhardt2019-02-151-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the lifecycle functions for maps (allocation, deallocation, resize) are not named in a uniform way and do not have a uniform function signature. Rename the functions to fix that, and stick to libgit2's naming scheme of saying `git_foo_new`. This results in the following new interface for allocation: - `int git_<t>map_new(git_<t>map **out)` to allocate a new map, returning an error code if we ran out of memory - `void git_<t>map_free(git_<t>map *map)` to free a map - `void git_<t>map_clear(git<t>map *map)` to remove all entries from a map This commit also fixes all existing callers.
* | cache: fix misnaming of `git_cache_free`Patrick Steinhardt2019-02-211-1/+1
|/ | | | | | | | | Functions that free a structure's contents but not the structure itself shall be named `dispose` in the libgit2 project, but the function `git_cache_free` does not follow this naming pattern. Fix this by renaming it to `git_cache_dispose` and adjusting all callers to make use of the new name.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-3/+3
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-011-10/+10
| | | | Use the new object_type enumeration names within the codebase.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-3/+3
| | | | | | | Instead of using the `khiter_t`, `git_strmap_iter` and `khint_t` types, simply use `size_t` instead. This decouples code from the khash stuff and makes it possible to move the khash includes into the implementation files.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* oidmap: remove GIT__USE_OIDMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-1/+1
|
* khash: avoid using `kh_key`/`kh_val` as lvaluePatrick Steinhardt2017-02-171-2/+2
|
* khash: avoid using `kh_del` directlyPatrick Steinhardt2017-02-171-1/+1
|
* khash: avoid using `kh_key` directlyPatrick Steinhardt2017-02-171-4/+2
|
* khash: avoid using `kh_val`/`kh_value` directlyPatrick Steinhardt2017-02-171-5/+5
|
* khash: avoid using `kh_exist` directlyPatrick Steinhardt2017-02-171-1/+1
|
* khash: avoid using `kh_clear` directlyPatrick Steinhardt2017-02-171-1/+1
|
* khash: avoid using `kh_get` directlyPatrick Steinhardt2017-02-171-2/+2
|
* khash: avoid using `kh_end` directlyPatrick Steinhardt2017-02-171-3/+3
|
* khash: avoid using `kh_foreach`/`kh_foreach_value` directlyPatrick Steinhardt2017-02-171-2/+2
|
* khash: avoid using `kh_size` directlyPatrick Steinhardt2017-02-171-5/+5
|
* giterr_set: consistent error messagesEdward Thomson2016-12-291-1/+1
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* Fix #3094 - improve use of portable size_t/ssize_t format specifiers.Matthew Plough2015-07-121-4/+4
| | | | The header src/cc-compat.h defines portable format specifiers PRIuZ, PRIdZ, and PRIxZ. The original report highlighted the need to use these specifiers in examples/network/fetch.c. For this commit, I checked all C source and header files not in deps/ and transitioned to the appropriate format specifier where appropriate.
* cache: add a check for a failed allocationCarlos Martín Nieto2015-06-101-0/+1
| | | | Rather minimal change, but it's the kind of thing we should do.
* Refactor git_cache to use an rwlockJustin Spahr-Summers2014-08-261-9/+9
| | | | | This significantly reduces contention when many threads are trying to read from the cache simultaneously.
* util: It's called `memzero`Vicent Marti2013-06-121-1/+1
|
* Add safe memset and use itRussell Belfer2013-06-071-1/+1
| | | | | | This adds a `git__memset` routine that will not be optimized away and updates the places where I memset() right before a free() call to use it.
* Mutex init can failRussell Belfer2013-05-311-1/+4
| | | | | | | It is obviously quite a serious problem if this happens, but mutex initialization can fail and we should detect it. It's a bit like a memory allocation failure, in that you're probably pretty screwed if this occurs, but at least we'll catch it.
* Zero memory for major objects before freeingRussell Belfer2013-05-311-2/+2
| | | | | | | By zeroing out the memory when we free larger objects (i.e. those that serve as collections of other data, such as repos, odb, refdb), I'm hoping that it will be easier for libgit2 bindings to find errors in their object management code.
* Docs for git_libgit2_opts and cache disable tweakRussell Belfer2013-05-241-0/+5
| | | | | | | This adds docs for the cache control options to git_libgit2_opts and also tweaks the cache code so that if the cache is disabled, then the next time we attempt to insert something into the cache in question, we will actually clear any old cached objects.
* git_atomic_ssize for 64-bit atomics only on 64-bit platformsEdward Thomson2013-04-251-6/+7
|
* repo: Add `git_repository__cleanup`Vicent Marti2013-04-241-0/+3
|
* opts: Add getter for cached memoryvmg/atomic64Vicent Marti2013-04-231-2/+1
|
* cache: More aggressive defaultVicent Marti2013-04-221-1/+1
|
* cache: Shared meter for memory usageVicent Marti2013-04-221-4/+12
|
* cache: Max cache size, and evict when the cache fills upvmg/new-cacheVicent Marti2013-04-221-7/+18
|
* Add callback to git_objects_tableRussell Belfer2013-04-221-6/+8
| | | | | | | | | | This adds create and free callback to the git_objects_table so that more of the creation and destruction of objects can be table driven instead of using switch statements. This also makes the semantics of certain object creation functions consistent so that we can make better use of function pointers. This also fixes a theoretical error case where an object allocation fails and we end up storing NULL into the cache.
* Add range checking around cache optsRussell Belfer2013-04-221-6/+17
| | | | | | | Add a git_cache_set_max_object_size method that does more checking around setting the max object size. Also add a git_cache_size to read the number of objects currently in the cache. This makes it easier to write tests.
* Global option settersVicent Marti2013-04-221-6/+4
|
* Clear the cache when there are too many items to expireVicent Marti2013-04-221-1/+20
|
* Some statsVicent Marti2013-04-221-0/+21
|
* Per-object max sizeVicent Marti2013-04-221-28/+28
|
* What has science done.Vicent Marti2013-04-221-2/+2
|
* Random evictionVicent Marti2013-04-221-1/+18
|
* Per-object filteringVicent Marti2013-04-221-6/+31
|
* lol this worked first try wtfVicent Marti2013-04-221-61/+108
|
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* orite C89Justin Spahr-Summers2012-12-091-2/+2
|