summaryrefslogtreecommitdiff
path: root/src/mwindow.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove sus unsigned long constantCalvin Buckley2021-07-071-1/+1
|
* Convert long long constant specifiers to stdint macrosCalvin Buckley2021-07-071-1/+1
|
* mwindow: Fix a bug in the LRU window finding codelhchavez2021-01-201-1/+3
| | | | | | | This change now updates the `lru_window` variable to match the current file's MRU window. This makes it such that it doesn't always choose the file that happened to come last in the list of window files, and instead should now correctly choose the file with the least-recently-used one.
* threads: rename git_atomic to git_atomic32Edward Thomson2020-12-061-3/+3
| | | | | Clarify the `git_atomic` type and functions now that we have a 64 bit version as well (`git_atomic64`).
* Make the pack and mwindow implementations data-race-freelhchavez2020-11-281-46/+74
| | | | | | | | | | | | | | | | | | | | | | | | | This change fixes a packfile heap corruption that can happen when interacting with multiple packfiles concurrently across multiple threads. This is exacerbated by setting a lower mwindow open file limit. This change: * Renames most of the internal methods in pack.c to clearly indicate that they expect to be called with a certain lock held, making reasoning about the state of locks a bit easier. * Splits the `git_pack_file` lock in two: the one in `git_pack_file` only protects the `index_map`. The protection to `git_mwindow_file` is now in that struct. * Explicitly checks for freshness of the `git_pack_file` in `git_packfile_unpack_header`: this allows the mwindow implementation to close files whenever there is enough cache pressure, and `git_packfile_unpack_header` will reopen the packfile if needed. * After a call to `p_munmap()`, the `data` and `len` fields are poisoned with `NULL` to make use-after-frees more evident and crash rather than being open to the possibility of heap corruption. * Adds a test case to prevent this from regressing in the future. Fixes: #5591
* mwindow: use GIT_ASSERTEdward Thomson2020-11-271-15/+21
|
* runtime: move init/shutdown into the "runtime"Edward Thomson2020-10-111-6/+7
| | | | | Provide a mechanism for system components to register for initialization and shutdown of the libgit2 runtime.
* mwindow: localize mutexEdward Thomson2020-10-111-2/+11
| | | | | | Move the mwindow mutex into the mwindow code itself, initializing it in the mwindow global initialization function instead of in the global initializer.
* Preserve behaviour of `git_mwindow_scan_recently_used` with `*out_window` setAndrew Hickman2020-08-051-2/+9
|
* Fix `git_mwindow_scan_recently_used` spuriously returning trueAndrew Hickman2020-08-051-5/+1
|
* Minor nits and style formattinglhchavez2020-07-121-2/+3
|
* Review feedbacklhchavez2020-06-261-56/+95
| | | | | | | | | | * Change the default of the file limit to 0 (unlimited). * Changed the heuristic to close files to be the file that contains the least-recently-used window such that the window is the most-recently-used in the file, and the file does not have in-use windows. * Parameterized the filelimit test to check for a limit of 1 and 100 open windows.
* mwindow: set limit on number of open fileslhchavez2020-06-211-15/+45
| | | | | | | | | | | | | | | | | | There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR #5386, originally written by @josharian. Fixes: #2758
* internal: use off64_t instead of git_off_tethomson/off_tEdward Thomson2019-11-251-9/+9
| | | | Prefer `off64_t` internally.
* fileops: rename to "futils.h" to match function signaturesPatrick Steinhardt2019-07-201-1/+1
| | | | | | | | | Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
* maps: provide return value when deleting entriesPatrick Steinhardt2019-02-151-4/+2
| | | | | | | | | | Currently, the delete functions of maps do not provide a return value. Like this, it is impossible to tell whether the entry has really been deleted or not. Change the implementation to provide either a return value of zero if the entry has been successfully deleted or `GIT_ENOTFOUND` if the key could not be found. Convert callers to the `delete_at` functions to instead use this higher-level interface.
* strmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-1/+1
| | | | | | | | | | | | Currently, one would use the function `git_strmap_insert` to insert key/value pairs into a map. This function has historically been a macro, which is why its syntax is kind of weird: instead of returning an error code directly, it instead has 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. Introduce a new function `git_strmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all callers of `git_strmap_insert` to make use of it.
* strmap: introduce `git_strmap_get` and use it throughout the treePatrick Steinhardt2019-02-151-7/+4
| | | | | | | | | | | | | | 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_strmap_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-1/+1
| | | | | | | | | | | | | | | | 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.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-6/+6
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-2/+2
| | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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.
* strmap: remove GIT__USE_STRMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-1/+1
|
* 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
* mwindow: init mwindow files in git_libgit2_initethomson/mwindow_initEdward Thomson2016-08-041-19/+8
|
* mwindow: free unused windows if we fail to mmapcmn/mwindow-try-harderCarlos Martín Nieto2016-03-091-2/+12
| | | | | | The first time may be due to memory fragmentation or just bad luck on a 32-bit system. When we hit the mmap error for the first time, free up the unused windows and try again.
* Remove extra semicolon outside of a functionStefan Widgren2015-02-151-1/+1
| | | | | Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
* mwindow: clean up pack map at shutdownEdward Thomson2014-10-261-0/+2
|
* pack: clean up error returnsCarlos Martín Nieto2014-06-251-12/+10
| | | | | | | | | Set a message when we fail to lock. Also make the put function void, since it's called from free, which cannot report errors. The only errors we can experience here are internal state corruption, so we assert that we are trying to put a pack which we have previously got.
* pack: free the new pack struct if we fail to insertCarlos Martín Nieto2014-06-251-1/+4
| | | | | | | | If we fail to insert the packfile in the map, make sure to free it. This makes the free function only attempt to remove its mwindows from the global list if we have opened the packfile to avoid accessing the list unlocked.
* Share packs across repository instancescmn/global-mwfCarlos Martín Nieto2014-06-231-8/+116
| | | | | | | | | | | Opening the same repository multiple times will currently open the same file multiple times, as well as map the same region of the file multiple times. This is not necessary, as the packfile data is immutable. Instead of opening and closing packfiles directly, introduce an indirection and allocate packfiles globally. This does mean locking on each packfile open, but we already use this lock for the global mwindow list so it doesn't introduce a new contention point.
* Further threading fixesRussell Belfer2013-04-221-1/+1
| | | | | | | | | | | | | This builds on the earlier thread safety work to make it so that setting the odb, index, refdb, or config for a repository is done in a threadsafe manner with minimized locking time. This is done by adding a lock to the repository object and using it to guard the assignment of the above listed pointers. The lock is only held to assign the pointer value. This also contains some minor fixes to the other work with pack files to reduce the time that locks are being held to and fix an apparently memory leak.
* Several warnings detected by static code analyzer fixedArkadiy Shapkin2013-03-181-3/+3
| | | | | | | Implicit type conversion argument of function to size_t type Suspicious sequence of types castings: size_t -> int -> size_t Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)' Unsigned type is never < 0
* Global options setterVicent Marti2013-01-231-16/+7
|
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* git_mwindow_file_deregister() shouldn't return errorsScott J. Goldman2013-01-051-9/+4
| | | | | | | | | | | As a function that appears to only be called on error paths, I don't think it makes sense for it to return an error, or clobber the global giterr. Note that no existing callsites actually check the return code. In my own application, there are errors where the real error ends up being hidden, as git_mwindow_file_deregister() clobbers the global giterr. I'm not sure this error is even relevant?
* Always check the result of git_mutex_lockJustin Spahr-Summers2012-12-091-5/+24
|
* Make the memory-window conrol structures globalCarlos Martín Nieto2012-08-201-11/+37
| | | | | | | | | | | | | Up to now, the idea was that the user would do all the operations for one repository in the same thread. Thus we could have the memory-mapped window information thread-local and avoid any locking. This is not practical in a few environments, such as Apple's GCD which allocates threads arbitrarily or the .NET CLR, where the OS-level thread can change at any moment. Make the control structure global and protect it with a mutex so we don't depend on the thread currently executing the code.
* mwindow: allow memory-window files to deregisterCarlos Martin Nieto2012-06-281-0/+17
| | | | | | | | | Once a file is registered, there is no way to deregister it, even after the structure that contains it is no longer needed and has been freed. This may be the source of #624. Allow and use the deregister function to remove our file from the global list.
* Actually do the mmap... unsurprisingly, this makes the indexer work on SFSChris Young2012-06-121-0/+1
| | | | | On RAM: the .idx and .pack files become links to a .lock and the original download respectively. Assume some feature (such as record locking) supported by SFS but not JXFS or RAM: is required.
* Remove left-over debugging outputCarlos Martín Nieto2012-05-231-2/+0
|
* Update test suiteVicent Martí2012-05-021-2/+1
|
* Merge branch 'new-error-handling' into developmentVicent Martí2012-05-021-27/+27
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .travis.yml include/git2/diff.h src/config_file.c src/diff.c src/diff_output.c src/mwindow.c src/path.c tests-clar/clar_helpers.c tests-clar/object/tree/frompath.c tests/t00-core.c tests/t03-objwrite.c tests/t08-tag.c tests/t10-refs.c tests/t12-repo.c tests/t18-status.c tests/test_helpers.c tests/test_main.c
| * indexer: start writing the stream indexerCarlos Martín Nieto2012-04-131-1/+5
| | | | | | | | | | | | This will allow us to index a packfile as soon as we receive it from the network as well as storing it with its final name so we don't need to pass temporary file names around.
| * Convert attr, ignore, mwindow, status to new errorsRussell Belfer2012-03-161-15/+16
| | | | | | | | | | Also cleaned up some previously converted code that still had little things to polish.
| * Continue error conversionRussell Belfer2012-03-141-1/+1
| | | | | | | | | | | | | | This converts blob.c, fileops.c, and all of the win32 files. Also, various minor cleanups throughout the code. Plus, in testing the win32 build, I cleaned up a bunch (although not all) of the warnings with the 64-bit build.
| * Migrate ODB files to new error handlingRussell Belfer2012-03-121-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to the new style of error handling. Also got the unix and win32 versions of map.c. There are some minor changes to other files but no others were completely converted. This also contains an update to filebuf so that a zeroed out filebuf will not think that the fd (== 0) is actually open (and inadvertently call close() on fd 0 if cleaned up). Lastly, this was built and tested on win32 and contains a bunch of fixes for the win32 build which was pretty broken.
* | mwindow: make sure the whole range is contained inside the same windowCarlos Martín Nieto2012-04-041-3/+4
|/ | | | | | | | | Looking through the open windows to check whether we can re-use an open window should take into account whether both `offset` and `offset + extra` are contained within the same window. Failure to do so can lead to invalid memory accesses. This closes #614. While we're in the area remove an outdated assert.
* Update Copyright headerschu2012-02-131-1/+1
| | | | Signed-off-by: schu <schu-github@schulog.org>