Function report |
Source Code:mm\swapfile.c |
Create Date:2022-07-28 15:19:59 |
Last Modify:2020-03-17 22:19:49 | Copyright©Brick |
home page | Tree |
Annotation kernel can get tool activity | Download SCCT | Chinese |
Name:SYSCALL_DEFINE2
Proto:SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
Type:
Parameter:Nothing
3121 | unsigned char * swap_map = NULL |
3122 | struct swap_cluster_info * cluster_info = NULL |
3123 | unsigned long * frontswap_map = NULL |
3126 | bool inced_nr_rotate_swap = false |
3128 | If swap_flags & ~SWAP_FLAGS_VALID Then Return -EINVAL |
3131 | If Not Check operation authority Then Return -EPERM |
3137 | p = alloc_swap_info() |
3141 | INIT_WORK( & discard worker , swap_discard_work) |
3143 | name = getname(specialfile) |
3149 | swap_file = file_open_name(name, O_RDWR | O_LARGEFILE, 0) |
3156 | seldom referenced = swap_file |
3161 | error = claim_swapfile(p, inode) |
3162 | If Value for the false possibility is greater at compile time(error) Then Go to bad_swap |
3168 | If Not readpage Then |
3172 | page = read_mapping_page(mapping, 0, swap_file) |
3177 | swap_header = kmap(page) |
3179 | maxpages = read_swap_header(p, swap_header, inode) |
3187 | If Not swap_map Then |
3192 | If bdi_cap_stable_pages_required(inode_to_bdi(inode)) Then SWP_USED etc: see above |= SWP_STABLE_WRITES |
3195 | If bdi_cap_synchronous_io(inode_to_bdi(inode)) Then SWP_USED etc: see above |= SWP_SYNCHRONOUS_IO |
3208 | nr_cluster = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER) |
3210 | cluster_info = kvcalloc(nr_cluster, size of cluster_info , GFP_KERNEL) |
3212 | If Not cluster_info Then |
3217 | When ci < nr_cluster cycle Process spin lock initialization( & (Protect swap_cluster_info fields* and swap_info_struct->swap_map* elements correspond to the swap* cluster)) |
3220 | per cpu's swap location = alloc_percpu(structpercpu_cluster) |
3221 | If Not per cpu's swap location Then |
3225 | for_each_possible_cpu(cpu) |
3227 | cluster = per_cpu_ptr(per cpu's swap location , cpu) |
3228 | cluster_set_null( & Current cluster index ) |
3230 | Else |
3231 | atomic_inc( & nr_rotate_swap) |
3232 | inced_nr_rotate_swap = true |
3239 | nr_extents = setup_swap_map_and_extents(p, swap_header, swap_map, cluster_info, maxpages, & span) |
3241 | If Value for the false possibility is greater at compile time(nr_extents < 0) Then |
3242 | error = nr_extents |
3243 | Go to bad_swap |
3246 | If IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_FRONTSWAP) Then frontswap_map = kvcalloc(BITS_TO_LONGS(maxpages), sizeof(long), GFP_KERNEL) |
3267 | If swap_flags & discard swap area at swapon-time Then SWP_USED etc: see above &= ~SWP_PAGE_DISCARD |
3269 | Else if swap_flags & discard page-clusters after use Then SWP_USED etc: see above &= ~SWP_AREA_DISCARD |
3273 | If SWP_USED etc: see above & SWP_AREA_DISCARD Then |
3274 | err = swapon tell device that all the old swap contents can be discarded,* to allow the swap device to optimize its wear-levelling. |
3275 | If Value for the false possibility is greater at compile time(err) Then pr_err("swapon: discard_swap(%p): %d\n", p, err) |
3290 | error = Flush file data before changing attributes. Caller must hold any locks* required to prevent further writes to this file until we're done setting* flags. |
3291 | If error Then |
3293 | Go to bad_swap |
3296 | mutex_lock( & swapon_mutex) |
3297 | prio = -1 |
3298 | If swap_flags & set if swap priority specified Then prio = (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT |
3301 | enable_swap_info(p, prio, swap_map, cluster_info, frontswap_map) |
3303 | pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s%s\n", al of usable pages of swap << (PAGE_SHIFT determines the page size - 10), pointer to actual string , swap priority of this type , nr_extents, (unsignedlonglong)span << (PAGE_SHIFT determines the page size - 10), (SWP_USED etc: see above & SWP_SOLIDSTATE) ? "SS" : "", (SWP_USED etc: see above & SWP_DISCARDABLE) ? "D" : "", (SWP_USED etc: see above & SWP_AREA_DISCARD) ? "s" : "", (SWP_USED etc: see above & SWP_PAGE_DISCARD) ? "c" : "", (frontswap_map) ? "FS" : "") |
3314 | wake_up_interruptible( & proc_poll_wait) |
3316 | error = 0 |
3317 | Go to out |
3318 | bad_swap : |
3320 | per cpu's swap location = NULL |
3321 | If inode && S_ISBLK(i_mode) && swap device or bdev of swap file Then |
3328 | seldom referenced = NULL |
3329 | SWP_USED etc: see above = 0 |
3330 | spin_unlock( & swap_lock) |
3334 | If inced_nr_rotate_swap Then atomic_dec( & nr_rotate_swap) |
3336 | If swap_file Then |
3343 | out : |
3350 | If inode Then inode_unlock(inode) |
3352 | If Not error Then enable_swap_slots_cache() |
3354 | Return error |
Source code conversion tool public plug-in interface | X |
---|---|
Support c/c++/esqlc/java Oracle/Informix/Mysql Plug-in can realize: logical Report Code generation and batch code conversion |