Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

CacheFiles: Downgrade the requirements passed to the allocator

Downgrade the requirements passed to the allocator in the gfp flags parameter.
FS-Cache/CacheFiles can handle OOM conditions simply by aborting the attempt to
store an object or a page in the cache.

Signed-off-by: David Howells <dhowells@redhat.com>

+19 -15
+4 -4
fs/cachefiles/interface.c
··· 41 41 42 42 _enter("{%s},%p,", cache->cache.identifier, cookie); 43 43 44 - lookup_data = kmalloc(sizeof(*lookup_data), GFP_KERNEL); 44 + lookup_data = kmalloc(sizeof(*lookup_data), cachefiles_gfp); 45 45 if (!lookup_data) 46 46 goto nomem_lookup_data; 47 47 48 48 /* create a new object record and a temporary leaf image */ 49 - object = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL); 49 + object = kmem_cache_alloc(cachefiles_object_jar, cachefiles_gfp); 50 50 if (!object) 51 51 goto nomem_object; 52 52 ··· 63 63 * - stick the length on the front and leave space on the back for the 64 64 * encoder 65 65 */ 66 - buffer = kmalloc((2 + 512) + 3, GFP_KERNEL); 66 + buffer = kmalloc((2 + 512) + 3, cachefiles_gfp); 67 67 if (!buffer) 68 68 goto nomem_buffer; 69 69 ··· 219 219 return; 220 220 } 221 221 222 - auxdata = kmalloc(2 + 512 + 3, GFP_KERNEL); 222 + auxdata = kmalloc(2 + 512 + 3, cachefiles_gfp); 223 223 if (!auxdata) { 224 224 _leave(" [nomem]"); 225 225 return;
+2
fs/cachefiles/internal.h
··· 23 23 #define CACHEFILES_DEBUG_KLEAVE 2 24 24 #define CACHEFILES_DEBUG_KDEBUG 4 25 25 26 + #define cachefiles_gfp (__GFP_WAIT | __GFP_NORETRY | __GFP_NOMEMALLOC) 27 + 26 28 /* 27 29 * node records 28 30 */
+1 -1
fs/cachefiles/key.c
··· 78 78 79 79 _debug("max: %d", max); 80 80 81 - key = kmalloc(max, GFP_KERNEL); 81 + key = kmalloc(max, cachefiles_gfp); 82 82 if (!key) 83 83 return NULL; 84 84
+10 -8
fs/cachefiles/rdwr.c
··· 238 238 _debug("read back %p{%lu,%d}", 239 239 netpage, netpage->index, page_count(netpage)); 240 240 241 - monitor = kzalloc(sizeof(*monitor), GFP_KERNEL); 241 + monitor = kzalloc(sizeof(*monitor), cachefiles_gfp); 242 242 if (!monitor) 243 243 goto nomem; 244 244 ··· 257 257 goto backing_page_already_present; 258 258 259 259 if (!newpage) { 260 - newpage = page_cache_alloc_cold(bmapping); 260 + newpage = __page_cache_alloc(cachefiles_gfp | 261 + __GFP_COLD); 261 262 if (!newpage) 262 263 goto nomem_monitor; 263 264 } 264 265 265 266 ret = add_to_page_cache(newpage, bmapping, 266 - netpage->index, GFP_KERNEL); 267 + netpage->index, cachefiles_gfp); 267 268 if (ret == 0) 268 269 goto installed_new_backing_page; 269 270 if (ret != -EEXIST) ··· 482 481 netpage, netpage->index, page_count(netpage)); 483 482 484 483 if (!monitor) { 485 - monitor = kzalloc(sizeof(*monitor), GFP_KERNEL); 484 + monitor = kzalloc(sizeof(*monitor), cachefiles_gfp); 486 485 if (!monitor) 487 486 goto nomem; 488 487 ··· 497 496 goto backing_page_already_present; 498 497 499 498 if (!newpage) { 500 - newpage = page_cache_alloc_cold(bmapping); 499 + newpage = __page_cache_alloc(cachefiles_gfp | 500 + __GFP_COLD); 501 501 if (!newpage) 502 502 goto nomem; 503 503 } 504 504 505 505 ret = add_to_page_cache(newpage, bmapping, 506 - netpage->index, GFP_KERNEL); 506 + netpage->index, cachefiles_gfp); 507 507 if (ret == 0) 508 508 goto installed_new_backing_page; 509 509 if (ret != -EEXIST) ··· 534 532 _debug("- monitor add"); 535 533 536 534 ret = add_to_page_cache(netpage, op->mapping, netpage->index, 537 - GFP_KERNEL); 535 + cachefiles_gfp); 538 536 if (ret < 0) { 539 537 if (ret == -EEXIST) { 540 538 page_cache_release(netpage); ··· 610 608 _debug("- uptodate"); 611 609 612 610 ret = add_to_page_cache(netpage, op->mapping, netpage->index, 613 - GFP_KERNEL); 611 + cachefiles_gfp); 614 612 if (ret < 0) { 615 613 if (ret == -EEXIST) { 616 614 page_cache_release(netpage);
+1 -1
fs/cachefiles/xattr.c
··· 174 174 ASSERT(dentry); 175 175 ASSERT(dentry->d_inode); 176 176 177 - auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL); 177 + auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, cachefiles_gfp); 178 178 if (!auxbuf) { 179 179 _leave(" = -ENOMEM"); 180 180 return -ENOMEM;
+1 -1
fs/fscache/page.c
··· 759 759 760 760 fscache_stat(&fscache_n_stores); 761 761 762 - op = kzalloc(sizeof(*op), GFP_NOIO); 762 + op = kzalloc(sizeof(*op), GFP_NOIO | __GFP_NOMEMALLOC | __GFP_NORETRY); 763 763 if (!op) 764 764 goto nomem; 765 765