How to implement memory control safely?

My goal is to provide a container for users, who can do anything in the container.

How can I limit the memory usage of containers? I hope that the user’s program will not be stopped, but will be limited in speed.

After using the – memory parameter, if the user uses a large amount of memory in the container and exceeds my limit, the application that uses the most memory will be stopped.

But I don’t want this application to be stopped. I hope that all applications will not be stopped, but the running speed will be reduced. Just like Windows, when the memory exceeds, the running speed will be reduced, and the application itself will not be stopped.

After using the oom score adj parameter, the application does not stop, but the Docker is likely to get stuck at this time with a high probability. It shows that all operations of the container in question cannot be responded to, such as docker stats test

The command does not report an error, but it is stuck and does not respond.