Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:Handle insertion into a terminal node.

Proto:static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, const struct assoc_array_ops *ops, const void *index_key, struct assoc_array_walk_result *result)

Type:bool

Parameter:

TypeParameterName
struct assoc_array_edit *edit
const struct assoc_array_ops *ops
const void *index_key
struct assoc_array_walk_result *result
488  node = Node in which leaf might be found
489  level = level
490  segment_cache[Number of slots per node ] = slot
492  pr_devel("-->%s()\n", __func__)
499  free_slot = -1
504  When i < Number of slots per node cycle
505  ptr = slots[i]
506  If Not ptr Then
507  free_slot = i
508  Continue
513  pr_devel("replace in slot %d\n", i)
514  leaf_p = slots[i]
515  dead_leaf = slots[i]
516  pr_devel("<--%s() = ok [replace]\n", __func__)
517  Return true
524  If free_slot >= 0 Then
525  pr_devel("insert in free slot %d\n", free_slot)
526  leaf_p = slots[free_slot]
527  adjust_count_on = node
528  pr_devel("<--%s() = ok [insert]\n", __func__)
529  Return true
539  new_n0 = 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).
540  If Not new_n0 Then Return false
542  new_meta[0] = assoc_array_node_to_ptr(new_n0)
543  new_n1 = 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).
544  If Not new_n1 Then Return false
546  new_meta[1] = assoc_array_node_to_ptr(new_n1)
549  pr_devel("no spare slots\n")
550  have_meta = false
551  When i < Number of slots per node cycle
552  ptr = slots[i]
553  If assoc_array_ptr_is_meta(ptr) Then
554  segment_cache[i] = 0xff
555  have_meta = true
556  Continue
558  base_seg = get_object_key_chunk(assoc_array_ptr_to_leaf(ptr), level)
560  base_seg >>= level & ASSOC_ARRAY_KEY_CHUNK_MASK
561  segment_cache[i] = base_seg & ASSOC_ARRAY_FAN_MASK
564  If have_meta Then
565  pr_devel("have meta\n")
566  Go to split_node
570  dissimilarity = 0
571  base_seg = segment_cache[0]
572  When i < Number of slots per node cycle dissimilarity |= segment_cache[i] ^ base_seg
575  pr_devel("only leaves; dissimilarity=%lx\n", dissimilarity)
577  If (dissimilarity & ASSOC_ARRAY_FAN_MASK) == 0 Then
581  If (segment_cache[Number of slots per node ] ^ base_seg) == 0 Then Go to all_leaves_cluster_together
592  pr_devel("present leaves cluster but not new leaf\n")
595  split_node :
596  pr_devel("split node\n")
613  to = assoc_array_node_to_ptr(new_n0)
614  back_pointer = back_pointer
615  parent_slot = parent_slot
616  back_pointer = assoc_array_node_to_ptr(new_n0)
617  parent_slot = -1
619  do_split_node :
620  pr_devel("do_split_node\n")
622  nr_leaves_on_branch = nr_leaves_on_branch
623  nr_leaves_on_branch = 0
631  When i < Number of slots per node cycle
632  slot = segment_cache[i]
633  If slot != 0xff Then When j < Number of slots per node + 1 cycle
635  If segment_cache[j] == slot Then Go to found_slot_for_multiple_occupancy
638  found_slot_for_multiple_occupancy :
639  pr_devel("same slot: %x %x [%02x]\n", i, j, slot)
640  BUG_ON(i >= Number of slots per node )
641  BUG_ON(j >= Number of slots per node + 1)
642  BUG_ON(slot >= Number of slots per node )
644  parent_slot = slot
647  When i < Number of slots per node cycle If assoc_array_ptr_is_meta(slots[i]) Then
649  slots[i] = slots[i]
650  Else slots[i] = NULL
652  BUG_ON(slots[slot] != NULL)
653  slots[slot] = assoc_array_node_to_ptr(new_n1)
656  free_slot = -1
657  next_slot = 0
658  When i < Number of slots per node cycle
659  If assoc_array_ptr_is_meta(slots[i]) Then Continue
661  If segment_cache[i] == slot Then
662  slots[next_slot++] = slots[i]
664  Else
665  Do
666  free_slot++
667  When (slots[free_slot] != NULL) cycle
668  slots[free_slot] = slots[i]
672  pr_devel("filtered: f=%x n=%x\n", free_slot, next_slot)
674  If segment_cache[Number of slots per node ] != slot Then
675  Do
676  free_slot++
677  When (slots[free_slot] != NULL) cycle
678  leaf_p = slots[free_slot]
679  adjust_count_on = new_n0
680  Else
681  leaf_p = slots[next_slot++]
682  adjust_count_on = new_n1
685  BUG_ON(next_slot <= 1)
687  set_backpointers_to = assoc_array_node_to_ptr(new_n0)
688  When i < Number of slots per node cycle
689  If segment_cache[i] == 0xff Then
690  ptr = slots[i]
692  If assoc_array_ptr_is_node(ptr) Then
695  Else
702  ptr = back_pointer
703  If Not ptr Then ptr = The node at the root of the tree
705  Else if assoc_array_ptr_is_node(ptr) Then ptr = slots[parent_slot]
707  Else ptr = next_node
709  excised_meta[0] = assoc_array_node_to_ptr(node)
710  pr_devel("<--%s() = ok [split node]\n", __func__)
711  Return true
713  all_leaves_cluster_together :
728  pr_devel("all leaves cluster together\n")
729  diff = INT_MAX
730  When i < Number of slots per node cycle
731  x = diff_objects(assoc_array_ptr_to_leaf(slots[i]), index_key)
733  If x < diff Then
734  BUG_ON(x < 0)
735  diff = x
738  BUG_ON(diff == INT_MAX)
739  BUG_ON(diff < level + ASSOC_ARRAY_LEVEL_STEP)
741  keylen = 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.(diff, Key data retrieved in chunks of this size )
742  keylen >>= ASSOC_ARRAY_KEY_CHUNK_SHIFT
744  new_s0 = 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).
746  If Not new_s0 Then Return false
748  new_meta[2] = assoc_array_shortcut_to_ptr(new_s0)
750  to = assoc_array_shortcut_to_ptr(new_s0)
751  back_pointer = back_pointer
752  parent_slot = parent_slot
753  next_node = assoc_array_node_to_ptr(new_n0)
754  back_pointer = assoc_array_shortcut_to_ptr(new_s0)
755  parent_slot = 0
756  back_pointer = assoc_array_node_to_ptr(new_n0)
757  parent_slot = -1
759  skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK
760  pr_devel("skip_to_level = %d [diff %d]\n", level, diff)
761  BUG_ON(level <= 0)
763  When i < keylen cycle index_key[i] = get_key_chunk(index_key, i * Key data retrieved in chunks of this size )
767  If level & ASSOC_ARRAY_KEY_CHUNK_MASK Then
768  blank = ULONG_MAX << (level & ASSOC_ARRAY_KEY_CHUNK_MASK)
769  pr_devel("blank off [%zu] %d: %lx\n", keylen - 1, level, blank)
770  index_key[keylen - 1] &= ~blank
776  When i < Number of slots per node cycle
777  ptr = slots[i]
778  base_seg = get_object_key_chunk(assoc_array_ptr_to_leaf(ptr), level)
780  base_seg >>= level & ASSOC_ARRAY_KEY_CHUNK_MASK
781  segment_cache[i] = base_seg & ASSOC_ARRAY_FAN_MASK
784  base_seg = get_key_chunk(index_key, level)
785  base_seg >>= level & ASSOC_ARRAY_KEY_CHUNK_MASK
786  segment_cache[Number of slots per node ] = base_seg & ASSOC_ARRAY_FAN_MASK
787  Go to do_split_node
Caller
NameDescribe
assoc_array_insertassoc_array_insert - Script insertion of an object into an associative array*@array: The array to insert into