Remove the hardcoded 4 MB free kernel memory limit and replace it

by uvmexp.freetarg, as discussed on tech-kern.
Main purpose is to make tmpfs usable (as far as possible) on small memory
machines.
This is a bit experimental, but we need to give it some real world exposure
to see how well it works.
This commit is contained in:
martin 2014-06-07 09:54:34 +00:00
parent db893a74ff
commit c7dd06b6bb
3 changed files with 9 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs.h,v 1.49 2014/04/30 01:33:51 christos Exp $ */
/* $NetBSD: tmpfs.h,v 1.50 2014/06/07 09:54:34 martin Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -306,13 +306,6 @@ bool tmpfs_strname_neqlen(struct componentname *, struct componentname *);
KASSERT((node)->tn_type == VDIR); \
KASSERT((node)->tn_size % sizeof(tmpfs_dirent_t) == 0);
/*
* Memory management stuff.
*/
/* Amount of memory pages to reserve for the system. */
#define TMPFS_PAGES_RESERVED (4 * 1024 * 1024 / PAGE_SIZE)
/*
* Routines to convert VFS structures to tmpfs internal ones.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_mem.c,v 1.5 2014/04/30 01:33:51 christos Exp $ */
/* $NetBSD: tmpfs_mem.c,v 1.6 2014/06/07 09:54:34 martin Exp $ */
/*
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.5 2014/04/30 01:33:51 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.6 2014/06/07 09:54:34 martin Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -89,7 +89,7 @@ tmpfs_mntmem_set(struct tmpfs_mount *mp, uint64_t memlimit)
* => If 'total' is true, then return _total_ amount of pages.
* => If false, then return the amount of _free_ memory pages.
*
* Remember to remove TMPFS_PAGES_RESERVED from the returned value to avoid
* Remember to remove uvmexp.freetarg from the returned value to avoid
* excessive memory usage.
*/
size_t
@ -118,10 +118,10 @@ tmpfs_bytes_max(struct tmpfs_mount *mp)
size_t freepages = tmpfs_mem_info(false);
uint64_t avail_mem;
if (freepages < TMPFS_PAGES_RESERVED) {
if (freepages < uvmexp.freetarg) {
freepages = 0;
} else {
freepages -= TMPFS_PAGES_RESERVED;
freepages -= uvmexp.freetarg;
}
avail_mem = round_page(mp->tm_bytes_used) + (freepages << PAGE_SHIFT);
return MIN(mp->tm_mem_limit, avail_mem);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_vfsops.c,v 1.61 2014/04/30 01:59:30 christos Exp $ */
/* $NetBSD: tmpfs_vfsops.c,v 1.62 2014/06/07 09:54:34 martin Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.61 2014/04/30 01:59:30 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.62 2014/06/07 09:54:34 martin Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -132,7 +132,7 @@ tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
/* Prohibit mounts if there is not enough memory. */
if (tmpfs_mem_info(true) < TMPFS_PAGES_RESERVED)
if (tmpfs_mem_info(true) < uvmexp.freetarg)
return EINVAL;
/* Get the memory usage limit for this file-system. */