Merge tag 'powerpc-4.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux-2.6-microblaze.git] / fs / buffer.c
index c8c2b7d..4cc679d 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/mpage.h>
 #include <linux/bit_spinlock.h>
 #include <linux/pagevec.h>
+#include <linux/sched/mm.h>
 #include <trace/events/block.h>
 
 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
@@ -813,12 +814,16 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
                bool retry)
 {
        struct buffer_head *bh, *head;
-       gfp_t gfp = GFP_NOFS;
+       gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
        long offset;
+       struct mem_cgroup *memcg;
 
        if (retry)
                gfp |= __GFP_NOFAIL;
 
+       memcg = get_mem_cgroup_from_page(page);
+       memalloc_use_memcg(memcg);
+
        head = NULL;
        offset = PAGE_SIZE;
        while ((offset -= size) >= 0) {
@@ -835,6 +840,9 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
                /* Link the buffer to its page */
                set_bh_page(bh, page, offset);
        }
+out:
+       memalloc_unuse_memcg();
+       mem_cgroup_put(memcg);
        return head;
 /*
  * In case anything failed, we just free everything we got.
@@ -848,7 +856,7 @@ no_grow:
                } while (head);
        }
 
-       return NULL;
+       goto out;
 }
 EXPORT_SYMBOL_GPL(alloc_page_buffers);