vm_object.c (98e0ffaefb0f241cda3a72395d3be04192ae0d47) vm_object.c (ff87ae350ea75191bb1b11f5b5ef7b4db55ee799)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 65 unchanged lines hidden (view full) ---

74#include <sys/mount.h>
75#include <sys/kernel.h>
76#include <sys/sysctl.h>
77#include <sys/mutex.h>
78#include <sys/proc.h> /* for curproc, pageproc */
79#include <sys/socket.h>
80#include <sys/resourcevar.h>
81#include <sys/rwlock.h>
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 65 unchanged lines hidden (view full) ---

74#include <sys/mount.h>
75#include <sys/kernel.h>
76#include <sys/sysctl.h>
77#include <sys/mutex.h>
78#include <sys/proc.h> /* for curproc, pageproc */
79#include <sys/socket.h>
80#include <sys/resourcevar.h>
81#include <sys/rwlock.h>
82#include <sys/user.h>
82#include <sys/vnode.h>
83#include <sys/vmmeter.h>
84#include <sys/sx.h>
85
86#include <vm/vm.h>
87#include <vm/vm_param.h>
88#include <vm/pmap.h>
89#include <vm/vm_map.h>

--- 2191 unchanged lines hidden (view full) ---

2281 /* Release the accumulated object locks. */
2282 for (depth = 0; depth < locked_depth; depth++) {
2283 tobject = object->backing_object;
2284 VM_OBJECT_RUNLOCK(object);
2285 object = tobject;
2286 }
2287}
2288
83#include <sys/vnode.h>
84#include <sys/vmmeter.h>
85#include <sys/sx.h>
86
87#include <vm/vm.h>
88#include <vm/vm_param.h>
89#include <vm/pmap.h>
90#include <vm/vm_map.h>

--- 2191 unchanged lines hidden (view full) ---

