Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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 activityDownload SCCTChinese

Name:SYSCALL_DEFINE2

Proto:SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)

Type:

Parameter:Nothing

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  If swap_flags & ~SWAP_FLAGS_VALID Then Return -EINVAL
3131  If Not Check operation authority Then Return -EPERM
3134  If Not 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, Then Return -ENOMEM
3137  p = alloc_swap_info()
3138  If IS_ERR(p) Then Return PTR_ERR(p)
3141  INIT_WORK( & discard worker , swap_discard_work)
3143  name = getname(specialfile)
3144  If IS_ERR(name) Then
3145  error = PTR_ERR(name)
3146  name = NULL
3147  Go to bad_swap
3149  swap_file = file_open_name(name, O_RDWR | O_LARGEFILE, 0)
3150  If IS_ERR(swap_file) Then
3151  error = PTR_ERR(swap_file)
3152  swap_file = NULL
3153  Go to bad_swap
3156  seldom referenced = swap_file
3157  mapping = f_mapping
3158  inode = host
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
3169  error = -EINVAL
3170  Go to bad_swap
3172  page = read_mapping_page(mapping, 0, swap_file)
3173  If IS_ERR(page) Then
3174  error = PTR_ERR(page)
3175  Go to bad_swap
3177  swap_header = kmap(page)
3179  maxpages = read_swap_header(p, swap_header, inode)
3180  If Value for the false possibility is greater at compile time(!maxpages) Then
3181  error = -EINVAL
3182  Go to 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  If Not swap_map Then
3188  error = -ENOMEM
3189  Go to bad_swap
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
3198  If swap device or bdev of swap file && blk_queue_nonrot(bdev_get_queue(swap device or bdev of swap file )) Then
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, size of cluster_info , GFP_KERNEL)
3212  If Not cluster_info Then
3213  error = -ENOMEM
3214  Go to bad_swap
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
3222  error = -ENOMEM
3223  Go to bad_swap
3230  Else
3231  atomic_inc( & nr_rotate_swap)
3232  inced_nr_rotate_swap = true
3235  error = swap_cgroup_swapon(strange name for an index , maxpages)
3236  If error Then Go to bad_swap
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)
3251  If 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. Then
3258  SWP_USED etc: see above |= SWP_DISCARDABLE | SWP_AREA_DISCARD | SWP_PAGE_DISCARD
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
3275  If Value for the false possibility is greater at compile time(err) Then pr_err("swapon: discard_swap(%p): %d\n", p, err)
3281  error = init_swap_address_space(strange name for an index , maxpages)
3282  If error Then Go to 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  If error Then
3292  i_flags &= ~Do not truncate: swapon got its bmaps
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" : "")
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  Go to out
3318  bad_swap :
3319  free previously allocated percpu memory
3320  per cpu's swap location = NULL
3321  If inode && S_ISBLK(i_mode) && swap device or bdev of swap file Then
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  spin_lock( & swap_lock)
3328  seldom referenced = NULL
3329  SWP_USED etc: see above = 0
3330  spin_unlock( & swap_lock)
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  If inced_nr_rotate_swap Then atomic_dec( & nr_rotate_swap)
3336  If swap_file Then
3337  If inode Then
3339  inode = NULL
3341  filp_close(swap_file, NULL)
3343  out :
3344  If page && Not IS_ERR(page) Then
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  If name Then putname(name)
3350  If inode Then inode_unlock(inode)
3352  If Not error Then enable_swap_slots_cache()
3354  Return error