git: a10870ecea81 - main - posix shm: mark backing objects with SHM_POSIXSHM flag
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 08 Oct 2024 12:39:23 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=a10870ecea813042db7c41e906e1a5c5693f8a34
commit a10870ecea813042db7c41e906e1a5c5693f8a34
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-07 01:26:38 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-10-08 12:37:57 +0000
posix shm: mark backing objects with SHM_POSIXSHM flag
and consistently store the pointer to shmfd into pager priv data space.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D46970
---
sys/kern/uipc_shm.c | 16 +++++++++++-----
sys/vm/vm_object.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index a5b2e62c568e..cf98e1410074 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -945,15 +945,20 @@ shm_alloc(struct ucred *ucred, mode_t mode, bool largepage)
shmfd->shm_gid = ucred->cr_gid;
shmfd->shm_mode = mode;
if (largepage) {
- shmfd->shm_object = phys_pager_allocate(NULL,
+ obj = shmfd->shm_object = phys_pager_allocate(NULL,
&shm_largepage_phys_ops, NULL, shmfd->shm_size,
VM_PROT_DEFAULT, 0, ucred);
+ VM_OBJECT_WLOCK(shmfd->shm_object);
+ obj->un_pager.phys.phys_priv = shmfd;
+ vm_object_set_flag(obj, OBJ_POSIXSHM);
+ VM_OBJECT_WUNLOCK(shmfd->shm_object);
shmfd->shm_lp_alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT;
} else {
obj = vm_pager_allocate(shmfd_pager_type, NULL,
shmfd->shm_size, VM_PROT_DEFAULT, 0, ucred);
VM_OBJECT_WLOCK(obj);
obj->un_pager.swp.swp_priv = shmfd;
+ vm_object_set_flag(obj, OBJ_POSIXSHM);
VM_OBJECT_WUNLOCK(obj);
shmfd->shm_object = obj;
}
@@ -993,11 +998,12 @@ shm_drop(struct shmfd *shmfd)
rangelock_destroy(&shmfd->shm_rl);
mtx_destroy(&shmfd->shm_mtx);
obj = shmfd->shm_object;
- if (!shm_largepage(shmfd)) {
- VM_OBJECT_WLOCK(obj);
+ VM_OBJECT_WLOCK(obj);
+ if (shm_largepage(shmfd))
+ obj->un_pager.phys.phys_priv = NULL;
+ else
obj->un_pager.swp.swp_priv = NULL;
- VM_OBJECT_WUNLOCK(obj);
- }
+ VM_OBJECT_WUNLOCK(obj);
vm_object_deallocate(obj);
free(shmfd, M_SHMFD);
}
diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h
index 73284fddd2a6..c7f0dd0943ba 100644
--- a/sys/vm/vm_object.h
+++ b/sys/vm/vm_object.h
@@ -172,6 +172,7 @@ struct vm_object {
void *data_ptr;
uintptr_t data_val;
};
+ void *phys_priv;
} phys;
} un_pager;
struct ucred *cred;
@@ -202,6 +203,7 @@ struct vm_object {
#define OBJ_PAGERPRIV1 0x00004000 /* Pager private */
#define OBJ_PAGERPRIV2 0x00008000 /* Pager private */
#define OBJ_SYSVSHM 0x00010000 /* SysV SHM */
+#define OBJ_POSIXSHM 0x00020000 /* Posix SHM */
/*
* Helpers to perform conversion between vm_object page indexes and offsets.