svn commit: r295971 - in head/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Wed Feb 24 15:15:48 UTC 2016


Author: kib
Date: Wed Feb 24 15:15:46 2016
New Revision: 295971
URL: https://svnweb.freebsd.org/changeset/base/295971

Log:
  Provide more correct sizing of the KVA consumed by a vnode, used by
  the virtvnodes calculation.  Include the size of fs-specific v_data as
  the nfs nclnode inline, the NFS nclnode is bigger than either ZFS
  znode or UFS inode.  Include the size of namecache_ts and short cache
  path element, multiplied by the name cache population factor, again
  inline.
  
  Inline defines are used to avoid pollution of the vnode.h with the
  subsystem-private objects.  Non-significant unsynchronized changes of
  the definitions are fine, we do not care about that precision, and
  e.g. ZFS consumes much malloced memory per vnode for reasons
  unaccounted in the formula.
  
  Lower the partition of kmem dedicated to vnodes, from 1/7 to 1/10.
  
  The measures reduce vnode cache pressure on kmem and bring the vnode
  cache memory use below some apparent thresholds that were exceeded by
  r291244 due to more robust vnode reuse.
  
  Reported and tested by:	marius (i386, previous version)
  Reviewed by:	bde
  Sponsored by:	The FreeBSD Foundation
  MFC after:	2 weeks

Modified:
  head/sys/kern/vfs_cache.c
  head/sys/kern/vfs_subr.c
  head/sys/sys/vnode.h

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c	Wed Feb 24 13:48:40 2016	(r295970)
+++ head/sys/kern/vfs_cache.c	Wed Feb 24 15:15:46 2016	(r295971)
@@ -171,7 +171,7 @@ SYSCTL_ULONG(_debug, OID_AUTO, numcache,
 static u_long	numcachehv;		/* number of cache entries with vnodes held */
 SYSCTL_ULONG(_debug, OID_AUTO, numcachehv, CTLFLAG_RD, &numcachehv, 0,
     "Number of namecache entries with vnodes held");
-static u_int	ncsizefactor = 2;
+u_int	ncsizefactor = 2;
 SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, &ncsizefactor, 0,
     "Size factor for namecache");
 

Modified: head/sys/kern/vfs_subr.c
==============================================================================
--- head/sys/kern/vfs_subr.c	Wed Feb 24 13:48:40 2016	(r295970)
+++ head/sys/kern/vfs_subr.c	Wed Feb 24 15:15:46 2016	(r295971)
@@ -407,6 +407,27 @@ vnode_fini(void *mem, int size)
 	rw_destroy(BO_LOCKPTR(bo));
 }
 
+/*
+ * Provide the size of NFS nclnode and NFS fh for calculation of the
+ * vnode memory consumption.  The size is specified directly to
+ * eliminate dependency on NFS-private header.
+ *
+ * Other filesystems may use bigger or smaller (like UFS and ZFS)
+ * private inode data, but the NFS-based estimation is ample enough.
+ * Still, we care about differences in the size between 64- and 32-bit
+ * platforms.
+ *
+ * Namecache structure size is heuristically
+ * sizeof(struct namecache_ts) + CACHE_PATH_CUTOFF + 1.
+ */
+#ifdef _LP64
+#define	NFS_NCLNODE_SZ	(528 + 64)
+#define	NC_SZ		148
+#else
+#define	NFS_NCLNODE_SZ	(360 + 32)
+#define	NC_SZ		92
+#endif
+
 static void
 vntblinit(void *dummy __unused)
 {
@@ -422,12 +443,12 @@ vntblinit(void *dummy __unused)
 	 * marginal ratio of desiredvnodes to the physical memory size is
 	 * 1:64.  However, desiredvnodes is limited by the kernel's heap
 	 * size.  The memory required by desiredvnodes vnodes and vm objects
-	 * must not exceed 1/7th of the kernel's heap size.
+	 * must not exceed 1/10th of the kernel's heap size.
 	 */
 	physvnodes = maxproc + pgtok(vm_cnt.v_page_count) / 64 +
 	    3 * min(98304 * 16, pgtok(vm_cnt.v_page_count)) / 64;
-	virtvnodes = vm_kmem_size / (7 * (sizeof(struct vm_object) +
-	    sizeof(struct vnode)));
+	virtvnodes = vm_kmem_size / (10 * (sizeof(struct vm_object) +
+	    sizeof(struct vnode) + NC_SZ * ncsizefactor + NFS_NCLNODE_SZ));
 	desiredvnodes = min(physvnodes, virtvnodes);
 	if (desiredvnodes > MAXVNODES_MAX) {
 		if (bootverbose)

Modified: head/sys/sys/vnode.h
==============================================================================
--- head/sys/sys/vnode.h	Wed Feb 24 13:48:40 2016	(r295970)
+++ head/sys/sys/vnode.h	Wed Feb 24 15:15:46 2016	(r295971)
@@ -372,6 +372,8 @@ struct vattr {
 MALLOC_DECLARE(M_VNODE);
 #endif
 
+extern u_int ncsizefactor;
+
 /*
  * Convert between vnode types and inode formats (since POSIX.1
  * defines mode word of stat structure in terms of inode formats).


More information about the svn-src-all mailing list