Skip to content
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

Revert "Ipv4.Fragments: use a mutable LRU cache (Lru.M.t instead of mutable cache : Lru.F.t):" #423

Merged
merged 1 commit into from Feb 8, 2020

Conversation

hannesm
Copy link
Member

@hannesm hannesm commented Feb 7, 2020

This reverts commit 2201224.

The motivation behind this change is that Lru.M.t uses a hashtable, pre-allocated in the size of the capacity (256 * 1024 ~> 2MB just for the keys (stored in an array)). This leads to quite some memory usage (as observed in mirage/qubes-mirage-firewall#93).

But the issue is slightly more complex: an OCaml hashtable has amortized time complexity of O(1), but in worst cases it may be much bigger (adding an element may lead to resize, which means allocation of a fresh array, re-hashing of all keys, and copying) -- leading to unpredictable behaviour, which is not what we want in real systems. Also, a hashtable is never shrinking its array.

I'm fine to revert this change once we find the performance bottleneck being in the IPv4 fragment cache.

//cc @talex5

@xaki23
Copy link

xaki23 commented Feb 7, 2020

build works, can not test functionality right now because it makes mirage-nat fail to build.

@hannesm hannesm merged commit 6144aa5 into mirage:master Feb 8, 2020
@hannesm hannesm deleted the fragments-lru-f branch February 8, 2020 10:33
hannesm added a commit to hannesm/opam-repository that referenced this pull request Feb 8, 2020
CHANGES:

* Revert "Ipv4.Fragments use a Lru.M.t instead of Lru.F.t" (mirage/mirage-tcpip#423 by @hannesm)
  A Lru.M.t allocates a Hashtbl.t of size = capacity (= 256 * 1024 in our case),
  this leads to excessive ~2MB memory consumption for each Fragment cache,
  reported by @xaki23 in mirage/qubes-mirage-firewall#93
* use SOCK_RAW for an ICMP socket in the unix sockets API (previously used
  SOCK_DGRAM which did not work)
  reported by @justinc1 in mirage/mirage-tcpip#358, fixed in mirage/mirage-tcpip#424 by @hannesm
* tcp is now compatible with lwt >= 5.0.0 (where Lwt.async requires a function
  of (unit -> unit Lwt.t) (mirage/mirage-tcpip#370 mirage/mirage-tcpip#425 @cfcs @hannesm, issue mirage/mirage-tcpip#392 @emillon)
* Add a dependency on dune-configurator to support dune 2.0.0 (mirage/mirage-tcpip#421 @avsm)
mgree pushed a commit to mgree/opam-repository that referenced this pull request Feb 19, 2020
CHANGES:

* Revert "Ipv4.Fragments use a Lru.M.t instead of Lru.F.t" (mirage/mirage-tcpip#423 by @hannesm)
  A Lru.M.t allocates a Hashtbl.t of size = capacity (= 256 * 1024 in our case),
  this leads to excessive ~2MB memory consumption for each Fragment cache,
  reported by @xaki23 in mirage/qubes-mirage-firewall#93
* use SOCK_RAW for an ICMP socket in the unix sockets API (previously used
  SOCK_DGRAM which did not work)
  reported by @justinc1 in mirage/mirage-tcpip#358, fixed in mirage/mirage-tcpip#424 by @hannesm
* tcp is now compatible with lwt >= 5.0.0 (where Lwt.async requires a function
  of (unit -> unit Lwt.t) (mirage/mirage-tcpip#370 mirage/mirage-tcpip#425 @cfcs @hannesm, issue mirage/mirage-tcpip#392 @emillon)
* Add a dependency on dune-configurator to support dune 2.0.0 (mirage/mirage-tcpip#421 @avsm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants