summaryrefslogtreecommitdiffstats
path: root/sys/fs/tmpfs/tmpfs.h
diff options
context:
space:
mode:
authorgleb <gleb@FreeBSD.org>2012-04-07 15:23:51 +0000
committergleb <gleb@FreeBSD.org>2012-04-07 15:23:51 +0000
commitc4ba84f86e0e1f38a9b7138ac26876c1b293d20f (patch)
treea1ae0c42f1a9be9480e7e83902f2cecbf1671e5d /sys/fs/tmpfs/tmpfs.h
parentccd4f1d859903108662a41c03b085705ba7d8219 (diff)
downloadFreeBSD-src-c4ba84f86e0e1f38a9b7138ac26876c1b293d20f.zip
FreeBSD-src-c4ba84f86e0e1f38a9b7138ac26876c1b293d20f.tar.gz
Add reserved memory limit sysctl to tmpfs.
Cleanup availble and used memory functions. Check if free pages available before allocating new node. Discussed with: delphij
Diffstat (limited to 'sys/fs/tmpfs/tmpfs.h')
-rw-r--r--sys/fs/tmpfs/tmpfs.h57
1 files changed, 7 insertions, 50 deletions
diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h
index efa7c6d..fad97ac 100644
--- a/sys/fs/tmpfs/tmpfs.h
+++ b/sys/fs/tmpfs/tmpfs.h
@@ -337,11 +337,10 @@ struct tmpfs_mount {
* system, set during mount time. This variable must never be
* used directly as it may be bigger than the current amount of
* free memory; in the extreme case, it will hold the SIZE_MAX
- * value. Instead, use the TMPFS_PAGES_MAX macro. */
+ * value. */
size_t tm_pages_max;
- /* Number of pages in use by the file system. Cannot be bigger
- * than the value returned by TMPFS_PAGES_MAX in any case. */
+ /* Number of pages in use by the file system. */
size_t tm_pages_used;
/* Pointer to the node representing the root directory of this
@@ -486,57 +485,15 @@ int tmpfs_truncate(struct vnode *, off_t);
* Memory management stuff.
*/
-/* Amount of memory pages to reserve for the system (e.g., to not use by
- * tmpfs).
- * XXX: Should this be tunable through sysctl, for instance? */
-#define TMPFS_PAGES_RESERVED (4 * 1024 * 1024 / PAGE_SIZE)
-
/*
- * Returns information about the number of available memory pages,
- * including physical and virtual ones.
- *
- * Remember to remove TMPFS_PAGES_RESERVED from the returned value to avoid
- * excessive memory usage.
- *
+ * Amount of memory pages to reserve for the system (e.g., to not use by
+ * tmpfs).
*/
-static __inline size_t
-tmpfs_mem_info(void)
-{
-
- return (swap_pager_avail + cnt.v_free_count + cnt.v_cache_count);
-}
-
-/* Returns the maximum size allowed for a tmpfs file system. This macro
- * must be used instead of directly retrieving the value from tm_pages_max.
- * The reason is that the size of a tmpfs file system is dynamic: it lets
- * the user store files as long as there is enough free memory (including
- * physical memory and swap space). Therefore, the amount of memory to be
- * used is either the limit imposed by the user during mount time or the
- * amount of available memory, whichever is lower. To avoid consuming all
- * the memory for a given mount point, the system will always reserve a
- * minimum of TMPFS_PAGES_RESERVED pages, which is also taken into account
- * by this macro (see above). */
-static __inline size_t
-TMPFS_PAGES_MAX(struct tmpfs_mount *tmp)
-{
- size_t freepages;
-
- freepages = tmpfs_mem_info();
- freepages -= freepages < TMPFS_PAGES_RESERVED ?
- freepages : TMPFS_PAGES_RESERVED;
-
- return MIN(tmp->tm_pages_max, freepages + tmp->tm_pages_used);
-}
+#define TMPFS_PAGES_MINRESERVED (4 * 1024 * 1024 / PAGE_SIZE)
-/* Returns the available space for the given file system. */
-#define TMPFS_META_PAGES(tmp) (howmany((tmp)->tm_nodes_inuse * (sizeof(struct tmpfs_node) \
- + sizeof(struct tmpfs_dirent)), PAGE_SIZE))
-#define TMPFS_FILE_PAGES(tmp) ((tmp)->tm_pages_used)
+size_t tmpfs_mem_avail(void);
-#define TMPFS_PAGES_AVAIL(tmp) (TMPFS_PAGES_MAX(tmp) > \
- TMPFS_META_PAGES(tmp)+TMPFS_FILE_PAGES(tmp)? \
- TMPFS_PAGES_MAX(tmp) - TMPFS_META_PAGES(tmp) \
- - TMPFS_FILE_PAGES(tmp):0)
+size_t tmpfs_pages_used(struct tmpfs_mount *tmp);
#endif
OpenPOWER on IntegriCloud