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 5cb15d5d9SPeter Rival * Common Development and Distribution License (the "License"). 6cb15d5d9SPeter Rival * 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 /* 22*ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 23cb15d5d9SPeter Rival * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifndef _SYS_SWAP_H 407c478bd9Sstevel@tonic-gate #define _SYS_SWAP_H 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 437c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 447c478bd9Sstevel@tonic-gate #include <vm/anon.h> 457c478bd9Sstevel@tonic-gate #include <sys/fs/swapnode.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 487c478bd9Sstevel@tonic-gate extern "C" { 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 527c478bd9Sstevel@tonic-gate #error "Cannot use swapctl in the large files compilation environment" 537c478bd9Sstevel@tonic-gate #endif 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* The following are for the swapctl system call */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #define SC_ADD 1 /* add a specified resource for swapping */ 587c478bd9Sstevel@tonic-gate #define SC_LIST 2 /* list all the swapping resources */ 597c478bd9Sstevel@tonic-gate #define SC_REMOVE 3 /* remove the specified swapping resource */ 607c478bd9Sstevel@tonic-gate #define SC_GETNSWP 4 /* get number of swap resources configured */ 617c478bd9Sstevel@tonic-gate #define SC_AINFO 5 /* get anonymous memory resource information */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate typedef struct swapres { 647c478bd9Sstevel@tonic-gate char *sr_name; /* pathname of the resource specified */ 657c478bd9Sstevel@tonic-gate off_t sr_start; /* starting offset of the swapping resource */ 667c478bd9Sstevel@tonic-gate off_t sr_length; /* length of the swap area */ 677c478bd9Sstevel@tonic-gate } swapres_t; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate typedef struct swapent { 707c478bd9Sstevel@tonic-gate char *ste_path; /* get the name of the swap file */ 717c478bd9Sstevel@tonic-gate off_t ste_start; /* starting block for swapping */ 727c478bd9Sstevel@tonic-gate off_t ste_length; /* length of swap area */ 737c478bd9Sstevel@tonic-gate long ste_pages; /* numbers of pages for swapping */ 747c478bd9Sstevel@tonic-gate long ste_free; /* numbers of ste_pages free */ 757c478bd9Sstevel@tonic-gate int ste_flags; /* see below */ 767c478bd9Sstevel@tonic-gate } swapent_t; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate typedef struct swaptable { 797c478bd9Sstevel@tonic-gate int swt_n; /* number of swapents following */ 807c478bd9Sstevel@tonic-gate struct swapent swt_ent[1]; /* array of swt_n swapents */ 817c478bd9Sstevel@tonic-gate } swaptbl_t; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* Kernel's view of user ILP32 swapres and swapent structures */ 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate typedef struct swapres32 { 897c478bd9Sstevel@tonic-gate caddr32_t sr_name; /* pathname of the resource specified */ 907c478bd9Sstevel@tonic-gate off32_t sr_start; /* starting offset of the swapping resource */ 917c478bd9Sstevel@tonic-gate off32_t sr_length; /* length of the swap area */ 927c478bd9Sstevel@tonic-gate } swapres32_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate typedef struct swapent32 { 957c478bd9Sstevel@tonic-gate caddr32_t ste_path; /* get the name of the swap file */ 967c478bd9Sstevel@tonic-gate off32_t ste_start; /* starting block for swapping */ 977c478bd9Sstevel@tonic-gate off32_t ste_length; /* length of swap area */ 987c478bd9Sstevel@tonic-gate int32_t ste_pages; /* numbers of pages for swapping */ 997c478bd9Sstevel@tonic-gate int32_t ste_free; /* numbers of ste_pages free */ 1007c478bd9Sstevel@tonic-gate int32_t ste_flags; /* see below */ 1017c478bd9Sstevel@tonic-gate } swapent32_t; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate typedef struct swaptable32 { 1047c478bd9Sstevel@tonic-gate int32_t swt_n; /* number of swapents following */ 1057c478bd9Sstevel@tonic-gate struct swapent32 swt_ent[1]; /* array of swt_n swapents */ 1067c478bd9Sstevel@tonic-gate } swaptbl32_t; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 1117c478bd9Sstevel@tonic-gate extern int swapctl(int, void *, int *); 1127c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_SYSCALL32) 1137c478bd9Sstevel@tonic-gate extern int swapctl32(int, void *, int *); 1147c478bd9Sstevel@tonic-gate #endif /* _LP64 && _SYSCALL32 */ 1157c478bd9Sstevel@tonic-gate #else /* !_KERNEL */ 1167c478bd9Sstevel@tonic-gate extern int swapctl(int, void *); 1177c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* ste_flags values */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #define ST_INDEL 0x01 /* Deletion of file is in progress. */ 1237c478bd9Sstevel@tonic-gate /* Prevents others from deleting or */ 1247c478bd9Sstevel@tonic-gate /* allocating from it */ 1257c478bd9Sstevel@tonic-gate #define ST_DOINGDEL 0x02 /* Set during deletion of file */ 1267c478bd9Sstevel@tonic-gate /* Clearing during deletion signals */ 1277c478bd9Sstevel@tonic-gate /* that you want to add the file back */ 1287c478bd9Sstevel@tonic-gate /* again, and will eventually cause */ 1297c478bd9Sstevel@tonic-gate /* it to be added back */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * VM - virtual swap device. 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate struct swapinfo { 1357c478bd9Sstevel@tonic-gate ulong_t si_soff; /* starting offset (bytes) of file */ 1367c478bd9Sstevel@tonic-gate ulong_t si_eoff; /* ending offset (bytes) of file */ 1377c478bd9Sstevel@tonic-gate struct vnode *si_vp; /* vnode (commonvp if device) */ 1387c478bd9Sstevel@tonic-gate struct swapinfo *si_next; /* next swap area */ 1397c478bd9Sstevel@tonic-gate int si_allocs; /* # of conseq. allocs from this area */ 1407c478bd9Sstevel@tonic-gate short si_flags; /* flags defined below */ 1417c478bd9Sstevel@tonic-gate pgcnt_t si_npgs; /* number of pages of swap space */ 1427c478bd9Sstevel@tonic-gate pgcnt_t si_nfpgs; /* number of free pages of swap space */ 1437c478bd9Sstevel@tonic-gate int si_pnamelen; /* swap file name length + 1 */ 1447c478bd9Sstevel@tonic-gate char *si_pname; /* swap file name */ 1457c478bd9Sstevel@tonic-gate ssize_t si_mapsize; /* # bytes allocated for bitmap */ 1467c478bd9Sstevel@tonic-gate uint_t *si_swapslots; /* bitmap of slots, unset == free */ 1477c478bd9Sstevel@tonic-gate pgcnt_t si_hint; /* first page to check if free */ 1487c478bd9Sstevel@tonic-gate ssize_t si_checkcnt; /* # of checks to find freeslot */ 1497c478bd9Sstevel@tonic-gate ssize_t si_alloccnt; /* used to find ave checks */ 1507c478bd9Sstevel@tonic-gate }; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Stuff to convert an anon slot pointer to a page name. 1547c478bd9Sstevel@tonic-gate * Because the address of the slot (ap) is a unique identifier, we 155cb15d5d9SPeter Rival * use it to generate a unique (vp,off), as shown in the comment for 156cb15d5d9SPeter Rival * swap_alloc(). 1577c478bd9Sstevel@tonic-gate * 1587c478bd9Sstevel@tonic-gate * The off bits are shifted PAGESHIFT to directly form a page aligned 1597c478bd9Sstevel@tonic-gate * offset; the vp index bits map 1-1 to a vnode. 1607c478bd9Sstevel@tonic-gate * 1617c478bd9Sstevel@tonic-gate */ 162cb15d5d9SPeter Rival #define MAX_SWAP_VNODES_LOG2 11 /* log2(MAX_SWAP_VNODES) */ 163cb15d5d9SPeter Rival #define MAX_SWAP_VNODES (1U << MAX_SWAP_VNODES_LOG2) /* max # swap vnodes */ 164cb15d5d9SPeter Rival #define AN_VPMASK (MAX_SWAP_VNODES - 1) /* vp index mask */ 165cb15d5d9SPeter Rival #define AN_VPSHIFT MAX_SWAP_VNODES_LOG2 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * Convert from an anon slot to associated vnode and offset. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate #define swap_xlate(AP, VPP, OFFP) \ 1707c478bd9Sstevel@tonic-gate { \ 1717c478bd9Sstevel@tonic-gate *(VPP) = (AP)->an_vp; \ 1727c478bd9Sstevel@tonic-gate *(OFFP) = (AP)->an_off; \ 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate #define swap_xlate_nopanic swap_xlate 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * Get a vnode name for an anon slot. 1787c478bd9Sstevel@tonic-gate * The vnum, offset are derived from anon struct address which is 179cb15d5d9SPeter Rival * 16 bytes aligned. anon structs may be kmem_cache_alloc'd concurrently by 180cb15d5d9SPeter Rival * multiple threads and come from a small range of addresses (same slab), in 181cb15d5d9SPeter Rival * which case high order AP bits do not vary much, so choose vnum from low 182cb15d5d9SPeter Rival * order bits which vary the most. Different threads will thus get different 183cb15d5d9SPeter Rival * vnums and vnodes, which avoids vph_mutex_contention on the subsequent 184cb15d5d9SPeter Rival * page_hashin(). 1857c478bd9Sstevel@tonic-gate * 186cb15d5d9SPeter Rival * +-----------...-------------------+-----------------------+----+ 187cb15d5d9SPeter Rival * | swap offset | vnum |0000| 188cb15d5d9SPeter Rival * +-----------...-------------------+-----------------------+----+ 189cb15d5d9SPeter Rival * 63 15 14 4 3 0 1907c478bd9Sstevel@tonic-gate */ 1917c478bd9Sstevel@tonic-gate #define swap_alloc(AP) \ 1927c478bd9Sstevel@tonic-gate { \ 193cb15d5d9SPeter Rival (AP)->an_vp = swapfs_getvp(((uintptr_t)(AP) >> AN_CACHE_ALIGN_LOG2) \ 194cb15d5d9SPeter Rival & AN_VPMASK); \ 195cb15d5d9SPeter Rival (AP)->an_off = (anoff_t)((((uintptr_t)(AP)) >> \ 196cb15d5d9SPeter Rival AN_VPSHIFT + AN_CACHE_ALIGN_LOG2) << PAGESHIFT); \ 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * Free the page name for the specified anon slot. 2017c478bd9Sstevel@tonic-gate * For now there's nothing to do. 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate #define swap_free(AP) 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* Flags for swap_phys_alloc */ 2067c478bd9Sstevel@tonic-gate #define SA_NOT 0x01 /* Must have slot from swap dev other than input one */ 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* Special error codes for swap_newphysname() */ 2097c478bd9Sstevel@tonic-gate #define SE_NOSWAP -1 /* No physical swap slots available */ 2107c478bd9Sstevel@tonic-gate #define SE_NOANON -2 /* No anon slot for swap slot */ 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #ifdef _KERNEL 2137c478bd9Sstevel@tonic-gate extern struct anon *swap_anon(struct vnode *vp, u_offset_t off); 2147c478bd9Sstevel@tonic-gate extern int swap_phys_alloc(struct vnode **vpp, u_offset_t *offp, size_t *lenp, 2157c478bd9Sstevel@tonic-gate uint_t flags); 2167c478bd9Sstevel@tonic-gate extern void swap_phys_free(struct vnode *vp, u_offset_t off, size_t len); 2177c478bd9Sstevel@tonic-gate extern int swap_getphysname(struct vnode *vp, u_offset_t off, 2187c478bd9Sstevel@tonic-gate struct vnode **pvpp, u_offset_t *poffp); 2197c478bd9Sstevel@tonic-gate extern int swap_newphysname(struct vnode *vp, u_offset_t offset, 2207c478bd9Sstevel@tonic-gate u_offset_t *offp, size_t *lenp, struct vnode **pvpp, u_offset_t *poffp); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate extern struct swapinfo *swapinfo; 2237c478bd9Sstevel@tonic-gate extern int swap_debug; 2247c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate #ifdef SWAP_DEBUG 2277c478bd9Sstevel@tonic-gate #define SW_RENAME 0x01 2287c478bd9Sstevel@tonic-gate #define SW_RESV 0x02 2297c478bd9Sstevel@tonic-gate #define SW_ALLOC 0x04 2307c478bd9Sstevel@tonic-gate #define SW_CTL 0x08 2317c478bd9Sstevel@tonic-gate #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5) \ 2327c478bd9Sstevel@tonic-gate if (swap_debug & f) \ 2337c478bd9Sstevel@tonic-gate printf(s, x1, x2, x3, x4, x5); 2347c478bd9Sstevel@tonic-gate #else /* SWAP_DEBUG */ 2357c478bd9Sstevel@tonic-gate #define SWAP_PRINT(f, s, x1, x2, x3, x4, x5) 2367c478bd9Sstevel@tonic-gate #endif /* SWAP_DEBUG */ 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate #endif 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate #endif /* _SYS_SWAP_H */ 243