[Bug 271580] vmemoryuse counts shared memory as a sum for all processes

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 27 May 2026 11:28:51 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271580

--- Comment #3 from Dmitry Afanasiev <KOT@MATPOCKuH.Ru> ---
Created attachment 271242
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=271242&action=edit
dump code for tests

I reproduced this on a fresh 14.4 system (fca6c9e8f747) using the attached
simple test program.

The following RCTL limits are configured:
jail:pg199:memoryuse:deny=8589934592/user
jail:pg199:vmemoryuse:deny=34359738368

When allocating 10 GB of shared memory, the program succeeds:
[postgres9@pg199 ~]$ ./shm 10
mapped 10737418240 bytes at 0x823b13000
hello from parent
hello from child

top shows:
  PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
72662    779        1  59    0    10G    10G nanslp   7   0:08   0.00% shm
72663    779        1  59    0    10G    24K nanslp   8   0:08   0.00% shm

However, in my opinion, allocation of 10 GB should be denied by the per-user
memoryuse limit:
jail:pg199:memoryuse:deny=8589934592/user

When allocating 16 GB, fork() fails:
[postgres9@pg199 ~]$ ./shm 16
mapped 17179869184 bytes at 0x8229fb000
fork: Resource temporarily unavailable

Additionally, it appears that memoryuse may not be enforced at all.
I also tested a direct jail-wide limit:
rctl -r jail:pg199:memoryuse:deny=$((4*1024*1024*1024))

Despite this, the process was still able to allocate and fully populate 16 GB
of memory successfully.

-- 
You are receiving this mail because:
You are the assignee for the bug.