3

I'm using cgroups with the memory controller to set a memory limit for each user (using the memory.limit_in_bytes setting).

The problem is that this setting also accounts cache usage. Therefore, if the limit is 1GB, and the user merely downloads or copies a 1GB file, their processes get killed. What's worse, the cached pages remain in memory, so the user's "memory usage" remains close to 1GB even when they have zero processes running.

Naturally, this makes no sense. I only want to limit total private (non-anonymous) memory usage per user. How can I achieve that?

Alternatively, get the OOM killer to try dropping the user's cached pages before going off killing processes, which doesn't even free the cached pages.

21
  • Please don't do this. It will just make performance worse for everyone by increasing the amount of I/O needed. If the memory is available, and you prohibit people from using it, you make performance worse for no gain. What is your actual requirement? (As opposed to what tool you think you need to meet it.) There's probably a good way to solve it. Mar 15, 2013 at 7:27
  • "What's worse, the cached pages remain in memory, so the user's "memory usage" remains close to 1GB" No! That's good. If someone else happens to read that same file, no I/O will be needed. If nobody does, the operating system will use the memory for something else anyway. Having data that might be useful is way better than having nothing! Mar 15, 2013 at 7:29
  • 1
    My requirement is preventing one user's runaway process(es) from crashing the entire system. Mar 15, 2013 at 7:49
  • 1
    I know cached memory is good. What's not good is that it's counted towards the user's total. But if it gets to that, I'll take clearing caches over not even allowing that user to log back in. Mar 15, 2013 at 7:50
  • 1
    Huh?? That makes no sense. One process/thread can only be reading from one spot on the disk at the same time - the rest is "just in case" cache that can be thrown out at any moment. Mar 15, 2013 at 8:05

1 Answer 1

2

Posting what I think might be a better answer.

My requirement is preventing one user's runaway process(es) from crashing the entire system.

Linux already has a feature for doing exactly this: the OOM killer.

The OOM killer runs when the system runs out of memory, and favors processes that consume a lot of RAM quickly. It is also less likely to kill long-running / system (superuser) processes.

The OOM killer can be further tuned by tweaking the /proc/<pid>/oom_score_adj file. The setting is inherited by child processes, so you only need to set it on each user's root process. (See Documentation/filesystems/proc.txt, section 3.1)

You must log in to answer this question.

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