[Bug 275436] tmpfs does not honor memory limits on writes

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 29 Nov 2023 19:19:02 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275436

            Bug ID: 275436
           Summary: tmpfs does not honor memory limits on writes
           Product: Base System
           Version: 15.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: karels@freebsd.org

Created attachment 246673
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=246673&action=edit
sample patch that works around the problem

The tmpfs file system checks for available memory when a file is created, but
not during writes.  If I create a file, then run the system nearly out of
memory, I can write to that file until processes are killed because the system
is out of memory, and in some cases the system is so screwed up that a shutdown
cannot be run.  A df shows continuously growing usage and size while showing 0
for free space all along; this can go on for gigabytes.  Note, this is using a
tmpfs file system with the default size.

I'll attach a patch that adds a check in the write path, which helps.  It still
runs the system out of memory and swap, so there are two additional changes in
the patch: one divides swap space by two, and the other asks the VM system for
the free memory in excess of the free target, using that in place of simply
free memory.  I am not convinced that any of the changes are correct, but they
help considerably.  With these changes, a large memory process keeps running
although swap is exhausted when the writes fail.  More details or tests
available on request.

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