2282 /* Release the accumulated object locks. */
2283 for (depth = 0; depth < locked_depth; depth++) {
2284 tobject = object->backing_object;
2285 VM_OBJECT_RUNLOCK(object);
2286 object = tobject;
2287 }
2288}
2289
2290static int
2291sysctl_vm_object_list(SYSCTL_HANDLER_ARGS)
2292{
2293 struct kinfo_vmobject kvo;
2294 char *fullpath, *freepath;
2295 struct vnode *vp;
2296 struct vattr va;
2297 vm_object_t obj;
2298 vm_page_t m;
2299 int count, error;
2300
2301 if (req->oldptr == NULL) {
2302 /*
2303 * If an old buffer has not been provided, generate an
2304 * estimate of the space needed for a subsequent call.
2305 */
2306 mtx_lock(&vm_object_list_mtx);
2307 count = 0;
2308 TAILQ_FOREACH(obj, &vm_object_list, object_list) {
2309 if (obj->type == OBJT_DEAD)
2310 continue;
2311 count++;
2312 }
2313 mtx_unlock(&vm_object_list_mtx);
2314 return (SYSCTL_OUT(req, NULL, sizeof(struct kinfo_vmobject) *
2315 count * 11 / 10));
2316 }
2317
2318 error = 0;
2319
2320 /*
2321 * VM objects are type stable and are never removed from the
2322 * list once added. This allows us to safely read obj->object_list
2323 * after reacquiring the VM object lock.
2324 */
2325 mtx_lock(&vm_object_list_mtx);
2326 TAILQ_FOREACH(obj, &vm_object_list, object_list) {
2327 if (obj->type == OBJT_DEAD)
2328 continue;
2329 VM_OBJECT_RLOCK(obj);
2330 if (obj->type == OBJT_DEAD) {
2331 VM_OBJECT_RUNLOCK(obj);
2332 continue;
2333 }
2334 mtx_unlock(&vm_object_list_mtx);
2335 kvo.kvo_size = ptoa(obj->size);
2336 kvo.kvo_resident = obj->resident_page_count;
2337 kvo.kvo_ref_count = obj->ref_count;
2338 kvo.kvo_shadow_count = obj->shadow_count;
2339 kvo.kvo_memattr = obj->memattr;
2340 kvo.kvo_active = 0;
2341 kvo.kvo_inactive = 0;
2342 TAILQ_FOREACH(m, &obj->memq, listq) {
2343 /*
2344 * A page may belong to the object but be
2345 * dequeued and set to PQ_NONE while the
2346 * object lock is not held. This makes the
2347 * reads of m->queue below racy, and we do not
2348 * count pages set to PQ_NONE. However, this
2349 * sysctl is only meant to give an
2350 * approximation of the system anyway.
2351 */
2352 if (m->queue == PQ_ACTIVE)
2353 kvo.kvo_active++;
2354 else if (m->queue == PQ_INACTIVE)
2355 kvo.kvo_inactive++;
2356 }
2357
2358 kvo.kvo_vn_fileid = 0;
2359 kvo.kvo_vn_fsid = 0;
2360 freepath = NULL;
2361 fullpath = "";
2362 vp = NULL;
2363 switch (obj->type) {
2364 case OBJT_DEFAULT:
2365 kvo.kvo_type = KVME_TYPE_DEFAULT;
2366 break;
2367 case OBJT_VNODE:
2368 kvo.kvo_type = KVME_TYPE_VNODE;
2369 vp = obj->handle;
2370 vref(vp);
2371 break;
2372 case OBJT_SWAP:
2373 kvo.kvo_type = KVME_TYPE_SWAP;
2374 break;
2375 case OBJT_DEVICE:
2376 kvo.kvo_type = KVME_TYPE_DEVICE;
2377 break;
2378 case OBJT_PHYS:
2379 kvo.kvo_type = KVME_TYPE_PHYS;
2380 break;
2381 case OBJT_DEAD:
2382 kvo.kvo_type = KVME_TYPE_DEAD;
2383 break;
2384 case OBJT_SG:
2385 kvo.kvo_type = KVME_TYPE_SG;
2386 break;
2387 case OBJT_MGTDEVICE:
2388 kvo.kvo_type = KVME_TYPE_MGTDEVICE;
2389 break;
2390 default:
2391 kvo.kvo_type = KVME_TYPE_UNKNOWN;
2392 break;
2393 }
2394 VM_OBJECT_RUNLOCK(obj);
2395 if (vp != NULL) {
2396 vn_fullpath(curthread, vp, &fullpath, &freepath);
2397 vn_lock(vp, LK_SHARED | LK_RETRY);
2398 if (VOP_GETATTR(vp, &va, curthread->td_ucred) == 0) {
2399 kvo.kvo_vn_fileid = va.va_fileid;
2400 kvo.kvo_vn_fsid = va.va_fsid;
2401 }
2402 vput(vp);
2403 }
2404
2405 strlcpy(kvo.kvo_path, fullpath, sizeof(kvo.kvo_path));
2406 if (freepath != NULL)
2407 free(freepath, M_TEMP);
2408
2409 /* Pack record size down */
2410 kvo.kvo_structsize = offsetof(struct kinfo_vmobject, kvo_path) +
2411 strlen(kvo.kvo_path) + 1;
2412 kvo.kvo_structsize = roundup(kvo.kvo_structsize,
2413 sizeof(uint64_t));
2414 error = SYSCTL_OUT(req, &kvo, kvo.kvo_structsize);
2415 mtx_lock(&vm_object_list_mtx);
2416 if (error)
2417 break;
2418 }
2419 mtx_unlock(&vm_object_list_mtx);
2420 return (error);
2421}
2422SYSCTL_PROC(_vm, OID_AUTO, objects, CTLTYPE_STRUCT | CTLFLAG_RW | CTLFLAG_SKIP |
2423 CTLFLAG_MPSAFE, NULL, 0, sysctl_vm_object_list, "S,kinfo_vmobject",
2424 "List of VM objects");
2425
2289#include "opt_ddb.h"
2290#ifdef DDB
2291#include <sys/kernel.h>
2292
2293#include <sys/cons.h>
2294
2295#include <ddb/ddb.h>
2296

--- 226 unchanged lines hidden ---
2426#include "opt_ddb.h"
2427#ifdef DDB
2428#include <sys/kernel.h>
2429
2430#include <sys/cons.h>
2431
2432#include <ddb/ddb.h>
2433

--- 226 unchanged lines hidden ---