Commit 2ae88149a27cadf2840e0ab8155bef13be285c03

Authored by Nick Piggin
Committed by Linus Torvalds
1 parent 858cbcdd4f

[PATCH] mm: clean up pagecache allocation

- Consolidate page_cache_alloc

- Fix splice: only the pagecache pages and filesystem data need to use
  mapping_gfp_mask.

- Fix grab_cache_page_nowait: same as splice, also honour NUMA placement.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 3 changed files with 19 additions and 28 deletions Side-by-side Diff

... ... @@ -74,7 +74,7 @@
74 74 wait_on_page_writeback(page);
75 75  
76 76 if (PagePrivate(page))
77   - try_to_release_page(page, mapping_gfp_mask(mapping));
  77 + try_to_release_page(page, GFP_KERNEL);
78 78  
79 79 /*
80 80 * If we succeeded in removing the mapping, set LRU flag
... ... @@ -333,7 +333,7 @@
333 333 break;
334 334  
335 335 error = add_to_page_cache_lru(page, mapping, index,
336   - mapping_gfp_mask(mapping));
  336 + GFP_KERNEL);
337 337 if (unlikely(error)) {
338 338 page_cache_release(page);
339 339 if (error == -EEXIST)
... ... @@ -557,7 +557,6 @@
557 557 {
558 558 struct file *file = sd->file;
559 559 struct address_space *mapping = file->f_mapping;
560   - gfp_t gfp_mask = mapping_gfp_mask(mapping);
561 560 unsigned int offset, this_len;
562 561 struct page *page;
563 562 pgoff_t index;
... ... @@ -591,7 +590,7 @@
591 590 goto find_page;
592 591  
593 592 page = buf->page;
594   - if (add_to_page_cache(page, mapping, index, gfp_mask)) {
  593 + if (add_to_page_cache(page, mapping, index, GFP_KERNEL)) {
595 594 unlock_page(page);
596 595 goto find_page;
597 596 }
... ... @@ -613,7 +612,7 @@
613 612 * This will also lock the page
614 613 */
615 614 ret = add_to_page_cache_lru(page, mapping, index,
616   - gfp_mask);
  615 + GFP_KERNEL);
617 616 if (unlikely(ret))
618 617 goto out;
619 618 }
include/linux/pagemap.h
... ... @@ -52,19 +52,23 @@
52 52 void release_pages(struct page **pages, int nr, int cold);
53 53  
54 54 #ifdef CONFIG_NUMA
55   -extern struct page *page_cache_alloc(struct address_space *x);
56   -extern struct page *page_cache_alloc_cold(struct address_space *x);
  55 +extern struct page *__page_cache_alloc(gfp_t gfp);
57 56 #else
  57 +static inline struct page *__page_cache_alloc(gfp_t gfp)
  58 +{
  59 + return alloc_pages(gfp, 0);
  60 +}
  61 +#endif
  62 +
58 63 static inline struct page *page_cache_alloc(struct address_space *x)
59 64 {
60   - return alloc_pages(mapping_gfp_mask(x), 0);
  65 + return __page_cache_alloc(mapping_gfp_mask(x));
61 66 }
62 67  
63 68 static inline struct page *page_cache_alloc_cold(struct address_space *x)
64 69 {
65   - return alloc_pages(mapping_gfp_mask(x)|__GFP_COLD, 0);
  70 + return __page_cache_alloc(mapping_gfp_mask(x)|__GFP_COLD);
66 71 }
67   -#endif
68 72  
69 73 typedef int filler_t(void *, struct page *);
70 74  
... ... @@ -467,25 +467,15 @@
467 467 }
468 468  
469 469 #ifdef CONFIG_NUMA
470   -struct page *page_cache_alloc(struct address_space *x)
  470 +struct page *__page_cache_alloc(gfp_t gfp)
471 471 {
472 472 if (cpuset_do_page_mem_spread()) {
473 473 int n = cpuset_mem_spread_node();
474   - return alloc_pages_node(n, mapping_gfp_mask(x), 0);
  474 + return alloc_pages_node(n, gfp, 0);
475 475 }
476   - return alloc_pages(mapping_gfp_mask(x), 0);
  476 + return alloc_pages(gfp, 0);
477 477 }
478   -EXPORT_SYMBOL(page_cache_alloc);
479   -
480   -struct page *page_cache_alloc_cold(struct address_space *x)
481   -{
482   - if (cpuset_do_page_mem_spread()) {
483   - int n = cpuset_mem_spread_node();
484   - return alloc_pages_node(n, mapping_gfp_mask(x)|__GFP_COLD, 0);
485   - }
486   - return alloc_pages(mapping_gfp_mask(x)|__GFP_COLD, 0);
487   -}
488   -EXPORT_SYMBOL(page_cache_alloc_cold);
  478 +EXPORT_SYMBOL(__page_cache_alloc);
489 479 #endif
490 480  
491 481 static int __sleep_on_page_lock(void *word)
... ... @@ -826,7 +816,6 @@
826 816 grab_cache_page_nowait(struct address_space *mapping, unsigned long index)
827 817 {
828 818 struct page *page = find_get_page(mapping, index);
829   - gfp_t gfp_mask;
830 819  
831 820 if (page) {
832 821 if (!TestSetPageLocked(page))
... ... @@ -834,9 +823,8 @@
834 823 page_cache_release(page);
835 824 return NULL;
836 825 }
837   - gfp_mask = mapping_gfp_mask(mapping) & ~__GFP_FS;
838   - page = alloc_pages(gfp_mask, 0);
839   - if (page && add_to_page_cache_lru(page, mapping, index, gfp_mask)) {
  826 + page = __page_cache_alloc(mapping_gfp_mask(mapping) & ~__GFP_FS);
  827 + if (page && add_to_page_cache_lru(page, mapping, index, GFP_KERNEL)) {
840 828 page_cache_release(page);
841 829 page = NULL;
842 830 }