]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
CacheFiles: Downgrade the requirements passed to the allocator
authorDavid Howells <dhowells@redhat.com>
Thu, 20 Dec 2012 21:52:33 +0000 (21:52 +0000)
committerDavid Howells <dhowells@redhat.com>
Thu, 20 Dec 2012 21:58:25 +0000 (21:58 +0000)
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>
fs/cachefiles/interface.c
fs/cachefiles/internal.h
fs/cachefiles/key.c
fs/cachefiles/rdwr.c
fs/cachefiles/xattr.c
fs/fscache/page.c

index 67bef6d01484a1b058f6513fce1277db72903650..9bff0f878cfdd30526bcee737e8727fef97cab0c 100644 (file)
@@ -41,12 +41,12 @@ static struct fscache_object *cachefiles_alloc_object(
 
        _enter("{%s},%p,", cache->cache.identifier, cookie);
 
-       lookup_data = kmalloc(sizeof(*lookup_data), GFP_KERNEL);
+       lookup_data = kmalloc(sizeof(*lookup_data), cachefiles_gfp);
        if (!lookup_data)
                goto nomem_lookup_data;
 
        /* create a new object record and a temporary leaf image */
-       object = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL);
+       object = kmem_cache_alloc(cachefiles_object_jar, cachefiles_gfp);
        if (!object)
                goto nomem_object;
 
@@ -63,7 +63,7 @@ static struct fscache_object *cachefiles_alloc_object(
         * - stick the length on the front and leave space on the back for the
         *   encoder
         */
-       buffer = kmalloc((2 + 512) + 3, GFP_KERNEL);
+       buffer = kmalloc((2 + 512) + 3, cachefiles_gfp);
        if (!buffer)
                goto nomem_buffer;
 
@@ -219,7 +219,7 @@ static void cachefiles_update_object(struct fscache_object *_object)
                return;
        }
 
-       auxdata = kmalloc(2 + 512 + 3, GFP_KERNEL);
+       auxdata = kmalloc(2 + 512 + 3, cachefiles_gfp);
        if (!auxdata) {
                _leave(" [nomem]");
                return;
index bd6bc1bde2d725afc0260ddc77502d5031dcee98..49382519907a28ec7addc1f3a6257871cba9a025 100644 (file)
@@ -23,6 +23,8 @@ extern unsigned cachefiles_debug;
 #define CACHEFILES_DEBUG_KLEAVE        2
 #define CACHEFILES_DEBUG_KDEBUG        4
 
+#define cachefiles_gfp (__GFP_WAIT | __GFP_NORETRY | __GFP_NOMEMALLOC)
+
 /*
  * node records
  */
index 81b8b2b3a67476e238650701561474d7c90ed04a..33b58c60f2d11ff83662b6d23b144daf4ee44712 100644 (file)
@@ -78,7 +78,7 @@ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type)
 
        _debug("max: %d", max);
 
-       key = kmalloc(max, GFP_KERNEL);
+       key = kmalloc(max, cachefiles_gfp);
        if (!key)
                return NULL;
 
index 3367abdcdac47448f4ebb23e5a1657731211ac4a..9108b8ea505ab23133a9902e28082aa6181b88f6 100644 (file)
@@ -238,7 +238,7 @@ static int cachefiles_read_backing_file_one(struct cachefiles_object *object,
        _debug("read back %p{%lu,%d}",
               netpage, netpage->index, page_count(netpage));
 
-       monitor = kzalloc(sizeof(*monitor), GFP_KERNEL);
+       monitor = kzalloc(sizeof(*monitor), cachefiles_gfp);
        if (!monitor)
                goto nomem;
 
@@ -257,13 +257,14 @@ static int cachefiles_read_backing_file_one(struct cachefiles_object *object,
                        goto backing_page_already_present;
 
                if (!newpage) {
-                       newpage = page_cache_alloc_cold(bmapping);
+                       newpage = __page_cache_alloc(cachefiles_gfp |
+                                                    __GFP_COLD);
                        if (!newpage)
                                goto nomem_monitor;
                }
 
                ret = add_to_page_cache(newpage, bmapping,
-                                       netpage->index, GFP_KERNEL);
+                                       netpage->index, cachefiles_gfp);
                if (ret == 0)
                        goto installed_new_backing_page;
                if (ret != -EEXIST)
@@ -481,7 +482,7 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
                       netpage, netpage->index, page_count(netpage));
 
                if (!monitor) {
-                       monitor = kzalloc(sizeof(*monitor), GFP_KERNEL);
+                       monitor = kzalloc(sizeof(*monitor), cachefiles_gfp);
                        if (!monitor)
                                goto nomem;
 
@@ -496,13 +497,14 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
                                goto backing_page_already_present;
 
                        if (!newpage) {
-                               newpage = page_cache_alloc_cold(bmapping);
+                               newpage = __page_cache_alloc(cachefiles_gfp |
+                                                            __GFP_COLD);
                                if (!newpage)
                                        goto nomem;
                        }
 
                        ret = add_to_page_cache(newpage, bmapping,
-                                               netpage->index, GFP_KERNEL);
+                                               netpage->index, cachefiles_gfp);
                        if (ret == 0)
                                goto installed_new_backing_page;
                        if (ret != -EEXIST)
@@ -532,7 +534,7 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
                _debug("- monitor add");
 
                ret = add_to_page_cache(netpage, op->mapping, netpage->index,
-                                       GFP_KERNEL);
+                                       cachefiles_gfp);
                if (ret < 0) {
                        if (ret == -EEXIST) {
                                page_cache_release(netpage);
@@ -608,7 +610,7 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object,
                _debug("- uptodate");
 
                ret = add_to_page_cache(netpage, op->mapping, netpage->index,
-                                       GFP_KERNEL);
+                                       cachefiles_gfp);
                if (ret < 0) {
                        if (ret == -EEXIST) {
                                page_cache_release(netpage);
index e18b183b47e1c2e11aa49ad37ec6cf227305f68f..73b46288b54b839c523289a5471a376f14097e9c 100644 (file)
@@ -174,7 +174,7 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object,
        ASSERT(dentry);
        ASSERT(dentry->d_inode);
 
-       auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL);
+       auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, cachefiles_gfp);
        if (!auxbuf) {
                _leave(" = -ENOMEM");
                return -ENOMEM;
index d7c663cfc9231ad9827d2e4e2da26d4712afad30..248a12e225324e4e8a8eed9dc3f1e2bbd0410b45 100644 (file)
@@ -759,7 +759,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
 
        fscache_stat(&fscache_n_stores);
 
-       op = kzalloc(sizeof(*op), GFP_NOIO);
+       op = kzalloc(sizeof(*op), GFP_NOIO | __GFP_NOMEMALLOC | __GFP_NORETRY);
        if (!op)
                goto nomem;