首先改动alloc_diskmem()函数,给这个函数中申请内存的语句、也就是alloc_pages()的gfp_mask中加上__GFP_HIGHMEM标志, 这使得申请块设备的内存块时,会优先考虑使用高端内存。 修改过的函数如下: int alloc_diskmem(void) { int ret; int i; struct page *page;
INIT_RADIX_TREE(&simp_blkdev_data, GFP_KERNEL);
for (i = 0; i < (simp_blkdev_bytes + SIMP_BLKDEV_DATASEGSIZE - 1) >> SIMP_BLKDEV_DATASEGSHIFT; i++) { page = alloc_pages(GFP_KERNEL | __GFP_ZERO | __GFP_HIGHMEM, SIMP_BLKDEV_DATASEGORDER); if (!page) { ret = -ENOMEM; goto err_alloc; }
ret = radix_tree_insert(&simp_blkdev_data, i, page); if (IS_ERR_VALUE(ret)) goto err_radix_tree_insert; } return 0;
参照以上的思路,我们写出了新的simp_blkdev_trans_oneseg()函数: static int simp_blkdev_trans_oneseg(struct page *start_page, unsigned long offset, void *buf, unsigned int len, int dir) { unsigned int done_cnt; struct page *this_page; unsigned int this_off; unsigned int this_cnt; void *dsk_mem;