Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andrea Righi
Date: Wednesday, June 11, 2008 - 1:17 pm

Andrew Morton wrote:

If I'm not doing something wrong, here is what happens on my i386 box:

$ uname -m
i686
$ cat 64-bit-page-align.c
#include <stdio.h>
#include <asm/page.h>

#define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
#define PAGE_ALIGN64(addr) (((((addr)+PAGE_SIZE-1))>>PAGE_SHIFT)<<PAGE_SHIFT)

#define SIZE ((1ULL << 32) - 1)

int main(int argc, char **argv)
{
	unsigned long long good, bad;

	good = (unsigned long long)PAGE_ALIGN64(SIZE);
	bad = (unsigned long long)PAGE_ALIGN(SIZE);

	fprintf(stdout, "good = %llu, bad = %llu\n", good, bad);

	return 0;
}
$ gcc -O2 -o 64-bit-page-align 64-bit-page-align.c
$ ./64-bit-page-align
good = 4294967296, bad = 0
                   ^^^^^^^
On a x86_64, instead, both PAGE_ALIGN()s work as expected:

$ uname -m
x86_64
$ gcc -O2 -o 64-bit-page-align 64-bit-page-align.c
$ ./64-bit-page-align
good = 4294967296, bad = 4294967296

At least we could add something like:

#ifdef CONFIG_32BIT
#define PAGE_ALIGN64(addr) (((((addr)+PAGE_SIZE-1))>>PAGE_SHIFT)<<PAGE_SHIFT)
#else
#define PAGE_ALIGN64(addr) PAGE_ALIGN(addr)
#endif

But IMHO the single PAGE_ALIGN64() implementation is more clear.

-Andrea
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[-mm][PATCH 0/4] Add memrlimit controller (v5), Balbir Singh, (Wed May 21, 8:29 am)
[-mm][PATCH 2/4] Setup the memrlimit controller (v5), Balbir Singh, (Wed May 21, 8:29 am)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrew Morton, (Wed May 21, 9:18 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrea Righi, (Wed Jun 11, 10:10 am)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Balbir Singh, (Wed Jun 11, 10:33 am)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrea Righi, (Wed Jun 11, 11:48 am)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrew Morton, (Wed Jun 11, 12:15 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrea Righi, (Wed Jun 11, 1:17 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrew Morton, (Wed Jun 11, 1:43 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrew Morton, (Wed Jun 11, 3:55 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Balbir Singh, (Wed Jun 11, 11:13 pm)
Re: [-mm][PATCH 2/4] Setup the memrlimit controller (v5), Andrew Morton, (Thu Jun 12, 2:02 am)