Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:load_image_lzo - Load compressed image data and decompress them with LZO.*@handle: Swap map handle to use for loading data.*@snapshot: Image to copy uncompressed data into.*@nr_to_read: Number of pages to load.

Proto:static int load_image_lzo(struct swap_map_handle *handle, struct snapshot_handle *snapshot, unsigned int nr_to_read)

Type:int

Parameter:

TypeParameterName
struct swap_map_handle *handle
struct snapshot_handle *snapshot
unsigned intnr_to_read
1159  ret = 0
1160  eof = 0
1167  ring = 0 , pg = 0 , ring_size = 0 , have = 0 , asked = 0
1169  read_pages = 0
1170  unsigned char * * page = NULL
1171  struct dec_data * data = NULL
1172  struct crc_data * crc = NULL
1174  hib_init_batch( & hb)
1180  nr_threads = num_online_cpus() - 1
1181  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. )
1183  page = 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.)
1184  If Not page Then
1185  pr_err("Failed to allocate LZO page\n")
1186  ret = -ENOMEM
1187  Go to out_clean
1190  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.)
1191  If Not data Then
1192  pr_err("Failed to allocate LZO data\n")
1193  ret = -ENOMEM
1194  Go to out_clean
1196  When thr < nr_threads cycle memset( & data[thr], 0, offsetof(structdec_data, go))
1199  crc = Allocation memory
1200  If Not crc Then
1201  pr_err("Failed to allocate crc\n")
1202  ret = -ENOMEM
1203  Go to out_clean
1205  memset(crc, 0, offsetof(structcrc_data, go))
1207  clean_pages_on_decompress = true
1212  When thr < nr_threads cycle
1213  init_waitqueue_head( & start decompression )
1214  init_waitqueue_head( & decompression done )
1216  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(Deompression function that runs in its own thread., & data[thr], "image_decompress/%u", thr)
1219  If IS_ERR(hread ) Then
1220  hread = NULL
1221  pr_err("Cannot start decompression threads\n")
1222  ret = -ENOMEM
1223  Go to out_clean
1230  init_waitqueue_head( & start crc update )
1231  init_waitqueue_head( & crc update done )
1233  crc32 = 0
1234  points to handle's crc32 = crc32
1235  When thr < nr_threads cycle
1236  uncompressed data [thr] = unc
1237  uncompressed lengths [thr] = uncompressed length
1240  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")
1241  If IS_ERR(hread ) Then
1242  hread = NULL
1243  pr_err("Cannot start CRC32 thread\n")
1244  ret = -ENOMEM
1245  Go to out_clean
1255  If Number of free pages that are not high. > snapshot_get_image_size() Then read_pages = (Number of free pages that are not high. - snapshot_get_image_size()) / 2
1257  read_pages = 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(read_pages, Minimum/maximum number of pages for read buffering. , LZO_MAX_RD_PAGES)
1259  When i < read_pages cycle
1260  page[i] = __get_free_page(i < Number of pages/bytes we need for compressed data (worst case). ? GFP_NOIO | __GFP_HIGH : GFP_NOIO | DOC: Action modifiers* Action modifiers* ~~~~~~~~~~~~~~~~* %__GFP_NOWARN suppresses allocation failure reports.* %__GFP_COMP address compound page metadata.* %__GFP_ZERO returns a zeroed page on success. | __GFP_NORETRY)
1265  If Not page[i] Then
1267  ring_size = i
1268  pr_err("Failed to allocate LZO pages\n")
1269  ret = -ENOMEM
1270  Go to out_clean
1271  Else
1272  Break
1276  want = ring_size = i
1278  pr_info("Using %u thread(s) for decompression\n", nr_threads)
1279  pr_info("Loading and decompressing image data (%u pages)...\n", nr_to_read)
1281  m = nr_to_read / 10
1282  If Not m Then m = 1
1284  nr_pages = 0
1285  start = ktime_get()
1287  ret = snapshot_write_next - Get the address to store the next image page.*@handle: Snapshot handle structure to guide the writing.* On the first call, @handle should point to a zeroed snapshot_handle* structure
1288  If ret <= 0 Then Go to out_finish
1291  cycle
1292  When Not eof && i < want cycle
1293  ret = swap_read_page(handle, page[ring], & hb)
1294  If ret Then
1299  If cur && entries[k] Then
1301  Go to out_finish
1302  Else
1303  eof = 1
1304  Break
1307  If ++ring >= ring_size Then ring = 0
1310  asked += i
1311  want -= i
1316  If Not have Then
1317  If Not asked Then Break
1320  ret = hib_wait_io( & hb)
1321  If ret Then Go to out_finish
1323  have += asked
1324  asked = 0
1325  If eof Then eof = 2
1329  If r current threads Then
1332  r current threads = 0
1335  When have && thr < nr_threads cycle
1340  pr_err("Invalid LZO compressed length\n")
1341  ret = -1
1342  Go to out_finish
1347  If need > have Then
1348  If eof > 1 Then
1349  ret = -1
1350  Go to out_finish
1352  Break
1360  have--
1361  want++
1362  If ++pg >= ring_size Then pg = 0
1374  ret = hib_wait_io( & hb)
1375  If ret Then Go to out_finish
1377  have += asked
1378  asked = 0
1379  If eof Then eof = 2
1383  When thr < run_threads cycle
1388  ret = urn code
1390  If ret < 0 Then
1391  pr_err("LZO decompression failed\n")
1392  Go to out_finish
1398  pr_err("Invalid LZO uncompressed length\n")
1399  ret = -1
1400  Go to out_finish
1423  r current threads = thr
1424  atomic_set( & ady to start flag , 1)
1425  wake_up( & start crc update )
1428  out_finish :
1429  If r current threads Then
1430  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 ))
1431  atomic_set( & ady to stop flag , 0)
1433  stop = ktime_get()
1434  If Not ret Then
1435  pr_info("Image loading done\n")
1436  snapshot_write_finalize - Complete the loading of a hibernation image.* Must be called after the last call to snapshot_write_next() in case the last* page in the image happens to be a highmem page and its contents should be* stored in highmem
1437  If Not snapshot_image_loaded(snapshot) Then ret = -ENODATA
1439  If Not ret Then
1441  If crc32 != crc32 Then
1442  pr_err("Invalid image CRC32!\n")
1443  ret = -ENODATA
1448  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.
1449  out_clean :
1450  When i < ring_size cycle free_page((unsignedlong)page[i])
1452  If crc Then
1453  If hread Then stop a thread
1455  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.
1457  If data Then
1458  When thr < nr_threads cycle If hread Then
1460  stop a thread
1461  vfree(data)
1463  vfree(page)
1465  Return ret
Caller
NameDescribe
swsusp_readswsusp_read - read the hibernation image.*@flags_p: flags passed by the "frozen" kernel in the image header should* be written into this memory location