Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\hashtab.c Create Date:2022-07-28 13:09:23
Last Modify:2022-05-23 09:15:29 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:htab_map_alloc

Proto:static struct bpf_map *htab_map_alloc(union bpf_attr *attr)

Type:struct bpf_map

Parameter:

TypeParameterName
union bpf_attr *attr
297  percpu = one of enum bpf_map_type == BPF_MAP_TYPE_PERCPU_HASH || one of enum bpf_map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH
299  lru = one of enum bpf_map_type == BPF_MAP_TYPE_LRU_HASH || one of enum bpf_map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH
306  percpu_lru = BPF_MAP_CREATE related * flags defined above. & Instead of having one common LRU list in the* BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list* which can scale and perform better.* Note, the LRU nodes (including free nodes) cannot be moved* across different LRU lists.
307  prealloc = Not ( BPF_MAP_CREATE related * flags defined above. & lags for BPF_MAP_CREATE command )
312  htab = 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).
313  If Not htab Then Return ERR_PTR( - ENOMEM)
316  bpf_map_init_from_attr( & map, attr)
318  If percpu_lru Then
323  max_entries = undup - round up to the next specified multiple*@x: the value to up*@y: multiple to round up to* Rounds @x up to next multiple of @y. If @y will always be a power* of 2, consider using the faster round_up().( max number of entries in a map , num_possible_cpus())
325  If max_entries < max number of entries in a map Then max_entries = unddown - round down to next specified multiple*@x: the value to round*@y: multiple to round down to* Rounds @x down to next multiple of @y. If @y will always be a power* of 2, consider using the faster round_down().( max number of entries in a map , num_possible_cpus())
331  number of hash buckets = undup_pow_of_two - round the given value up to nearest power of two*@n: parameter* round the given value up to the nearest power of two* - the result is undefined when n == 0* - this can be used to initialise global variables from constant data(max_entries)
333  size of each element in bytes = sizeof(structhtab_elem) + und_up - round up to next specified power of 2*@x: the value to round*@y: multiple to round up to (must be a power of 2)* Rounds @x up to next multiple of @y (which must be a power of 2).* To perform arbitrary rounding up, use roundup() below.(key_size, 8)
335  If percpu Then size of each element in bytes += size of *
337  Else size of each element in bytes += und_up - round up to next specified power of 2*@x: the value to round*@y: multiple to round up to (must be a power of 2)* Rounds @x up to next multiple of @y (which must be a power of 2).* To perform arbitrary rounding up, use roundup() below.(value_size, 8)
340  err = -E2BIG
342  If number of hash buckets == 0 || number of hash buckets > U32_MAX / sizeof(structbucket) Then Go to free_htab
346  cost = number of hash buckets * sizeof(structbucket) + size of each element in bytes * max_entries
349  If percpu Then cost += und_up - round up to next specified power of 2*@x: the value to round*@y: multiple to round up to (must be a power of 2)* Rounds @x up to next multiple of @y (which must be a power of 2).* To perform arbitrary rounding up, use roundup() below.(value_size, 8) * num_possible_cpus() * max_entries
352  Else cost += size of each element in bytes * num_possible_cpus()
356  err = bpf_map_charge_init( & memory, cost)
357  If err Then Go to free_htab
360  err = -ENOMEM
361  buckets = bpf_map_area_alloc( number of hash buckets * sizeof(structbucket), numa_node)
364  If Not buckets Then Go to free_charge
367  If map_flags & Zero-initialize hash function seed. This should only be used for testing. Then hashrnd = 0
369  Else hashrnd = get_random_int()
372  When i < number of hash buckets cycle
373  INIT_HLIST_NULLS_HEAD( & head, i)
374  raw_spin_lock_init( & lock)
377  If prealloc Then
378  err = prealloc_init(htab)
379  If err Then Go to free_buckets
382  If Not percpu && Not lru Then
387  If err Then Go to free_prealloc
392  Return map
394  free_prealloc :
395  prealloc_destroy(htab)
396  free_buckets :
397  bpf_map_area_free(buckets)
398  free_charge :
399  bpf_map_charge_finish( & memory)
400  free_htab :
401  kfree(htab)
402  Return ERR_PTR(err)
Caller
NameDescribe
htab_of_map_alloc