Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:z3fold_alloc() - allocates a region of a given size*@pool: z3fold pool from which to allocate*@size: size in bytes of the desired allocation*@gfp: gfp flags used if the pool needs to grow*@handle: handle of the new allocation* This function will attempt

Proto:static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, unsigned long *handle)

Type:int

Parameter:

TypeParameterName
struct z3fold_pool *pool
size_tsize
gfp_tgfp
unsigned long *handle
1092  chunks = Converts an allocation size in bytes to size in z3fold chunks
1093  struct z3fold_header * zhdr = NULL
1094  struct page * page = NULL
1096  can_sleep = gfpflags_allow_blocking(gfp)
1098  If Not size Then Return -EINVAL
1101  If size > PAGE_SIZE Then Return -ENOSPC
1104  If size > PAGE_SIZE - ZHDR_SIZE_ALIGNED - CHUNK_SIZE Then bud = HEADLESS
1106  Else
1107  retry :
1108  zhdr = rns _locked_ z3fold page header or NULL
1109  If zhdr Then
1110  If first_chunks == 0 Then
1111  If middle_chunks != 0 && chunks >= start_middle Then bud = LAST
1114  Else bud = FIRST
1116  Else if last_chunks == 0 Then bud = LAST
1118  Else if middle_chunks == 0 Then bud = MIDDLE
1120  Else
1131  Go to found
1133  bud = FIRST
1136  page = NULL
1137  If can_sleep Then
1138  spin_lock( & stale_lock)
1139  zhdr = list_first_entry_or_null - get the first element from a list*@ptr: the list head to take the element from.*@type: the type of the struct this is embedded in.*@member: the name of the list_head within the struct.( & stale, structz3fold_header, buddy)
1146  If zhdr Then
1148  spin_unlock( & stale_lock)
1151  Else
1152  spin_unlock( & stale_lock)
1155  If Not page Then page = alloc_page(gfp)
1158  If Not page Then Return -ENOMEM
1161  zhdr = Initializes the z3fold header of a newly allocated z3fold page
1162  If Not zhdr Then
1163  __free_page(page)
1164  Return -ENOMEM
1166  atomic64_inc( & pages_nr)
1168  If bud == HEADLESS Then
1169  Atomically set a bit in memory
1170  Go to headless
1172  If can_sleep Then
1173  lock_page may only be called if we have the page's inode pinned.
1174  __SetPageMovable(page, i_mapping)
1175  lock_page - unlock a locked page*@page: the page* Unlocks the page and wakes up sleepers in ___wait_on_page_locked().* Also wakes sleepers in wait_on_page_writeback() because the wakeup* mechanism between PageLocked pages and PageWriteback pages is shared.
1176  Else
1182  Lock a z3fold page
1184  found :
1185  If bud == FIRST Then first_chunks = chunks
1187  Else if bud == LAST Then last_chunks = chunks
1189  Else
1190  middle_chunks = chunks
1191  start_middle = first_chunks + ZHDR_CHUNKS
1193  Add to the appropriate unbuddied list
1195  headless :
1196  spin_lock( & lock)
1198  If Not list_empty - tests whether a list is empty*@head: the list to test. Then deletes entry from list
1201  list_add - add a new entry*@new: new entry to be added*@head: list head to add it after* Insert a new entry after the specified head.* This is good for implementing stacks.
1203  handle = encode_handle(zhdr, bud)
1204  spin_unlock( & lock)
1205  If bud != HEADLESS Then Unlock a z3fold page
1208  Return 0
Caller
NameDescribe
z3fold_zpool_malloc