Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151295626
D46959.id144356.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
10 KB
Referenced Files
None
Subscribers
None
D46959.id144356.diff
View Options
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -42,6 +42,7 @@
#include <sys/eventhandler.h>
#include <sys/exec.h>
#include <sys/fcntl.h>
+#include <sys/ipc.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/limits.h>
@@ -60,6 +61,7 @@
#include <sys/sbuf.h>
#include <sys/sysent.h>
#include <sys/sched.h>
+#include <sys/shm.h>
#include <sys/smp.h>
#include <sys/stack.h>
#include <sys/stat.h>
@@ -2615,6 +2617,8 @@
vm_offset_t addr;
unsigned int last_timestamp;
int error;
+ key_t key;
+ unsigned short seq;
bool guard, super;
PROC_LOCK_ASSERT(p, MA_OWNED);
@@ -2705,6 +2709,12 @@
kve->kve_ref_count = obj->ref_count;
kve->kve_shadow_count = obj->shadow_count;
VM_OBJECT_RUNLOCK(obj);
+ if ((obj->flags & OBJ_SYSVSHM) != 0) {
+ kve->kve_flags |= KVME_FLAG_SYSVSHM;
+ shmobjinfo(lobj, &key, &seq);
+ kve->kve_vn_fileid = key;
+ kve->kve_vn_fsid_freebsd11 = seq;
+ }
if (vp != NULL) {
vn_fullpath(vp, &fullpath, &freepath);
kve->kve_vn_type = vntype_to_kinfo(vp->v_type);
diff --git a/sys/kern/sysv_ipc.c b/sys/kern/sysv_ipc.c
--- a/sys/kern/sysv_ipc.c
+++ b/sys/kern/sysv_ipc.c
@@ -36,7 +36,6 @@
* $NetBSD: sysv_ipc.c,v 1.9 1995/06/02 19:04:22 mycroft Exp $
*/
-#include <sys/cdefs.h>
#include "opt_sysvipc.h"
#include <sys/param.h>
@@ -51,6 +50,8 @@
#ifndef SYSVSHM
void (*shmfork_hook)(struct proc *, struct proc *) = NULL;
void (*shmexit_hook)(struct vmspace *) = NULL;
+void (*shmobjinfo_hook)(struct vm_object *, key_t *key,
+ unsigned short *seq) = NULL;
/* called from kern_fork.c */
void
@@ -67,6 +68,15 @@
if (shmexit_hook != NULL)
shmexit_hook(vm);
}
+
+void
+shmobjinfo(struct vm_object *obj, key_t *key, unsigned short *seq)
+{
+ *key = 0; /* For non-present sysvshm.ko */
+ *seq = 0;
+ if (shmobjinfo_hook != NULL)
+ shmobjinfo_hook(obj, key, seq);
+}
#endif
/*
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -55,7 +55,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "opt_sysvipc.h"
#include <sys/param.h>
diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c
--- a/sys/kern/sysv_sem.c
+++ b/sys/kern/sysv_sem.c
@@ -44,7 +44,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "opt_sysvipc.h"
#include <sys/param.h>
diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c
--- a/sys/kern/sysv_shm.c
+++ b/sys/kern/sysv_shm.c
@@ -68,7 +68,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "opt_sysvipc.h"
#include <sys/param.h>
@@ -134,6 +133,8 @@
#ifndef SYSVSHM
static void shmexit_myhook(struct vmspace *vm);
static void shmfork_myhook(struct proc *p1, struct proc *p2);
+static void shmobjinfo_myhook(vm_object_t obj, key_t *key,
+ unsigned short *seq);
#endif
static int sysctl_shmsegs(SYSCTL_HANDLER_ARGS);
static void shm_remove(struct shmid_kernel *, int);
@@ -743,6 +744,10 @@
return (ENOMEM);
}
+ VM_OBJECT_WLOCK(shm_object);
+ vm_object_set_flag(shm_object, OBJ_SYSVSHM);
+ VM_OBJECT_WUNLOCK(shm_object);
+
shmseg->object = shm_object;
shmseg->u.shm_perm.cuid = shmseg->u.shm_perm.uid = cred->cr_uid;
shmseg->u.shm_perm.cgid = shmseg->u.shm_perm.gid = cred->cr_gid;
@@ -853,6 +858,29 @@
}
}
+#ifdef SYSVSHM
+void
+shmobjinfo(vm_object_t obj, key_t *key, unsigned short *seq)
+#else
+static void
+shmobjinfo_myhook(vm_object_t obj, key_t *key, unsigned short *seq)
+#endif
+{
+ int i;
+
+ *key = 0; /* For statically compiled-in sysv_shm.c */
+ *seq = 0;
+ SYSVSHM_LOCK();
+ for (i = 0; i < shmalloced; i++) {
+ if (shmsegs[i].object == obj) {
+ *key = shmsegs[i].u.shm_perm.key;
+ *seq = shmsegs[i].u.shm_perm.seq;
+ break;
+ }
+ }
+ SYSVSHM_UNLOCK();
+}
+
static void
shmrealloc(void)
{
@@ -959,6 +987,7 @@
#ifndef SYSVSHM
shmexit_hook = &shmexit_myhook;
shmfork_hook = &shmfork_myhook;
+ shmobjinfo_hook = &shmobjinfo_myhook;
#endif
/* Set current prisons according to their allow.sysvipc. */
@@ -1026,6 +1055,7 @@
#ifndef SYSVSHM
shmexit_hook = NULL;
shmfork_hook = NULL;
+ shmobjinfo_hook = NULL;
#endif
sx_destroy(&sysvshmsx);
return (0);
diff --git a/sys/sys/ipc.h b/sys/sys/ipc.h
--- a/sys/sys/ipc.h
+++ b/sys/sys/ipc.h
@@ -127,6 +127,7 @@
struct thread;
struct proc;
struct vmspace;
+struct vm_object;
#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
@@ -137,6 +138,8 @@
int ipcperm(struct thread *, struct ipc_perm *, int);
extern void (*shmfork_hook)(struct proc *, struct proc *);
extern void (*shmexit_hook)(struct vmspace *);
+extern void (*shmobjinfo_hook)(struct vm_object *obj, key_t *key,
+ unsigned short *seq);
#else /* ! _KERNEL */
diff --git a/sys/sys/shm.h b/sys/sys/shm.h
--- a/sys/sys/shm.h
+++ b/sys/sys/shm.h
@@ -149,6 +149,7 @@
#ifdef _KERNEL
struct proc;
struct vmspace;
+struct vm_object;
extern struct shminfo shminfo;
@@ -158,6 +159,7 @@
void shmexit(struct vmspace *);
void shmfork(struct proc *, struct proc *);
+void shmobjinfo(struct vm_object *obj, key_t *key, unsigned short *seq);
int kern_get_shmsegs(struct thread *td, struct shmid_kernel **res,
size_t *sz);
diff --git a/sys/sys/user.h b/sys/sys/user.h
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -514,6 +514,7 @@
#define KVME_FLAG_GROWS_UP 0x00000010
#define KVME_FLAG_GROWS_DOWN 0x00000020
#define KVME_FLAG_USER_WIRED 0x00000040
+#define KVME_FLAG_SYSVSHM 0x00000080
#if defined(__amd64__)
#define KINFO_OVMENTRY_SIZE 1168
@@ -576,6 +577,8 @@
#define kve_vn_fsid kve_type_spec._kve_vn_fsid
#define kve_obj kve_type_spec._kve_obj
+#define KVMO_FLAG_SYSVSHM 0x0001
+
/*
* The "vm.objects" sysctl provides a list of all VM objects in the system
* via an array of these entries.
@@ -599,7 +602,8 @@
uint64_t kvo_me; /* Uniq handle for anon obj */
uint64_t _kvo_qspare[6];
uint32_t kvo_swapped; /* Number of swapped pages */
- uint32_t _kvo_ispare[7];
+ uint32_t kvo_flags;
+ uint32_t _kvo_ispare[6];
char kvo_path[PATH_MAX]; /* Pathname, if any. */
};
#define kvo_vn_fsid kvo_type_spec._kvo_vn_fsid
diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h
--- a/sys/vm/vm_object.h
+++ b/sys/vm/vm_object.h
@@ -182,23 +182,26 @@
/*
* Flags
*/
-#define OBJ_FICTITIOUS 0x0001 /* (c) contains fictitious pages */
-#define OBJ_UNMANAGED 0x0002 /* (c) contains unmanaged pages */
-#define OBJ_POPULATE 0x0004 /* pager implements populate() */
-#define OBJ_DEAD 0x0008 /* dead objects (during rundown) */
-#define OBJ_ANON 0x0010 /* (c) contains anonymous memory */
-#define OBJ_UMTXDEAD 0x0020 /* umtx pshared was terminated */
-#define OBJ_SIZEVNLOCK 0x0040 /* lock vnode to check obj size */
-#define OBJ_PG_DTOR 0x0080 /* dont reset object, leave that for dtor */
-#define OBJ_SHADOWLIST 0x0100 /* Object is on the shadow list. */
-#define OBJ_SWAP 0x0200 /* object swaps, type will be OBJT_SWAP
+#define OBJ_FICTITIOUS 0x00000001 /* (c) contains fictitious pages */
+#define OBJ_UNMANAGED 0x00000002 /* (c) contains unmanaged pages */
+#define OBJ_POPULATE 0x00000004 /* pager implements populate() */
+#define OBJ_DEAD 0x00000008 /* dead objects (during rundown) */
+#define OBJ_ANON 0x00000010 /* (c) contains anonymous memory */
+#define OBJ_UMTXDEAD 0x00000020 /* umtx pshared was terminated */
+#define OBJ_SIZEVNLOCK 0x00000040 /* lock vnode to check obj size */
+#define OBJ_PG_DTOR 0x00000080 /* do not reset object, leave that
+ for dtor */
+#define OBJ_SHADOWLIST 0x00000100 /* Object is on the shadow list. */
+#define OBJ_SWAP 0x00000200 /* object swaps, type will be OBJT_SWAP
or dynamically registered */
-#define OBJ_SPLIT 0x0400 /* object is being split */
-#define OBJ_COLLAPSING 0x0800 /* Parent of collapse. */
-#define OBJ_COLORED 0x1000 /* pg_color is defined */
-#define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */
-#define OBJ_PAGERPRIV1 0x4000 /* Pager private */
-#define OBJ_PAGERPRIV2 0x8000 /* Pager private */
+#define OBJ_SPLIT 0x00000400 /* object is being split */
+#define OBJ_COLLAPSING 0x00000800 /* Parent of collapse. */
+#define OBJ_COLORED 0x00001000 /* pg_color is defined */
+#define OBJ_ONEMAPPING 0x00002000 /* One USE (a single, non-forked)
+ mapping flag */
+#define OBJ_PAGERPRIV1 0x00004000 /* Pager private */
+#define OBJ_PAGERPRIV2 0x00008000 /* Pager private */
+#define OBJ_SYSVSHM 0x00010000 /* SysV SHM */
/*
* Helpers to perform conversion between vm_object page indexes and offsets.
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -67,6 +67,7 @@
#include <sys/systm.h>
#include <sys/blockcount.h>
#include <sys/cpuset.h>
+#include <sys/ipc.h>
#include <sys/jail.h>
#include <sys/limits.h>
#include <sys/lock.h>
@@ -77,6 +78,7 @@
#include <sys/pctrie.h>
#include <sys/proc.h>
#include <sys/refcount.h>
+#include <sys/shm.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/resourcevar.h>
@@ -2506,6 +2508,8 @@
vm_page_t m;
u_long sp;
int count, error;
+ key_t key;
+ unsigned short seq;
bool want_path;
if (req->oldptr == NULL) {
@@ -2553,6 +2557,7 @@
kvo->kvo_memattr = obj->memattr;
kvo->kvo_active = 0;
kvo->kvo_inactive = 0;
+ kvo->kvo_flags = 0;
if (!swap_only) {
TAILQ_FOREACH(m, &obj->memq, listq) {
/*
@@ -2590,6 +2595,12 @@
kvo->kvo_swapped = sp > UINT32_MAX ? UINT32_MAX : sp;
}
VM_OBJECT_RUNLOCK(obj);
+ if ((obj->flags & OBJ_SYSVSHM) != 0) {
+ kvo->kvo_flags |= KVMO_FLAG_SYSVSHM;
+ shmobjinfo(obj, &key, &seq);
+ kvo->kvo_vn_fileid = key;
+ kvo->kvo_vn_fsid_freebsd11 = seq;
+ }
if (vp != NULL) {
vn_fullpath(vp, &fullpath, &freepath);
vn_lock(vp, LK_SHARED | LK_RETRY);
diff --git a/usr.bin/procstat/procstat_vm.c b/usr.bin/procstat/procstat_vm.c
--- a/usr.bin/procstat/procstat_vm.c
+++ b/usr.bin/procstat/procstat_vm.c
@@ -114,6 +114,8 @@
KVME_FLAG_GROWS_DOWN ? "true" : "false");
xo_emit("{en:wired/%s}", kve->kve_flags &
KVME_FLAG_USER_WIRED ? "true" : "false");
+ xo_emit("{en:sysvshm/%s}", kve->kve_flags &
+ KVME_FLAG_SYSVSHM ? "true" : "false");
xo_close_container("kve_flags");
switch (kve->kve_type) {
case KVME_TYPE_NONE:
@@ -164,6 +166,10 @@
}
xo_emit("{d:kve_type/%-2s} ", str);
xo_emit("{e:kve_type/%s}", lstr);
+ if ((kve->kve_flags & KVME_FLAG_SYSVSHM) != 0)
+ xo_emit(" {:sysvipc:/sysvshm(%ju:%u)/%ju:%u}",
+ (uintmax_t)kve->kve_vn_fileid,
+ kve->kve_vn_fsid_freebsd11);
xo_emit("{:kve_path/%-s/%s}\n", kve->kve_path);
xo_close_instance("vm");
}
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -1539,6 +1539,9 @@
break;
}
xo_emit("{:type/%-2s} ", str);
+ if ((kvo->kvo_flags & KVMO_FLAG_SYSVSHM) != 0)
+ xo_emit("{:sysvshm/sysvshm(%ju:%u)} ",
+ (uintmax_t)kvo->kvo_vn_fileid, kvo->kvo_vn_fsid_freebsd11);
xo_emit("{:path/%-s}\n", kvo->kvo_path);
xo_close_instance("object");
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 8, 9:46 AM (55 m, 53 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31092612
Default Alt Text
D46959.id144356.diff (10 KB)
Attached To
Mode
D46959: sysvshm: report mapped segments in procstat and objects in vmstat -o
Attached
Detach File
Event Timeline
Log In to Comment