xref: /illumos-gate/usr/src/uts/common/vm/seg_spt.h (revision 284ce987a33170d916c005f044ef6ce9ce8e1517)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52ba723d8Smec  * Common Development and Distribution License (the "License").
62ba723d8Smec  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22a98e9dbfSaguzovsk  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*284ce987SPatrick Mooney  * Copyright 2018 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_VM_SEG_SPT_H
287c478bd9Sstevel@tonic-gate #define	_VM_SEG_SPT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifndef _ASM
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
387c478bd9Sstevel@tonic-gate #include <sys/lgrp.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Passed data when creating spt segment.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate struct  segspt_crargs {
447c478bd9Sstevel@tonic-gate 	struct	seg	*seg_spt;
457c478bd9Sstevel@tonic-gate 	struct anon_map *amp;
467c478bd9Sstevel@tonic-gate 	uint_t		prot;
477c478bd9Sstevel@tonic-gate 	uint_t		flags;
487c478bd9Sstevel@tonic-gate 	uint_t		szc;
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct spt_data {
527c478bd9Sstevel@tonic-gate 	struct vnode	*spt_vp;
537c478bd9Sstevel@tonic-gate 	struct anon_map	*spt_amp;
547c478bd9Sstevel@tonic-gate 	size_t 		spt_realsize;
557c478bd9Sstevel@tonic-gate 	struct page	**spt_ppa;
567c478bd9Sstevel@tonic-gate 	ushort_t	*spt_ppa_lckcnt;
577c478bd9Sstevel@tonic-gate 	uint_t		spt_prot;
587c478bd9Sstevel@tonic-gate 	kmutex_t 	spt_lock;
597c478bd9Sstevel@tonic-gate 	size_t		spt_pcachecnt;	/* # of times in pcache */
607c478bd9Sstevel@tonic-gate 	uint_t		spt_flags;	/* Dynamic ISM or regular ISM */
612ba723d8Smec 	kcondvar_t	spt_cv;
622ba723d8Smec 	ushort_t	spt_gen;	/* only updated for DISM */
637c478bd9Sstevel@tonic-gate 	/*
647c478bd9Sstevel@tonic-gate 	 * Initial memory allocation policy
657c478bd9Sstevel@tonic-gate 	 * used during pre-allocation done in shmat()
667c478bd9Sstevel@tonic-gate 	 */
677c478bd9Sstevel@tonic-gate 	lgrp_mem_policy_info_t	spt_policy_info;
687c478bd9Sstevel@tonic-gate } spt_data_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Private data for spt_shm segment.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate typedef struct shm_data {
747c478bd9Sstevel@tonic-gate 	struct as	*shm_sptas;
757c478bd9Sstevel@tonic-gate 	struct anon_map *shm_amp;
76a98e9dbfSaguzovsk 	spgcnt_t	shm_softlockcnt; /* # outstanding lock operations */
777c478bd9Sstevel@tonic-gate 	struct seg 	*shm_sptseg;	/* pointer to spt segment */
787c478bd9Sstevel@tonic-gate 	char		*shm_vpage;	/* indicating locked pages */
797c478bd9Sstevel@tonic-gate 	spgcnt_t	shm_lckpgs;	/* # of locked pages per attached seg */
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	 * Memory allocation policy after shmat()
827c478bd9Sstevel@tonic-gate 	 */
837c478bd9Sstevel@tonic-gate 	lgrp_mem_policy_info_t	shm_policy_info;
84a98e9dbfSaguzovsk 	kmutex_t shm_segfree_syncmtx;	/* barrier lock for segspt_shmfree() */
857c478bd9Sstevel@tonic-gate } shm_data_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #define	DISM_PG_LOCKED		0x1	/* DISM page is locked */
887c478bd9Sstevel@tonic-gate #define	DISM_PPA_CHANGED	0x2	/* DISM new lock, need to rebuild ppa */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	DISM_LOCK_MAX		0xfffe	/* max number of locks per DISM page */
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #ifdef _KERNEL
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #ifndef _ASM
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Functions used in shm.c to call ISM.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate int	sptcreate(size_t size, struct seg **sptseg, struct anon_map *amp,
1017c478bd9Sstevel@tonic-gate 	    uint_t prot, uint_t flags, uint_t szc);
1027c478bd9Sstevel@tonic-gate void	sptdestroy(struct as *, struct anon_map *);
103*284ce987SPatrick Mooney int	segspt_shmattach(struct seg **, void *);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define	isspt(sp)	((sp)->shm_sptinfo ? (sp)->shm_sptinfo->sptas : NULL)
1067c478bd9Sstevel@tonic-gate #define	spt_locked(a)	((a) & SHM_SHARE_MMU)
1077c478bd9Sstevel@tonic-gate #define	spt_pageable(a)	((a) & SHM_PAGEABLE)
1087c478bd9Sstevel@tonic-gate #define	spt_invalid(a)	(spt_locked((a)) && spt_pageable((a)))
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * This can be applied to a segment with seg->s_ops == &segspt_shmops
1127c478bd9Sstevel@tonic-gate  * to determine the real size of the ISM segment.
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate #define	spt_realsize(seg) (((struct spt_data *)(((struct shm_data *)\
1157c478bd9Sstevel@tonic-gate 			((seg)->s_data))->shm_sptseg->s_data))->spt_realsize)
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * This can be applied to a segment with seg->s_ops == &segspt_ops
1197c478bd9Sstevel@tonic-gate  * to determine the flags of the {D}ISM segment.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate #define	spt_flags(seg) (((struct spt_data *)((seg)->s_data))->spt_flags)
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * For large page support
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate extern int segvn_anypgsz;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * In a 64-bit address space, we'll try to put ISM segments between
1327c478bd9Sstevel@tonic-gate  * PREDISM_BASE and PREDISM_BOUND.  The HAT may use these constants to
1337c478bd9Sstevel@tonic-gate  * predict that a VA is contained by an ISM segment, which may optimize
1347c478bd9Sstevel@tonic-gate  * translation.  The range must _only_ be treated as advisory; ISM segments
1357c478bd9Sstevel@tonic-gate  * may fall outside of the range, and non-ISM segments may be contained
1367c478bd9Sstevel@tonic-gate  * within the range.
1377c478bd9Sstevel@tonic-gate  * In order to avoid collision between ISM/DISM addresses with e.g.
1387c478bd9Sstevel@tonic-gate  * process heap addresses we will try to put ISM/DISM segments above
1397c478bd9Sstevel@tonic-gate  * PREDISM_1T_BASESHIFT (1T).
1407c478bd9Sstevel@tonic-gate  * The HAT is still expecting that any VA larger than PREDISM_BASESHIFT
1417c478bd9Sstevel@tonic-gate  * may belong to ISM/DISM (so on tlb miss it will probe first for 4M
1427c478bd9Sstevel@tonic-gate  * translation)
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate #define	PREDISM_BASESHIFT	33
1457c478bd9Sstevel@tonic-gate #define	PREDISM_1T_BASESHIFT	40
1467c478bd9Sstevel@tonic-gate #define	PREDISM_BASE		((uintptr_t)1 << PREDISM_BASESHIFT)
1477c478bd9Sstevel@tonic-gate #define	PREDISM_1T_BASE		((uintptr_t)1 << PREDISM_1T_BASESHIFT)
1487c478bd9Sstevel@tonic-gate #define	PREDISM_BOUND		((uintptr_t)1 << 63)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #endif	/* _VM_SEG_SPT_H */
157