FreeBSD Bugzilla – Attachment 246880 Details for
Bug 275436
tmpfs does not honor memory limits on writes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
revised patch/proof of concept
tmpfs.mem.patch2 (text/plain), 2.90 KB, created by
Mike Karels
on 2023-12-07 18:43:38 UTC
(
hide
)
Description:
revised patch/proof of concept
Filename:
MIME Type:
Creator:
Mike Karels
Created:
2023-12-07 18:43:38 UTC
Size:
2.90 KB
patch
obsolete
>diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h >index 7ebdffbec84f..5c86a386b9da 100644 >--- a/sys/fs/tmpfs/tmpfs.h >+++ b/sys/fs/tmpfs/tmpfs.h >@@ -543,6 +543,14 @@ tmpfs_update(struct vnode *vp) > #define TMPFS_PAGES_MINRESERVED (4 * 1024 * 1024 / PAGE_SIZE) > #endif > >+/* >+ * Percent of available memory + swap available to use by tmpfs file systems >+ * without a size limit. >+ */ >+#if !defined(TMPFS_MEM_PERCENT) >+#define TMPFS_MEM_PERCENT 95 >+#endif >+ > /* > * Amount of memory to reserve for extended attributes. > */ >diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c >index 2fe7f7e3ca58..39d24b131c2e 100644 >--- a/sys/fs/tmpfs/tmpfs_subr.c >+++ b/sys/fs/tmpfs/tmpfs_subr.c >@@ -73,6 +73,9 @@ SYSCTL_NODE(_vfs, OID_AUTO, tmpfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, > "tmpfs file system"); > > static long tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED; >+static long tmpfs_pages_avail_init; >+static int tmpfs_mem_percent = TMPFS_MEM_PERCENT; >+static void tmpfs_set_reserve_from_percent(void); > > MALLOC_DEFINE(M_TMPFSDIR, "tmpfs dir", "tmpfs dirent structure"); > static uma_zone_t tmpfs_node_pool; >@@ -290,6 +293,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)); > } > >@@ -365,6 +370,9 @@ tmpfs_subr_init(void) > sizeof(struct tmpfs_node), tmpfs_node_ctor, tmpfs_node_dtor, > tmpfs_node_init, tmpfs_node_fini, UMA_ALIGN_PTR, 0); > VFS_SMR_ZONE_SET(tmpfs_node_pool); >+ >+ tmpfs_pages_avail_init = tmpfs_mem_avail(); >+ tmpfs_set_reserve_from_percent(); > return (0); > } > >@@ -403,6 +411,41 @@ SYSCTL_PROC(_vfs_tmpfs, OID_AUTO, memory_reserved, > sysctl_mem_reserved, "L", > "Amount of available memory and swap below which tmpfs growth stops"); > >+static int >+sysctl_mem_percent(SYSCTL_HANDLER_ARGS) >+{ >+ int error, percent; >+ >+ percent = *(int *)arg1; >+ error = sysctl_handle_int(oidp, &percent, 0, req); >+ if (error || !req->newptr) >+ return (error); >+ >+ if ((unsigned) percent > 100) >+ return (EINVAL); >+ >+ *(long *)arg1 = percent; >+ tmpfs_set_reserve_from_percent(); >+ return (0); >+} >+ >+static void >+tmpfs_set_reserve_from_percent(void) >+{ >+ size_t reserved; >+ >+ reserved = tmpfs_pages_avail_init * (100 - tmpfs_mem_percent) / 100; >+ if (reserved < TMPFS_PAGES_MINRESERVED) >+ tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED; >+ else >+ tmpfs_pages_reserved = reserved; >+} >+ >+SYSCTL_PROC(_vfs_tmpfs, OID_AUTO, mem_percent, >+ CTLTYPE_INT|CTLFLAG_MPSAFE|CTLFLAG_RW, &tmpfs_mem_percent, 0, >+ sysctl_mem_percent, "I", >+ "Percent of available memory that can be used if no size limit"); >+ > static __inline int tmpfs_dirtree_cmp(struct tmpfs_dirent *a, > struct tmpfs_dirent *b); > RB_PROTOTYPE_STATIC(tmpfs_dir, tmpfs_dirent, uh.td_entries, tmpfs_dirtree_cmp);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 275436
:
246673
|
246718
| 246880