Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\power\swap.c Create Date:2022-07-28 10:02:42
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:save_image_lzo - Save the suspend image data compressed with LZO.*@handle: Swap map handle to use for saving the image.*@snapshot: Image to read data from.*@nr_to_write: Number of pages to save.

Proto:static int save_image_lzo(struct swap_map_handle *handle, struct snapshot_handle *snapshot, unsigned int nr_to_write)

Type:int

Parameter:

TypeParameterName
struct swap_map_handle *handle
struct snapshot_handle *snapshot
unsigned intnr_to_write
671  ret = 0
679  unsigned char * page = NULL
680  struct cmp_data * data = NULL
681  struct crc_data * crc = NULL
683  hib_init_batch( & hb)
689  nr_threads = num_online_cpus() - 1
690  nr_threads = clamp_val - return a value clamped to a given range using val's type*@val: current value*@lo: minimum allowable value*@hi: maximum allowable value* This macro does no typechecking and uses temporary variables of whatever* type the input argument @val is(nr_threads, 1, Maximum number of threads for compression/decompression. )
692  page = __get_free_page(GFP_NOIO | __GFP_HIGH)
693  If Not page Then
694  pr_err("Failed to allocate LZO page\n")
695  ret = -ENOMEM
696  Go to out_clean
699  data = vmalloc(array_size() - Calculate size of 2-dimensional array.*@a: dimension one*@b: dimension two* Calculates size of 2-dimensional array: @a *@b.* Returns: number of bytes needed to represent the array or SIZE_MAX on* overflow.)
700  If Not data Then
701  pr_err("Failed to allocate LZO data\n")
702  ret = -ENOMEM
703  Go to out_clean
705  When thr < nr_threads cycle memset( & data[thr], 0, offsetof(structcmp_data, go))
708  crc = Allocation memory
709  If Not crc Then
710  pr_err("Failed to allocate crc\n")
711  ret = -ENOMEM
712  Go to out_clean
714  memset(crc, 0, offsetof(structcrc_data, go))
719  When thr < nr_threads cycle
720  init_waitqueue_head( & start compression )
721  init_waitqueue_head( & compression done )
723  hread = kthread_run - create and wake a thread.*@threadfn: the function to run until signal_pending(current).*@data: data ptr for @threadfn.*@namefmt: printf-style name for the thread.* Description: Convenient wrapper for kthread_create() followed by(Compression function that runs in its own thread., & data[thr], "image_compress/%u", thr)
726  If IS_ERR(hread ) Then
727  hread = NULL
728  pr_err("Cannot start compression threads\n")
729  ret = -ENOMEM
730  Go to out_clean
737  init_waitqueue_head( & start crc update )
738  init_waitqueue_head( & crc update done )
740  crc32 = 0
741  points to handle's crc32 = crc32
742  When thr < nr_threads cycle
743  uncompressed data [thr] = unc
744  uncompressed lengths [thr] = uncompressed length
747  hread = kthread_run - create and wake a thread.*@threadfn: the function to run until signal_pending(current).*@data: data ptr for @threadfn.*@namefmt: printf-style name for the thread.* Description: Convenient wrapper for kthread_create() followed by(CRC32 update function that runs in its own thread., crc, "image_crc32")
748  If IS_ERR(hread ) Then
749  hread = NULL
750  pr_err("Cannot start CRC32 thread\n")
751  ret = -ENOMEM
752  Go to out_clean
759  reqd_free_pages = Number of pages required to be kept free while writing the image. Always* half of all available low pages before the writing starts.
761  pr_info("Using %u thread(s) for compression\n", nr_threads)
762  pr_info("Compressing and saving image data (%u pages)...\n", nr_to_write)
764  m = nr_to_write / 10
765  If Not m Then m = 1
767  nr_pages = 0
768  start = ktime_get()
769  cycle
770  When thr < nr_threads cycle
771  When off < LZO_UNC_SIZE cycle
787  If Not off Then Break
796  If Not thr Then Break
799  r current threads = thr
800  atomic_set( & ady to start flag , 1)
801  wake_up( & start crc update )
803  When thr < run_threads cycle
808  ret = urn code
810  If ret < 0 Then
811  pr_err("LZO compression failed\n")
812  Go to out_finish
818  pr_err("Invalid LZO compressed length\n")
819  ret = -1
820  Go to out_finish
839  If ret Then Go to out_finish
844  wait_event - sleep until a condition gets true*@wq_head: the waitqueue to wait on*@condition: a C expression for the event to wait for* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the*@condition evaluates to true(crc update done , atomic_read( & ady to stop flag ))
845  atomic_set( & ady to stop flag , 0)
848  out_finish :
849  err2 = hib_wait_io( & hb)
850  stop = ktime_get()
851  If Not ret Then ret = err2
853  If Not ret Then pr_info("Image saving done\n")
855  swsusp_show_speed - Print time elapsed between two events during hibernation.*@start: Starting event.*@stop: Final event.*@nr_pages: Number of memory pages processed between @start and @stop.*@msg: Additional diagnostic message to print.
856  out_clean :
857  If crc Then
858  If hread Then stop a thread
860  kfree - free previously allocated memory*@objp: pointer returned by kmalloc.* If @objp is NULL, no operation is performed.* Don't free memory not originally allocated by kmalloc()* or you will run into trouble.
862  If data Then
863  When thr < nr_threads cycle If hread Then
865  stop a thread
866  vfree(data)
868  If page Then free_page((unsignedlong)page)
870  Return ret
Caller
NameDescribe
swsusp_writeswsusp_write - Write entire image and metadata.*@flags: flags to pass to the "boot" kernel in the image header* It is important _NOT_ to umount filesystems at this point. We want* them synced (in case something goes wrong) but we DO not want to mark