diff mbox series

[2/2] fs: Don't open-code lru_to_page

Message ID 20181129075301.29087-2-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Nikolay Borisov Nov. 29, 2018, 7:52 a.m. UTC
There are a bunch of filesystems which essentially open-code lru_to_page
helper. Change them to using the helper. No functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---

Since this is a mostly mechanical change I've actually batched all of them in 
a single patch. 

 fs/afs/file.c        | 5 +++--
 fs/btrfs/extent_io.c | 2 +-
 fs/ceph/addr.c       | 5 ++---
 fs/cifs/file.c       | 3 ++-
 fs/ext4/readpage.c   | 2 +-
 fs/ocfs2/aops.c      | 3 ++-
 fs/orangefs/inode.c  | 2 +-
 mm/swap.c            | 2 +-
 8 files changed, 13 insertions(+), 11 deletions(-)

Comments

Michal Hocko Nov. 29, 2018, 8:18 a.m. UTC | #1
On Thu 29-11-18 09:52:57, Nikolay Borisov wrote:
> There are a bunch of filesystems which essentially open-code lru_to_page
> helper. Change them to using the helper. No functional changes.

I would just squash the two into a single patch. It makes the first one
more obvious. Or is there any reason to have them separate?

> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
> 
> Since this is a mostly mechanical change I've actually batched all of them in 
> a single patch. 
> 
>  fs/afs/file.c        | 5 +++--
>  fs/btrfs/extent_io.c | 2 +-
>  fs/ceph/addr.c       | 5 ++---
>  fs/cifs/file.c       | 3 ++-
>  fs/ext4/readpage.c   | 2 +-
>  fs/ocfs2/aops.c      | 3 ++-
>  fs/orangefs/inode.c  | 2 +-
>  mm/swap.c            | 2 +-
>  8 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/afs/file.c b/fs/afs/file.c
> index d6bc3f5d784b..323ae9912203 100644
> --- a/fs/afs/file.c
> +++ b/fs/afs/file.c
> @@ -17,6 +17,7 @@
>  #include <linux/writeback.h>
>  #include <linux/gfp.h>
>  #include <linux/task_io_accounting_ops.h>
> +#include <linux/mm.h>
>  #include "internal.h"
>  
>  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,
>  	/* Count the number of contiguous pages at the front of the list.  Note
>  	 * that the list goes prev-wards rather than next-wards.
>  	 */
> -	first = list_entry(pages->prev, struct page, lru);
> +	first = lru_to_page(pages);
>  	index = first->index + 1;
>  	n = 1;
>  	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,
>  	 * page at the end of the file.
>  	 */
>  	do {
> -		page = list_entry(pages->prev, struct page, lru);
> +		page = lru_to_page(pages);
>  		list_del(&page->lru);
>  		index = page->index;
>  		if (add_to_page_cache_lru(page, mapping, index,
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 19f4b8fd654f..8332c5f4b1c3 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -4104,7 +4104,7 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages,
>  	u64 prev_em_start = (u64)-1;
>  
>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> -		page = list_entry(pages->prev, struct page, lru);
> +		page = lru_to_page(pages);
>  
>  		prefetchw(&page->flags);
>  		list_del(&page->lru);
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 8eade7a993c1..5d0c05e288cc 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>  	struct ceph_osd_client *osdc =
>  		&ceph_inode_to_client(inode)->client->osdc;
>  	struct ceph_inode_info *ci = ceph_inode(inode);
> -	struct page *page = list_entry(page_list->prev, struct page, lru);
> +	struct page *page = lru_to_page(page_list);
>  	struct ceph_vino vino;
>  	struct ceph_osd_request *req;
>  	u64 off;
> @@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>  			if (got)
>  				ceph_put_cap_refs(ci, got);
>  			while (!list_empty(page_list)) {
> -				page = list_entry(page_list->prev,
> -						  struct page, lru);
> +				page = lru_to_page(page_list);
>  				list_del(&page->lru);
>  				put_page(page);
>  			}
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 74c33d5fafc8..b16a4d887d17 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -33,6 +33,7 @@
>  #include <linux/mount.h>
>  #include <linux/slab.h>
>  #include <linux/swap.h>
> +#include <linux/mm.h>
>  #include <asm/div64.h>
>  #include "cifsfs.h"
>  #include "cifspdu.h"
> @@ -3975,7 +3976,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
>  
>  	INIT_LIST_HEAD(tmplist);
>  
> -	page = list_entry(page_list->prev, struct page, lru);
> +	page = lru_to_page(page_list);
>  
>  	/*
>  	 * Lock the page and put it in the cache. Since no one else
> diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
> index f461d75ac049..6aa282ee455a 100644
> --- a/fs/ext4/readpage.c
> +++ b/fs/ext4/readpage.c
> @@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
>  
>  		prefetchw(&page->flags);
>  		if (pages) {
> -			page = list_entry(pages->prev, struct page, lru);
> +			page = lru_to_page(pages);
>  			list_del(&page->lru);
>  			if (add_to_page_cache_lru(page, mapping, page->index,
>  				  readahead_gfp_mask(mapping)))
> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> index eb1ce30412dc..832c1759a09a 100644
> --- a/fs/ocfs2/aops.c
> +++ b/fs/ocfs2/aops.c
> @@ -30,6 +30,7 @@
>  #include <linux/quotaops.h>
>  #include <linux/blkdev.h>
>  #include <linux/uio.h>
> +#include <linux/mm.h>
>  
>  #include <cluster/masklog.h>
>  
> @@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
>  	 * Check whether a remote node truncated this file - we just
>  	 * drop out in that case as it's not worth handling here.
>  	 */
> -	last = list_entry(pages->prev, struct page, lru);
> +	last = lru_to_page(pages);
>  	start = (loff_t)last->index << PAGE_SHIFT;
>  	if (start >= i_size_read(inode))
>  		goto out_unlock;
> diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
> index fe53381b26b1..f038235c64bd 100644
> --- a/fs/orangefs/inode.c
> +++ b/fs/orangefs/inode.c
> @@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file,
>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
>  		struct page *page;
>  
> -		page = list_entry(pages->prev, struct page, lru);
> +		page = lru_to_page(pages);
>  		list_del(&page->lru);
>  		if (!add_to_page_cache(page,
>  				       mapping,
> diff --git a/mm/swap.c b/mm/swap.c
> index aa483719922e..20b9e9d99652 100644
> --- a/mm/swap.c
> +++ b/mm/swap.c
> @@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages)
>  	while (!list_empty(pages)) {
>  		struct page *victim;
>  
> -		victim = list_entry(pages->prev, struct page, lru);
> +		victim = lru_to_page(pages);
>  		list_del(&victim->lru);
>  		put_page(victim);
>  	}
> -- 
> 2.17.1
Nikolay Borisov Nov. 29, 2018, 8:50 a.m. UTC | #2
On 29.11.18 г. 10:18 ч., Michal Hocko wrote:
> On Thu 29-11-18 09:52:57, Nikolay Borisov wrote:
>> There are a bunch of filesystems which essentially open-code lru_to_page
>> helper. Change them to using the helper. No functional changes.
> 
> I would just squash the two into a single patch. It makes the first one
> more obvious. Or is there any reason to have them separate?

No reason, just didn't know how people would react so that's why I chose
to send as two separate.

If I squash them who would be the best person to take them ?

> 
>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> 
> Acked-by: Michal Hocko <mhocko@suse.com>
> 
>> ---
>>
>> Since this is a mostly mechanical change I've actually batched all of them in 
>> a single patch. 
>>
>>  fs/afs/file.c        | 5 +++--
>>  fs/btrfs/extent_io.c | 2 +-
>>  fs/ceph/addr.c       | 5 ++---
>>  fs/cifs/file.c       | 3 ++-
>>  fs/ext4/readpage.c   | 2 +-
>>  fs/ocfs2/aops.c      | 3 ++-
>>  fs/orangefs/inode.c  | 2 +-
>>  mm/swap.c            | 2 +-
>>  8 files changed, 13 insertions(+), 11 deletions(-)
>>
>> diff --git a/fs/afs/file.c b/fs/afs/file.c
>> index d6bc3f5d784b..323ae9912203 100644
>> --- a/fs/afs/file.c
>> +++ b/fs/afs/file.c
>> @@ -17,6 +17,7 @@
>>  #include <linux/writeback.h>
>>  #include <linux/gfp.h>
>>  #include <linux/task_io_accounting_ops.h>
>> +#include <linux/mm.h>
>>  #include "internal.h"
>>  
>>  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,
>>  	/* Count the number of contiguous pages at the front of the list.  Note
>>  	 * that the list goes prev-wards rather than next-wards.
>>  	 */
>> -	first = list_entry(pages->prev, struct page, lru);
>> +	first = lru_to_page(pages);
>>  	index = first->index + 1;
>>  	n = 1;
>>  	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,
>>  	 * page at the end of the file.
>>  	 */
>>  	do {
>> -		page = list_entry(pages->prev, struct page, lru);
>> +		page = lru_to_page(pages);
>>  		list_del(&page->lru);
>>  		index = page->index;
>>  		if (add_to_page_cache_lru(page, mapping, index,
>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>> index 19f4b8fd654f..8332c5f4b1c3 100644
>> --- a/fs/btrfs/extent_io.c
>> +++ b/fs/btrfs/extent_io.c
>> @@ -4104,7 +4104,7 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages,
>>  	u64 prev_em_start = (u64)-1;
>>  
>>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
>> -		page = list_entry(pages->prev, struct page, lru);
>> +		page = lru_to_page(pages);
>>  
>>  		prefetchw(&page->flags);
>>  		list_del(&page->lru);
>> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
>> index 8eade7a993c1..5d0c05e288cc 100644
>> --- a/fs/ceph/addr.c
>> +++ b/fs/ceph/addr.c
>> @@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>>  	struct ceph_osd_client *osdc =
>>  		&ceph_inode_to_client(inode)->client->osdc;
>>  	struct ceph_inode_info *ci = ceph_inode(inode);
>> -	struct page *page = list_entry(page_list->prev, struct page, lru);
>> +	struct page *page = lru_to_page(page_list);
>>  	struct ceph_vino vino;
>>  	struct ceph_osd_request *req;
>>  	u64 off;
>> @@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>>  			if (got)
>>  				ceph_put_cap_refs(ci, got);
>>  			while (!list_empty(page_list)) {
>> -				page = list_entry(page_list->prev,
>> -						  struct page, lru);
>> +				page = lru_to_page(page_list);
>>  				list_del(&page->lru);
>>  				put_page(page);
>>  			}
>> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
>> index 74c33d5fafc8..b16a4d887d17 100644
>> --- a/fs/cifs/file.c
>> +++ b/fs/cifs/file.c
>> @@ -33,6 +33,7 @@
>>  #include <linux/mount.h>
>>  #include <linux/slab.h>
>>  #include <linux/swap.h>
>> +#include <linux/mm.h>
>>  #include <asm/div64.h>
>>  #include "cifsfs.h"
>>  #include "cifspdu.h"
>> @@ -3975,7 +3976,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
>>  
>>  	INIT_LIST_HEAD(tmplist);
>>  
>> -	page = list_entry(page_list->prev, struct page, lru);
>> +	page = lru_to_page(page_list);
>>  
>>  	/*
>>  	 * Lock the page and put it in the cache. Since no one else
>> diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
>> index f461d75ac049..6aa282ee455a 100644
>> --- a/fs/ext4/readpage.c
>> +++ b/fs/ext4/readpage.c
>> @@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
>>  
>>  		prefetchw(&page->flags);
>>  		if (pages) {
>> -			page = list_entry(pages->prev, struct page, lru);
>> +			page = lru_to_page(pages);
>>  			list_del(&page->lru);
>>  			if (add_to_page_cache_lru(page, mapping, page->index,
>>  				  readahead_gfp_mask(mapping)))
>> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
>> index eb1ce30412dc..832c1759a09a 100644
>> --- a/fs/ocfs2/aops.c
>> +++ b/fs/ocfs2/aops.c
>> @@ -30,6 +30,7 @@
>>  #include <linux/quotaops.h>
>>  #include <linux/blkdev.h>
>>  #include <linux/uio.h>
>> +#include <linux/mm.h>
>>  
>>  #include <cluster/masklog.h>
>>  
>> @@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
>>  	 * Check whether a remote node truncated this file - we just
>>  	 * drop out in that case as it's not worth handling here.
>>  	 */
>> -	last = list_entry(pages->prev, struct page, lru);
>> +	last = lru_to_page(pages);
>>  	start = (loff_t)last->index << PAGE_SHIFT;
>>  	if (start >= i_size_read(inode))
>>  		goto out_unlock;
>> diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
>> index fe53381b26b1..f038235c64bd 100644
>> --- a/fs/orangefs/inode.c
>> +++ b/fs/orangefs/inode.c
>> @@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file,
>>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
>>  		struct page *page;
>>  
>> -		page = list_entry(pages->prev, struct page, lru);
>> +		page = lru_to_page(pages);
>>  		list_del(&page->lru);
>>  		if (!add_to_page_cache(page,
>>  				       mapping,
>> diff --git a/mm/swap.c b/mm/swap.c
>> index aa483719922e..20b9e9d99652 100644
>> --- a/mm/swap.c
>> +++ b/mm/swap.c
>> @@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages)
>>  	while (!list_empty(pages)) {
>>  		struct page *victim;
>>  
>> -		victim = list_entry(pages->prev, struct page, lru);
>> +		victim = lru_to_page(pages);
>>  		list_del(&victim->lru);
>>  		put_page(victim);
>>  	}
>> -- 
>> 2.17.1
>
Michal Hocko Nov. 29, 2018, 9:04 a.m. UTC | #3
On Thu 29-11-18 10:50:08, Nikolay Borisov wrote:
> 
> 
> On 29.11.18 г. 10:18 ч., Michal Hocko wrote:
> > On Thu 29-11-18 09:52:57, Nikolay Borisov wrote:
> >> There are a bunch of filesystems which essentially open-code lru_to_page
> >> helper. Change them to using the helper. No functional changes.
> > 
> > I would just squash the two into a single patch. It makes the first one
> > more obvious. Or is there any reason to have them separate?
> 
> No reason, just didn't know how people would react so that's why I chose
> to send as two separate.

This is a matter of taste I guess. But I usually prefer to have callers
along with a new helper in a single patch. This is not a new helper
per-se but doing it the same way seems reasonable to me. Not that I
would insist of course. You can use my ack for both patch in case you
decide to leave it as is.

> If I squash them who would be the best person to take them ?

Sounds like a mmotm material to me.
David Hildenbrand Nov. 29, 2018, 10:12 a.m. UTC | #4
On 29.11.18 09:18, Michal Hocko wrote:
> On Thu 29-11-18 09:52:57, Nikolay Borisov wrote:
>> There are a bunch of filesystems which essentially open-code lru_to_page
>> helper. Change them to using the helper. No functional changes.
> 
> I would just squash the two into a single patch. It makes the first one
> more obvious. Or is there any reason to have them separate?
> 
>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> 
> Acked-by: Michal Hocko <mhocko@suse.com>

mm_inline.h is 99.9% about lru and there is barely anything about lru in
mm.h. However this simple macro seems to differ from the other inlined
functions.

So to the squashed patch

Reviewed-by: David Hildenbrand <david@redhat.com>
Mike Rapoport Nov. 29, 2018, 11:17 a.m. UTC | #5
On Thu, Nov 29, 2018 at 10:50:08AM +0200, Nikolay Borisov wrote:
> 
> 
> On 29.11.18 г. 10:18 ч., Michal Hocko wrote:
> > On Thu 29-11-18 09:52:57, Nikolay Borisov wrote:
> >> There are a bunch of filesystems which essentially open-code lru_to_page
> >> helper. Change them to using the helper. No functional changes.
> > 
> > I would just squash the two into a single patch. It makes the first one
> > more obvious. Or is there any reason to have them separate?
> 
> No reason, just didn't know how people would react so that's why I chose
> to send as two separate.

I'm with Michal on this, a single patch seems better here.
Yet, for either way:

Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
 
> If I squash them who would be the best person to take them ?
> 
> > 
> >> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> > 
> > Acked-by: Michal Hocko <mhocko@suse.com>
> > 
> >> ---
> >>
> >> Since this is a mostly mechanical change I've actually batched all of them in 
> >> a single patch. 
> >>
> >>  fs/afs/file.c        | 5 +++--
> >>  fs/btrfs/extent_io.c | 2 +-
> >>  fs/ceph/addr.c       | 5 ++---
> >>  fs/cifs/file.c       | 3 ++-
> >>  fs/ext4/readpage.c   | 2 +-
> >>  fs/ocfs2/aops.c      | 3 ++-
> >>  fs/orangefs/inode.c  | 2 +-
> >>  mm/swap.c            | 2 +-
> >>  8 files changed, 13 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/fs/afs/file.c b/fs/afs/file.c
> >> index d6bc3f5d784b..323ae9912203 100644
> >> --- a/fs/afs/file.c
> >> +++ b/fs/afs/file.c
> >> @@ -17,6 +17,7 @@
> >>  #include <linux/writeback.h>
> >>  #include <linux/gfp.h>
> >>  #include <linux/task_io_accounting_ops.h>
> >> +#include <linux/mm.h>
> >>  #include "internal.h"
> >>  
> >>  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,
> >>  	/* Count the number of contiguous pages at the front of the list.  Note
> >>  	 * that the list goes prev-wards rather than next-wards.
> >>  	 */
> >> -	first = list_entry(pages->prev, struct page, lru);
> >> +	first = lru_to_page(pages);
> >>  	index = first->index + 1;
> >>  	n = 1;
> >>  	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,
> >>  	 * page at the end of the file.
> >>  	 */
> >>  	do {
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  		list_del(&page->lru);
> >>  		index = page->index;
> >>  		if (add_to_page_cache_lru(page, mapping, index,
> >> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> >> index 19f4b8fd654f..8332c5f4b1c3 100644
> >> --- a/fs/btrfs/extent_io.c
> >> +++ b/fs/btrfs/extent_io.c
> >> @@ -4104,7 +4104,7 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages,
> >>  	u64 prev_em_start = (u64)-1;
> >>  
> >>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  
> >>  		prefetchw(&page->flags);
> >>  		list_del(&page->lru);
> >> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> >> index 8eade7a993c1..5d0c05e288cc 100644
> >> --- a/fs/ceph/addr.c
> >> +++ b/fs/ceph/addr.c
> >> @@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
> >>  	struct ceph_osd_client *osdc =
> >>  		&ceph_inode_to_client(inode)->client->osdc;
> >>  	struct ceph_inode_info *ci = ceph_inode(inode);
> >> -	struct page *page = list_entry(page_list->prev, struct page, lru);
> >> +	struct page *page = lru_to_page(page_list);
> >>  	struct ceph_vino vino;
> >>  	struct ceph_osd_request *req;
> >>  	u64 off;
> >> @@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
> >>  			if (got)
> >>  				ceph_put_cap_refs(ci, got);
> >>  			while (!list_empty(page_list)) {
> >> -				page = list_entry(page_list->prev,
> >> -						  struct page, lru);
> >> +				page = lru_to_page(page_list);
> >>  				list_del(&page->lru);
> >>  				put_page(page);
> >>  			}
> >> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> >> index 74c33d5fafc8..b16a4d887d17 100644
> >> --- a/fs/cifs/file.c
> >> +++ b/fs/cifs/file.c
> >> @@ -33,6 +33,7 @@
> >>  #include <linux/mount.h>
> >>  #include <linux/slab.h>
> >>  #include <linux/swap.h>
> >> +#include <linux/mm.h>
> >>  #include <asm/div64.h>
> >>  #include "cifsfs.h"
> >>  #include "cifspdu.h"
> >> @@ -3975,7 +3976,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
> >>  
> >>  	INIT_LIST_HEAD(tmplist);
> >>  
> >> -	page = list_entry(page_list->prev, struct page, lru);
> >> +	page = lru_to_page(page_list);
> >>  
> >>  	/*
> >>  	 * Lock the page and put it in the cache. Since no one else
> >> diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
> >> index f461d75ac049..6aa282ee455a 100644
> >> --- a/fs/ext4/readpage.c
> >> +++ b/fs/ext4/readpage.c
> >> @@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
> >>  
> >>  		prefetchw(&page->flags);
> >>  		if (pages) {
> >> -			page = list_entry(pages->prev, struct page, lru);
> >> +			page = lru_to_page(pages);
> >>  			list_del(&page->lru);
> >>  			if (add_to_page_cache_lru(page, mapping, page->index,
> >>  				  readahead_gfp_mask(mapping)))
> >> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> >> index eb1ce30412dc..832c1759a09a 100644
> >> --- a/fs/ocfs2/aops.c
> >> +++ b/fs/ocfs2/aops.c
> >> @@ -30,6 +30,7 @@
> >>  #include <linux/quotaops.h>
> >>  #include <linux/blkdev.h>
> >>  #include <linux/uio.h>
> >> +#include <linux/mm.h>
> >>  
> >>  #include <cluster/masklog.h>
> >>  
> >> @@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
> >>  	 * Check whether a remote node truncated this file - we just
> >>  	 * drop out in that case as it's not worth handling here.
> >>  	 */
> >> -	last = list_entry(pages->prev, struct page, lru);
> >> +	last = lru_to_page(pages);
> >>  	start = (loff_t)last->index << PAGE_SHIFT;
> >>  	if (start >= i_size_read(inode))
> >>  		goto out_unlock;
> >> diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
> >> index fe53381b26b1..f038235c64bd 100644
> >> --- a/fs/orangefs/inode.c
> >> +++ b/fs/orangefs/inode.c
> >> @@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file,
> >>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> >>  		struct page *page;
> >>  
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  		list_del(&page->lru);
> >>  		if (!add_to_page_cache(page,
> >>  				       mapping,
> >> diff --git a/mm/swap.c b/mm/swap.c
> >> index aa483719922e..20b9e9d99652 100644
> >> --- a/mm/swap.c
> >> +++ b/mm/swap.c
> >> @@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages)
> >>  	while (!list_empty(pages)) {
> >>  		struct page *victim;
> >>  
> >> -		victim = list_entry(pages->prev, struct page, lru);
> >> +		victim = lru_to_page(pages);
> >>  		list_del(&victim->lru);
> >>  		put_page(victim);
> >>  	}
> >> -- 
> >> 2.17.1
> > 
>
Pankaj Gupta Nov. 29, 2018, 11:38 a.m. UTC | #6
> >> There are a bunch of filesystems which essentially open-code lru_to_page
> >> helper. Change them to using the helper. No functional changes.
> > 
> > I would just squash the two into a single patch. It makes the first one
> > more obvious. Or is there any reason to have them separate?
> 
> No reason, just didn't know how people would react so that's why I chose
> to send as two separate.
> 
> If I squash them who would be the best person to take them ?

For squashed version:
Acked-by: Pankaj gupta <pagupta@redhat.com>

> 
> > 
> >> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> > 
> > Acked-by: Michal Hocko <mhocko@suse.com>
> > 
> >> ---
> >>
> >> Since this is a mostly mechanical change I've actually batched all of them
> >> in
> >> a single patch.
> >>
> >>  fs/afs/file.c        | 5 +++--
> >>  fs/btrfs/extent_io.c | 2 +-
> >>  fs/ceph/addr.c       | 5 ++---
> >>  fs/cifs/file.c       | 3 ++-
> >>  fs/ext4/readpage.c   | 2 +-
> >>  fs/ocfs2/aops.c      | 3 ++-
> >>  fs/orangefs/inode.c  | 2 +-
> >>  mm/swap.c            | 2 +-
> >>  8 files changed, 13 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/fs/afs/file.c b/fs/afs/file.c
> >> index d6bc3f5d784b..323ae9912203 100644
> >> --- a/fs/afs/file.c
> >> +++ b/fs/afs/file.c
> >> @@ -17,6 +17,7 @@
> >>  #include <linux/writeback.h>
> >>  #include <linux/gfp.h>
> >>  #include <linux/task_io_accounting_ops.h>
> >> +#include <linux/mm.h>
> >>  #include "internal.h"
> >>  
> >>  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,
> >>  	/* Count the number of contiguous pages at the front of the list.  Note
> >>  	 * that the list goes prev-wards rather than next-wards.
> >>  	 */
> >> -	first = list_entry(pages->prev, struct page, lru);
> >> +	first = lru_to_page(pages);
> >>  	index = first->index + 1;
> >>  	n = 1;
> >>  	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,
> >>  	 * page at the end of the file.
> >>  	 */
> >>  	do {
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  		list_del(&page->lru);
> >>  		index = page->index;
> >>  		if (add_to_page_cache_lru(page, mapping, index,
> >> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> >> index 19f4b8fd654f..8332c5f4b1c3 100644
> >> --- a/fs/btrfs/extent_io.c
> >> +++ b/fs/btrfs/extent_io.c
> >> @@ -4104,7 +4104,7 @@ int extent_readpages(struct address_space *mapping,
> >> struct list_head *pages,
> >>  	u64 prev_em_start = (u64)-1;
> >>  
> >>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  
> >>  		prefetchw(&page->flags);
> >>  		list_del(&page->lru);
> >> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> >> index 8eade7a993c1..5d0c05e288cc 100644
> >> --- a/fs/ceph/addr.c
> >> +++ b/fs/ceph/addr.c
> >> @@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct
> >> ceph_rw_context *rw_ctx,
> >>  	struct ceph_osd_client *osdc =
> >>  		&ceph_inode_to_client(inode)->client->osdc;
> >>  	struct ceph_inode_info *ci = ceph_inode(inode);
> >> -	struct page *page = list_entry(page_list->prev, struct page, lru);
> >> +	struct page *page = lru_to_page(page_list);
> >>  	struct ceph_vino vino;
> >>  	struct ceph_osd_request *req;
> >>  	u64 off;
> >> @@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct
> >> ceph_rw_context *rw_ctx,
> >>  			if (got)
> >>  				ceph_put_cap_refs(ci, got);
> >>  			while (!list_empty(page_list)) {
> >> -				page = list_entry(page_list->prev,
> >> -						  struct page, lru);
> >> +				page = lru_to_page(page_list);
> >>  				list_del(&page->lru);
> >>  				put_page(page);
> >>  			}
> >> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> >> index 74c33d5fafc8..b16a4d887d17 100644
> >> --- a/fs/cifs/file.c
> >> +++ b/fs/cifs/file.c
> >> @@ -33,6 +33,7 @@
> >>  #include <linux/mount.h>
> >>  #include <linux/slab.h>
> >>  #include <linux/swap.h>
> >> +#include <linux/mm.h>
> >>  #include <asm/div64.h>
> >>  #include "cifsfs.h"
> >>  #include "cifspdu.h"
> >> @@ -3975,7 +3976,7 @@ readpages_get_pages(struct address_space *mapping,
> >> struct list_head *page_list,
> >>  
> >>  	INIT_LIST_HEAD(tmplist);
> >>  
> >> -	page = list_entry(page_list->prev, struct page, lru);
> >> +	page = lru_to_page(page_list);
> >>  
> >>  	/*
> >>  	 * Lock the page and put it in the cache. Since no one else
> >> diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
> >> index f461d75ac049..6aa282ee455a 100644
> >> --- a/fs/ext4/readpage.c
> >> +++ b/fs/ext4/readpage.c
> >> @@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space
> >> *mapping,
> >>  
> >>  		prefetchw(&page->flags);
> >>  		if (pages) {
> >> -			page = list_entry(pages->prev, struct page, lru);
> >> +			page = lru_to_page(pages);
> >>  			list_del(&page->lru);
> >>  			if (add_to_page_cache_lru(page, mapping, page->index,
> >>  				  readahead_gfp_mask(mapping)))
> >> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> >> index eb1ce30412dc..832c1759a09a 100644
> >> --- a/fs/ocfs2/aops.c
> >> +++ b/fs/ocfs2/aops.c
> >> @@ -30,6 +30,7 @@
> >>  #include <linux/quotaops.h>
> >>  #include <linux/blkdev.h>
> >>  #include <linux/uio.h>
> >> +#include <linux/mm.h>
> >>  
> >>  #include <cluster/masklog.h>
> >>  
> >> @@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct
> >> address_space *mapping,
> >>  	 * Check whether a remote node truncated this file - we just
> >>  	 * drop out in that case as it's not worth handling here.
> >>  	 */
> >> -	last = list_entry(pages->prev, struct page, lru);
> >> +	last = lru_to_page(pages);
> >>  	start = (loff_t)last->index << PAGE_SHIFT;
> >>  	if (start >= i_size_read(inode))
> >>  		goto out_unlock;
> >> diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
> >> index fe53381b26b1..f038235c64bd 100644
> >> --- a/fs/orangefs/inode.c
> >> +++ b/fs/orangefs/inode.c
> >> @@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file,
> >>  	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> >>  		struct page *page;
> >>  
> >> -		page = list_entry(pages->prev, struct page, lru);
> >> +		page = lru_to_page(pages);
> >>  		list_del(&page->lru);
> >>  		if (!add_to_page_cache(page,
> >>  				       mapping,
> >> diff --git a/mm/swap.c b/mm/swap.c
> >> index aa483719922e..20b9e9d99652 100644
> >> --- a/mm/swap.c
> >> +++ b/mm/swap.c
> >> @@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages)
> >>  	while (!list_empty(pages)) {
> >>  		struct page *victim;
> >>  
> >> -		victim = list_entry(pages->prev, struct page, lru);
> >> +		victim = lru_to_page(pages);
> >>  		list_del(&victim->lru);
> >>  		put_page(victim);
> >>  	}
> >> --
> >> 2.17.1
> > 
> 
>
Yan, Zheng Nov. 30, 2018, 9:11 a.m. UTC | #7
On Thu, Nov 29, 2018 at 3:56 PM Nikolay Borisov <nborisov@suse.com> wrote:
>
> There are a bunch of filesystems which essentially open-code lru_to_page
> helper. Change them to using the helper. No functional changes.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>
> Since this is a mostly mechanical change I've actually batched all of them in
> a single patch.
>
>  fs/afs/file.c        | 5 +++--
>  fs/btrfs/extent_io.c | 2 +-
>  fs/ceph/addr.c       | 5 ++---
>  fs/cifs/file.c       | 3 ++-
>  fs/ext4/readpage.c   | 2 +-
>  fs/ocfs2/aops.c      | 3 ++-
>  fs/orangefs/inode.c  | 2 +-
>  mm/swap.c            | 2 +-
>  8 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/fs/afs/file.c b/fs/afs/file.c
> index d6bc3f5d784b..323ae9912203 100644
> --- a/fs/afs/file.c
> +++ b/fs/afs/file.c
> @@ -17,6 +17,7 @@
>  #include <linux/writeback.h>
>  #include <linux/gfp.h>
>  #include <linux/task_io_accounting_ops.h>
> +#include <linux/mm.h>
>  #include "internal.h"
>
>  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,
>         /* Count the number of contiguous pages at the front of the list.  Note
>          * that the list goes prev-wards rather than next-wards.
>          */
> -       first = list_entry(pages->prev, struct page, lru);
> +       first = lru_to_page(pages);
>         index = first->index + 1;
>         n = 1;
>         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,
>          * page at the end of the file.
>          */
>         do {
> -               page = list_entry(pages->prev, struct page, lru);
> +               page = lru_to_page(pages);
>                 list_del(&page->lru);
>                 index = page->index;
>                 if (add_to_page_cache_lru(page, mapping, index,
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 19f4b8fd654f..8332c5f4b1c3 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -4104,7 +4104,7 @@ int extent_readpages(struct address_space *mapping, struct list_head *pages,
>         u64 prev_em_start = (u64)-1;
>
>         for (page_idx = 0; page_idx < nr_pages; page_idx++) {
> -               page = list_entry(pages->prev, struct page, lru);
> +               page = lru_to_page(pages);
>
>                 prefetchw(&page->flags);
>                 list_del(&page->lru);
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 8eade7a993c1..5d0c05e288cc 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -306,7 +306,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>         struct ceph_osd_client *osdc =
>                 &ceph_inode_to_client(inode)->client->osdc;
>         struct ceph_inode_info *ci = ceph_inode(inode);
> -       struct page *page = list_entry(page_list->prev, struct page, lru);
> +       struct page *page = lru_to_page(page_list);
>         struct ceph_vino vino;
>         struct ceph_osd_request *req;
>         u64 off;
> @@ -333,8 +333,7 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
>                         if (got)
>                                 ceph_put_cap_refs(ci, got);
>                         while (!list_empty(page_list)) {
> -                               page = list_entry(page_list->prev,
> -                                                 struct page, lru);
> +                               page = lru_to_page(page_list);
>                                 list_del(&page->lru);
>                                 put_page(page);
>                         }

For the ceph patch

Acked-by:: "Yan, Zheng" <zyan@redhat.com

> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 74c33d5fafc8..b16a4d887d17 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -33,6 +33,7 @@
>  #include <linux/mount.h>
>  #include <linux/slab.h>
>  #include <linux/swap.h>
> +#include <linux/mm.h>
>  #include <asm/div64.h>
>  #include "cifsfs.h"
>  #include "cifspdu.h"
> @@ -3975,7 +3976,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
>
>         INIT_LIST_HEAD(tmplist);
>
> -       page = list_entry(page_list->prev, struct page, lru);
> +       page = lru_to_page(page_list);
>
>         /*
>          * Lock the page and put it in the cache. Since no one else
> diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
> index f461d75ac049..6aa282ee455a 100644
> --- a/fs/ext4/readpage.c
> +++ b/fs/ext4/readpage.c
> @@ -128,7 +128,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
>
>                 prefetchw(&page->flags);
>                 if (pages) {
> -                       page = list_entry(pages->prev, struct page, lru);
> +                       page = lru_to_page(pages);
>                         list_del(&page->lru);
>                         if (add_to_page_cache_lru(page, mapping, page->index,
>                                   readahead_gfp_mask(mapping)))
> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
> index eb1ce30412dc..832c1759a09a 100644
> --- a/fs/ocfs2/aops.c
> +++ b/fs/ocfs2/aops.c
> @@ -30,6 +30,7 @@
>  #include <linux/quotaops.h>
>  #include <linux/blkdev.h>
>  #include <linux/uio.h>
> +#include <linux/mm.h>
>
>  #include <cluster/masklog.h>
>
> @@ -397,7 +398,7 @@ static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
>          * Check whether a remote node truncated this file - we just
>          * drop out in that case as it's not worth handling here.
>          */
> -       last = list_entry(pages->prev, struct page, lru);
> +       last = lru_to_page(pages);
>         start = (loff_t)last->index << PAGE_SHIFT;
>         if (start >= i_size_read(inode))
>                 goto out_unlock;
> diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
> index fe53381b26b1..f038235c64bd 100644
> --- a/fs/orangefs/inode.c
> +++ b/fs/orangefs/inode.c
> @@ -77,7 +77,7 @@ static int orangefs_readpages(struct file *file,
>         for (page_idx = 0; page_idx < nr_pages; page_idx++) {
>                 struct page *page;
>
> -               page = list_entry(pages->prev, struct page, lru);
> +               page = lru_to_page(pages);
>                 list_del(&page->lru);
>                 if (!add_to_page_cache(page,
>                                        mapping,
> diff --git a/mm/swap.c b/mm/swap.c
> index aa483719922e..20b9e9d99652 100644
> --- a/mm/swap.c
> +++ b/mm/swap.c
> @@ -126,7 +126,7 @@ void put_pages_list(struct list_head *pages)
>         while (!list_empty(pages)) {
>                 struct page *victim;
>
> -               victim = list_entry(pages->prev, struct page, lru);
> +               victim = lru_to_page(pages);
>                 list_del(&victim->lru);
>                 put_page(victim);
>         }
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/fs/afs/file.c b/fs/afs/file.c
index d6bc3f5d784b..323ae9912203 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -17,6 +17,7 @@ 
 #include <linux/writeback.h>
 #include <linux/gfp.h>
 #include <linux/task_io_accounting_ops.h>
+#include <linux/mm.h>
 #include "internal.h"
 
 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,
 	/* Count the number of contiguous pages at the front of the list.  Note
 	 * that the list goes prev-wards rather than next-wards.
 	 */
-	first = list_entry(pages->prev, struct page, lru);
+	first = lru_to_page(pages);
 	index = first->index + 1;
 	n = 1;
 	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,
 	 * page at the end of the file.
 	 */
 	do {
-		page = list_entry(pages->prev, struct page, lru);
+		page = lru_to_page(pages);
 		list_del(&page->lru);
 		index = page->index;
 		if (add_to_page_cache_lru(page, mapping, index,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 19f4b8fd654f..8332c5f4b1c3 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4104,7 +4104,7 @@  int extent_readpages(struct address_space *mapping, struct list_head *pages,
 	u64 prev_em_start = (u64)-1;
 
 	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
-		page = list_entry(pages->prev, struct page, lru);
+		page = lru_to_page(pages);
 
 		prefetchw(&page->flags);
 		list_del(&page->lru);
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 8eade7a993c1..5d0c05e288cc 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -306,7 +306,7 @@  static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
 	struct ceph_osd_client *osdc =
 		&ceph_inode_to_client(inode)->client->osdc;
 	struct ceph_inode_info *ci = ceph_inode(inode);
-	struct page *page = list_entry(page_list->prev, struct page, lru);
+	struct page *page = lru_to_page(page_list);
 	struct ceph_vino vino;
 	struct ceph_osd_request *req;
 	u64 off;
@@ -333,8 +333,7 @@  static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
 			if (got)
 				ceph_put_cap_refs(ci, got);
 			while (!list_empty(page_list)) {
-				page = list_entry(page_list->prev,
-						  struct page, lru);
+				page = lru_to_page(page_list);
 				list_del(&page->lru);
 				put_page(page);
 			}
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 74c33d5fafc8..b16a4d887d17 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -33,6 +33,7 @@ 
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/swap.h>
+#include <linux/mm.h>
 #include <asm/div64.h>
 #include "cifsfs.h"
 #include "cifspdu.h"
@@ -3975,7 +3976,7 @@  readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
 
 	INIT_LIST_HEAD(tmplist);
 
-	page = list_entry(page_list->prev, struct page, lru);
+	page = lru_to_page(page_list);
 
 	/*
 	 * Lock the page and put it in the cache. Since no one else
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index f461d75ac049..6aa282ee455a 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -128,7 +128,7 @@  int ext4_mpage_readpages(struct address_space *mapping,
 
 		prefetchw(&page->flags);
 		if (pages) {
-			page = list_entry(pages->prev, struct page, lru);
+			page = lru_to_page(pages);
 			list_del(&page->lru);
 			if (add_to_page_cache_lru(page, mapping, page->index,
 				  readahead_gfp_mask(mapping)))
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index eb1ce30412dc..832c1759a09a 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -30,6 +30,7 @@ 
 #include <linux/quotaops.h>
 #include <linux/blkdev.h>
 #include <linux/uio.h>
+#include <linux/mm.h>
 
 #include <cluster/masklog.h>
 
@@ -397,7 +398,7 @@  static int ocfs2_readpages(struct file *filp, struct address_space *mapping,
 	 * Check whether a remote node truncated this file - we just
 	 * drop out in that case as it's not worth handling here.
 	 */
-	last = list_entry(pages->prev, struct page, lru);
+	last = lru_to_page(pages);
 	start = (loff_t)last->index << PAGE_SHIFT;
 	if (start >= i_size_read(inode))
 		goto out_unlock;
diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index fe53381b26b1..f038235c64bd 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -77,7 +77,7 @@  static int orangefs_readpages(struct file *file,
 	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
 		struct page *page;
 
-		page = list_entry(pages->prev, struct page, lru);
+		page = lru_to_page(pages);
 		list_del(&page->lru);
 		if (!add_to_page_cache(page,
 				       mapping,
diff --git a/mm/swap.c b/mm/swap.c
index aa483719922e..20b9e9d99652 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -126,7 +126,7 @@  void put_pages_list(struct list_head *pages)
 	while (!list_empty(pages)) {
 		struct page *victim;
 
-		victim = list_entry(pages->prev, struct page, lru);
+		victim = lru_to_page(pages);
 		list_del(&victim->lru);
 		put_page(victim);
 	}