内核中看到struct page中有如下的定义:
struct page {
unsigned long flags; /* Atomic flags, some possibly
* updated asynchronously */
atomic_t _count; /* Usage count, see below. */
union {
atomic_t _mapcount; /* Count of ptes mapped in mms,
* to show when page is mapped
* & limit reverse map searches.
*/
struct { /* SLUB */
u16 inuse;
u16 objects;
};
};
......
}
page结构体中定义的联合竟然没有指定成员,这个怎么访问呢?难道我的内核代码被我错误地修改了?对比了一下其他的代码,也是一样。自己试了一下,还真是可以。在结构体中定义的联合中的成员,可以直接访问,而不需要通过中间变量。假设p是struct page类型的指针,这时要访问_mapcount时,只需要直接p->_mapcount即可。访问inuse和objects也是一样,直接p->inse和p->objects即可。