函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:mm\percpu.c Create Date:2022-07-27 15:51:47
Last Modify:2022-05-23 13:52:24 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:pcpu_alloc - the percpu allocator*@size: size of area to allocate in bytes*@align: alignment of area (max PAGE_SIZE)*@reserved: allocate from the reserved chunk if available*@gfp: allocation flags* Allocate percpu area of @size bytes aligned at @align

函数原型:static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, gfp_t gfp)

返回类型:void

参数:

类型参数名称
size_tsize
size_talign
boolreserved
gfp_tgfp
1590  pcpu_gfp等于gfp按位与GFP_KERNEL按位或__GFP_NORETRY按位或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.的值
1591  is_atomic等于gfp按位与GFP_KERNEL的值不等于GFP_KERNEL
1592  do_warn等于非gfp按位与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.的值
1593  warn_limit等于10
1598  __percpuptr
1607  如果此条件成立可能性小(为编译器优化)(align < PCPU_MIN_ALLOC_SIZE)则align等于PCPU_MIN_ALLOC_SIZE
1610  size等于@a is a power of 2 value (size, PCPU_MIN_ALLOC_SIZE)
1611  bits等于size右移minimum allocation size and shift in bytes
1612  bit_align等于align右移minimum allocation size and shift in bytes
1614  如果此条件成立可能性小(为编译器优化)(!size || size > minimum unit size, also is the maximum supported allocation size || align > PAGE_SIZE || !s_power_of_2() - check if a value is a power of two*@n: the value to check* Determine whether some value is a power of two, where zero is* *not* considered a power of two.* Return: true if @n is a power of 2, otherwise false.)则
1616  WARN(do_warn, "illegal size (%zu) or align (%zu) for percpu allocation\n", size, align)
1618  返回:NULL
1621  如果非is_atomic
1627  如果gfp按位与__GFP_NOFAILmutex_lock( & pcpu_alloc_mutex)
1629  否则如果mutex_lock_killable( & pcpu_alloc_mutex)则返回:NULL
1633  spin_lock_irqsave( & pcpu_lock, flags)
1636  如果reservedOptional reserved chunk. This chunk reserves part of the first* chunk and serves it for reserved allocations. When the reserved* region doesn't exist, the following variable is NULL.
1637  chunk等于Optional reserved chunk. This chunk reserves part of the first* chunk and serves it for reserved allocations. When the reserved* region doesn't exist, the following variable is NULL.
1639  off等于pcpu_find_block_fit - finds the block index to start searching*@chunk: chunk of interest*@alloc_bits: size of request in allocation units*@align: alignment of area (max PAGE_SIZE bytes)*@pop_only: use populated regions only* Given a chunk and an
1640  如果off小于0则
1641  err等于"alloc from reserved chunk failed"
1642  转到:fail_unlock
1645  off等于pcpu_alloc_area - allocates an area from a pcpu_chunk*@chunk: chunk of interest*@alloc_bits: size of request in allocation units*@align: alignment of area (max PAGE_SIZE)*@start: bit_off to start searching* This function takes in a @start offset to begin
1646  如果off大于等于0则转到:area_found
1649  err等于"alloc from reserved chunk failed"
1650  转到:fail_unlock
1653  restart :
1655 slot小于pcpu_nr_slots循环
1657  off等于pcpu_find_block_fit - finds the block index to start searching*@chunk: chunk of interest*@alloc_bits: size of request in allocation units*@align: alignment of area (max PAGE_SIZE bytes)*@pop_only: use populated regions only* Given a chunk and an
1659  如果off小于0则
1662  继续下一循环
1665  off等于pcpu_alloc_area - allocates an area from a pcpu_chunk*@chunk: chunk of interest*@alloc_bits: size of request in allocation units*@align: alignment of area (max PAGE_SIZE)*@start: bit_off to start searching* This function takes in a @start offset to begin
1666  如果off大于等于0则转到:area_found
1672  spin_unlock_irqrestore( & pcpu_lock, flags)
1679  如果is_atomic
1680  err等于"atomic alloc failed, no space left"
1681  转到:fail
1684  如果链表为空
1685  chunk等于pcpu_create_chunk(pcpu_gfp)
1686  如果非chunk
1687  err等于"failed to allocate new chunk"
1688  转到:fail
1691  spin_lock_irqsave( & pcpu_lock, flags)
1692  pcpu_chunk_relocate - put chunk in the appropriate chunk slot*@chunk: chunk of interest*@oslot: the previous slot it was on* This function is called after an allocation or free changed @chunk
1693  否则
1694  spin_lock_irqsave( & pcpu_lock, flags)
1697  转到:restart
1699  area_found :
1700  pcpu_stats_area_alloc(chunk, size)
1701  spin_unlock_irqrestore( & pcpu_lock, flags)
1704  如果非is_atomic
1707  page_start等于PFN_DOWN(off)
1708  page_end等于PFN_UP(off + size)
1712  WARN_ON( no [de]population allowed )
1714  ret等于pcpu_populate_chunk - populate and map an area of a pcpu_chunk*@chunk: chunk of interest*@page_start: the start page*@page_end: the end page*@gfp: allocation flags passed to the underlying memory allocator* For each cpu, populate and map pages
1716  spin_lock_irqsave( & pcpu_lock, flags)
1717  如果ret
1719  err等于"failed to populate"
1720  转到:fail_unlock
1722  pcpu_chunk_populated - post-population bookkeeping*@chunk: pcpu_chunk which got populated*@page_start: the start page*@page_end: the end page* Pages in [@page_start,@page_end) have been populated to @chunk. Update* the bookkeeping information accordingly
1723  spin_unlock_irqrestore( & pcpu_lock, flags)
1726  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.
1729  如果The number of empty populated pages, protected by pcpu_lock. The* reserved chunk doesn't contribute to the count.小于PCPU_EMPTY_POP_PAGES_LOWpcpu_schedule_balance_work()
1733  遍历可用CPU(cpu)
1734  memset((void * )pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size)
1736  ptr等于 UP, it's always identity mapped ( base address of this chunk + off)
1737  kmemleak_alloc_percpu(ptr, size, gfp)
1739  trace_percpu_alloc_percpu(reserved, is_atomic, size, align, base address of this chunk , off, ptr)
1742  返回:ptr
1744  fail_unlock :
1745  spin_unlock_irqrestore( & pcpu_lock, flags)
1746  fail :
1747  trace_percpu_alloc_percpu_fail(reserved, is_atomic, size, align)
1749  如果非is_atomicdo_warnwarn_limit
1750  打印警告信息("allocation failed, size=%zu align=%zu atomic=%d, %s\n", size, align, is_atomic, err)
1752  dump_stack()
1753  如果非warn_limit先自减则打印信息("limit reached, disable warning\n")
1756  如果is_atomic
1758  pcpu_atomic_alloc_failed = true
1759  pcpu_schedule_balance_work()
1760  否则
1761  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.
1763  返回:NULL
调用者
名称描述
__alloc_percpu_gfp__alloc_percpu_gfp - allocate dynamic percpu area*@size: size of area to allocate in bytes*@align: alignment of area (max PAGE_SIZE)*@gfp: allocation flags* Allocate zero-filled percpu area of @size bytes aligned at @align
__alloc_percpu__alloc_percpu - allocate dynamic percpu area*@size: size of area to allocate in bytes*@align: alignment of area (max PAGE_SIZE)* Equivalent to __alloc_percpu_gfp(size, align, %GFP_KERNEL).
__alloc_reserved_percpu__alloc_reserved_percpu - allocate reserved percpu area*@size: size of area to allocate in bytes*@align: alignment of area (max PAGE_SIZE)* Allocate zero-filled percpu area of @size bytes aligned at @align* from reserved percpu area if arch has set it up;