Bug 271579 - Incorrect vmemoryuse per user rctl limits for jails calculation
Summary: Incorrect vmemoryuse per user rctl limits for jails calculation
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.2-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-23 10:07 UTC by Dmitry Afanasiev
Modified: 2023-05-25 18:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Afanasiev 2023-05-23 10:07:02 UTC
I want to limit a per user memory usage for every running jail.
I'm tried to set a limits like this:
jail:pg198:vmemoryuse:deny=17179869184/user
jail:pg199:vmemoryuse:deny=17179869184/user

I have users with same uid in there jails, resulting a memory allocation for user in jail pg198, makes impossible to use this limit for same user in jail pg199.

To check I used this simple code:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[]) {
        long size = atol(argv[1]);
        void *buf = malloc(size);

        if (buf == NULL) {
                fprintf(stderr, "malloc(%li) failed: %s\n", size, strerror(errno));
                return 1;
        }

        fgets(buf, size < 1024 ? size : 1024, stdin);
        return 0;
}

And when a user in one jail is running a command:
./alloc $((10*1024*1024*1024))
User in a different jail can't allocate memory:
malloc(10737418240) failed: Cannot allocate memory

A limits like jail:jailname:vmemoryuse:deny=limit/user should limit a allocated memory per user for each jail, but not for user in all jails.