)]}'
{
  "commit": "488ccd984c734e6a028a0dec2b1a23b7102b0771",
  "tree": "20ba9d7c205a8d489b5329f9a80969c28518b66a",
  "parents": [
    "a4a23bfd90de9e5dfe850ca20fc1209d1398f23e"
  ],
  "author": {
    "name": "Ghanan Gowripalan",
    "email": "ghanan@fuchsia.infra.roller.google.com",
    "time": "Tue Apr 25 21:30:07 2023 +0000"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Tue Apr 25 14:31:20 2023 -0700"
  },
  "message": "[roll] Roll fuchsia [netstack3] Optimize timer dispatcher memory use\n\nMitigate a memory leak in the `fuchsia_async::{Send,Local}Executor`\ncaused by its inability to properly cleanup abandoned timers\n(`fuchsia_async::Timer`). This change does not fix the root-cause of\nthe issue in the executor but mitigates its problems in Netstack3\nuntil a more global fix is ready.\n\nPreviously, the timer dispatcher created a `fuchsia_async::Timer` for\nevery timer that was scheduled (through the core). This resulted in an\nentry being created in the `fuchsia_async::{Send,Local}Executor`\u0027s\n`TimerHeap` per scheduled timer. However, the executor does not properly\ncleanup timers that have since been abandoned (e.g. aborted) and the\n`TimerHeap` will instead keep the entry for the abandoned timer in its\nheap until the timer\u0027s originally scheduled instant is reached. This\ncan eventually lead to unbounded memory growth/a leak.\n\nNetstack3 will now defer creating a `fuchsia_async::Timer` with the\nexecutor. It will instead lazily create the timer with the executor\nonly for the instant that the next timer is going to fire. That is,\nif 2 timers are scheduled where A is scheduled to fire before B, then\na timer will be scheduled with the executor for A and only after it\nfires will a timer be scheduled with the executor for B. This is\nadvantageous because if timer B were to be rescheduled, no existing\n`fuchsia_async::Timer` exists that could be leaked.\n\nNetstack3 will also group timers together based on the time the timers\nare scheduled to fire at. This change effectively reduces the timer\ngranularity from nanoseconds to milliseconds and rounds up all instants\nthat a timer is expected to fire to the nearest millisecond. More\nconcretely, given 3 timers that fire at 0.1ms, 0.7ms and 1.1ms, the\nfirst two timers will be scheduled to fire at 1ms and the second at 2ms.\nThis allows less thrash with `fuchsia_async::Timer`s registered with the\nexecutor when soon-to-fire timers are quickly scheduled then later\nde/re-scheduled (e.g. TCP socket timers for retransmission timeouts\nthat are rescheduled on each incoming TCP segment). See comments inline\nfor why we allow rounding instants up but not down, and why the chosen\ngranularity is milliseconds.\n\nWith an emulator running a debug `core_with_netstack3.x64` build and the\nbelow command, I see the memory growth after ~11 hours has significantly\nreduced from 24MiB to 0.01MiB.\n```\nwhile true; do ffx profile memory | grep -A6 \u0027 netstack\u0027 | grep scudo; sleep 1; done\n```\n\nLogs showing the (almost negligible) memory growth:\n```\n$ # Start\n$ ffx profile memory | grep -A6 \u0027 netstack\u0027\nProcess name: netstack.cm\nProcess koid: 19072\nPrivate:      1.81 MiB\nPSS:          7.60 MiB (Proportional Set Size)\nTotal:        17.79 MiB (Private + Shared unscaled)\n                              Private       Scaled        Total\n    [scudo]                  1.18 MiB     1.18 MiB     1.18 MiB\n$ date\nFri Apr 21 10:03:36 PM PDT 2023\n$\n$\n$ # End\n$ date\nSat Apr 22 09:13:34 AM PDT 2023\n$ ffx profile memory | grep -A6 \u0027 netstack\u0027\nProcess name: netstack.cm\nProcess koid: 19072\nPrivate:      1.82 MiB\nPSS:          7.61 MiB (Proportional Set Size)\nTotal:        17.80 MiB (Private + Shared unscaled)\n                              Private       Scaled        Total\n    [scudo]                  1.19 MiB     1.19 MiB     1.19 MiB\n```\n\nOriginal-Bug: 125301\nOriginal-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/842918\nOriginal-Revision: 6723baee8d4c2b47a0b5ade2c48e146850e7492f\nGitOrigin-RevId: a36c1dc36565444a370c73f638cd7d674c6a1fb0\nChange-Id: If3d679bdceab54ab2f0d2732ee3a8bc2908b768c\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "4e94cd4a647a4694e52faf9bb37765a777df281e",
      "old_mode": 33188,
      "old_path": "stem",
      "new_id": "b86651bdcee54d49a57ea79d8144da47b348eb9e",
      "new_mode": 33188,
      "new_path": "stem"
    }
  ]
}
