这样新的地址空间ID就可以给next进程使用了。 然后根据第二步得到地址空间ID(两种情况:一是本来就有空闲的进程地址空间ID,另外就是通过steal_context采用替换策略得到的ID)更新地址空间ID位图context_map。在设置位图之前,需要调用find_next_zero_bit找到对应的空闲比特位。 find_next_zero_bit也就是我们bug出现死循环...
find_next_zero_bit函数从第i个页框开始搜索空的页框,并返回空的页框i,如果后面有连续areasize个空的页,则找到了并记下起始位置start,如果没有连续的areasize个页框,就从新查找连续areasize个空的页。 found: bdata->last_success = start << PAGE_SHIFT; if (align < PAGE_SIZE && bdata->last_offset...
find_next_zero_bit(void *addr, int size, int offset):从offset所指向的位开始,在一段连续的内存中,找从这里起(含offset这一位)的后面第一个为'0'的位。 这三个函数是找第一个为'0'的位,但找的对象一个为连续的内存,一个为双字,还有一个虽是双字,但是却指定了起始位置:offset。 --- __ffs(unsi...
static inline int variable_test_bit(int nr, volatile const unsigned long *addr) 9. find_first_zero_bit int find_first_zero_bit (void * addr, unsigned size) addr为内存区的起始地址,size为要查找的最大长度,返回第一个位为0的位号 10. find_next_zero_bit int find_next_zero_bit (void * ...
inode_bitmap_bh = NULL; if (++group == ngroups) group = 0; continue; } repeatinthis_group: // 在 inode 位图中查找 ino+1 开始的下一个为0的位 ino = ext4_find_next_zero_bit((unsigned long *) inode_bitmap_bh->b_data,
位图(bitmap)是一种非常有用的数据结构,在处理系统中的进程数管理、磁盘中的磁盘块管理、以及内存中的内存页的使用情况管理时非常有用。 同时在内核中对位图进行各种操作,现在总结一些常用的操作,以便在以后用到时方便回顾。 几个常用的宏定义: #define BIT_PER_TYPE 8 ...
sidx = find_next_zero_bit(bdata->node_bootmem_map, midx, sidx); ... 将页标记为已分配 if (__reserve(bdata, PFN_DOWN(start_off) + merge, PFN_UP(end_off), BOOTMEM_EXCLUSIVE)) ... } ... return NULL; } static int __
//find_next_zero_bit函数在文件描述符位图fds_bits中从next_fd位开始搜索下一个(包括next_fd)为0的位,也就是分配一个文教描述符 /* * N.B. For clone tasks sharing a files structure, this test * will limit the total number of files that can be opened. ...
staticvoidchoose_address(struct usb_device*udev){int devnum;struct usb_bus*bus=udev->bus;devnum=find_next_zero_bit(bus->devmap.devicemap,128,bus->devnum_next);//在bus->devnum_next~128区间中,循环查找下一个非0(没有设备)的编号if(devnum>=128)//若编号大于等于128,说明没有找到空余的地址...
find_first_zero_bit和find_first_bit的第二个参数size是以位(bit)为单位的,find_next_zero_bit和find_next_bit从第offset位(包含offset)开始查找为0和为1的位置,找不到则返回size。 有了以上的宏和函数,可以很方便地找到位图中的某位,比如要获取文件描述符的函数alloc_fd,它最终调用find_next_zero_bit来查...