Skip to contentSkip to conversation

pagemap: use PAGE_MASK/PAGE_ALIGN()

RFC PATCH Christian Ehrhardt 2 participants 2 messages Aug 8, 2007 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 14 lines · you

Use existing macros (PAGE_MASK/PAGE_ALIGN()) instead of open-coding them.

---

 lxc-dave/fs/proc/task_mmu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN fs/proc/task_mmu.c~pagemap-use-PAGE_MASK fs/proc/task_mmu.c

fs/proc/task_mmu.c static ssize_t pagemap_read(struct file · line 674

Quoted 8 lines
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~pagemap-use-PAGE_MASK +2 -2
@@ -669,9 +669,9 @@ static ssize_t pagemap_read(struct file 
 		goto out;
 
 	ret = -ENOMEM;
-	uaddr = (unsigned long)buf & ~(PAGE_SIZE-1);
+	uaddr = (unsigned long)buf & PAGE_MASK;
 	uend = (unsigned long)(buf + count);
-	pagecount = (uend - uaddr + PAGE_SIZE-1) / PAGE_SIZE;
+	pagecount = (uend - PAGE_ALIGN(uaddr)) / PAGE_SIZE;

Unless I'm missing something the PAGE_ALIGN as ist stands is now a NOP because uaddr is already page aligned. You probably wanted to PAGE_ALIGN(uend). However, this will likely add an additional instruction to the generated code.

regards Christian

#3 lore raw
Quoted 8 lines · Christian Ehrhardt

Review

Quoted 7 lines
      ret = -ENOMEM;
(quoted diff) +2 -2
-     uaddr = (unsigned long)buf & ~(PAGE_SIZE-1);
+     uaddr = (unsigned long)buf & PAGE_MASK;
      uend = (unsigned long)(buf + count);
-     pagecount = (uend - uaddr + PAGE_SIZE-1) / PAGE_SIZE;
+     pagecount = (uend - PAGE_ALIGN(uaddr)) / PAGE_SIZE;
Quoted 4 lines

Unless I'm missing something the PAGE_ALIGN as ist stands is now a NOP because uaddr is already page aligned. You probably wanted to PAGE_ALIGN(uend). However, this will likely add an additional instruction to the generated code.

Yeah, I aligned the wrong thing. I'll fix that up.

-- Dave