2007-08-28 19:23:28

by Christoph Lameter

[permalink] [raw]
Subject: [07/36] Use page_cache_xxx in mm/filemap_xip.c

Use page_cache_xxx in mm/filemap_xip.c

Signed-off-by: Christoph Lameter <[email protected]>
---
mm/filemap_xip.c | 28 ++++++++++++++--------------
1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index ba6892d..5237e53 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -61,24 +61,24 @@ do_xip_mapping_read(struct address_space *mapping,

BUG_ON(!mapping->a_ops->get_xip_page);

- index = *ppos >> PAGE_CACHE_SHIFT;
- offset = *ppos & ~PAGE_CACHE_MASK;
+ index = page_cache_index(mapping, *ppos);
+ offset = page_cache_offset(mapping, *ppos);

isize = i_size_read(inode);
if (!isize)
goto out;

- end_index = (isize - 1) >> PAGE_CACHE_SHIFT;
+ end_index = page_cache_index(mapping, isize - 1);
for (;;) {
struct page *page;
unsigned long nr, ret;

/* nr is the maximum number of bytes to copy from this page */
- nr = PAGE_CACHE_SIZE;
+ nr = page_cache_size(mapping);
if (index >= end_index) {
if (index > end_index)
goto out;
- nr = ((isize - 1) & ~PAGE_CACHE_MASK) + 1;
+ nr = page_cache_next(mapping, size - 1) + 1;
if (nr <= offset) {
goto out;
}
@@ -117,8 +117,8 @@ do_xip_mapping_read(struct address_space *mapping,
*/
ret = actor(desc, page, offset, nr);
offset += ret;
- index += offset >> PAGE_CACHE_SHIFT;
- offset &= ~PAGE_CACHE_MASK;
+ index += page_cache_index(mapping, offset);
+ offset = page_cache_offset(mapping, offset);

if (ret == nr && desc->count)
continue;
@@ -131,7 +131,7 @@ no_xip_page:
}

out:
- *ppos = ((loff_t) index << PAGE_CACHE_SHIFT) + offset;
+ *ppos = page_cache_pos(mapping, index, offset);
if (filp)
file_accessed(filp);
}
@@ -220,7 +220,7 @@ static int xip_file_fault(struct vm_area_struct *area, struct vm_fault *vmf)

/* XXX: are VM_FAULT_ codes OK? */

- size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+ size = page_cache_next(mapping, i_size_read(inode));
if (vmf->pgoff >= size)
return VM_FAULT_SIGBUS;

@@ -289,9 +289,9 @@ __xip_file_write(struct file *filp, const char __user *buf,
unsigned long offset;
size_t copied;

- offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
- index = pos >> PAGE_CACHE_SHIFT;
- bytes = PAGE_CACHE_SIZE - offset;
+ offset = page_cache_offset(mapping, pos); /* Within page */
+ index = page_cache_index(mapping, pos);
+ bytes = page_cache_size(mapping) - offset;
if (bytes > count)
bytes = count;

@@ -405,8 +405,8 @@ EXPORT_SYMBOL_GPL(xip_file_write);
int
xip_truncate_page(struct address_space *mapping, loff_t from)
{
- pgoff_t index = from >> PAGE_CACHE_SHIFT;
- unsigned offset = from & (PAGE_CACHE_SIZE-1);
+ pgoff_t index = page_cache_index(mapping, from);
+ unsigned offset = page_cache_offset(mapping, from);
unsigned blocksize;
unsigned length;
struct page *page;
--
1.5.2.4

--


2007-08-28 19:54:20

by Jörn Engel

[permalink] [raw]
Subject: Re: [07/36] Use page_cache_xxx in mm/filemap_xip.c

On Tue, 28 August 2007 12:05:58 -0700, [email protected] wrote:
>
> - index = *ppos >> PAGE_CACHE_SHIFT;
> - offset = *ppos & ~PAGE_CACHE_MASK;
> + index = page_cache_index(mapping, *ppos);
> + offset = page_cache_offset(mapping, *ppos);

Part of me feels inclined to marge this patch now because it makes the
code more readable, even if page_cache_index() is implemented as
#define page_cache_index(mapping, pos) ((pos) >> PAGE_CACHE_SHIFT)

I know there is little use in yet another global search'n'replace
wankfest and Andrew might wash my mouth just for mentioning it. Still,
hard to dislike this part of your patch.

Jörn

--
He who knows others is wise.
He who knows himself is enlightened.
-- Lao Tsu

2007-08-28 19:57:18

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [07/36] Use page_cache_xxx in mm/filemap_xip.c

On Tue, Aug 28, 2007 at 09:49:38PM +0200, J??rn Engel wrote:
> On Tue, 28 August 2007 12:05:58 -0700, [email protected] wrote:
> >
> > - index = *ppos >> PAGE_CACHE_SHIFT;
> > - offset = *ppos & ~PAGE_CACHE_MASK;
> > + index = page_cache_index(mapping, *ppos);
> > + offset = page_cache_offset(mapping, *ppos);
>
> Part of me feels inclined to marge this patch now because it makes the
> code more readable, even if page_cache_index() is implemented as
> #define page_cache_index(mapping, pos) ((pos) >> PAGE_CACHE_SHIFT)
>
> I know there is little use in yet another global search'n'replace
> wankfest and Andrew might wash my mouth just for mentioning it. Still,
> hard to dislike this part of your patch.

Yes, I I suggested that before. Andrew seems to somehow hate this
patchset, but even if we don;'t get it in the lowercase macros are much
much better then the current PAGE_CACHE_* confusion.

2007-08-28 23:49:42

by Nick Piggin

[permalink] [raw]
Subject: Re: [07/36] Use page_cache_xxx in mm/filemap_xip.c

Christoph Hellwig wrote:
> On Tue, Aug 28, 2007 at 09:49:38PM +0200, J??rn Engel wrote:
>
>>On Tue, 28 August 2007 12:05:58 -0700, [email protected] wrote:
>>
>>>
>>>- index = *ppos >> PAGE_CACHE_SHIFT;
>>>- offset = *ppos & ~PAGE_CACHE_MASK;
>>>+ index = page_cache_index(mapping, *ppos);
>>>+ offset = page_cache_offset(mapping, *ppos);
>>
>>Part of me feels inclined to marge this patch now because it makes the
>>code more readable, even if page_cache_index() is implemented as
>>#define page_cache_index(mapping, pos) ((pos) >> PAGE_CACHE_SHIFT)
>>
>>I know there is little use in yet another global search'n'replace
>>wankfest and Andrew might wash my mouth just for mentioning it. Still,
>>hard to dislike this part of your patch.
>
>
> Yes, I I suggested that before. Andrew seems to somehow hate this
> patchset, but even if we don;'t get it in the lowercase macros are much
> much better then the current PAGE_CACHE_* confusion.

I don't mind the change either. The open coded macros are very
recognisable, but it isn't hard to have a typo and get one
slightly wrong.

If it goes upstream now it wouldn't have the mapping argument
though, would it? Or the need to replace PAGE_CACHE_SIZE I guess.

--
SUSE Labs, Novell Inc.