Skip to content

Issue in swap usage #356

Closed
Closed

Description

@A404M

After using linux-zen kernel for more than a year I realized that my system uses swap not in order that is optimized in any way.
I realized that my ram usage is always around 69% (yes I'm curious and that's funny) that was because when my ram gets around 50% usage the kernel will start using swappiness and when it gets to 69% nearly all other allocations would move some pages to swap until my swap gets nearly full and the kernel will fill ram again, but my swappiness was 1 and no matter value value it has, the kernel will always do that.
And as soon as I switched to vanilla linux kernel the problem went away.
I wonder if this functionality is intended or not?
I use the latest version of both kernels which comes in arch Linux repositories
Because I use linux-zen because waydroid only works with kernels which come with binder modules and linux-zen has it.
Thanks for your great efforts

Activity

  1. damentz commented on Aug 20, 2024

    @damentz
    Member

    Is this impacting the responsiveness of your system? Using swap in and of itself is not a problem unless it's actively causing issues with running applications.

    We have some patches in our zen-sauce branch that affect swappiness. For the most part, proactive compaction and other aggressive reclaim/compaction behavior is disabled since it disrupts foregrounds tasks too much under memory pressure. What you're seeing instead is that memory is pushed to swap preemptively as a side effect.

  2. heftig commented on Aug 20, 2024

    @heftig

    I do wonder what causes the ZEN kernel to swap so aggressively even with its default settings and plenty of unused RAM.

                   total        used        free      shared     buffers       cache   available
    Mem:             29G        8.7G         14G        127M        106K        6.6G         20G
    Swap:            10G        2.3G        8.4G
    Total:           39G         11G         22G
    

    Though I don't remember how the vanilla kernel behaves.

  3. A404M commented on Aug 21, 2024

    @A404M
    Author

    Is this impacting the responsiveness of your system? Using swap in and of itself is not a problem unless it's actively causing issues with running applications.

    We have some patches in our zen-sauce branch that affect swappiness. For the most part, proactive compaction and other aggressive reclaim/compaction behavior is disabled since it disrupts foregrounds tasks too much under memory pressure. What you're seeing instead is that memory is pushed to swap preemptively as a side effect.

    Yes it does actually affect my system responsiveness a lot
    Because I use 4 or 5 apps in foreground apps at the same time
    I have more than enough RAM for them (16GB but the apps are not that heavy) but It does move my active memory to swap and that hurts performance in my case
    I have been in Linux vanilla kernel after posting the issue till now and I really like it, the performance is much better here even when my whole ram and swap gets filled up

  4. damentz commented on Aug 21, 2024

    @damentz
    Member

    There's a few commits that could be the problem:

    1. f61fea1 - patches from https://github.com/kerneltoast to tame the memory subsystem. They fixed real issues I was running into where as memory pressure increased, foreground applications would stall while compaction executed. I think now what we're seeing is instead of compacting, pages are tossed into swap to be handled later.
    2. e33a55b - disabling compaction of unevictable pages, possibly could be related? This follows guidance from adjustments when PREEMPT_RT is turned on in ifdef macros. Restore with sudo sysctl -w vm.compact_unevictable_allowed=1
    3. 47aa999 - proactive compaction causes stalls in foreground applications if set too aggressive. Even at light settings I had problems with it so we use kerneltoast's patch. You can restore the default with sudo sysctl -w vm.compaction_proactiveness=20.
    4. 627d13a - disabling watermark boosting is similar in effect of disabling proactive compaction. Restore to default with sudo sysctl -w vm.watermark_boost_factor=15000
    5. 1b4743e - protecting cache of data accessed in the last second, probably not related but you can tune in the value in /sys/kernel/mm/lru_gen/min_ttl_ms and restore it to 0 for testing.

    @A404M would you be able to try testing the tunables to see if they're related? Worst case it's the first commit I mentioned. Speaking of which, we've been rebasing these patches for a while now, might be worth seeing if anything has changed in kerneltoast's current branch: https://github.com/kerneltoast/kernel_x86_laptop/commits/v6.10-sultan/

  5. damentz commented on Sep 29, 2024

    @damentz
    Member

    @A404M have you had a chance to tweak any of the files/sysctls I referenced?

  6. A404M commented on Oct 3, 2024

    @A404M
    Author

    @damentz I haven't had the time to try it
    But tomorrow is my day off, I will try it then
    Sorry for the delay

  7. pckotzer commented on Oct 6, 2024

    @pckotzer

    I have with the zen kernel almost not functinally swapiness value, its just didnt worked, i have set it to 200, but then after i used kerneltoast defconfig and all his patches without the thermal stuff on 6.11, swapiness value worked. And also i build Android and ram is exactly that whats needed sometimes on mass. Just want to say after his arch_defconfig and all his patches, the swap or zram i use, is much better now. I dont have to wait now that long when zram is used. Normally i would have to wait longer in the default kernel settings, when android.pb build starts, this is the part which i dont like cause normally it would take a long time, but now after the patches and the defconfig its much better. I dont have to wait that long now. It clearly improved something. It was the kernel_86_leptop from kerneltoast aka sultan

    @A404M What swapiness value you have? when i have 200, it will most likely use the swap or zram more, but when its low like 10 it should be use ram before its getting full and then start using swap.

  8. pckotzer commented on Oct 26, 2024

    @pckotzer

    Installing liqu kernel will also work @damentz ?

  9. damentz commented on Oct 27, 2024

    @damentz
    Member

    Installing liqu kernel will also work @damentz ?

    Yes, Liquorix has the same configuration for memory as Zen Kernel.

  10. pckotzer commented on Oct 28, 2024

    @pckotzer

    I tested and it behaves like nothing has happend, its almost too late for swaping, on my self build zenkernel, also with latest changes it dont does that. I think this is something relevant in the defconfig, but for now i dont know which exactly

  11. damentz commented on Oct 28, 2024

    @damentz
    Member

    @pckotzer can you try disabling MG-LRU? You can make the change realtime in /sys/kernel/mm/lru_gen I believe, or in the folder above it.

  12. pckotzer commented on Oct 28, 2024

    @pckotzer

    I dont find that option in /sys/kernel/mm/lru_gen, have only: ksm swap transparent_hugepage in mm folder.
    Right now on my self build, i have just used some stuff of sultans x86 kernel. In the normal kernel i tested a moment ago it also stutters when here its fine, i think its worth looking in the defconfig, i just mergerd everything that make sense too me and now its good, he knows how to toast a kernel haha

  13. damentz commented on Oct 28, 2024

    @damentz
    Member

    So your self build isn't using MG-LRU? What I was asking is on a Zen or Liquorix kernel, set /sys/kernel/mm/lru_gen/enabled to "n" and see if you can reproduce the issues you're running into.

    You can also adjust /sys/kernel/mm/lru_gen/min_ttl_ms to 0 to reproduce stock.

    What I'm trying to figure out is if MG-LRU itself is an issue here as you don't enable it with @kerneltoast's. If it is, we need to figure out what's going on with it.

  14. kerneltoast commented on Oct 28, 2024

    @kerneltoast

    So your self build isn't using MG-LRU? What I was asking is on a Zen or Liquorix kernel, set /sys/kernel/mm/lru_gen/enabled to "n" and see if you can reproduce the issues you're running into.

    You can also adjust /sys/kernel/mm/lru_gen/min_ttl_ms to 0 to reproduce stock.

    What I'm trying to figure out is if MG-LRU itself is an issue here as you don't enable it with @kerneltoast's. If it is, we need to figure out what's going on with it.

    FYI, I disable mglru in my laptop kernel defconfig.

  15. 9 remaining items

  16. damentz commented on Nov 8, 2024

    @damentz
    Member

    @heftig looks like we should turn off zswap by default as it hinders responsiveness under load.

    Also, maybe we should restore this commit since it didn't make a difference? 573d80b

  17. damentz commented on Nov 11, 2024

    @damentz
    Member

    @A404M next linux-zen release will reapply a patch we reverted and disable zswap compressed cache by default. Can you also confirm that zswap.enable=0 helps on your system?

  18. damentz commented on Nov 17, 2024

    @damentz
    Member

    Ok, I'm going to mark this as resolved. @A404M if this didn't help and you're still having problems, let us know and we'll reopen.

  19. A404M commented on Nov 17, 2024

    @A404M
    Author

    Ok, I'm going to mark this as resolved. @A404M if this didn't help and you're still having problems, let us know and we'll reopen.

    I'm sorry for not being active here
    I have some problems at job and I can't take a break even for a day to do the works you mentioned.
    I guess the best thing is to close this issue and I will recheck when I got free time.
    I'm sorry again for not answering😞

  20. added a commit that references this issue on Nov 17, 2024
  21. ReillyBrogan commented on Nov 20, 2024

    @ReillyBrogan

    Has anyone reached out to the kernel zswap maintainers about this behavior?

  22. damentz commented on Nov 21, 2024

    @damentz
    Member

    Has anyone reached out to the kernel zswap maintainers about this behavior?

    Not that I'm aware of, but for whoever reports, a script or series of instructions to reproduce the issue reliably will be important. More importantly you want whatever utility you're running to have numbers that indicate the "stutter" and "jank", otherwise it's hard for maintainers to prioritize a solution.

  23. damentz commented on Dec 5, 2024

    @damentz
    Member

    Reopening while we experiment with different methods to prevent excessive swapping.

  24. reopened this on Dec 5, 2024
  25. damentz commented on Dec 10, 2024

    @damentz
    Member

    This is resolved by 856c387, where lru_gen_min_ttl parameter was causing early OOMs and excessive swapping. Proactive compaction restore to default will also stay while we determine a non-zero value for interactive systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions