函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:mm\swapfile.c Create Date:2022-07-27 16:50:24
Last Modify:2020-03-17 22:19:49 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:SYSCALL_DEFINE2

函数原型:SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)

返回类型:

参数:

3113  struct file * swap_file = NULL
3121  unsigned char * swap_map = NULL
3122  struct swap_cluster_info * cluster_info = NULL
3123  unsigned long * frontswap_map = NULL
3124  struct page * page = NULL
3125  struct inode * inode = NULL
3126  bool inced_nr_rotate_swap = false
3128  如果swap_flags按位与SWAP_FLAGS_VALID的反则返回:负EINVAL
3131  如果非操作权限检查则返回:负EPERM
3134  如果非all available (active, not full) swap_info_structs* protected with swap_avail_lock, ordered by priority.* This is used by get_swap_page() instead of swap_active_head* because swap_active_head includes all swap_info_structs,则返回:负ENOMEM
3137  p等于alloc_swap_info()
3138  如果是错误则返回:错误
3141  INIT_WORK( & discard worker , swap_discard_work)
3143  name等于getname(specialfile)
3144  如果是错误
3145  error等于错误
3146  name = NULL
3147  转到:bad_swap
3149  swap_file等于file_open_name(name, O_RDWR | O_LARGEFILE, 0)
3150  如果是错误
3151  error等于错误
3152  swap_file = NULL
3153  转到:bad_swap
3156  seldom referenced 等于swap_file
3157  mapping等于f_mapping
3158  inode等于host
3161  error等于claim_swapfile(p, inode)
3162  如果此条件成立可能性小(为编译器优化)(error)则转到:bad_swap
3168  如果非readpage
3169  error等于负EINVAL
3170  转到:bad_swap
3172  page等于read_mapping_page(mapping, 0, swap_file)
3173  如果是错误
3174  error等于错误
3175  转到:bad_swap
3177  swap_header等于kmap(page)
3179  maxpages等于read_swap_header(p, swap_header, inode)
3180  如果此条件成立可能性小(为编译器优化)(!maxpages)则
3181  error等于负EINVAL
3182  转到:bad_swap
3186  swap_map等于vzalloc - allocate virtually contiguous memory with zero fill*@size: allocation size* Allocate enough pages to cover @size from the page level* allocator and map them into contiguous kernel virtual space
3187  如果非swap_map
3188  error等于负ENOMEM
3189  转到:bad_swap
3192  如果bdi_cap_stable_pages_required(inode_to_bdi(inode))则SWP_USED etc: see above 或等于SWP_STABLE_WRITES
3195  如果bdi_cap_synchronous_io(inode_to_bdi(inode))则SWP_USED etc: see above 或等于SWP_SYNCHRONOUS_IO
3198  如果swap device or bdev of swap file blk_queue_nonrot(bdev_get_queue(swap device or bdev of swap file ))则
3202  SWP_USED etc: see above 或等于SWP_SOLIDSTATE
3207  likely index for next allocation 等于1加prandom_u32 - pseudo random number generator* A 32 bit pseudo-random number is generated using a fast* algorithm suitable for simulation. This algorithm is NOT* considered safe for cryptographic use.取模dex of last free in swap_map
3208  nr_cluster等于DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER)
3210  cluster_info等于kvcalloc(nr_cluster, cluster_info的长度, GFP_KERNEL)
3212  如果非cluster_info
3213  error等于负ENOMEM
3214  转到:bad_swap
3217 ci小于nr_cluster循环spin_lock_init( & (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  如果非per cpu's swap location
3222  error等于负ENOMEM
3223  转到:bad_swap
3230  否则
3231  atomic_inc( & nr_rotate_swap)
3232  inced_nr_rotate_swap = true
3235  error等于swap_cgroup_swapon(strange name for an index , maxpages)
3236  如果error则转到:bad_swap
3239  nr_extents等于setup_swap_map_and_extents(p, swap_header, swap_map, cluster_info, maxpages, & span)
3241  如果此条件成立可能性小(为编译器优化)(nr_extents < 0)则
3242  error等于nr_extents
3243  转到:bad_swap
3246  如果IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',* 0 otherwise.(CONFIG_FRONTSWAP)则frontswap_map等于kvcalloc(BITS_TO_LONGS(maxpages), sizeof(long), GFP_KERNEL)
3251  如果swap device or bdev of swap file swap_flags按位与able discard for swap Helper to sys_swapon determining if a given swap* backing device queue supports DISCARD operations.
3258  SWP_USED etc: see above 或等于SWP_DISCARDABLE按位或SWP_AREA_DISCARD按位或SWP_PAGE_DISCARD
3267  如果swap_flags按位与discard swap area at swapon-time SWP_USED etc: see above 与等于SWP_PAGE_DISCARD的反
3269  否则如果swap_flags按位与discard page-clusters after use SWP_USED etc: see above 与等于SWP_AREA_DISCARD的反
3273  如果SWP_USED etc: see above 按位与SWP_AREA_DISCARD
3275  如果此条件成立可能性小(为编译器优化)(err)则打印错误信息("swapon: discard_swap(%p): %d\n", p, err)
3281  error等于init_swap_address_space(strange name for an index , maxpages)
3282  如果error则转到:bad_swap
3289  i_flags或等于Do not truncate: swapon got its bmaps
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  如果error
3292  i_flags与等于Do not truncate: swapon got its bmaps 的反
3293  转到:bad_swap
3296  mutex_lock( & swapon_mutex)
3297  prio等于负1
3298  如果swap_flags按位与set if swap priority specified prio等于swap_flags按位与SWAP_FLAG_PRIO_MASK的值右移SWAP_FLAG_PRIO_SHIFT
3301  enable_swap_info(p, prio, swap_map, cluster_info, frontswap_map)
3303  打印信息("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" : "")
3312  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
3313  atomic_inc( & Activity counter to indicate that a swapon or swapoff has occurred )
3314  wake_up_interruptible( & proc_poll_wait)
3316  error等于0
3317  转到:out
3318  bad_swap :
3319  释放内存
3320  per cpu's swap location = NULL
3321  如果inodeS_ISBLK(i_mode)且swap device or bdev of swap file
3322  set_blocksize(swap device or bdev of swap file , seldom referenced )
3323  blkdev_put(swap device or bdev of swap file , le is open for reading | le is open for writing | File is opened with O_EXCL (only set for block devices) )
3325  Free all of a swapdev's extent information
3326  swap_cgroup_swapoff(strange name for an index )
3327  加自旋锁
3328  seldom referenced = NULL
3329  SWP_USED etc: see above 等于0
3330  自旋锁解锁
3331  vfree - release memory allocated by vmalloc()*@addr: memory base address* Free the virtually continuous memory area starting at @addr, as* obtained from vmalloc(), vmalloc_32() or __vmalloc()
3332  kvfree() - Free memory.*@addr: Pointer to allocated memory.* kvfree frees memory allocated by any of vmalloc(), kmalloc() or kvmalloc().* It is slightly more efficient to use kfree() or vfree() if you are certain* that you know which one to use.
3333  kvfree() - Free memory.*@addr: Pointer to allocated memory.* kvfree frees memory allocated by any of vmalloc(), kmalloc() or kvmalloc().* It is slightly more efficient to use kfree() or vfree() if you are certain* that you know which one to use.
3334  如果inced_nr_rotate_swapatomic_dec( & nr_rotate_swap)
3336  如果swap_file
3337  如果inode
3339  inode = NULL
3341  filp_close(swap_file, NULL)
3343  out :
3344  如果page且非是错误
3345  kunmap(page)
3346  Perform a free_page(), also freeing any swap cache associated with* this page if it is the last user of the page.
3348  如果nameputname(name)
3350  如果inodeinode_unlock(inode)
3352  如果非errorenable_swap_slots_cache()
3354  返回:error