Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:lc_create - prepares to track objects in an active set*@name: descriptive name only used in lc_seq_printf_stats and lc_seq_dump_details*@max_pending_changes: maximum changes to accumulate until a transaction is required*@e_count: number of elements

Proto:struct lru_cache *lc_create(const char *name, struct kmem_cache *cache, unsigned max_pending_changes, unsigned e_count, size_t e_size, size_t e_off)

Type:struct lru_cache

Parameter:

TypeParameterName
const char *name
struct kmem_cache *cache
unsignedmax_pending_changes
unsignede_count
size_te_size
size_te_off
91  struct hlist_head * slot = NULL
92  struct lc_element * * element = NULL
95  cache_obj_size = kmem_cache_size(cache)
98  WARN_ON(cache_obj_size < e_size)
99  If cache_obj_size < e_size Then Return NULL
104  If e_count > Arbitrary limit on maximum tracked objects. Practical limit is much* lower due to allocation failures, probably. For typical use cases,* nr_elements should be a few thousand at most.* This also limits the maximum value of lc_element.lc_index, allowing the Then Return NULL
107  slot = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc).
108  If Not slot Then Go to out_fail
110  element = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc).
111  If Not element Then Go to out_fail
114  lc = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
115  If Not lc Then Go to out_fail
118  Initialization list head
119  Initialization list head
120  Initialization list head
121  Initialization list head
123  name = name
124  size of tracked objects, used to memset(,0,) them in lc_reset = e_size
125  offset of struct lc_element member in the tracked object = e_off
126  number of elements (indices) = e_count
127  allow to accumulate a few (index:label) changes, * but no more than max_pending_changes = max_pending_changes
128  the pre-created kmem cache to allocate the objects from = cache
129  lc_element = element
130  nr_elements there = slot
133  When i < e_count cycle
134  p = kmem_cache_alloc(cache, GFP_KERNEL)
135  If Not p Then Break
137  memset(p, 0, size of tracked objects, used to memset(,0,) them in lc_reset )
138  e = p + e_off
139  ack "pointer" into lc_cache->element[index],* for paranoia, and for "lc_element_to_index" = i
140  we want to track a larger set of objects,* it needs to become arch independend u64 = special label when on free list
141  r pending changes = special label when on free list
142  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.
143  element[i] = e
145  If i == e_count Then Return lc
149  When i cycle
150  p = element[i]
151  kmem_cache_free(cache, p - e_off)
153  kfree(lc)
154  out_fail :
155  kfree(element)
156  kfree(slot)
157  Return NULL