From c7dd06b6bbf9e664c6e2de85124e6326b1b8e9e2 Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 7 Jun 2014 09:54:34 +0000 Subject: [PATCH] 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. --- sys/fs/tmpfs/tmpfs.h | 9 +-------- sys/fs/tmpfs/tmpfs_mem.c | 10 +++++----- sys/fs/tmpfs/tmpfs_vfsops.c | 6 +++--- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h index d4b90bf0e281..8625ffb44a20 100644 --- a/sys/fs/tmpfs/tmpfs.h +++ b/sys/fs/tmpfs/tmpfs.h @@ -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. */ diff --git a/sys/fs/tmpfs/tmpfs_mem.c b/sys/fs/tmpfs/tmpfs_mem.c index 8f752410d661..0abf8123e5ca 100644 --- a/sys/fs/tmpfs/tmpfs_mem.c +++ b/sys/fs/tmpfs/tmpfs_mem.c @@ -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 -__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 #include @@ -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); diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c index 35f7ede27751..ba412b55787c 100644 --- a/sys/fs/tmpfs/tmpfs_vfsops.c +++ b/sys/fs/tmpfs/tmpfs_vfsops.c @@ -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 -__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 #include @@ -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. */