MCPcopy Create free account
hub / github.com/F-Stack/f-stack / kern_vfs_bio_buffer_alloc

Function kern_vfs_bio_buffer_alloc

freebsd/kern/vfs_bio.c:1040–1150  ·  view source on GitHub ↗

* Calculating buffer cache scaling values and reserve space for buffer * headers. This is called during low level kernel initialization and * may be called more then once. We CANNOT write to the memory area * being reserved at this time. */

Source from the content-addressed store, hash-verified

1038 * being reserved at this time.
1039 */
1040caddr_t
1041kern_vfs_bio_buffer_alloc(caddr_t v, long physmem_est)
1042{
1043 int tuned_nbuf;
1044 long maxbuf, maxbuf_sz, buf_sz, biotmap_sz;
1045
1046 /*
1047 * physmem_est is in pages. Convert it to kilobytes (assumes
1048 * PAGE_SIZE is >= 1K)
1049 */
1050 physmem_est = physmem_est * (PAGE_SIZE / 1024);
1051
1052 maxbcachebuf_adjust();
1053 /*
1054 * The nominal buffer size (and minimum KVA allocation) is BKVASIZE.
1055 * For the first 64MB of ram nominally allocate sufficient buffers to
1056 * cover 1/4 of our ram. Beyond the first 64MB allocate additional
1057 * buffers to cover 1/10 of our ram over 64MB. When auto-sizing
1058 * the buffer cache we limit the eventual kva reservation to
1059 * maxbcache bytes.
1060 *
1061 * factor represents the 1/4 x ram conversion.
1062 */
1063 if (nbuf == 0) {
1064 int factor = 4 * BKVASIZE / 1024;
1065
1066 nbuf = 50;
1067 if (physmem_est > 4096)
1068 nbuf += min((physmem_est - 4096) / factor,
1069 65536 / factor);
1070 if (physmem_est > 65536)
1071 nbuf += min((physmem_est - 65536) * 2 / (factor * 5),
1072 32 * 1024 * 1024 / (factor * 5));
1073
1074 if (maxbcache && nbuf > maxbcache / BKVASIZE)
1075 nbuf = maxbcache / BKVASIZE;
1076 tuned_nbuf = 1;
1077 } else
1078 tuned_nbuf = 0;
1079
1080 /* XXX Avoid unsigned long overflows later on with maxbufspace. */
1081 maxbuf = (LONG_MAX / 3) / BKVASIZE;
1082 if (nbuf > maxbuf) {
1083 if (!tuned_nbuf)
1084 printf("Warning: nbufs lowered from %d to %ld\n", nbuf,
1085 maxbuf);
1086 nbuf = maxbuf;
1087 }
1088
1089 /*
1090 * Ideal allocation size for the transient bio submap is 10%
1091 * of the maximal space buffer map. This roughly corresponds
1092 * to the amount of the buffer mapped for typical UFS load.
1093 *
1094 * Clip the buffer map to reserve space for the transient
1095 * BIOs, if its extent is bigger than 90% (80% on i386) of the
1096 * maximum buffer map extent on the platform.
1097 *

Callers 1

vm_ksubmap_initFunction · 0.85

Calls 3

maxbcachebuf_adjustFunction · 0.85
minFunction · 0.85
printfFunction · 0.70

Tested by

no test coverage detected