History

fs: don't open code lru_to_page()

Multiple filesystems open code lru_to_page(). Rectify this by moving the macro from mm_inline (which is specific to lru stuff) to the more generic mm.h header and start using the macro where appropriate. No functional changes.

Nikolay Borisov committed 7 years ago

Commit f86196e1 parent 08d405c10 files · +15 −15Browse files

Unified · Split

10 files
  1. fs/afs/file.c +3 −2
  2. fs/btrfs/extent_io.c +1 −2
  3. fs/ceph/addr.c +2 −3
  4. fs/cifs/file.c +2 −1
  5. fs/ext4/readpage.c +1 −1
  6. fs/ocfs2/aops.c +2 −1
  7. fs/orangefs/inode.c +1 −1
  8. include/linux/mm.h +2 −0
  9. include/linux/mm_inline.h +0 −3
  10. mm/swap.c +1 −1
fs/afs/file.c+3−2
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 #include <linux/writeback.h>
1818 #include <linux/gfp.h>
1919 #include <linux/task_io_accounting_ops.h>
20+#include <linux/mm.h>
2021 #include "internal.h"
2122
2223 static int afs_file_mmap(struct file *file, struct vm_area_struct *vma);
@@ -441,7 +442,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, · 418 unmodified lines
441442 /* Count the number of contiguous pages at the front of the list. Note
442443 * that the list goes prev-wards rather than next-wards.
443444 */
444− first = list_entry(pages->prev, struct page, lru);
445+ first = lru_to_page(pages);
445446 index = first->index + 1;
446447 n = 1;
447448 for (p = first->lru.prev; p != pages; p = p->prev) {
@@ -473,7 +474,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, · 25 unmodified lines
473474 * page at the end of the file.
474475 */
475476 do {
476− page = list_entry(pages->prev, struct page, lru);
477+ page = lru_to_page(pages);
477478 list_del(&page->lru);
478479 index = page->index;
479480 if (add_to_page_cache_lru(page, mapping, index,
fs/btrfs/extent_io.c+1−2
@@ -4103,8 +4103,7 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages, · 4102 unmodified lines
41034103
41044104 while (!list_empty(pages)) {
41054105 for (nr = 0; nr < ARRAY_SIZE(pagepool) && !list_empty(pages);) {
4106− struct page *page = list_entry(pages->prev,
4107− struct page, lru);
4106+ struct page *page = lru_to_page(pages);
41084107
41094108 prefetchw(&page->flags);
41104109 list_del(&page->lru);
fs/ceph/addr.c+2−3
@@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx, · 305 unmodified lines
306306 struct ceph_osd_client *osdc =
307307 &ceph_inode_to_client(inode)->client->osdc;
308308 struct ceph_inode_info *ci = ceph_inode(inode);
309− struct page *page = list_entry(page_list->prev, struct page, lru);
309+ struct page *page = lru_to_page(page_list);
310310 struct ceph_vino vino;
311311 struct ceph_osd_request *req;
312312 u64 off;
@@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx, · 20 unmodified lines
333333 if (got)
334334 ceph_put_cap_refs(ci, got);
335335 while (!list_empty(page_list)) {
336− page = list_entry(page_list->prev,
337− struct page, lru);
336+ page = lru_to_page(page_list);
338337 list_del(&page->lru);
339338 put_page(page);
340339 }
fs/cifs/file.c+2−1
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #include <linux/mount.h>
3434 #include <linux/slab.h>
3535 #include <linux/swap.h>
36+#include <linux/mm.h>
3637 #include <asm/div64.h>
3738 #include "cifsfs.h"
3839 #include "cifspdu.h"
@@ -3964,7 +3965,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list, · 3925 unmodified lines
39643965
39653966 INIT_LIST_HEAD(tmplist);
39663967
3967− page = list_entry(page_list->prev, struct page, lru);
3968+ page = lru_to_page(page_list);
39683969
39693970 /*
39703971 * Lock the page and put it in the cache. Since no one else
fs/ext4/readpage.c+1−1
@@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space *mapping, · 127 unmodified lines
128128
129129 prefetchw(&page->flags);
130130 if (pages) {
131− page = list_entry(pages->prev, struct page, lru);
131+ page = lru_to_page(pages);
132132 list_del(&page->lru);
133133 if (add_to_page_cache_lru(page, mapping, page->index,
134134 readahead_gfp_mask(mapping)))
fs/ocfs2/aops.c+2−1
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #include <linux/quotaops.h>
3131 #include <linux/blkdev.h>
3232 #include <linux/uio.h>
33+#include <linux/mm.h>
3334
3435 #include <cluster/masklog.h>
3536
@@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping, · 361 unmodified lines
397398 * Check whether a remote node truncated this file - we just
398399 * drop out in that case as it's not worth handling here.
399400 */
400− last = list_entry(pages->prev, struct page, lru);
401+ last = lru_to_page(pages);
401402 start = (loff_t)last->index << PAGE_SHIFT;
402403 if (start >= i_size_read(inode))
403404 goto out_unlock;
fs/orangefs/inode.c+1−1
@@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file, · 76 unmodified lines
7777 for (page_idx = 0; page_idx < nr_pages; page_idx++) {
7878 struct page *page;
7979
80− page = list_entry(pages->prev, struct page, lru);
80+ page = lru_to_page(pages);
8181 list_del(&page->lru);
8282 if (!add_to_page_cache(page,
8383 mapping,
include/linux/mm.h+2−0
@@ -171,6 +171,8 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, · 170 unmodified lines
171171 /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */
172172 #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE)
173173
174+#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
175+
174176 /*
175177 * Linux kernel virtual memory manager primitives.
176178 * The idea being to have a "virtual" mm in the same way
include/linux/mm_inline.h+0−3
@@ -124,7 +124,4 @@ static __always_inline enum lru_list page_lru(struct page *page) · 123 unmodified lines
124124 }
125125 return lru;
126126 }
127−
128−#define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
129−
130127 #endif
mm/swap.c+1−1
@@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages) · 125 unmodified lines
126126 while (!list_empty(pages)) {
127127 struct page *victim;
128128
129− victim = list_entry(pages->prev, struct page, lru);
129+ victim = lru_to_page(pages);
130130 list_del(&victim->lru);
131131 put_page(victim);
132132 }