vm_glue.c revision 2692
1178622Smarcel/* 2178622Smarcel * Copyright (c) 1991, 1993 3178622Smarcel * The Regents of the University of California. All rights reserved. 4178622Smarcel * 5178622Smarcel * This code is derived from software contributed to Berkeley by 6178622Smarcel * The Mach Operating System project at Carnegie-Mellon University. 7178622Smarcel * 8178622Smarcel * Redistribution and use in source and binary forms, with or without 9178622Smarcel * modification, are permitted provided that the following conditions 10178622Smarcel * are met: 11178622Smarcel * 1. Redistributions of source code must retain the above copyright 12178622Smarcel * notice, this list of conditions and the following disclaimer. 13178622Smarcel * 2. Redistributions in binary form must reproduce the above copyright 14178622Smarcel * notice, this list of conditions and the following disclaimer in the 15178622Smarcel * documentation and/or other materials provided with the distribution. 16178622Smarcel * 3. All advertising materials mentioning features or use of this software 17178622Smarcel * must display the following acknowledgement: 18178622Smarcel * This product includes software developed by the University of 19178622Smarcel * California, Berkeley and its contributors. 20178622Smarcel * 4. Neither the name of the University nor the names of its contributors 21178622Smarcel * may be used to endorse or promote products derived from this software 22178622Smarcel * without specific prior written permission. 23178622Smarcel * 24178622Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25178622Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26178622Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27178622Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2878342Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29178622Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30178622Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31178622Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32178622Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33178622Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34178622Smarcel * SUCH DAMAGE. 35178622Smarcel * 36178622Smarcel * from: @(#)vm_glue.c 8.6 (Berkeley) 1/5/94 37178622Smarcel * 38196196Sattilio * 39212453Smav * Copyright (c) 1987, 1990 Carnegie-Mellon University. 40178622Smarcel * All rights reserved. 41178622Smarcel * 42178622Smarcel * Permission to use, copy, modify and distribute this software and 43222813Sattilio * its documentation is hereby granted, provided that both the copyright 44222813Sattilio * notice and this permission notice appear in all copies of the 45178622Smarcel * software, derivative works or modified versions, and any portions 46210939Sjhb * thereof, and that both notices appear in supporting documentation. 47222813Sattilio * 48178622Smarcel * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 49178622Smarcel * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 50178622Smarcel * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 51178622Smarcel * 52178622Smarcel * Carnegie Mellon requests users of this software to return to 53178622Smarcel * 54183060Smarcel * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55209975Snwhitehorn * School of Computer Science 56198378Snwhitehorn * Carnegie Mellon University 57198378Snwhitehorn * Pittsburgh PA 15213-3890 58183060Smarcel * 59178622Smarcel * any improvements or extensions that they make and grant Carnegie the 60178622Smarcel * rights to redistribute these changes. 61178622Smarcel * 62178622Smarcel * $Id: vm_glue.c,v 1.6 1994/08/18 22:36:01 wollman Exp $ 63 */ 64 65#include <sys/param.h> 66#include <sys/systm.h> 67#include <sys/proc.h> 68#include <sys/resourcevar.h> 69#include <sys/buf.h> 70#include <sys/user.h> 71 72#include <sys/kernel.h> 73#include <sys/dkstat.h> 74 75#include <vm/vm.h> 76#include <vm/vm_page.h> 77#include <vm/vm_pageout.h> 78#include <vm/vm_kern.h> 79 80#include <machine/stdarg.h> 81 82extern char kstack[]; 83int avefree = 0; /* XXX */ 84int readbuffers = 0; /* XXX allow kgdb to read kernel buffer pool */ 85/* vm_map_t upages_map; */ 86 87int 88kernacc(addr, len, rw) 89 caddr_t addr; 90 int len, rw; 91{ 92 boolean_t rv; 93 vm_offset_t saddr, eaddr; 94 vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE; 95 96 saddr = trunc_page(addr); 97 eaddr = round_page(addr+len); 98 rv = vm_map_check_protection(kernel_map, saddr, eaddr, prot); 99 return(rv == TRUE); 100} 101 102int 103useracc(addr, len, rw) 104 caddr_t addr; 105 int len, rw; 106{ 107 boolean_t rv; 108 vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE; 109 110 /* 111 * XXX - check separately to disallow access to user area and user 112 * page tables - they are in the map. 113 * 114 * XXX - VM_MAXUSER_ADDRESS is an end address, not a max. It was 115 * once only used (as an end address) in trap.c. Use it as an end 116 * address here too. This bogusness has spread. I just fixed 117 * where it was used as a max in vm_mmap.c. 118 */ 119 if ((vm_offset_t) addr + len > /* XXX */ VM_MAXUSER_ADDRESS 120 || (vm_offset_t) addr + len < (vm_offset_t) addr) { 121 return (FALSE); 122 } 123 124 rv = vm_map_check_protection(&curproc->p_vmspace->vm_map, 125 trunc_page(addr), round_page(addr+len), prot); 126 return(rv == TRUE); 127} 128 129#ifdef KGDB 130/* 131 * Change protections on kernel pages from addr to addr+len 132 * (presumably so debugger can plant a breakpoint). 133 * All addresses are assumed to reside in the Sysmap, 134 */ 135chgkprot(addr, len, rw) 136 register caddr_t addr; 137 int len, rw; 138{ 139 vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE; 140 141 vm_map_protect(kernel_map, trunc_page(addr), 142 round_page(addr+len), prot, FALSE); 143} 144#endif 145void 146vslock(addr, len) 147 caddr_t addr; 148 u_int len; 149{ 150 vm_map_pageable(&curproc->p_vmspace->vm_map, trunc_page(addr), 151 round_page(addr+len), FALSE); 152} 153 154void 155vsunlock(addr, len, dirtied) 156 caddr_t addr; 157 u_int len; 158 int dirtied; 159{ 160#ifdef lint 161 dirtied++; 162#endif lint 163 vm_map_pageable(&curproc->p_vmspace->vm_map, trunc_page(addr), 164 round_page(addr+len), TRUE); 165} 166 167/* 168 * Implement fork's actions on an address space. 169 * Here we arrange for the address space to be copied or referenced, 170 * allocate a user struct (pcb and kernel stack), then call the 171 * machine-dependent layer to fill those in and make the new process 172 * ready to run. 173 * NOTE: the kernel stack may be at a different location in the child 174 * process, and thus addresses of automatic variables may be invalid 175 * after cpu_fork returns in the child process. We do nothing here 176 * after cpu_fork returns. 177 */ 178int 179vm_fork(p1, p2, isvfork) 180 register struct proc *p1, *p2; 181 int isvfork; 182{ 183 register struct user *up; 184 vm_offset_t addr, ptaddr; 185 int i; 186 struct vm_map *vp; 187 188 while( cnt.v_free_count < cnt.v_free_min) 189 VM_WAIT; 190 191 /* 192 * avoid copying any of the parent's pagetables or other per-process 193 * objects that reside in the map by marking all of them non-inheritable 194 */ 195 (void)vm_map_inherit(&p1->p_vmspace->vm_map, 196 UPT_MIN_ADDRESS - UPAGES * NBPG, VM_MAX_ADDRESS, VM_INHERIT_NONE); 197 p2->p_vmspace = vmspace_fork(p1->p_vmspace); 198 199#ifdef SYSVSHM 200 if (p1->p_vmspace->vm_shm) 201 shmfork(p1, p2, isvfork); 202#endif 203 204 /* 205 * Allocate a wired-down (for now) pcb and kernel stack for the process 206 */ 207 208 addr = (vm_offset_t) kstack; 209 210 vp = &p2->p_vmspace->vm_map; 211 212 /* ream out old pagetables and kernel stack */ 213 (void)vm_deallocate(vp, addr, UPT_MAX_ADDRESS - addr); 214 215 /* get new pagetables and kernel stack */ 216 (void)vm_allocate(vp, &addr, UPT_MAX_ADDRESS - addr, FALSE); 217 218 /* force in the page table encompassing the UPAGES */ 219 ptaddr = trunc_page((u_int)vtopte(addr)); 220 vm_map_pageable(vp, ptaddr, ptaddr + NBPG, FALSE); 221 222 /* and force in (demand-zero) the UPAGES */ 223 vm_map_pageable(vp, addr, addr + UPAGES * NBPG, FALSE); 224 225 /* get a kernel virtual address for the UPAGES for this proc */ 226 up = (struct user *)kmem_alloc_pageable(kernel_map, UPAGES * NBPG); 227 228 /* and force-map the upages into the kernel pmap */ 229 for (i = 0; i < UPAGES; i++) 230 pmap_enter(vm_map_pmap(kernel_map), 231 ((vm_offset_t) up) + NBPG * i, 232 pmap_extract(vp->pmap, addr + NBPG * i), 233 VM_PROT_READ|VM_PROT_WRITE, 1); 234 235 /* and allow the UPAGES page table entry to be paged (at the vm system level) */ 236 vm_map_pageable(vp, ptaddr, ptaddr + NBPG, TRUE); 237 238 p2->p_addr = up; 239 240 /* 241 * p_stats and p_sigacts currently point at fields 242 * in the user struct but not at &u, instead at p_addr. 243 * Copy p_sigacts and parts of p_stats; zero the rest 244 * of p_stats (statistics). 245 */ 246 p2->p_stats = &up->u_stats; 247 p2->p_sigacts = &up->u_sigacts; 248 up->u_sigacts = *p1->p_sigacts; 249 bzero(&up->u_stats.pstat_startzero, 250 (unsigned) ((caddr_t)&up->u_stats.pstat_endzero - 251 (caddr_t)&up->u_stats.pstat_startzero)); 252 bcopy(&p1->p_stats->pstat_startcopy, &up->u_stats.pstat_startcopy, 253 ((caddr_t)&up->u_stats.pstat_endcopy - 254 (caddr_t)&up->u_stats.pstat_startcopy)); 255 256 257 /* 258 * cpu_fork will copy and update the kernel stack and pcb, 259 * and make the child ready to run. It marks the child 260 * so that it can return differently than the parent. 261 * It returns twice, once in the parent process and 262 * once in the child. 263 */ 264 return (cpu_fork(p1, p2)); 265} 266 267/* 268 * Set default limits for VM system. 269 * Called for proc 0, and then inherited by all others. 270 */ 271void 272vm_init_limits(p) 273 register struct proc *p; 274{ 275 int rss_limit; 276 277 /* 278 * Set up the initial limits on process VM. 279 * Set the maximum resident set size to be half 280 * of (reasonably) available memory. Since this 281 * is a soft limit, it comes into effect only 282 * when the system is out of memory - half of 283 * main memory helps to favor smaller processes, 284 * and reduces thrashing of the object cache. 285 */ 286 p->p_rlimit[RLIMIT_STACK].rlim_cur = DFLSSIZ; 287 p->p_rlimit[RLIMIT_STACK].rlim_max = MAXSSIZ; 288 p->p_rlimit[RLIMIT_DATA].rlim_cur = DFLDSIZ; 289 p->p_rlimit[RLIMIT_DATA].rlim_max = MAXDSIZ; 290 /* limit the limit to no less than 128K */ 291 rss_limit = max(cnt.v_free_count / 2, 32); 292 p->p_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit); 293 p->p_rlimit[RLIMIT_RSS].rlim_max = RLIM_INFINITY; 294} 295 296#ifdef DEBUG 297int enableswap = 1; 298int swapdebug = 0; 299#define SDB_FOLLOW 1 300#define SDB_SWAPIN 2 301#define SDB_SWAPOUT 4 302#endif 303 304void 305faultin(p) 306struct proc *p; 307{ 308 vm_offset_t i; 309 vm_offset_t vaddr, ptaddr; 310 vm_offset_t v, v1; 311 struct user *up; 312 int s; 313 int opflag; 314 315 if ((p->p_flag & P_INMEM) == 0) { 316 int rv0, rv1; 317 vm_map_t map; 318 319 ++p->p_lock; 320 321 map = &p->p_vmspace->vm_map; 322 /* force the page table encompassing the kernel stack (upages) */ 323 ptaddr = trunc_page((u_int)vtopte(kstack)); 324 vm_map_pageable(map, ptaddr, ptaddr + NBPG, FALSE); 325 326 /* wire in the UPAGES */ 327 vm_map_pageable(map, (vm_offset_t) kstack, 328 (vm_offset_t) kstack + UPAGES * NBPG, FALSE); 329 330 /* and map them nicely into the kernel pmap */ 331 for (i = 0; i < UPAGES; i++) { 332 vm_offset_t off = i * NBPG; 333 vm_offset_t pa = (vm_offset_t) 334 pmap_extract(&p->p_vmspace->vm_pmap, 335 (vm_offset_t) kstack + off); 336 pmap_enter(vm_map_pmap(kernel_map), 337 ((vm_offset_t)p->p_addr) + off, 338 pa, VM_PROT_READ|VM_PROT_WRITE, 1); 339 } 340 341 /* and let the page table pages go (at least above pmap level) */ 342 vm_map_pageable(map, ptaddr, ptaddr + NBPG, TRUE); 343 344 s = splhigh(); 345 346 if (p->p_stat == SRUN) 347 setrunqueue(p); 348 349 p->p_flag |= P_INMEM; 350 351 /* undo the effect of setting SLOCK above */ 352 --p->p_lock; 353 splx(s); 354 355 } 356 357} 358 359int swapinreq; 360int percentactive; 361/* 362 * This swapin algorithm attempts to swap-in processes only if there 363 * is enough space for them. Of course, if a process waits for a long 364 * time, it will be swapped in anyway. 365 */ 366void 367scheduler() 368{ 369 register struct proc *p; 370 register int pri; 371 struct proc *pp; 372 int ppri; 373 vm_offset_t addr; 374 int lastidle, lastrun; 375 int curidle, currun; 376 int forceload; 377 int percent; 378 int ntries; 379 380 lastidle = 0; 381 lastrun = 0; 382 383loop: 384 ntries = 0; 385 386 curidle = cp_time[CP_IDLE]; 387 currun = cp_time[CP_USER] + cp_time[CP_SYS] + cp_time[CP_NICE]; 388 percent = (100*(currun-lastrun)) / ( 1 + (currun-lastrun) + (curidle-lastidle)); 389 lastrun = currun; 390 lastidle = curidle; 391 if( percent > 100) 392 percent = 100; 393 percentactive = percent; 394 395 if( percentactive < 25) 396 forceload = 1; 397 else 398 forceload = 0; 399 400loop1: 401 pp = NULL; 402 ppri = INT_MIN; 403 for (p = (struct proc *)allproc; p != NULL; p = p->p_next) { 404 if (p->p_stat == SRUN && (p->p_flag & P_INMEM) == 0) { 405 int mempri; 406 pri = p->p_swtime + p->p_slptime - p->p_nice * 8; 407 mempri = pri > 0 ? pri : 0; 408 /* 409 * if this process is higher priority and there is 410 * enough space, then select this process instead 411 * of the previous selection. 412 */ 413 if (pri > ppri && 414 (((cnt.v_free_count + (mempri * (4*PAGE_SIZE) / PAGE_SIZE) >= (p->p_vmspace->vm_swrss)) || (ntries > 0 && forceload)))) { 415 pp = p; 416 ppri = pri; 417 } 418 } 419 } 420 421 if ((pp == NULL) && (ntries == 0) && forceload) { 422 ++ntries; 423 goto loop1; 424 } 425 426 /* 427 * Nothing to do, back to sleep 428 */ 429 if ((p = pp) == NULL) { 430 tsleep((caddr_t)&proc0, PVM, "sched", 0); 431 goto loop; 432 } 433 434 /* 435 * We would like to bring someone in. (only if there is space). 436 */ 437/* 438 printf("swapin: %d, free: %d, res: %d, min: %d\n", 439 p->p_pid, cnt.v_free_count, cnt.v_free_reserved, cnt.v_free_min); 440*/ 441 (void) splhigh(); 442 if ((forceload && (cnt.v_free_count > (cnt.v_free_reserved + UPAGES + 1))) || 443 (cnt.v_free_count >= cnt.v_free_min)) { 444 spl0(); 445 faultin(p); 446 p->p_swtime = 0; 447 goto loop; 448 } 449 /* 450 * log the memory shortage 451 */ 452 swapinreq += p->p_vmspace->vm_swrss; 453 /* 454 * Not enough memory, jab the pageout daemon and wait til the 455 * coast is clear. 456 */ 457 if( cnt.v_free_count < cnt.v_free_min) { 458 VM_WAIT; 459 } else { 460 tsleep((caddr_t)&proc0, PVM, "sched", 0); 461 } 462 (void) spl0(); 463 goto loop; 464} 465 466#define swappable(p) \ 467 (((p)->p_lock == 0) && \ 468 ((p)->p_flag & (P_TRACED|P_NOSWAP|P_SYSTEM|P_INMEM|P_WEXIT|P_PHYSIO)) == P_INMEM) 469 470extern int vm_pageout_free_min; 471/* 472 * Swapout is driven by the pageout daemon. Very simple, we find eligible 473 * procs and unwire their u-areas. We try to always "swap" at least one 474 * process in case we need the room for a swapin. 475 * If any procs have been sleeping/stopped for at least maxslp seconds, 476 * they are swapped. Else, we swap the longest-sleeping or stopped process, 477 * if any, otherwise the longest-resident process. 478 */ 479void 480swapout_threads() 481{ 482 register struct proc *p; 483 struct proc *outp, *outp2; 484 int outpri, outpri2; 485 int tpri; 486 int didswap = 0; 487 int swapneeded = swapinreq; 488 extern int maxslp; 489 int runnablenow; 490 int s; 491 492swapmore: 493 runnablenow = 0; 494 outp = outp2 = NULL; 495 outpri = outpri2 = INT_MIN; 496 for (p = (struct proc *)allproc; p != NULL; p = p->p_next) { 497 if (!swappable(p)) 498 continue; 499 switch (p->p_stat) { 500 case SRUN: 501 ++runnablenow; 502 /* 503 * count the process as being in a runnable state 504 */ 505 if ((tpri = p->p_swtime + p->p_nice * 8) > outpri2) { 506 outp2 = p; 507 outpri2 = tpri; 508 } 509 continue; 510 511 case SSLEEP: 512 case SSTOP: 513 /* 514 * do not swapout a process that is waiting for VM datastructures 515 * there is a possible deadlock. 516 */ 517 if (!lock_try_write( &p->p_vmspace->vm_map.lock)) { 518 continue; 519 } 520 vm_map_unlock( &p->p_vmspace->vm_map); 521 /* 522 * If the process has been asleep for awhile and had most 523 * of its pages taken away already, swap it out. 524 */ 525 if ((p->p_slptime > maxslp) && (p->p_vmspace->vm_pmap.pm_stats.resident_count <= 6)) { 526 swapout(p); 527 didswap++; 528 } else if ((tpri = p->p_slptime + p->p_nice * 8) > outpri) { 529 outp = p; 530 outpri = tpri ; 531 } 532 continue; 533 } 534 } 535 /* 536 * We swapout only if there are more than two runnable processes or if 537 * another process needs some space to swapin. 538 */ 539 if ((swapinreq || ((percentactive > 90) && (runnablenow > 2))) && 540 (((cnt.v_free_count + cnt.v_inactive_count) <= (cnt.v_free_target + cnt.v_inactive_target)) || 541 (cnt.v_free_count < cnt.v_free_min))) { 542 if ((p = outp) == 0) { 543 p = outp2; 544 } 545 546 /* 547 * Only swapout processes that have already had most 548 * of their pages taken away. 549 */ 550 if (p && (p->p_vmspace->vm_pmap.pm_stats.resident_count <= 6)) { 551 swapout(p); 552 didswap = 1; 553 } 554 } 555 556 /* 557 * if we previously had found a process to swapout, and we need to swapout 558 * more then try again. 559 */ 560#if 0 561 if( p && swapinreq) 562 goto swapmore; 563#endif 564 565 /* 566 * If we swapped something out, and another process needed memory, 567 * then wakeup the sched process. 568 */ 569 if (didswap) { 570 if (swapneeded) 571 wakeup((caddr_t)&proc0); 572 swapinreq = 0; 573 } 574} 575 576void 577swapout(p) 578 register struct proc *p; 579{ 580 vm_offset_t addr; 581 struct pmap *pmap = &p->p_vmspace->vm_pmap; 582 vm_map_t map = &p->p_vmspace->vm_map; 583 vm_offset_t ptaddr; 584 int i; 585 586 ++p->p_stats->p_ru.ru_nswap; 587 /* 588 * remember the process resident count 589 */ 590 p->p_vmspace->vm_swrss = 591 p->p_vmspace->vm_pmap.pm_stats.resident_count; 592 /* 593 * and decrement the amount of needed space 594 */ 595 swapinreq -= min(swapinreq, p->p_vmspace->vm_pmap.pm_stats.resident_count); 596 597 (void) splhigh(); 598 p->p_flag &= ~P_INMEM; 599 if (p->p_stat == SRUN) 600 remrq(p); 601 (void) spl0(); 602 603 ++p->p_lock; 604/* let the upages be paged */ 605 pmap_remove(vm_map_pmap(kernel_map), 606 (vm_offset_t) p->p_addr, ((vm_offset_t) p->p_addr) + UPAGES * NBPG); 607 608 vm_map_pageable(map, (vm_offset_t) kstack, 609 (vm_offset_t) kstack + UPAGES * NBPG, TRUE); 610 611 --p->p_lock; 612 p->p_swtime = 0; 613} 614 615/* 616 * The rest of these routines fake thread handling 617 */ 618 619#ifndef assert_wait 620void 621assert_wait(event, ruptible) 622 int event; 623 boolean_t ruptible; 624{ 625#ifdef lint 626 ruptible++; 627#endif 628 curproc->p_thread = event; 629} 630#endif 631 632void 633thread_block(char *msg) 634{ 635 if (curproc->p_thread) 636 tsleep((caddr_t)curproc->p_thread, PVM, msg, 0); 637} 638 639 640void 641thread_sleep_(event, lock, wmesg) 642 int event; 643 simple_lock_t lock; 644 char *wmesg; 645{ 646 647 curproc->p_thread = event; 648 simple_unlock(lock); 649 if (curproc->p_thread) { 650 tsleep((caddr_t)event, PVM, wmesg, 0); 651 } 652} 653 654#ifndef thread_wakeup 655void 656thread_wakeup(event) 657 int event; 658{ 659 wakeup((caddr_t)event); 660} 661#endif 662 663/* 664 * DEBUG stuff 665 */ 666 667int indent = 0; 668 669#include <machine/stdarg.h> /* see subr_prf.c */ 670 671/*ARGSUSED2*/ 672void 673#if __STDC__ 674iprintf(const char *fmt, ...) 675#else 676iprintf(fmt /* , va_alist */) 677 char *fmt; 678 /* va_dcl */ 679#endif 680{ 681 register int i; 682 va_list ap; 683 684 for (i = indent; i >= 8; i -= 8) 685 printf("\t"); 686 while (--i >= 0) 687 printf(" "); 688 va_start(ap, fmt); 689 printf("%r", fmt, ap); 690 va_end(ap); 691} 692