Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:hibernate_preallocate_memory - Preallocate memory for hibernation image

Proto:int hibernate_preallocate_memory(void)

Type:int

Parameter:Nothing

1703  pages = 0
1708  pr_info("Preallocating image memory... ")
1709  start = ktime_get()
1711  error = memory_bm_create - Allocate memory for a memory bitmap.
1712  If error Then Go to err_out
1715  error = memory_bm_create - Allocate memory for a memory bitmap.
1716  If error Then Go to err_out
1719  Numbers of normal and highmem page frames allocated for hibernation image* before suspending devices. = 0
1720  Numbers of normal and highmem page frames allocated for hibernation image* before suspending devices. = 0
1723  save_highmem = count_highmem_pages()
1724  saveable = _data_pages - Compute the total number of saveable non-highmem pages.
1730  count = saveable
1731  saveable += save_highmem
1732  highmem = save_highmem
1733  size = 0
1734  do nothing (zone)
1735  size += snapshot_additional_pages - Estimate the number of extra pages needed
1736  If s_highmem - helper function to quickly check if a struct zone is a* highmem zone or not. This is an attempt to keep references* to ZONE_{DMA/NORMAL/HIGHMEM/etc} in general code to a minimum.*@zone - pointer to struct zone variable Then highmem += zone_page_state(zone, NR_FREE_PAGES)
1738  Else count += zone_page_state(zone, NR_FREE_PAGES)
1741  avail_normal = count
1742  count += highmem
1743  count -= linux/mm/page_alloc.c
1746  size += page_key_additional_pages(saveable)
1749  max_size = (count - size + PAGES_FOR_IO ) / 2 - 2 * DIV_ROUND_UP(Number of bytes to reserve for memory allocations made by device drivers* from their ->freeze() and ->freeze_noirq() callbacks so that they don't* cause image creation to fail (tunable via /sys/power/reserved_size)., PAGE_SIZE)
1752  size = DIV_ROUND_UP(Preferred image size in bytes (tunable via /sys/power/image_size).* When it is set to N, swsusp will do its best to ensure the image* size will not exceed N bytes, but if that is impossible, it will* try to create the smallest image possible., PAGE_SIZE)
1753  If size > max_size Then size = max_size
1760  If size >= saveable Then
1761  pages = preallocate_image_highmem(save_highmem)
1762  pages += preallocate_image_memory(saveable - pages, avail_normal)
1763  Go to out
1767  pages = minimum_image_size - Estimate the minimum acceptable size of an image
1773  If avail_normal > pages Then avail_normal -= pages
1775  Else avail_normal = 0
1777  If size < pages Then size = min_t - return minimum of two values, using the specified type*@type: data type to use*@x: first value*@y: second value(unsignedlong, pages, max_size)
1786  shrink_all_memory(saveable - size)
1795  pages_highmem = preallocate_image_highmem(highmem / 2)
1796  alloc = count - max_size
1797  If alloc > pages_highmem Then alloc -= pages_highmem
1799  Else alloc = 0
1801  pages = preallocate_image_memory(alloc, avail_normal)
1802  If pages < alloc Then
1804  alloc -= pages
1805  pages += pages_highmem
1806  pages_highmem = preallocate_image_highmem(alloc)
1807  If pages_highmem < alloc Then Go to err_out
1809  pages += pages_highmem
1814  alloc = count - pages - size
1815  pages += preallocate_image_highmem(alloc)
1816  Else
1821  alloc = max_size - size
1822  size = preallocate_highmem_fraction(alloc, highmem, count)
1823  pages_highmem += size
1824  alloc -= size
1825  size = preallocate_image_memory(alloc, avail_normal)
1826  pages_highmem += preallocate_image_highmem(alloc - size)
1827  pages += pages_highmem + size
1835  pages -= _unnecessary_pages - Release preallocated pages not needed for the image.
1837  out :
1838  stop = ktime_get()
1839  Like KERN_CONT, pr_cont() should only be used when continuing* a line with no newline ('\n') enclosed. Otherwise it defaults* back to KERN_DEFAULT.("done (allocated %lu pages)\n", pages)
1840  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.
1842  Return 0
1844  err_out :
1845  Like KERN_CONT, pr_cont() should only be used when continuing* a line with no newline ('\n') enclosed. Otherwise it defaults* back to KERN_DEFAULT.("\n")
1846  swsusp_free - Free pages allocated for hibernation image.* Image pages are alocated before snapshot creation, so they need to be* released after resume.
1847  Return -ENOMEM
Caller
NameDescribe
hibernation_snapshothibernation_snapshot - Quiesce devices and create a hibernation image.*@platform_mode: If set, use platform driver to prepare for the transition.* This routine must be called with system_transition_mutex held.