26 comments

  • freedomben 4 hours ago

    More of a meta comment, but I'm always grateful for these sort of network-related debugging blog posts. As a software eng who has a good grasp of networking at a conceptual layer, but has struggled to translate concept into concrete implementation in linux, I get a lot of value from these. Thank you to the author(s) for putting in the effort to write this up.

    • waschl an hour ago

      Same here. Is there any good printed/printable resource on all of the state of the art protocol configurations? Like what can all be configured, how can stuff break? It seems there is a myriad of man pages, mailing lists with that arcane knowledge

    • wfn an hour ago

      Indeed this was such a pleasurable read (and very nicely written too). Absolutely agree, +1 :)

    • hollowonepl 41 minutes ago

      that's exactly the comment I wanted to give. I love to see people feel encouraged to go into such rabbit holes and also dare to spend time to describe it and share with the community!

  • montjoy 4 hours ago

    Lots of little gems in this article. e.g.

    > We launch nginx as a systemd service, and systemd places each service into its own cgroup and sets default controllers

    Thank you for sharing.

  • basilikum 2 hours ago

    > Memory reclaim reports how many pages it scanned and how many it managed to free per cgroup. Once roughly two megabytes' worth of pages have been scanned, the kernel turns that into a ratio. If it freed less than about 40% of what it walked, that counts as memory pressure, and every socket in the cgroup gets throttled for that one second. What's NOT in the formula is how much free memory the machine has.

    Maybe I'm missing something, but can someone explain why memory pressure is detected like this in the first place? The article goes on to say that there was a TODO comment in the source to scale the scanning window proportional to the memory size, but why is memory pressure even measured like this without considering the free memory at all? Am I missing something or does that indeed make no sense?

    • majke 2 hours ago

      Afaiu memory pressure is a boolean. Either the cgroup is under pressure or not. What is the question?

      • basilikum an hour ago

        Further up they say (emphasis mine)

        > The memory controller helps you set limits for the maximum memory consumption of a service, which we are actually not using. It's the well-known memory.high, memory.max, etc. But the memory controller has an undocumented feature, which activates when the controller is only loaded.

        Why is there even memory pressure in the first place when the cgroup does not have a limit and there is lots of free memory?

        • majke 31 minutes ago

          ok, this is more of cgroup question than tcp, not my area of expertise.

      • loeg an hour ago

        This condition as described should not be considered memory pressure true.

  • rid 2 hours ago

    I think the workaround for this at the moment is the boot parameter:

       cgroup.memory=nosocket
    
    If you're not bothered about socket memory counting towards the cgroup's limit (it's usually negligible).
  • dedalus 3 hours ago

    We should have a target rate test on prod to ensure we always hit that and assert in logs when it goes slow (in this case its memory throttle tomorrow is something else) as to ensure consistent performance for our apps

  • eikenberry 2 minutes ago

    > The two-megabyte window was a hardcoded constant in the kernel version we were debugging, with a TODO: in the kernel asking it to scale with the machine size.

    That TODO was removed about a month ago but remains there in spirit.

    https://github.com/torvalds/linux/commit/0041eef981cc55bb1f3...

  • kalak 2 hours ago

    > Disclaimer: No AI was used for writing this blog. Enjoy a humanly engineered piece.

    The disclaimer now belongs on articles that were human written?

    • fullstop an hour ago

      I don't think that AI generated articles are going to specify that they were written by AI any time soon.

      • hollowonepl 37 minutes ago

        They don't need to... it's clear when they are.. not only the dash length but certain phrases like "what happened" and "why it mattered" kind of section summaries. It's annoying when I see my team mates share such material without editing at least a bit and then claimed they've done the work.

        • fullstop 34 minutes ago

          On a project that I'm involved with between our organization and another, I am cc'd on a number of the emails. Right now it seems like there is a LLM on our side responding to a LLM on their side. It's both dystopian and depressing.

  • tonymet 38 minutes ago

    Do you need systemd or cgroups for this? Seems like unnecessary configuration and complexity.

    great effort debugging and isolating the root cause, but also an unnecessary issue.

  • jeffbee 4 hours ago

    One of the wrongest default parameters in Linux is the dirty page ratio. By default, if I recall correctly, it permits up to 20% of pages to be dirty. If you're doing some quick arithmetic you already see the problem. The whole "pressure stall" concept has been adopted to hide this fact, when the better option is to simply lower the dirty page limit (not ratio) to 1GiB or less.

    • mk12 3 hours ago

      The dirty ratio also behaves differently than I assumed at first. 20% does not mean 20% of all memory, it means 20% of "dirtyable" memory. Also, 1GB dirty threshold does not mean that writes only get slowed down at 1GB. There is a "freerun" threshold at the midpoint between the background dirty limit and the dirty limit, and the kernel starts progressively throttling writers at that midpoint.

    • the8472 3 hours ago

      depends, if you have servers that buffer large blobs in tempfiles you don't really want those flushed to storage unless there's a real memory shortage.

      • hosteur 3 hours ago

        But is that a default usecase?

      • jeffbee 3 hours ago

        No, on a multi-tenant machine I really, really want that tempfile thing to be throttled on dirty page creation. If that process thinks it can run in constant space without externalizing the page cache then it knows what to do: write its temporary objects to anonymous memory, not files.

    • loeg an hour ago

      I set vm.dirty_bytes to 256MiB.

    • tremon 2 hours ago

      The volume of the writeout in itself would not be a problem if it weren't that the dirty page table is locked until writeout completes. That means that new page allocations are stalled while writeout is in progress. And you're right, the default dirty page ratio is way too high, especially in the much-ram-meets-spinning-rust scenario. I have had rsync backups stall for over a minute while the archive server digests its dirty page buffer, only to have the server then stop writing for long enough to allow the disks to go back to standby mode.

      It would take major engineering effort in the VFS layer to avoid locking the page table during writeout, but that's what a proper solution would look like in my eyes.