2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 /* osi_vm.c implements:
13 * osi_VM_FlushVCache(avc, slept)
14 * osi_ubc_flush_dirty_and_wait(vp, flags)
15 * osi_VM_StoreAllSegments(avc)
16 * osi_VM_TryToSmush(avc, acred, sync)
17 * osi_VM_FlushPages(avc, credp)
18 * osi_VM_Truncate(avc, alen, acred)
21 #include <afsconfig.h>
22 #include "afs/param.h"
26 #include "afs/sysincludes.h" /* Standard vendor system headers */
27 #include "afsincludes.h" /* Afs-based standard headers */
28 #include "afs/afs_stats.h" /* statistics */
29 #include <vm/vm_object.h>
30 #include <vm/vm_map.h>
34 /* Try to discard pages, in order to recycle a vcache entry.
36 * We also make some sanity checks: ref count, open count, held locks.
38 * We also do some non-VM-related chores, such as releasing the cred pointer
39 * (for AIX and Solaris) and releasing the gnode (for AIX).
41 * Locking: afs_xvcache lock is held. If it is dropped and re-acquired,
42 * *slept should be set to warn the caller.
44 * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
45 * is not dropped and re-acquired for any platform. It may be that *slept is
46 * therefore obsolescent.
48 * OSF/1 Locking: VN_LOCK has been called.
50 int osi_VM_FlushVCache(struct vcache *avc, int *slept)
52 struct vm_object *obj;
54 if (VREFCOUNT(avc) > 1)
60 /* if a lock is held, give up */
61 if (CheckLock(&avc->lock) || afs_CheckBozonLock(&avc->pvnLock))
66 simple_lock(&vp->v_interlock);
67 if (VOP_GETVOBJECT(vp, &obj) == 0) {
68 vm_object_page_remove(obj, 0, 0, FALSE);
70 if (obj->ref_count == 0) {
72 simple_lock(&vp->v_interlock);
78 simple_unlock(&vp->v_interlock);
84 /* Try to store pages to cache, in order to store a file back to the server.
86 * Locking: the vcache entry's lock is held. It will usually be dropped and
89 void osi_VM_StoreAllSegments(struct vcache *avc)
92 struct vm_object *obj;
94 ReleaseWriteLock(&avc->lock);
100 simple_lock(&vp->v_interlock);
101 if (VOP_GETVOBJECT(vp, &obj) == 0 &&
102 (obj->flags & OBJ_MIGHTBEDIRTY)) {
104 LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) {
105 if (VOP_GETVOBJECT(vp, &obj) == 0) {
106 vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
112 simple_unlock(&vp->v_interlock);
114 } while (anyio && (--tries > 0));
116 ObtainWriteLock(&avc->lock,94);
119 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
120 * try to free pages, when deleting a file.
122 * Locking: the vcache entry's lock is held. It may be dropped and
125 * Since we drop and re-obtain the lock, we can't guarantee that there won't
126 * be some pages around when we return, newly created by concurrent activity.
128 void osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync)
131 struct vm_object *obj;
133 ReleaseWriteLock(&avc->lock);
139 simple_lock(&vp->v_interlock);
140 if (VOP_GETVOBJECT(vp, &obj) == 0 &&
141 (obj->flags & OBJ_MIGHTBEDIRTY)) {
143 LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ, curproc)) {
144 if (VOP_GETVOBJECT(vp, &obj) == 0) {
145 vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
151 simple_unlock(&vp->v_interlock);
153 } while (anyio && (--tries > 0));
154 simple_lock(&vp->v_interlock);
155 if (VOP_GETVOBJECT(vp, &obj) == 0) {
156 vm_object_page_remove(obj, 0, 0, FALSE);
158 simple_unlock(&vp->v_interlock);
159 /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/
161 ObtainWriteLock(&avc->lock,59);
164 /* Purge VM for a file when its callback is revoked.
166 * Locking: No lock is held, not even the global lock.
168 void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
171 struct vm_object *obj;
173 simple_lock(&vp->v_interlock);
174 if (VOP_GETVOBJECT(vp, &obj) == 0) {
175 vm_object_page_remove(obj, 0, 0, FALSE);
177 simple_unlock(&vp->v_interlock);
178 /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0);*/
181 /* Purge pages beyond end-of-file, when truncating a file.
183 * Locking: no lock is held, not even the global lock.
184 * activeV is raised. This is supposed to block pageins, but at present
185 * it only works on Solaris.
187 void osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
189 vnode_pager_setsize(AFSTOV(avc), alen);