how to get the address of other page descriptors from alloc_pages()?

Submitted by luludede
on December 26, 2009 - 9:55am

Hi,

In Linux kernel, alloc_pages() allocate a congiguous series of pages and return the page descriptor of the first page.
Can anyone tell me how to get the other page descriptors(2nd page descriptor, 3rd page descriptor)?

I used firstpage+i to access the other page descriptors and the program crashed when executing add_to_page_cache_lru(firstpage+2, mapping, first_index+i,GFP_KERNEL);
It seems that use firstpage+i can not get the correct page descriptors.
Can anyone tell me the right way to access the descriptors of the pages allocated by alloc_pages ?

Thank you very much.
========================================================
The code:
firstpage = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO|__GFP_COLD, 4);
if(unlikely(firstpage == NULL)) {
goto normal_handling;
}
printk(KERN_INFO "deng: all 16 pages are allocated in memory\n"winking smiley;
for(i=0; i<16; i++) {/*add 16 pages to lru list*/
printk(KERN_INFO "deng: add firstpage+%d to page cache lru\n", i);
error= add_to_page_cache_lru(firstpage+i, mapping,
first_index+i,GFP_KERNEL);

========================================================
kernel info:
deng: first page isn't in memory
deng: all 16 pages are not in memory
deng: all 16 pages are allocated in memory
deng: add firstpage+0 to page cache lru
deng: add firstpage+1 to page cache lru
------------[ cut here ]------------
kernel BUG at include/linux/mm.h:304!
invalid opcode: 0000 [#1] SMP
last sysfs file: /sys/devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/devnum
Modules linked in: nfsd sco lockd nfs_acl auth_rpcgss exportfs bridge stp llc bnep l2cap bluetooth sunrpc ip6t_REJECT nf_conntrack_ipv6 ip6table_filter ip6_tables ipv6 dm_multipath raid0 raid1 raid456 raid6_pq async_xor async_memcpy async_tx xor uinput ppdev pcspkr snd_ens1371 gameport snd_rawmidi snd_seq_device snd_ac97_codec ac97_bus snd_pcm snd_timer snd soundcore pcnet32 snd_page_alloc mii parport_pc parport floppy i2c_piix4 i2c_core mptspi mptscsih mptbase scsi_transport_spi [last unloaded: microcode]

Pid: 2738, comm: spew Not tainted (2.6.30.9 #7) VMware Virtual Platform
EIP: 0060:[] EFLAGS: 00010246 CPU: 0
EIP is at add_to_page_cache_locked+0x67/0xde
EAX: c143823c EBX: c143823c ECX: 00000000 EDX: 00000000
ESI: 00000000 EDI: d07a8ac8 EBP: de58de34 ESP: de58de20
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process spew (pid: 2738, ti=de58c000 task=c9f90000 task.ti=de58c000)
Stack:
00000001 d07a8ad8 c143823c 00000001 c1438200 de58de48 c0491879 000000d0
00000001 00000001 de58dec8 c0492826 000000d0 c0862f4e 00000001 de58de64
00000000 00000000 00000000 de58df20 d333e288 de58df5c 00000000 00000000
Call Trace:
[] ? add_to_page_cache_lru+0x2b/0x5b
[] ? generic_file_aio_read+0x260/0x736
[] ? do_sync_read+0xae/0xe9
[] ? autoremove_wake_function+0x0/0x34
[] ? selinux_file_permission+0x49/0x4d
[] ? security_file_permission+0x14/0x16
[] ? rw_verify_area+0x9d/0xc0
[] ? do_sync_read+0x0/0xe9
[] ? vfs_read+0x82/0xe1
[] ? sys_read+0x40/0x62
[] ? syscall_call+0x7/0xb
Code: 89 c6 0f 85 91 00 00 00 8b 45 08 83 e0 fd e8 7c fe 0e 00 85 c0 89 c6 75 79 66 83 3b 00 89 d8 79 03 8b 43 0c 8b 50 04 85 d2 75 04 <0f> 0b eb fe 3e ff 40 04 8b 45 ec 89 7b 10 89 43 30 8d 47 10 89
EIP: [] add_to_page_cache_locked+0x67/0xde SS:ESP 0068:de58de20
---[ end trace c12cba1f7403675e ]---