mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-24 07:40:52 +00:00
MFp4: Make use of the kernel unit number allocation facility
for tmpfs nodes. Submitted by: Mingyan Guo <guomingyan gmail com> Approved by: re (tmpfs blanket)
This commit is contained in:
parent
1e3703993b
commit
8d9a89a3a0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=171362
@ -288,10 +288,8 @@ struct tmpfs_mount {
|
||||
* of empty files and then simply removing them. */
|
||||
ino_t tm_nodes_max;
|
||||
|
||||
/* Number of nodes currently allocated. This number only grows.
|
||||
* When it reaches tm_nodes_max, no more new nodes can be allocated.
|
||||
* Of course, the old, unused ones can be reused. */
|
||||
ino_t tm_nodes_last;
|
||||
/* unrhdr used to allocate inode numbers */
|
||||
struct unrhdr * tm_ino_unr;
|
||||
|
||||
/* Number of nodes currently that are in use. */
|
||||
ino_t tm_nodes_inuse;
|
||||
|
@ -114,6 +114,7 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type,
|
||||
nnode->tn_uid = uid;
|
||||
nnode->tn_gid = gid;
|
||||
nnode->tn_mode = mode;
|
||||
nnode->tn_id = alloc_unr(tmp->tm_ino_unr);
|
||||
|
||||
/* Type-specific initialization. */
|
||||
switch (nnode->tn_type) {
|
||||
@ -225,6 +226,7 @@ tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node)
|
||||
break;
|
||||
}
|
||||
|
||||
free_unr(tmp->tm_ino_unr, node->tn_id);
|
||||
uma_zfree(tmp->tm_node_pool, node);
|
||||
|
||||
TMPFS_LOCK(tmp);
|
||||
|
@ -146,19 +146,7 @@ tmpfs_node_ctor(void *mem, int size, void *arg, int flags)
|
||||
{
|
||||
struct tmpfs_node *node = (struct tmpfs_node *)mem;
|
||||
|
||||
if (node->tn_id == 0) {
|
||||
/* if this node structure first time used */
|
||||
struct tmpfs_mount *tmp = (struct tmpfs_mount *)arg;
|
||||
TMPFS_LOCK(tmp);
|
||||
node->tn_id = tmp->tm_nodes_last++;
|
||||
TMPFS_UNLOCK(tmp);
|
||||
if (node->tn_id == INT_MAX)
|
||||
panic("all avariable id is used.");
|
||||
node->tn_gen = arc4random();
|
||||
} else {
|
||||
node->tn_gen++;
|
||||
}
|
||||
|
||||
node->tn_gen++;
|
||||
node->tn_size = 0;
|
||||
node->tn_status = 0;
|
||||
node->tn_flags = 0;
|
||||
@ -185,6 +173,7 @@ tmpfs_node_init(void *mem, int size, int flags)
|
||||
node->tn_id = 0;
|
||||
|
||||
mtx_init(&node->tn_interlock, "tmpfs node interlock", NULL, MTX_DEF);
|
||||
node->tn_gen = arc4random();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -278,13 +267,13 @@ tmpfs_mount(struct mount *mp, struct thread *td)
|
||||
|
||||
mtx_init(&tmp->allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF);
|
||||
tmp->tm_nodes_max = nodes;
|
||||
tmp->tm_nodes_last = 2;
|
||||
tmp->tm_nodes_inuse = 0;
|
||||
tmp->tm_maxfilesize = get_swpgtotal() * PAGE_SIZE;
|
||||
LIST_INIT(&tmp->tm_nodes_used);
|
||||
|
||||
tmp->tm_pages_max = pages;
|
||||
tmp->tm_pages_used = 0;
|
||||
tmp->tm_ino_unr = new_unrhdr(2, INT_MAX, &tmp->allnode_lock);
|
||||
tmp->tm_dirent_pool = uma_zcreate(
|
||||
"TMPFS dirent",
|
||||
sizeof(struct tmpfs_dirent),
|
||||
@ -307,9 +296,11 @@ tmpfs_mount(struct mount *mp, struct thread *td)
|
||||
if (error != 0 || root == NULL) {
|
||||
uma_zdestroy(tmp->tm_node_pool);
|
||||
uma_zdestroy(tmp->tm_dirent_pool);
|
||||
delete_unrhdr(tmp->tm_ino_unr);
|
||||
free(tmp, M_TMPFSMNT);
|
||||
return error;
|
||||
}
|
||||
KASSERT(root->tn_id == 2, ("tmpfs root with invalid ino: %d", root->tn_id));
|
||||
tmp->tm_root = root;
|
||||
|
||||
MNT_ILOCK(mp);
|
||||
@ -377,6 +368,7 @@ tmpfs_unmount(struct mount *mp, int mntflags, struct thread *l)
|
||||
|
||||
uma_zdestroy(tmp->tm_dirent_pool);
|
||||
uma_zdestroy(tmp->tm_node_pool);
|
||||
delete_unrhdr(tmp->tm_ino_unr);
|
||||
|
||||
mtx_destroy(&tmp->allnode_lock);
|
||||
MPASS(tmp->tm_pages_used == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user