1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 #pragma ident "%Z%%M% %I% %E% SMI" 23 24 /* 25 * Copyright (c) 1986 by Sun Microsystems, Inc. 26 */ 27 28 #include "mallint.h" 29 #include <errno.h> 30 31 /* 32 * mallopt -- System V-compatible malloc "optimizer" 33 */ 34 mallopt(cmd, value) 35 int cmd, value; 36 { 37 if (__mallinfo.smblks != 0) 38 return(-1); /* small block has been allocated */ 39 40 switch (cmd) { 41 case M_MXFAST: /* small block size */ 42 if (value < 0) 43 return(-1); 44 __mallinfo.mxfast = value; 45 break; 46 47 case M_NLBLKS: /* # small blocks per holding block */ 48 if (value <= 0) 49 return(-1); 50 __mallinfo.nlblks = value; 51 break; 52 53 case M_GRAIN: /* small block rounding factor */ 54 if (value <= 0) 55 return(-1); 56 /* round up to multiple of minimum alignment */ 57 __mallinfo.grain = roundup(value, ALIGNSIZ); 58 break; 59 60 case M_KEEP: /* Sun algorithm always preserves data */ 61 break; 62 63 default: 64 return(-1); 65 } 66 67 /* make sure that everything is consistent */ 68 __mallinfo.mxfast = roundup(__mallinfo.mxfast, __mallinfo.grain); 69 70 return(0); 71 } 72 73 74 /* 75 * mallinfo -- System V-compatible malloc information reporter 76 */ 77 struct mallinfo 78 mallinfo() 79 { 80 struct mallinfo mi; 81 82 mi = __mallinfo; 83 mi.uordblks = mi.uordbytes - (mi.allocated * sizeof(uint)); 84 mi.fordblks = mi.arena - (mi.treeoverhead + mi.uordblks + 85 (mi.ordblks * sizeof(uint))); 86 return(mi); 87 } 88