Lines 73-78
SYSCTL_NODE(_vfs, OID_AUTO, tmpfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
Link Here
|
73 |
"tmpfs file system"); |
73 |
"tmpfs file system"); |
74 |
|
74 |
|
75 |
static long tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED; |
75 |
static long tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED; |
|
|
76 |
static long tmpfs_pages_avail_init; |
77 |
static int tmpfs_mem_percent = TMPFS_MEM_PERCENT; |
78 |
static void tmpfs_set_reserve_from_percent(void); |
76 |
|
79 |
|
77 |
MALLOC_DEFINE(M_TMPFSDIR, "tmpfs dir", "tmpfs dirent structure"); |
80 |
MALLOC_DEFINE(M_TMPFSDIR, "tmpfs dir", "tmpfs dirent structure"); |
78 |
static uma_zone_t tmpfs_node_pool; |
81 |
static uma_zone_t tmpfs_node_pool; |
Lines 290-295
tmpfs_can_alloc_page(vm_object_t obj, vm_pindex_t pindex)
Link Here
|
290 |
if (tm == NULL || vm_pager_has_page(obj, pindex, NULL, NULL) || |
293 |
if (tm == NULL || vm_pager_has_page(obj, pindex, NULL, NULL) || |
291 |
tm->tm_pages_max == 0) |
294 |
tm->tm_pages_max == 0) |
292 |
return (true); |
295 |
return (true); |
|
|
296 |
if (tm->tm_pages_max == ULONG_MAX) |
297 |
return (tmpfs_mem_avail() >= 1); |
293 |
return (tm->tm_pages_max > atomic_load_long(&tm->tm_pages_used)); |
298 |
return (tm->tm_pages_max > atomic_load_long(&tm->tm_pages_used)); |
294 |
} |
299 |
} |
295 |
|
300 |
|
Lines 365-370
tmpfs_subr_init(void)
Link Here
|
365 |
sizeof(struct tmpfs_node), tmpfs_node_ctor, tmpfs_node_dtor, |
370 |
sizeof(struct tmpfs_node), tmpfs_node_ctor, tmpfs_node_dtor, |
366 |
tmpfs_node_init, tmpfs_node_fini, UMA_ALIGN_PTR, 0); |
371 |
tmpfs_node_init, tmpfs_node_fini, UMA_ALIGN_PTR, 0); |
367 |
VFS_SMR_ZONE_SET(tmpfs_node_pool); |
372 |
VFS_SMR_ZONE_SET(tmpfs_node_pool); |
|
|
373 |
|
374 |
tmpfs_pages_avail_init = tmpfs_mem_avail(); |
375 |
tmpfs_set_reserve_from_percent(); |
368 |
return (0); |
376 |
return (0); |
369 |
} |
377 |
} |
370 |
|
378 |
|
Lines 403-408
SYSCTL_PROC(_vfs_tmpfs, OID_AUTO, memory_reserved,
Link Here
|
403 |
sysctl_mem_reserved, "L", |
411 |
sysctl_mem_reserved, "L", |
404 |
"Amount of available memory and swap below which tmpfs growth stops"); |
412 |
"Amount of available memory and swap below which tmpfs growth stops"); |
405 |
|
413 |
|
|
|
414 |
static int |
415 |
sysctl_mem_percent(SYSCTL_HANDLER_ARGS) |
416 |
{ |
417 |
int error, percent; |
418 |
|
419 |
percent = *(int *)arg1; |
420 |
error = sysctl_handle_int(oidp, &percent, 0, req); |
421 |
if (error || !req->newptr) |
422 |
return (error); |
423 |
|
424 |
if ((unsigned) percent > 100) |
425 |
return (EINVAL); |
426 |
|
427 |
*(long *)arg1 = percent; |
428 |
tmpfs_set_reserve_from_percent(); |
429 |
return (0); |
430 |
} |
431 |
|
432 |
static void |
433 |
tmpfs_set_reserve_from_percent(void) |
434 |
{ |
435 |
size_t reserved; |
436 |
|
437 |
reserved = tmpfs_pages_avail_init * (100 - tmpfs_mem_percent) / 100; |
438 |
if (reserved < TMPFS_PAGES_MINRESERVED) |
439 |
tmpfs_pages_reserved = TMPFS_PAGES_MINRESERVED; |
440 |
else |
441 |
tmpfs_pages_reserved = reserved; |
442 |
} |
443 |
|
444 |
SYSCTL_PROC(_vfs_tmpfs, OID_AUTO, mem_percent, |
445 |
CTLTYPE_INT|CTLFLAG_MPSAFE|CTLFLAG_RW, &tmpfs_mem_percent, 0, |
446 |
sysctl_mem_percent, "I", |
447 |
"Percent of available memory that can be used if no size limit"); |
448 |
|
406 |
static __inline int tmpfs_dirtree_cmp(struct tmpfs_dirent *a, |
449 |
static __inline int tmpfs_dirtree_cmp(struct tmpfs_dirent *a, |
407 |
struct tmpfs_dirent *b); |
450 |
struct tmpfs_dirent *b); |
408 |
RB_PROTOTYPE_STATIC(tmpfs_dir, tmpfs_dirent, uh.td_entries, tmpfs_dirtree_cmp); |
451 |
RB_PROTOTYPE_STATIC(tmpfs_dir, tmpfs_dirent, uh.td_entries, tmpfs_dirtree_cmp); |