1*27b03b36SApple OSS Distributions /* 2*27b03b36SApple OSS Distributions * Copyright (c) 2000-2014 Apple Inc. All rights reserved. 3*27b03b36SApple OSS Distributions * 4*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*27b03b36SApple OSS Distributions * 6*27b03b36SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*27b03b36SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*27b03b36SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*27b03b36SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*27b03b36SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*27b03b36SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*27b03b36SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*27b03b36SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*27b03b36SApple OSS Distributions * 15*27b03b36SApple OSS Distributions * Please obtain a copy of the License at 16*27b03b36SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*27b03b36SApple OSS Distributions * 18*27b03b36SApple OSS Distributions * The Original Code and all software distributed under the License are 19*27b03b36SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*27b03b36SApple OSS Distributions * Please see the License for the specific language governing rights and 24*27b03b36SApple OSS Distributions * limitations under the License. 25*27b03b36SApple OSS Distributions * 26*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*27b03b36SApple OSS Distributions */ 28*27b03b36SApple OSS Distributions /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ 29*27b03b36SApple OSS Distributions /* 30*27b03b36SApple OSS Distributions * Copyright (c) 1982, 1986, 1989, 1993 31*27b03b36SApple OSS Distributions * The Regents of the University of California. All rights reserved. 32*27b03b36SApple OSS Distributions * (c) UNIX System Laboratories, Inc. 33*27b03b36SApple OSS Distributions * All or some portions of this file are derived from material licensed 34*27b03b36SApple OSS Distributions * to the University of California by American Telephone and Telegraph 35*27b03b36SApple OSS Distributions * Co. or Unix System Laboratories, Inc. and are reproduced herein with 36*27b03b36SApple OSS Distributions * the permission of UNIX System Laboratories, Inc. 37*27b03b36SApple OSS Distributions * 38*27b03b36SApple OSS Distributions * Redistribution and use in source and binary forms, with or without 39*27b03b36SApple OSS Distributions * modification, are permitted provided that the following conditions 40*27b03b36SApple OSS Distributions * are met: 41*27b03b36SApple OSS Distributions * 1. Redistributions of source code must retain the above copyright 42*27b03b36SApple OSS Distributions * notice, this list of conditions and the following disclaimer. 43*27b03b36SApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright 44*27b03b36SApple OSS Distributions * notice, this list of conditions and the following disclaimer in the 45*27b03b36SApple OSS Distributions * documentation and/or other materials provided with the distribution. 46*27b03b36SApple OSS Distributions * 3. All advertising materials mentioning features or use of this software 47*27b03b36SApple OSS Distributions * must display the following acknowledgement: 48*27b03b36SApple OSS Distributions * This product includes software developed by the University of 49*27b03b36SApple OSS Distributions * California, Berkeley and its contributors. 50*27b03b36SApple OSS Distributions * 4. Neither the name of the University nor the names of its contributors 51*27b03b36SApple OSS Distributions * may be used to endorse or promote products derived from this software 52*27b03b36SApple OSS Distributions * without specific prior written permission. 53*27b03b36SApple OSS Distributions * 54*27b03b36SApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55*27b03b36SApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56*27b03b36SApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57*27b03b36SApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58*27b03b36SApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59*27b03b36SApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60*27b03b36SApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61*27b03b36SApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62*27b03b36SApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63*27b03b36SApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64*27b03b36SApple OSS Distributions * SUCH DAMAGE. 65*27b03b36SApple OSS Distributions * 66*27b03b36SApple OSS Distributions * @(#)buf.h 8.9 (Berkeley) 3/30/95 67*27b03b36SApple OSS Distributions */ 68*27b03b36SApple OSS Distributions 69*27b03b36SApple OSS Distributions #ifndef _SYS_BUF_INTERNAL_H_ 70*27b03b36SApple OSS Distributions #define _SYS_BUF_INTERNAL_H_ 71*27b03b36SApple OSS Distributions 72*27b03b36SApple OSS Distributions #include <sys/appleapiopts.h> 73*27b03b36SApple OSS Distributions 74*27b03b36SApple OSS Distributions #ifdef KERNEL 75*27b03b36SApple OSS Distributions #include <sys/queue.h> 76*27b03b36SApple OSS Distributions #include <sys/errno.h> 77*27b03b36SApple OSS Distributions #include <sys/vm.h> 78*27b03b36SApple OSS Distributions #include <sys/cdefs.h> 79*27b03b36SApple OSS Distributions #include <sys/buf.h> 80*27b03b36SApple OSS Distributions #include <sys/lock.h> 81*27b03b36SApple OSS Distributions 82*27b03b36SApple OSS Distributions #if CONFIG_PROTECT 83*27b03b36SApple OSS Distributions #include <sys/cprotect.h> 84*27b03b36SApple OSS Distributions #endif 85*27b03b36SApple OSS Distributions 86*27b03b36SApple OSS Distributions #define NOLIST ((struct buf *)0x87654321) 87*27b03b36SApple OSS Distributions 88*27b03b36SApple OSS Distributions /* 89*27b03b36SApple OSS Distributions * Attributes of an I/O to be used by lower layers 90*27b03b36SApple OSS Distributions */ 91*27b03b36SApple OSS Distributions struct bufattr { 92*27b03b36SApple OSS Distributions #if CONFIG_PROTECT 93*27b03b36SApple OSS Distributions struct cpx *ba_cpx; 94*27b03b36SApple OSS Distributions uint64_t ba_cp_file_off; 95*27b03b36SApple OSS Distributions #endif 96*27b03b36SApple OSS Distributions uint64_t ba_flags; /* flags. Some are only in-use on embedded devices */ 97*27b03b36SApple OSS Distributions void *ba_verify_ctx; 98*27b03b36SApple OSS Distributions }; 99*27b03b36SApple OSS Distributions 100*27b03b36SApple OSS Distributions /* 101*27b03b36SApple OSS Distributions * The buffer header describes an I/O operation in the kernel. 102*27b03b36SApple OSS Distributions */ 103*27b03b36SApple OSS Distributions struct buf { 104*27b03b36SApple OSS Distributions LIST_ENTRY(buf) b_hash; /* Hash chain. */ 105*27b03b36SApple OSS Distributions LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */ 106*27b03b36SApple OSS Distributions TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */ 107*27b03b36SApple OSS Distributions int b_timestamp; /* timestamp for queuing operation */ 108*27b03b36SApple OSS Distributions struct timeval b_timestamp_tv; /* microuptime for disk conditioner */ 109*27b03b36SApple OSS Distributions int b_whichq; /* the free list the buffer belongs to */ 110*27b03b36SApple OSS Distributions volatile uint32_t b_flags; /* B_* flags. */ 111*27b03b36SApple OSS Distributions volatile uint32_t b_lflags; /* BL_BUSY | BL_WANTED flags... protected by buf_mtx */ 112*27b03b36SApple OSS Distributions int b_error; /* errno value. */ 113*27b03b36SApple OSS Distributions int b_bufsize; /* Allocated buffer size. */ 114*27b03b36SApple OSS Distributions int b_bcount; /* Valid bytes in buffer. */ 115*27b03b36SApple OSS Distributions int b_resid; /* Remaining I/O. */ 116*27b03b36SApple OSS Distributions dev_t b_dev; /* Device associated with buffer. */ 117*27b03b36SApple OSS Distributions uintptr_t b_datap; /* Memory, superblocks, indirect etc.*/ 118*27b03b36SApple OSS Distributions daddr64_t b_lblkno; /* Logical block number. */ 119*27b03b36SApple OSS Distributions daddr64_t b_blkno; /* Underlying physical block number. */ 120*27b03b36SApple OSS Distributions void (*b_iodone)(buf_t, void *); /* Function to call upon completion. */ 121*27b03b36SApple OSS Distributions vnode_t b_vp; /* File vnode for data, device vnode for metadata. */ 122*27b03b36SApple OSS Distributions kauth_cred_t b_rcred; /* Read credentials reference. */ 123*27b03b36SApple OSS Distributions kauth_cred_t b_wcred; /* Write credentials reference. */ 124*27b03b36SApple OSS Distributions void * b_upl; /* Pointer to UPL */ 125*27b03b36SApple OSS Distributions buf_t b_real_bp; /* used to track bp generated through cluster_bp */ 126*27b03b36SApple OSS Distributions TAILQ_ENTRY(buf) b_act; /* Device driver queue when active */ 127*27b03b36SApple OSS Distributions void * b_drvdata; /* Device driver private use */ 128*27b03b36SApple OSS Distributions void * b_fsprivate; /* filesystem private use */ 129*27b03b36SApple OSS Distributions void * b_transaction; /* journal private use */ 130*27b03b36SApple OSS Distributions int b_dirtyoff; /* Offset in buffer of dirty region. */ 131*27b03b36SApple OSS Distributions int b_dirtyend; /* Offset of end of dirty region. */ 132*27b03b36SApple OSS Distributions int b_validoff; /* Offset in buffer of valid region. */ 133*27b03b36SApple OSS Distributions int b_validend; /* Offset of end of valid region. */ 134*27b03b36SApple OSS Distributions 135*27b03b36SApple OSS Distributions /* store extra information related to redundancy of data, such as 136*27b03b36SApple OSS Distributions * which redundancy copy to use, etc 137*27b03b36SApple OSS Distributions */ 138*27b03b36SApple OSS Distributions uint32_t b_redundancy_flags; 139*27b03b36SApple OSS Distributions 140*27b03b36SApple OSS Distributions proc_t b_proc; /* Associated proc; NULL if kernel. */ 141*27b03b36SApple OSS Distributions #ifdef BUF_MAKE_PRIVATE 142*27b03b36SApple OSS Distributions buf_t b_data_store; 143*27b03b36SApple OSS Distributions #endif 144*27b03b36SApple OSS Distributions struct bufattr b_attr; 145*27b03b36SApple OSS Distributions #ifdef JOE_DEBUG 146*27b03b36SApple OSS Distributions void * b_owner; 147*27b03b36SApple OSS Distributions int b_tag; 148*27b03b36SApple OSS Distributions void * b_lastbrelse; 149*27b03b36SApple OSS Distributions void * b_stackbrelse[6]; 150*27b03b36SApple OSS Distributions void * b_stackgetblk[6]; 151*27b03b36SApple OSS Distributions #endif 152*27b03b36SApple OSS Distributions uint32_t b_lblksize; /* Block size used to set b_lbkno */ 153*27b03b36SApple OSS Distributions }; 154*27b03b36SApple OSS Distributions 155*27b03b36SApple OSS Distributions extern vm_offset_t buf_kernel_addrperm; 156*27b03b36SApple OSS Distributions 157*27b03b36SApple OSS Distributions /* cluster_io definitions for use with io bufs */ 158*27b03b36SApple OSS Distributions #define b_uploffset b_bufsize 159*27b03b36SApple OSS Distributions #define b_orig b_freelist.tqe_prev 160*27b03b36SApple OSS Distributions #define b_shadow b_freelist.tqe_next 161*27b03b36SApple OSS Distributions #define b_shadow_ref b_validoff 162*27b03b36SApple OSS Distributions #ifdef BUF_MAKE_PRIVATE 163*27b03b36SApple OSS Distributions #define b_data_ref b_validend 164*27b03b36SApple OSS Distributions #endif 165*27b03b36SApple OSS Distributions #define b_trans_head b_freelist.tqe_prev 166*27b03b36SApple OSS Distributions #define b_trans_next b_freelist.tqe_next 167*27b03b36SApple OSS Distributions #define b_iostate b_rcred 168*27b03b36SApple OSS Distributions #define b_cliodone b_wcred 169*27b03b36SApple OSS Distributions 170*27b03b36SApple OSS Distributions /* 171*27b03b36SApple OSS Distributions * These flags are kept in b_lflags... 172*27b03b36SApple OSS Distributions * buf_mtx must be held before examining/updating 173*27b03b36SApple OSS Distributions */ 174*27b03b36SApple OSS Distributions #define BL_BUSY 0x00000001 /* I/O in progress. */ 175*27b03b36SApple OSS Distributions #define BL_WANTED 0x00000002 /* Process wants this buffer. */ 176*27b03b36SApple OSS Distributions #define BL_IOBUF 0x00000004 /* buffer allocated via 'buf_alloc' */ 177*27b03b36SApple OSS Distributions #define BL_WANTDEALLOC 0x00000010 /* buffer should be put on empty list when clean */ 178*27b03b36SApple OSS Distributions #define BL_SHADOW 0x00000020 179*27b03b36SApple OSS Distributions #define BL_EXTERNAL 0x00000040 180*27b03b36SApple OSS Distributions #define BL_WAITSHADOW 0x00000080 181*27b03b36SApple OSS Distributions #define BL_IOBUF_ALLOC 0x00000100 182*27b03b36SApple OSS Distributions #define BL_WANTED_REF 0x00000200 183*27b03b36SApple OSS Distributions #define BL_IOBUF_VDEV 0x00000400 /* iobuf was for a diskimage */ 184*27b03b36SApple OSS Distributions 185*27b03b36SApple OSS Distributions /* 186*27b03b36SApple OSS Distributions * Parameters for buffer cache garbage collection 187*27b03b36SApple OSS Distributions */ 188*27b03b36SApple OSS Distributions #define BUF_STALE_THRESHHOLD 30 /* Collect if untouched in the last 30 seconds */ 189*27b03b36SApple OSS Distributions #define BUF_MAX_GC_BATCH_SIZE 64 /* Under a single grab of the lock */ 190*27b03b36SApple OSS Distributions 191*27b03b36SApple OSS Distributions /* 192*27b03b36SApple OSS Distributions * mask used by buf_flags... these are the readable external flags 193*27b03b36SApple OSS Distributions */ 194*27b03b36SApple OSS Distributions #define BUF_X_RDFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\ 195*27b03b36SApple OSS Distributions B_META | B_CLUSTER | B_DELWRI | B_FUA | B_PASSIVE | B_IOSTREAMING |\ 196*27b03b36SApple OSS Distributions B_ENCRYPTED_IO | B_STATICCONTENT) 197*27b03b36SApple OSS Distributions /* 198*27b03b36SApple OSS Distributions * mask used by buf_clearflags/buf_setflags... these are the writable external flags 199*27b03b36SApple OSS Distributions */ 200*27b03b36SApple OSS Distributions #define BUF_X_WRFLAGS (B_PHYS | B_RAW | B_LOCKED | B_ASYNC | B_READ | B_WRITE | B_PAGEIO |\ 201*27b03b36SApple OSS Distributions B_NOCACHE | B_FUA | B_PASSIVE | B_IOSTREAMING) 202*27b03b36SApple OSS Distributions 203*27b03b36SApple OSS Distributions #if 0 204*27b03b36SApple OSS Distributions /* b_flags defined in buf.h */ 205*27b03b36SApple OSS Distributions #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ 206*27b03b36SApple OSS Distributions #define B_READ 0x00000001 /* Read buffer. */ 207*27b03b36SApple OSS Distributions #define B_ASYNC 0x00000002 /* Start I/O, do not wait. */ 208*27b03b36SApple OSS Distributions #define B_NOCACHE 0x00000004 /* Do not cache block after use. */ 209*27b03b36SApple OSS Distributions #define B_DELWRI 0x00000008 /* Delay I/O until buffer reused. */ 210*27b03b36SApple OSS Distributions #define B_LOCKED 0x00000010 /* Locked in core (not reusable). */ 211*27b03b36SApple OSS Distributions #define B_PHYS 0x00000020 /* I/O to user memory. */ 212*27b03b36SApple OSS Distributions #define B_CLUSTER 0x00000040 /* UPL based I/O generated by cluster layer */ 213*27b03b36SApple OSS Distributions #define B_PAGEIO 0x00000080 /* Page in/out */ 214*27b03b36SApple OSS Distributions #define B_META 0x00000100 /* buffer contains meta-data. */ 215*27b03b36SApple OSS Distributions #define B_RAW 0x00000200 /* Set by physio for raw transfers. */ 216*27b03b36SApple OSS Distributions #define B_FUA 0x00000400 /* Write-through disk cache(if supported) */ 217*27b03b36SApple OSS Distributions #define B_PASSIVE 0x00000800 /* PASSIVE I/Os are ignored by THROTTLE I/O */ 218*27b03b36SApple OSS Distributions #define B_IOSTREAMING 0x00001000 /* sequential access pattern detected */ 219*27b03b36SApple OSS Distributions #define B_ENCRYPTED_IO 0x00004000 /* Encrypted I/O */ 220*27b03b36SApple OSS Distributions #define B_STATICCONTENT 0x00008000 /* Buffer is likely to remain unaltered */ 221*27b03b36SApple OSS Distributions #endif 222*27b03b36SApple OSS Distributions 223*27b03b36SApple OSS Distributions /* 224*27b03b36SApple OSS Distributions * These flags are kept in b_flags... access is lockless 225*27b03b36SApple OSS Distributions * External flags are defined in buf.h and cannot overlap 226*27b03b36SApple OSS Distributions * the internal flags 227*27b03b36SApple OSS Distributions * 228*27b03b36SApple OSS Distributions * these flags are internal... there definition may change 229*27b03b36SApple OSS Distributions */ 230*27b03b36SApple OSS Distributions #define B_CACHE 0x00010000 /* getblk found us in the cache. */ 231*27b03b36SApple OSS Distributions #define B_DONE 0x00020000 /* I/O completed. */ 232*27b03b36SApple OSS Distributions #define B_INVAL 0x00040000 /* Does not contain valid info. */ 233*27b03b36SApple OSS Distributions #define B_ERROR 0x00080000 /* I/O error occurred. */ 234*27b03b36SApple OSS Distributions #define B_EINTR 0x00100000 /* I/O was interrupted */ 235*27b03b36SApple OSS Distributions #define B_AGE 0x00200000 /* Move to age queue when I/O done. */ 236*27b03b36SApple OSS Distributions #define B_FILTER 0x00400000 /* call b_iodone from biodone as an in-line filter */ 237*27b03b36SApple OSS Distributions #define B_CALL 0x00800000 /* Call b_iodone from biodone, assumes b_iodone consumes bp */ 238*27b03b36SApple OSS Distributions #define B_EOT 0x01000000 /* last buffer in a transaction list created by cluster_io */ 239*27b03b36SApple OSS Distributions #define B_WASDIRTY 0x02000000 /* page was found dirty in the VM cache */ 240*27b03b36SApple OSS Distributions #define B_HDRALLOC 0x04000000 /* zone allocated buffer header */ 241*27b03b36SApple OSS Distributions #define B_ZALLOC 0x08000000 /* b_datap is zalloc()ed */ 242*27b03b36SApple OSS Distributions /* 243*27b03b36SApple OSS Distributions * private flags used by by the cluster layer 244*27b03b36SApple OSS Distributions */ 245*27b03b36SApple OSS Distributions #define B_COMMIT_UPL 0x40000000 /* commit/abort the UPL on I/O success/failure */ 246*27b03b36SApple OSS Distributions #define B_TDONE 0x80000000 /* buf_t that is part of a cluster level transaction has completed */ 247*27b03b36SApple OSS Distributions 248*27b03b36SApple OSS Distributions /* Flags to low-level allocation routines. */ 249*27b03b36SApple OSS Distributions #define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ 250*27b03b36SApple OSS Distributions #define B_SYNC 0x02 /* Do all allocations synchronously. */ 251*27b03b36SApple OSS Distributions #define B_NOBUFF 0x04 /* Do not allocate struct buf */ 252*27b03b36SApple OSS Distributions 253*27b03b36SApple OSS Distributions /* 254*27b03b36SApple OSS Distributions * ba_flags (Buffer Attribute flags) 255*27b03b36SApple OSS Distributions * Some of these may be in-use only on embedded devices. 256*27b03b36SApple OSS Distributions */ 257*27b03b36SApple OSS Distributions #define BA_RAW_ENCRYPTED_IO 0x00000001 258*27b03b36SApple OSS Distributions #define BA_THROTTLED_IO 0x00000002 259*27b03b36SApple OSS Distributions #define BA_DELAYIDLESLEEP 0x00000004 /* Process is marked to delay idle sleep on disk IO */ 260*27b03b36SApple OSS Distributions #define BA_NOCACHE 0x00000008 261*27b03b36SApple OSS Distributions #define BA_META 0x00000010 262*27b03b36SApple OSS Distributions #define BA_GREEDY_MODE 0x00000020 /* High speed writes that consume more storage */ 263*27b03b36SApple OSS Distributions #define BA_QUICK_COMPLETE 0x00000040 /* Request quick completion at expense of storage efficiency */ 264*27b03b36SApple OSS Distributions #define BA_PASSIVE 0x00000080 265*27b03b36SApple OSS Distributions 266*27b03b36SApple OSS Distributions /* 267*27b03b36SApple OSS Distributions * Note: IO_TIERs consume 0x0100, 0x0200, 0x0400, 0x0800 268*27b03b36SApple OSS Distributions * These are now in-use by the I/O tiering system. 269*27b03b36SApple OSS Distributions */ 270*27b03b36SApple OSS Distributions #define BA_IO_TIER_MASK 0x00000f00 271*27b03b36SApple OSS Distributions #define BA_IO_TIER_SHIFT 8 272*27b03b36SApple OSS Distributions 273*27b03b36SApple OSS Distributions #define BA_ISOCHRONOUS 0x00001000 /* device specific isochronous throughput to media */ 274*27b03b36SApple OSS Distributions 275*27b03b36SApple OSS Distributions #define BA_STRATEGY_TRACKED_IO 0x00002000 /* tracked by spec_strategy */ 276*27b03b36SApple OSS Distributions #define BA_IO_TIER_UPGRADE 0x00004000 /* effective I/O tier is higher than BA_IO_TIER */ 277*27b03b36SApple OSS Distributions #define BA_IO_SCHEDULED 0x00008000 /* buf is associated with a mount point that is io scheduled */ 278*27b03b36SApple OSS Distributions #define BA_EXPEDITED_META_IO 0x00010000 /* metadata I/O which needs a high I/O tier */ 279*27b03b36SApple OSS Distributions #define BA_WILL_VERIFY 0x00020000 /* Cluster layer will verify data */ 280*27b03b36SApple OSS Distributions 281*27b03b36SApple OSS Distributions #define GET_BUFATTR_IO_TIER(bap) ((bap->ba_flags & BA_IO_TIER_MASK) >> BA_IO_TIER_SHIFT) 282*27b03b36SApple OSS Distributions #define SET_BUFATTR_IO_TIER(bap, tier) \ 283*27b03b36SApple OSS Distributions do { \ 284*27b03b36SApple OSS Distributions (bap)->ba_flags &= (~BA_IO_TIER_MASK); \ 285*27b03b36SApple OSS Distributions (bap)->ba_flags |= (((tier) << BA_IO_TIER_SHIFT) & BA_IO_TIER_MASK); \ 286*27b03b36SApple OSS Distributions } while(0) 287*27b03b36SApple OSS Distributions 288*27b03b36SApple OSS Distributions extern int niobuf_headers; /* The number of IO buffer headers for cluster IO */ 289*27b03b36SApple OSS Distributions extern int nbuf_headers; /* The number of buffer headers */ 290*27b03b36SApple OSS Distributions extern int max_nbuf_headers; /* The max number of buffer headers */ 291*27b03b36SApple OSS Distributions extern int nbuf_hashelements; /* The number of elements in bufhash */ 292*27b03b36SApple OSS Distributions extern struct buf *buf_headers; /* The buffer headers. */ 293*27b03b36SApple OSS Distributions 294*27b03b36SApple OSS Distributions 295*27b03b36SApple OSS Distributions /* 296*27b03b36SApple OSS Distributions * Definitions for the buffer free lists. 297*27b03b36SApple OSS Distributions */ 298*27b03b36SApple OSS Distributions 299*27b03b36SApple OSS Distributions enum bq_opts { 300*27b03b36SApple OSS Distributions BQ_LOCKED = 0, /* super-blocks &c */ 301*27b03b36SApple OSS Distributions BQ_LRU = 1, /* lru, useful buffers */ 302*27b03b36SApple OSS Distributions BQ_AGE = 2, /* rubbish */ 303*27b03b36SApple OSS Distributions BQ_EMPTY = 3, /* buffer headers with no memory */ 304*27b03b36SApple OSS Distributions BQ_META = 4, /* buffer containing metadata */ 305*27b03b36SApple OSS Distributions BQ_LAUNDRY = 5, /* buffers that need cleaning */ 306*27b03b36SApple OSS Distributions BQUEUES = 6 /* number of free buffer queues */ 307*27b03b36SApple OSS Distributions }; 308*27b03b36SApple OSS Distributions 309*27b03b36SApple OSS Distributions #define CLUSTER_IO_BLOCK_SIZE 0x1000 310*27b03b36SApple OSS Distributions 311*27b03b36SApple OSS Distributions __BEGIN_DECLS 312*27b03b36SApple OSS Distributions 313*27b03b36SApple OSS Distributions buf_t alloc_io_buf(vnode_t, int); 314*27b03b36SApple OSS Distributions void free_io_buf(buf_t); 315*27b03b36SApple OSS Distributions 316*27b03b36SApple OSS Distributions int allocbuf(struct buf *, int); 317*27b03b36SApple OSS Distributions void bufinit(void); 318*27b03b36SApple OSS Distributions 319*27b03b36SApple OSS Distributions void buf_list_lock(void); 320*27b03b36SApple OSS Distributions void buf_list_unlock(void); 321*27b03b36SApple OSS Distributions 322*27b03b36SApple OSS Distributions void cluster_init(void); 323*27b03b36SApple OSS Distributions 324*27b03b36SApple OSS Distributions uint32_t count_busy_buffers(void); 325*27b03b36SApple OSS Distributions 326*27b03b36SApple OSS Distributions int buf_flushdirtyblks_skipinfo(vnode_t, int, int, const char *); 327*27b03b36SApple OSS Distributions void buf_wait_for_shadow_io(vnode_t, daddr64_t); 328*27b03b36SApple OSS Distributions 329*27b03b36SApple OSS Distributions #ifdef BUF_MAKE_PRIVATE 330*27b03b36SApple OSS Distributions errno_t buf_make_private(buf_t bp); 331*27b03b36SApple OSS Distributions #endif 332*27b03b36SApple OSS Distributions 333*27b03b36SApple OSS Distributions #ifdef CONFIG_PROTECT 334*27b03b36SApple OSS Distributions void buf_setcpoff(buf_t, uint64_t); 335*27b03b36SApple OSS Distributions #endif 336*27b03b36SApple OSS Distributions 337*27b03b36SApple OSS Distributions __END_DECLS 338*27b03b36SApple OSS Distributions 339*27b03b36SApple OSS Distributions 340*27b03b36SApple OSS Distributions /* 341*27b03b36SApple OSS Distributions * Stats on usefulness of the buffer cache 342*27b03b36SApple OSS Distributions */ 343*27b03b36SApple OSS Distributions struct bufstats { 344*27b03b36SApple OSS Distributions long bufs_incore; /* found incore */ 345*27b03b36SApple OSS Distributions long bufs_busyincore; /* found incore. was busy */ 346*27b03b36SApple OSS Distributions long bufs_vmhits; /* not incore. found in VM */ 347*27b03b36SApple OSS Distributions long bufs_miss; /* not incore. not in VM */ 348*27b03b36SApple OSS Distributions long bufs_sleeps; /* buffer starvation */ 349*27b03b36SApple OSS Distributions long bufs_eblk; /* Calls to geteblk */ 350*27b03b36SApple OSS Distributions uint32_t bufs_iobufmax; /* Max. number of IO buffers used */ 351*27b03b36SApple OSS Distributions uint32_t bufs_iobufinuse; /* number of IO buffers in use */ 352*27b03b36SApple OSS Distributions long bufs_iobufsleeps; /* IO buffer starvation */ 353*27b03b36SApple OSS Distributions long bufs_iobufinuse_vdev; /* number of IO buffers in use by 354*27b03b36SApple OSS Distributions * diskimages */ 355*27b03b36SApple OSS Distributions }; 356*27b03b36SApple OSS Distributions 357*27b03b36SApple OSS Distributions #endif /* KERNEL */ 358*27b03b36SApple OSS Distributions #endif /* !_SYS_BUF_H_ */ 359