vfs_bio.c (17429) | vfs_bio.c (17761) |
---|---|
1/* 2 * Copyright (c) 1994 John S. Dyson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 4 unchanged lines hidden (view full) --- 13 * documentation and/or other materials provided with the distribution. 14 * 3. Absolutely no warranty of function or purpose is made by the author 15 * John S. Dyson. 16 * 4. This work was done expressly for inclusion into FreeBSD. Other use 17 * is allowed if this notation is included. 18 * 5. Modifications may be freely made to this file if the above conditions 19 * are met. 20 * | 1/* 2 * Copyright (c) 1994 John S. Dyson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 4 unchanged lines hidden (view full) --- 13 * documentation and/or other materials provided with the distribution. 14 * 3. Absolutely no warranty of function or purpose is made by the author 15 * John S. Dyson. 16 * 4. This work was done expressly for inclusion into FreeBSD. Other use 17 * is allowed if this notation is included. 18 * 5. Modifications may be freely made to this file if the above conditions 19 * are met. 20 * |
21 * $Id: vfs_bio.c,v 1.94 1996/06/30 05:17:08 davidg Exp $ | 21 * $Id: vfs_bio.c,v 1.95 1996/08/04 20:13:08 phk Exp $ |
22 */ 23 24/* 25 * this file contains a new buffer I/O scheme implementing a coherent 26 * VM object and buffer cache scheme. Pains have been taken to make 27 * sure that the performance degradation associated with schemes such 28 * as this is not realized. 29 * --- 78 unchanged lines hidden (view full) --- 108 bufmallocspace, maxbufmallocspace; 109 110static struct bufhashhdr bufhashtbl[BUFHSZ], invalhash; 111static struct bqueues bufqueues[BUFFER_QUEUES]; 112 113extern int vm_swap_size; 114 115#define BUF_MAXUSE 8 | 22 */ 23 24/* 25 * this file contains a new buffer I/O scheme implementing a coherent 26 * VM object and buffer cache scheme. Pains have been taken to make 27 * sure that the performance degradation associated with schemes such 28 * as this is not realized. 29 * --- 78 unchanged lines hidden (view full) --- 108 bufmallocspace, maxbufmallocspace; 109 110static struct bufhashhdr bufhashtbl[BUFHSZ], invalhash; 111static struct bqueues bufqueues[BUFFER_QUEUES]; 112 113extern int vm_swap_size; 114 115#define BUF_MAXUSE 8 |
116/* 117#define NO_B_MALLOC 118*/ |
|
116 117/* 118 * Initialize buffer headers and related structures. 119 */ 120void 121bufinit() 122{ 123 struct buf *bp; --- 715 unchanged lines hidden (view full) --- 839 bp->b_iodone = 0; 840 bp->b_error = 0; 841 bp->b_resid = 0; 842 bp->b_bcount = 0; 843 bp->b_npages = 0; 844 bp->b_data = buffers_kva + (bp - buf) * MAXBSIZE; 845 bp->b_dirtyoff = bp->b_dirtyend = 0; 846 bp->b_validoff = bp->b_validend = 0; | 119 120/* 121 * Initialize buffer headers and related structures. 122 */ 123void 124bufinit() 125{ 126 struct buf *bp; --- 715 unchanged lines hidden (view full) --- 842 bp->b_iodone = 0; 843 bp->b_error = 0; 844 bp->b_resid = 0; 845 bp->b_bcount = 0; 846 bp->b_npages = 0; 847 bp->b_data = buffers_kva + (bp - buf) * MAXBSIZE; 848 bp->b_dirtyoff = bp->b_dirtyend = 0; 849 bp->b_validoff = bp->b_validend = 0; |
847 bp->b_usecount = 2; | 850 bp->b_usecount = 4; |
848 if (bufspace >= maxbufspace + nbyteswritten) { 849 bp->b_flags |= B_INVAL; 850 brelse(bp); 851 goto trytofreespace; 852 } 853 return (bp); 854} 855 --- 259 unchanged lines hidden (view full) --- 1115 1116 if ((bp->b_flags & B_VMIO) == 0) { 1117 caddr_t origbuf; 1118 int origbufsize; 1119 /* 1120 * Just get anonymous memory from the kernel 1121 */ 1122 mbsize = (size + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1); | 851 if (bufspace >= maxbufspace + nbyteswritten) { 852 bp->b_flags |= B_INVAL; 853 brelse(bp); 854 goto trytofreespace; 855 } 856 return (bp); 857} 858 --- 259 unchanged lines hidden (view full) --- 1118 1119 if ((bp->b_flags & B_VMIO) == 0) { 1120 caddr_t origbuf; 1121 int origbufsize; 1122 /* 1123 * Just get anonymous memory from the kernel 1124 */ 1125 mbsize = (size + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1); |
1126#if !defined(NO_B_MALLOC) |
|
1123 if (bp->b_flags & B_MALLOC) 1124 newbsize = mbsize; 1125 else | 1127 if (bp->b_flags & B_MALLOC) 1128 newbsize = mbsize; 1129 else |
1130#endif |
|
1126 newbsize = round_page(size); 1127 1128 if (newbsize < bp->b_bufsize) { | 1131 newbsize = round_page(size); 1132 1133 if (newbsize < bp->b_bufsize) { |
1134#if !defined(NO_B_MALLOC) |
|
1129 /* 1130 * malloced buffers are not shrunk 1131 */ 1132 if (bp->b_flags & B_MALLOC) { 1133 if (newbsize) { 1134 bp->b_bcount = size; 1135 } else { 1136 free(bp->b_data, M_BIOBUF); 1137 bufspace -= bp->b_bufsize; 1138 bufmallocspace -= bp->b_bufsize; 1139 bp->b_data = (caddr_t) buffers_kva + (bp - buf) * MAXBSIZE; 1140 bp->b_bufsize = 0; 1141 bp->b_bcount = 0; 1142 bp->b_flags &= ~B_MALLOC; 1143 } 1144 return 1; 1145 } | 1135 /* 1136 * malloced buffers are not shrunk 1137 */ 1138 if (bp->b_flags & B_MALLOC) { 1139 if (newbsize) { 1140 bp->b_bcount = size; 1141 } else { 1142 free(bp->b_data, M_BIOBUF); 1143 bufspace -= bp->b_bufsize; 1144 bufmallocspace -= bp->b_bufsize; 1145 bp->b_data = (caddr_t) buffers_kva + (bp - buf) * MAXBSIZE; 1146 bp->b_bufsize = 0; 1147 bp->b_bcount = 0; 1148 bp->b_flags &= ~B_MALLOC; 1149 } 1150 return 1; 1151 } |
1152#endif |
|
1146 vm_hold_free_pages( 1147 bp, 1148 (vm_offset_t) bp->b_data + newbsize, 1149 (vm_offset_t) bp->b_data + bp->b_bufsize); 1150 } else if (newbsize > bp->b_bufsize) { | 1153 vm_hold_free_pages( 1154 bp, 1155 (vm_offset_t) bp->b_data + newbsize, 1156 (vm_offset_t) bp->b_data + bp->b_bufsize); 1157 } else if (newbsize > bp->b_bufsize) { |
1158#if !defined(NO_B_MALLOC) |
|
1151 /* 1152 * We only use malloced memory on the first allocation. 1153 * and revert to page-allocated memory when the buffer grows. 1154 */ 1155 if ( (bufmallocspace < maxbufmallocspace) && 1156 (bp->b_bufsize == 0) && 1157 (mbsize <= PAGE_SIZE/2)) { 1158 1159 bp->b_data = malloc(mbsize, M_BIOBUF, M_WAITOK); 1160 bp->b_bufsize = mbsize; 1161 bp->b_bcount = size; 1162 bp->b_flags |= B_MALLOC; 1163 bufspace += mbsize; 1164 bufmallocspace += mbsize; 1165 return 1; 1166 } | 1159 /* 1160 * We only use malloced memory on the first allocation. 1161 * and revert to page-allocated memory when the buffer grows. 1162 */ 1163 if ( (bufmallocspace < maxbufmallocspace) && 1164 (bp->b_bufsize == 0) && 1165 (mbsize <= PAGE_SIZE/2)) { 1166 1167 bp->b_data = malloc(mbsize, M_BIOBUF, M_WAITOK); 1168 bp->b_bufsize = mbsize; 1169 bp->b_bcount = size; 1170 bp->b_flags |= B_MALLOC; 1171 bufspace += mbsize; 1172 bufmallocspace += mbsize; 1173 return 1; 1174 } |
1175#endif |
|
1167 origbuf = NULL; 1168 origbufsize = 0; | 1176 origbuf = NULL; 1177 origbufsize = 0; |
1178#if !defined(NO_B_MALLOC) |
|
1169 /* 1170 * If the buffer is growing on it's other-than-first allocation, 1171 * then we revert to the page-allocation scheme. 1172 */ 1173 if (bp->b_flags & B_MALLOC) { 1174 origbuf = bp->b_data; 1175 origbufsize = bp->b_bufsize; 1176 bp->b_data = (caddr_t) buffers_kva + (bp - buf) * MAXBSIZE; 1177 bufspace -= bp->b_bufsize; 1178 bufmallocspace -= bp->b_bufsize; 1179 bp->b_bufsize = 0; 1180 bp->b_flags &= ~B_MALLOC; 1181 newbsize = round_page(newbsize); 1182 } | 1179 /* 1180 * If the buffer is growing on it's other-than-first allocation, 1181 * then we revert to the page-allocation scheme. 1182 */ 1183 if (bp->b_flags & B_MALLOC) { 1184 origbuf = bp->b_data; 1185 origbufsize = bp->b_bufsize; 1186 bp->b_data = (caddr_t) buffers_kva + (bp - buf) * MAXBSIZE; 1187 bufspace -= bp->b_bufsize; 1188 bufmallocspace -= bp->b_bufsize; 1189 bp->b_bufsize = 0; 1190 bp->b_flags &= ~B_MALLOC; 1191 newbsize = round_page(newbsize); 1192 } |
1193#endif |
|
1183 vm_hold_load_pages( 1184 bp, 1185 (vm_offset_t) bp->b_data + bp->b_bufsize, 1186 (vm_offset_t) bp->b_data + newbsize); | 1194 vm_hold_load_pages( 1195 bp, 1196 (vm_offset_t) bp->b_data + bp->b_bufsize, 1197 (vm_offset_t) bp->b_data + newbsize); |
1198#if !defined(NO_B_MALLOC) |
|
1187 if (origbuf) { 1188 bcopy(origbuf, bp->b_data, origbufsize); 1189 free(origbuf, M_BIOBUF); 1190 } | 1199 if (origbuf) { 1200 bcopy(origbuf, bp->b_data, origbufsize); 1201 free(origbuf, M_BIOBUF); 1202 } |
1203#endif |
|
1191 } 1192 } else { 1193 vm_page_t m; 1194 int desiredpages; 1195 1196 newbsize = (size + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1); 1197 desiredpages = (round_page(newbsize) >> PAGE_SHIFT); 1198 | 1204 } 1205 } else { 1206 vm_page_t m; 1207 int desiredpages; 1208 1209 newbsize = (size + DEV_BSIZE - 1) & ~(DEV_BSIZE - 1); 1210 desiredpages = (round_page(newbsize) >> PAGE_SHIFT); 1211 |
1212#if !defined(NO_B_MALLOC) |
|
1199 if (bp->b_flags & B_MALLOC) 1200 panic("allocbuf: VMIO buffer can't be malloced"); | 1213 if (bp->b_flags & B_MALLOC) 1214 panic("allocbuf: VMIO buffer can't be malloced"); |
1215#endif |
|
1201 1202 if (newbsize < bp->b_bufsize) { 1203 if (desiredpages < bp->b_npages) { 1204 for (i = desiredpages; i < bp->b_npages; i++) { 1205 /* 1206 * the page is not freed here -- it 1207 * is the responsibility of vnode_pager_setsize 1208 */ --- 562 unchanged lines hidden --- | 1216 1217 if (newbsize < bp->b_bufsize) { 1218 if (desiredpages < bp->b_npages) { 1219 for (i = desiredpages; i < bp->b_npages; i++) { 1220 /* 1221 * the page is not freed here -- it 1222 * is the responsibility of vnode_pager_setsize 1223 */ --- 562 unchanged lines hidden --- |