git: ed19c0989fe7 - main - tmpfs: enforce size limit on writes when file system size is default

From: Mike Karels <karels_at_FreeBSD.org>
Date: Tue, 19 Dec 2023 15:34:01 UTC
The branch main has been updated by karels:

URL: https://cgit.FreeBSD.org/src/commit/?id=ed19c0989fe77ec3c9d7bdb752bab6bbef4c0be6

commit ed19c0989fe77ec3c9d7bdb752bab6bbef4c0be6
Author:     Mike Karels <karels@FreeBSD.org>
AuthorDate: 2023-12-19 15:32:58 +0000
Commit:     Mike Karels <karels@FreeBSD.org>
CommitDate: 2023-12-19 15:32:58 +0000

    tmpfs: enforce size limit on writes when file system size is default
    
    tmpfs enforced the file system size limit on writes for file systems
    with a specified size, but not when the size was the default.  Add
    enforcement when the size is default: do not allocate additional
    pages if the available memory + swap falls to the reserve level.
    Note, enforcement is also done when attempting to create a file,
    both with and without an explicit file system size.
    
    PR:             275436
    MFC after:      1 month
    Reviewed by:    cy
    Differential Revision:  https://reviews.freebsd.org/D43010
---
 sys/fs/tmpfs/tmpfs_subr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index 2fe7f7e3ca58..e255c6488613 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -290,6 +290,8 @@ tmpfs_can_alloc_page(vm_object_t obj, vm_pindex_t pindex)
 	if (tm == NULL || vm_pager_has_page(obj, pindex, NULL, NULL) ||
 	    tm->tm_pages_max == 0)
 		return (true);
+	if (tm->tm_pages_max == ULONG_MAX)
+		return (tmpfs_mem_avail() >= 1);
 	return (tm->tm_pages_max > atomic_load_long(&tm->tm_pages_used));
 }