Module Name:    src
Committed By:   skrll
Date:           Mon Aug 22 23:07:36 UTC 2016

Modified Files:
        src/sys/fs/tmpfs: tmpfs_mem.c

Log Message:
Two fixes from rmind

- tmpfs_node_get: restore (decrement) the node count on the error path.
- tmpfs_bytes_max: save the value of uvmexp.freetarg (since it is
  unlocked/racy).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/fs/tmpfs/tmpfs_mem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/fs/tmpfs/tmpfs_mem.c
diff -u src/sys/fs/tmpfs/tmpfs_mem.c:1.8 src/sys/fs/tmpfs/tmpfs_mem.c:1.9
--- src/sys/fs/tmpfs/tmpfs_mem.c:1.8	Fri Jun 13 11:57:48 2014
+++ src/sys/fs/tmpfs/tmpfs_mem.c	Mon Aug 22 23:07:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_mem.c,v 1.8 2014/06/13 11:57:48 pooka Exp $	*/
+/*	$NetBSD: tmpfs_mem.c,v 1.9 2016/08/22 23:07:36 skrll 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.8 2014/06/13 11:57:48 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.9 2016/08/22 23:07:36 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -116,12 +116,13 @@ uint64_t
 tmpfs_bytes_max(struct tmpfs_mount *mp)
 {
 	psize_t freepages = tmpfs_mem_info(false);
+	int freetarg = uvmexp.freetarg;	// XXX unlocked
 	uint64_t avail_mem;
 
-	if (freepages < uvmexp.freetarg) {
+	if (freepages < freetarg) {
 		freepages = 0;
 	} else {
-		freepages -= uvmexp.freetarg;
+		freepages -= freetarg;
 	}
 	avail_mem = round_page(mp->tm_bytes_used) + (freepages << PAGE_SHIFT);
 	return MIN(mp->tm_mem_limit, avail_mem);
@@ -187,6 +188,7 @@ tmpfs_node_get(struct tmpfs_mount *mp)
 		return NULL;
 	}
 	if (!tmpfs_mem_incr(mp, sizeof(struct tmpfs_node))) {
+		atomic_dec_uint(&mp->tm_nodes_cnt);
 		return NULL;
 	}
 	return pool_get(&tmpfs_node_pool, PR_WAITOK);

Reply via email to