0

I would like to know, what is cache usage per process. Is there a way to do it? I'm currently on Ubuntu.

The problem is, that my PC fills up whole cache, and then when I need RAM just starts swapping instead of freeing up the cache. Not an ideal scenario. Knowing what process "needs" all that would really help. I suspect ESET AV as its "niceness" is -20 in htop. (yes I need AV, no its not my decision)

As you can see, there is 16GB worth of cache (some really small portion of this is buff, according to htop). This is after about 45 minutes of uptime. There is nothing swapped, but sometimes it just swaps like 5-7GB of data (when I start a VM or something like that).

USERNAME@HOSTNAME:[~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           23Gi       6,4Gi       354Mi       4,6Gi        16Gi        11Gi
Swap:          23Gi       3,0Mi        23Gi

Anyway, even without this problem, knowing exactly who is caching, and how much would be a nice info to have.

1
  • 1
    1. linuxatemyram.com 2. decrease swappiness or disable swap altogether - many people insist on it despite having more than enough RAM to never use it. Commented May 11, 2022 at 9:24

1 Answer 1

1

Cache usage isn’t tracked per process — pages are present in the cache, and can be used by any process on the system.

Processes which scan lots of files (such as anti-virus scanners, or backup tools) often produce the symptoms you’re seeing: constantly reading lots of files will evict other pages to swap, if swap is available. There are a few things you can consider to improve your system’s performance:

If you want to keep a large swap partition (e.g. for hibernation; the goal for that is 2/5 of the installed memory, although that’s not a hard limit), you can decrease vm.swappiness so that the kernel will consider swap to be more expensive than evicting page cache pages, and will therefore tend to reduce its cache usage instead of increasing its swap usage.

2
  • Could you please elaborate on "If you want to keep a large swap partition (e.g. for hibernation; the goal for that is 2/5 of the installed memory, although that’s not a hard limit), you can decrease vm.swappiness so that the kernel will consider swap to be more expensive than evicting page cache pages, and will therefore tend to reduce its cache usage instead of increasing its swap usage." especially not clear on " will therefore tend to reduce its cache usage instead of increasing its swap usage." Is it "increase its cache usage", instead of "reduce its cache usage "? Commented Aug 31, 2023 at 8:02
  • @merlachandra “swappiness” comes into play when the kernel has to decide between evicting a (dirty) page to swap and getting rid of a page in the page cache. If swap is more expensive (lower values of swappiness), it will prefer to avoid using it; its only other option is to get rid of some of the page cache. Globally this will result in lower cache usage. So it is “reduce its cache usage”. Commented Aug 31, 2023 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .