-
Notifications
You must be signed in to change notification settings - Fork 255
Add a LRU cache to limit indexing memory usage. #2079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3bbf3eb
Add a LRU cache to limit indexing memory usage.
Lucccyo f20f772
Add changelog for #2079
voodoos 5ae38c7
Promote test change
voodoos 70af090
refmt
voodoos 88680e9
On_disk_small: Reuse store and loc from parents
voodoos 8873a25
Promote parent in LRU when fetching a child
voodoos 6f1f871
Rename fetch_parent
voodoos 418a890
Make schema optional in `On_disk` to remove placeholder usages of `On…
voodoos ba73179
Factorize merge_union function
voodoos ebd1f00
Always upgrade reused links schemas
voodoos a07ff2a
Serialized should use the same cache logic as Serialized_reused
voodoos 3b94bad
Store info directly in `In_cache` instead of the LRU cell
voodoos 5cbfbd0
Use kb for chache size flag, default to 1gb
voodoos d8c9331
Remove todo
voodoos bc9c08e
Document default cache size
voodoos ba39e1e
find_and_wompress: directly return the root
voodoos daf5b2a
Union_find.union, no need for a new link
voodoos 50cd87a
Make the union find store more granular.
voodoos 69afef5
Add missing cache use
voodoos d9e1c02
Factor out the cache logic
voodoos b80cfc7
Also skip smalls that have already been skipped
voodoos 5a288d9
Remove unused Serialized_reused
voodoos 7b8bf4c
Remove remaining occurrence of Serialized_reused
voodoos 8302914
Split On_disk_ptr in two to better distinguish smalls
voodoos 50c0ad2
Push missing fix
voodoos f5205a0
Fix Union_find.merge in the general case
voodoos 844955d
In_cache: remove redundant status field
voodoos ee42496
Refactor Union_find.merge
voodoos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| type 'a cell = | ||
| { content : 'a; weight : int; mutable prev : 'a cell; mutable next : 'a cell } | ||
|
|
||
| type stats = | ||
| { mutable total_cap : int; | ||
| mutable promote_count : int; | ||
| mutable add_count : int; | ||
| mutable discard_count : int; | ||
| mutable add_size : int; | ||
| mutable discarded_size : int | ||
| } | ||
|
|
||
| type 'a dbll = | ||
| | Nil of int | ||
| | List of { first : 'a cell; last : 'a cell; size : int; cap : int } | ||
|
|
||
| type 'a t = { mutable dbll : 'a dbll; stats : stats } | ||
|
|
||
| exception Action_on_empty_list of string | ||
|
|
||
| let pp_stats t = | ||
| let size = | ||
| match t.dbll with | ||
| | Nil _ -> 0 | ||
| | List l -> l.size | ||
| in | ||
| Printf.eprintf | ||
| "total_cap \t\t: %d\n\ | ||
| size \t\t: %d\n\ | ||
| promote_count \t: %d\n\ | ||
| add_count \t\t: %d\n\ | ||
| discard_count \t: %d\n\ | ||
| add_size \t\t: %d\n\ | ||
| discard_size \t: %d\n\ | ||
| volume_conservation \t: %d = %d + %d : %b\n\ | ||
| %!" | ||
| t.stats.total_cap size t.stats.promote_count t.stats.add_count | ||
| t.stats.discard_count t.stats.add_size t.stats.discarded_size | ||
| t.stats.add_size t.stats.discarded_size size | ||
| (t.stats.add_size = t.stats.discarded_size + size) | ||
|
|
||
| let create cap = | ||
| let stats = | ||
| { total_cap = cap; | ||
| promote_count = 0; | ||
| add_count = 0; | ||
| discard_count = 0; | ||
| add_size = 0; | ||
| discarded_size = 0 | ||
| } | ||
| in | ||
| { dbll = Nil cap; stats } | ||
|
|
||
| let add_front t (v, w) = | ||
| t.stats.add_count <- t.stats.add_count + 1; | ||
| t.stats.add_size <- t.stats.add_size + w; | ||
| match t.dbll with | ||
| | Nil cap -> | ||
| let rec c = { content = v; weight = w; prev = c; next = c } in | ||
| t.dbll <- List { first = c; last = c; size = w; cap }; | ||
| c | ||
| | List l -> | ||
| let rec new_first = | ||
| { content = v; weight = w; prev = new_first; next = l.first } | ||
| in | ||
| l.first.prev <- new_first; | ||
| t.dbll <- | ||
| List { first = new_first; last = l.last; size = l.size + w; cap = l.cap }; | ||
| new_first | ||
|
|
||
| let discard t = | ||
| t.stats.discard_count <- t.stats.discard_count + 1; | ||
| match t.dbll with | ||
| | Nil _ -> | ||
| raise | ||
| (Action_on_empty_list | ||
| "Unable to discard the last element, the doubly linked list is empty.") | ||
| | List l -> | ||
| if l.first == l.last then ( | ||
| t.dbll <- Nil l.cap; | ||
| t.stats.discarded_size <- t.stats.discarded_size + l.last.weight; | ||
| l.last.content) | ||
| else | ||
| let discarded_value = l.last.content in | ||
| let discarded_weight = l.last.weight in | ||
| t.stats.discarded_size <- t.stats.discarded_size + discarded_weight; | ||
| let new_last = l.last.prev in | ||
| (* TODO Should we explicitely disconnect last's pointers ? *) | ||
| new_last.next <- new_last; | ||
| (* TODO Int.max 0 (l.size - discarded_weight) does seems useless. | ||
| We could use an assert to check it. *) | ||
| (* Unlinking the discaded cell is not strictly necessary but not doing it | ||
| could lead to memory leaks if the user of the cache keeps a reference | ||
| to the cell. *) | ||
| l.last.next <- l.last; | ||
| l.last.prev <- l.last; | ||
| t.dbll <- | ||
| List | ||
| { first = l.first; | ||
| last = new_last; | ||
| size = Int.max 0 (l.size - discarded_weight); | ||
| cap = l.cap | ||
| }; | ||
| discarded_value | ||
|
|
||
| let discard_size t s = | ||
| (* this is fold not iter *) | ||
| let rec iter acc t = | ||
| match t.dbll with | ||
| | Nil _ -> acc | ||
| | List l -> if l.size + s <= l.cap then acc else iter (discard t :: acc) t | ||
| in | ||
| iter [] t | ||
|
|
||
| let promote t c = | ||
| t.stats.promote_count <- t.stats.promote_count + 1; | ||
| match t.dbll with | ||
| | Nil _ -> | ||
| raise | ||
| (Action_on_empty_list | ||
| "Unable to promote a cell, the doubly linked list is empty.") | ||
| | List l -> | ||
| if l.first == c then () | ||
| else if l.last == c then ( | ||
| let new_last = l.last.prev in | ||
| new_last.next <- new_last; | ||
| let new_first = c in | ||
| new_first.next <- l.first; | ||
| new_first.prev <- new_first; | ||
| l.first.prev <- new_first; | ||
| t.dbll <- | ||
| List { first = new_first; last = new_last; size = l.size; cap = l.cap }) | ||
| else | ||
| let voisin_prev = c.prev in | ||
| let voisin_next = c.next in | ||
| voisin_prev.next <- voisin_next; | ||
| voisin_next.prev <- voisin_prev; | ||
| let new_first = c in | ||
| new_first.prev <- new_first; | ||
| new_first.next <- l.first; | ||
| l.first.prev <- new_first; | ||
| t.dbll <- | ||
| List { first = new_first; last = l.last; size = l.size; cap = l.cap } | ||
|
|
||
| let get c = c.content | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| type 'a cell = | ||
| { content : 'a; weight : int; mutable prev : 'a cell; mutable next : 'a cell } | ||
|
|
||
| type stats = | ||
| { mutable total_cap : int; | ||
| mutable promote_count : int; | ||
| mutable add_count : int; | ||
| mutable discard_count : int; | ||
| mutable add_size : int; | ||
| mutable discarded_size : int | ||
| } | ||
|
|
||
| type 'a dbll = | ||
| | Nil of int | ||
| | List of { first : 'a cell; last : 'a cell; size : int; cap : int } | ||
|
|
||
| type 'a t = { mutable dbll : 'a dbll; stats : stats } | ||
|
|
||
| exception Action_on_empty_list of string | ||
|
|
||
| val pp_stats : 'a t -> unit | ||
| val create : int -> 'a t | ||
| val add_front : 'a t -> 'a * int -> 'a cell | ||
| val discard_size : 'a t -> int -> 'a list | ||
| val promote : 'a t -> 'a cell -> unit | ||
| val get : 'a cell -> 'a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some TODOs here with nice ideas :) (but not essentials)