Print this page
arc_get_data_buf should be more aggressive in eviction when memory is unavailable


 204  * ==========================================================================
 205  */
 206 
 207 /*
 208  * Use zio_buf_alloc to allocate ZFS metadata.  This data will appear in a
 209  * crashdump if the kernel panics, so use it judiciously.  Obviously, it's
 210  * useful to inspect ZFS metadata, but if possible, we should avoid keeping
 211  * excess / transient data in-core during a crashdump.
 212  */
 213 void *
 214 zio_buf_alloc(size_t size)
 215 {
 216         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 217 
 218         ASSERT3U(c, <, SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 219 
 220         return (kmem_cache_alloc(zio_buf_cache[c], KM_PUSHPAGE));
 221 }
 222 
 223 /*














 224  * Use zio_data_buf_alloc to allocate data.  The data will not appear in a
 225  * crashdump if the kernel panics.  This exists so that we will limit the amount
 226  * of ZFS data that shows up in a kernel crashdump.  (Thus reducing the amount
 227  * of kernel heap dumped to disk when the kernel panics)
 228  */
 229 void *
 230 zio_data_buf_alloc(size_t size)
 231 {
 232         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 233 
 234         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 235 
 236         return (kmem_cache_alloc(zio_data_buf_cache[c], KM_PUSHPAGE));
 237 }
 238 















 239 void
 240 zio_buf_free(void *buf, size_t size)
 241 {
 242         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 243 
 244         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 245 
 246         kmem_cache_free(zio_buf_cache[c], buf);
 247 }
 248 
 249 void
 250 zio_data_buf_free(void *buf, size_t size)
 251 {
 252         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 253 
 254         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 255 
 256         kmem_cache_free(zio_data_buf_cache[c], buf);
 257 }
 258 




 204  * ==========================================================================
 205  */
 206 
 207 /*
 208  * Use zio_buf_alloc to allocate ZFS metadata.  This data will appear in a
 209  * crashdump if the kernel panics, so use it judiciously.  Obviously, it's
 210  * useful to inspect ZFS metadata, but if possible, we should avoid keeping
 211  * excess / transient data in-core during a crashdump.
 212  */
 213 void *
 214 zio_buf_alloc(size_t size)
 215 {
 216         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 217 
 218         ASSERT3U(c, <, SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 219 
 220         return (kmem_cache_alloc(zio_buf_cache[c], KM_PUSHPAGE));
 221 }
 222 
 223 /*
 224  * Same as zio_buf_alloc, but won't sleep in case memory cannot be allocated
 225  * and will instead return immediately with a failure.
 226  */
 227 void *
 228 zio_buf_alloc_canfail(size_t size)
 229 {
 230         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 231 
 232         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 233 
 234         return (kmem_cache_alloc(zio_buf_cache[c], KM_NOSLEEP | KM_NORMALPRI));
 235 }
 236 
 237 /*
 238  * Use zio_data_buf_alloc to allocate data.  The data will not appear in a
 239  * crashdump if the kernel panics.  This exists so that we will limit the amount
 240  * of ZFS data that shows up in a kernel crashdump.  (Thus reducing the amount
 241  * of kernel heap dumped to disk when the kernel panics)
 242  */
 243 void *
 244 zio_data_buf_alloc(size_t size)
 245 {
 246         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 247 
 248         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 249 
 250         return (kmem_cache_alloc(zio_data_buf_cache[c], KM_PUSHPAGE));
 251 }
 252 
 253 /*
 254  * Same as zio_data_buf_alloc, but won't sleep in case memory cannot be
 255  * allocated and will instead return immediately with a failure.
 256  */
 257 void *
 258 zio_data_buf_alloc_canfail(size_t size)
 259 {
 260         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 261 
 262         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 263 
 264         return (kmem_cache_alloc(zio_data_buf_cache[c],
 265             KM_NOSLEEP | KM_NORMALPRI));
 266 }
 267 
 268 void
 269 zio_buf_free(void *buf, size_t size)
 270 {
 271         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 272 
 273         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 274 
 275         kmem_cache_free(zio_buf_cache[c], buf);
 276 }
 277 
 278 void
 279 zio_data_buf_free(void *buf, size_t size)
 280 {
 281         size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
 282 
 283         ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
 284 
 285         kmem_cache_free(zio_data_buf_cache[c], buf);
 286 }
 287