2017-12-12 18:53:04
gcc优化引起get_free_page比__get_free_page返回值多4096
内核版本:1.3.100
extern inline unsigned long get_free_page(int priority)
{
unsigned long page;
page = __get_free_page(priority);
DDBUG("1.page=%p, nr=%d", page, page>>PAGE_SHIFT);
if (page){
memset((void *) page, 0, PAGE_SIZE);
}
DDBUG("2.page=%p, nr=%d", page, page>>PAGE_SHIFT);
return page;
}
page_alloc.c(245):__get_free_pages : 2.map_nr=431, ADDRESS(431)=001af000
/root/oldlinux/src/linux/include/linux/mm.h(242):get_free_page : 1.page=001af000, nr=431
/root/oldlinux/src/linux/include/linux/mm.h(246):get_free_page : 2.page=001b0000, nr=431
应该返回0x001af000结果错给了0x001b0000
修订:page使用volatile属性,告诉gcc,这个变量使用内存,使用前从内核中取
static inline unsigned long get_free_page(int priority)
{
volatile unsigned long page;
page = __get_free_page(priority);
DDBUG("1.page=%p, nr=%d", page, page>>PAGE_SHIFT);
if (page){
memset(page, 0, PAGE_SIZE);
}
DDBUG("2.page=%p, nr=%d", page, page>>PAGE_SHIFT);
return page;
}
page_alloc.c(245):__get_free_pages : 2.map_nr=431, ADDRESS(431)=001af000
/root/oldlinux/src/linux/include/linux/mm.h(241):get_free_page : 1.page=001af000, nr=431
/root/oldlinux/src/linux/include/linux/mm.h(245):get_free_page : 2.page=001af000, nr=431