FreeBSD Bugzilla – Attachment 187384 Details for
Bug 223015
tmpfs does not support sparse files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
POC for using resident_page_count
tmpfs.diff (text/plain), 3.20 KB, created by
Keith White
on 2017-10-22 23:53:45 UTC
(
hide
)
Description:
POC for using resident_page_count
Filename:
MIME Type:
Creator:
Keith White
Created:
2017-10-22 23:53:45 UTC
Size:
3.20 KB
patch
obsolete
>Index: /usr/src/sys/fs/tmpfs/tmpfs_subr.c >=================================================================== >--- /usr/src/sys/fs/tmpfs/tmpfs_subr.c (revision 324624) >+++ /usr/src/sys/fs/tmpfs/tmpfs_subr.c (working copy) >@@ -351,7 +351,7 @@ > uobj = node->tn_reg.tn_aobj; > if (uobj != NULL) { > if (uobj->size != 0) >- atomic_subtract_long(&tmp->tm_pages_used, uobj->size); >+ atomic_subtract_long(&tmp->tm_pages_used, uobj->resident_page_count); > KASSERT((uobj->flags & OBJ_TMPFS) == 0, > ("leaked OBJ_TMPFS node %p vm_obj %p", node, uobj)); > vm_object_deallocate(uobj); >@@ -1361,7 +1361,7 @@ > struct tmpfs_node *node; > vm_object_t uobj; > vm_page_t m; >- vm_pindex_t idx, newpages, oldpages; >+ vm_pindex_t idx, newpages, oldpages, oldresident, newresident; > off_t oldsize; > int base, rv; > >@@ -1379,6 +1379,7 @@ > * its own. > */ > oldsize = node->tn_size; >+ oldresident = uobj->resident_page_count; > oldpages = OFF_TO_IDX(oldsize + PAGE_MASK); > MPASS(oldpages == uobj->size); > newpages = OFF_TO_IDX(newsize + PAGE_MASK); >@@ -1388,10 +1389,6 @@ > return (0); > } > >- if (newpages > oldpages && >- tmpfs_pages_check_avail(tmp, newpages - oldpages) == 0) >- return (ENOSPC); >- > VM_OBJECT_WLOCK(uobj); > if (newsize < oldsize) { > /* >@@ -1457,9 +1454,11 @@ > } > } > uobj->size = newpages; >+ newresident = uobj->resident_page_count; >+ > VM_OBJECT_WUNLOCK(uobj); > >- atomic_add_long(&tmp->tm_pages_used, newpages - oldpages); >+ atomic_add_long(&tmp->tm_pages_used, newresident - oldresident); > > node->tn_size = newsize; > return (0); >Index: /usr/src/sys/fs/tmpfs/tmpfs_vnops.c >=================================================================== >--- /usr/src/sys/fs/tmpfs/tmpfs_vnops.c (revision 324624) >+++ /usr/src/sys/fs/tmpfs/tmpfs_vnops.c (working copy) >@@ -488,6 +488,8 @@ > struct tmpfs_node *node; > off_t oldsize; > int error, ioflag; >+ vm_pindex_t oldresident, newresident; >+ struct tmpfs_mount *tmp; > > vp = v->a_vp; > uio = v->a_uio; >@@ -494,7 +496,9 @@ > ioflag = v->a_ioflag; > error = 0; > node = VP_TO_TMPFS_NODE(vp); >+ oldresident = node->tn_reg.tn_aobj->resident_page_count; > oldsize = node->tn_size; >+ tmp = VFS_TO_TMPFS(vp->v_mount); > > if (uio->uio_offset < 0 || vp->v_type != VREG) > return (EINVAL); >@@ -502,11 +506,13 @@ > return (0); > if (ioflag & IO_APPEND) > uio->uio_offset = node->tn_size; >- if (uio->uio_offset + uio->uio_resid > >- VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) >+ if (uio->uio_offset + uio->uio_resid > tmp->tm_maxfilesize) > return (EFBIG); > if (vn_rlimit_fsize(vp, uio, uio->uio_td)) > return (EFBIG); >+/* XXX need to check for vm_object with holes, this test is simplistic XXX */ >+ if (tmp->tm_pages_used + howmany(uio->uio_resid, PAGE_SIZE) >= tmp->tm_pages_max) >+ return(ENOSPC); > if (uio->uio_offset + uio->uio_resid > node->tn_size) { > error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid, > FALSE); >@@ -524,6 +530,9 @@ > if (error != 0) > (void)tmpfs_reg_resize(vp, oldsize, TRUE); > >+ newresident = node->tn_reg.tn_aobj->resident_page_count; >+ if (newresident != oldresident) >+ atomic_add_long(&tmp->tm_pages_used, newresident - oldresident); > out: > MPASS(IMPLIES(error == 0, uio->uio_resid == 0)); > MPASS(IMPLIES(error != 0, oldsize == node->tn_size));
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 223015
:
187197
| 187384