]> www.infradead.org Git - users/jedix/linux-maple.git/log
users/jedix/linux-maple.git
4 years agowip: spanning store & signed full_cnt
Liam R. Howlett [Fri, 12 Jun 2020 14:57:22 +0000 (10:57 -0400)]
wip: spanning store & signed full_cnt

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, start passing big data through for all stores
Liam R. Howlett [Thu, 11 Jun 2020 01:13:38 +0000 (21:13 -0400)]
maple_tree: WIP, start passing big data through for all stores

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, diet
Liam R. Howlett [Tue, 9 Jun 2020 20:23:21 +0000 (16:23 -0400)]
maple_tree: WIP, diet

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, partial spanning store code.
Liam R. Howlett [Tue, 9 Jun 2020 20:11:57 +0000 (16:11 -0400)]
maple_tree: WIP, partial spanning store code.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: 3 wip
Liam R. Howlett [Tue, 2 Jun 2020 20:15:28 +0000 (16:15 -0400)]
maple_tree: 3 wip

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agowip, broken and abandoning this plan for no retry
Liam R. Howlett [Wed, 20 May 2020 22:28:28 +0000 (18:28 -0400)]
wip, broken and abandoning this plan for no retry

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Remove mt_is_advanced in favor of xa_is_advanced.
Liam R. Howlett [Wed, 20 May 2020 17:22:16 +0000 (13:22 -0400)]
maple_tree: Remove mt_is_advanced in favor of xa_is_advanced.

The two functions are now the same so just use the xa_ version.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agoxarray: Change range of xa_is_advanced
Liam R. Howlett [Wed, 20 May 2020 17:14:47 +0000 (13:14 -0400)]
xarray: Change range of xa_is_advanced

XA_ZERO_ENTRY is the is largest advanced internal entry.
Return true if an internal entry is less than the XA_ZERO_ENTRY.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix gap issues and combining issue
Liam R. Howlett [Tue, 19 May 2020 18:57:46 +0000 (14:57 -0400)]
maple_tree: Fix gap issues and combining issue

Incorrect gap calculation caused by mas_prev not setting the ma_state
limits correctly.

Gap relocation failed due to fully empty node (deleted)

Gap relocation issues when hitting a retry entry

Missing data due to combining nodes incorrectly when the right node has
a retry at the start.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree and mm/mmap: Try to stop tracepoints on BUG_ON
Liam R. Howlett [Sat, 9 May 2020 01:02:27 +0000 (21:02 -0400)]
maple_tree and mm/mmap: Try to stop tracepoints on BUG_ON

Restore printk's until we know it happens.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotrace/events/mm_mt.h: Fix prototype for __vma_mt_szero
Liam R. Howlett [Fri, 8 May 2020 15:29:55 +0000 (11:29 -0400)]
trace/events/mm_mt.h: Fix prototype for __vma_mt_szero

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotrace/events/mm_mt: Add maple tree mm tracepoints.
Liam R. Howlett [Fri, 8 May 2020 14:14:25 +0000 (10:14 -0400)]
trace/events/mm_mt: Add maple tree mm tracepoints.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotrace/events/mm rename to mm_mt
Liam R. Howlett [Fri, 8 May 2020 13:29:45 +0000 (09:29 -0400)]
trace/events/mm rename to mm_mt

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Fix unmapped_area_topdown with align_offset
Liam R. Howlett [Fri, 8 May 2020 02:12:58 +0000 (22:12 -0400)]
mm/mmap: Fix unmapped_area_topdown with align_offset

align_offset should be aligned to align_mask.. apparently.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Move maple tree logging to tracepoints
Liam R. Howlett [Thu, 7 May 2020 21:59:51 +0000 (17:59 -0400)]
mm/mmap: Move maple tree logging to tracepoints

Able to toggle at runtime? Count me in.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Fix maple tree calculation for topdown with alignment mask.
Liam R. Howlett [Thu, 7 May 2020 20:07:49 +0000 (16:07 -0400)]
mm/mmap: Fix maple tree calculation for topdown with alignment mask.

When using alignment mask, calculate the address correctly.

Found by LTP futex_wake04

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Add test for reverse search with mask.
Liam R. Howlett [Thu, 7 May 2020 20:07:17 +0000 (16:07 -0400)]
maple_tree: Add test for reverse search with mask.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Add call to maple_destroy
Liam R. Howlett [Thu, 7 May 2020 01:13:43 +0000 (21:13 -0400)]
mm/mmap: Add call to maple_destroy

When tearing down a vma, destroy the maple tree as well.

Also clean up some old print debugs.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_append of extra null.
Liam R. Howlett [Thu, 7 May 2020 01:12:28 +0000 (21:12 -0400)]
maple_tree: Fix mas_append of extra null.

When attempting to append to a node, it is possible that the source
contains multiple NULL entries that will be coalesced together and thus
will not overflow even though it may appear that was on initial
inspection.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Skip multiple deletes in split calculation.
Liam R. Howlett [Wed, 6 May 2020 18:04:47 +0000 (14:04 -0400)]
maple_tree: Skip multiple deletes in split calculation.

When splitting, do not split within consecutive NULL entries.  Doing so
would cause separated gaps.

Also reset mas->node before walking in two other places which could
potentially cause issue.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Reset mas location before walking in mas_rebalance_gaps.
Liam R. Howlett [Wed, 6 May 2020 03:17:52 +0000 (23:17 -0400)]
maple_tree: Reset mas location before walking in mas_rebalance_gaps.

After rebalancing, the mas node may not be in the correct location to
find the mas->index, so reset to MAS_START prior to starting the walk.

Added test case for this issue as well.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Move VM_BUG_ON inside other check for maple tree
Liam R. Howlett [Wed, 6 May 2020 01:18:56 +0000 (21:18 -0400)]
mm/mmap: Move VM_BUG_ON inside other check for maple tree

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix skip entries on spanning adds and issue in split data
Liam R. Howlett [Wed, 6 May 2020 01:15:23 +0000 (21:15 -0400)]
maple_tree: Fix skip entries on spanning adds and issue in split data

When spanning adds hit a skip entry, they were not updated and thus
future events may use the incorrect minimum from the previous
not-updated pivot.  Fix these pivots when writing spanning adds.

There was also an issue with using the incorrect ranges in the split
code path in mas_append_split_data() which could cause data to be
skipped.  This is now fixed and there are testcases to test for the
discovered event.

The spanning add issue was tested with set25 in check_erase2_testset.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix off-by-one error on mas->min when calling mas_prev.
Liam R. Howlett [Wed, 29 Apr 2020 19:04:29 +0000 (15:04 -0400)]
maple_tree: Fix off-by-one error on mas->min when calling mas_prev.

When using a non-zero slot, the mas->min was set incorrectly for
mas_prev causing the gap calculation to be off-by-one and verification
to fail.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotest_maple_tree: Add test which discovered the retry limit issues.
Liam R. Howlett [Tue, 21 Apr 2020 19:53:27 +0000 (15:53 -0400)]
test_maple_tree: Add test which discovered the retry limit issues.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix gap on skip entries caused by relocated data.
Liam R. Howlett [Tue, 21 Apr 2020 19:52:31 +0000 (15:52 -0400)]
maple_tree: Fix gap on skip entries caused by relocated data.

The gap should be zero for skip entries.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix overrunning end of node into RETRY entries.
Liam R. Howlett [Tue, 21 Apr 2020 19:50:51 +0000 (15:50 -0400)]
maple_tree: Fix overrunning end of node into RETRY entries.

When entries are moved and replaced with a RETRY, the node will end
prior to hitting a 0 pivot or the end of the node.  Fix this scenario by
detecting the pivot > mas->max and handle these cases correctly.

This also fixes the validation code to avoid checking the range on RETRY
entries.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix limits check with retry entries
Liam R. Howlett [Fri, 17 Apr 2020 19:19:47 +0000 (15:19 -0400)]
maple_tree: Fix limits check with retry entries

When entries are relocated, the retry entry may not fall within the
limits of this node as it has been relocated to the next node.

Also, add define U8_MAX UCHAR_MAX in test code.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotest_maple_tree: Don't count retry entries during entry counting.
Liam R. Howlett [Fri, 6 Mar 2020 18:59:43 +0000 (13:59 -0500)]
test_maple_tree: Don't count retry entries during entry counting.

retries are skipped, so don't count them so the test framework will come
up with the correct count.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Support freeing empty nodes on gap relocation.
Liam R. Howlett [Fri, 6 Mar 2020 18:45:54 +0000 (13:45 -0500)]
maple_tree: Support freeing empty nodes on gap relocation.

When a gap is created during a low memory situation, coalesce may not be
able to group the gap together.  This can be handled by moving the right
node to the left & using a SKIP entry.  Note that this situation should
not arise unless in a low-memory situation, so a SKIP entry is useful as
it indicates the tree may need to be rebuilt after memory pressure
subsides.

When an empty node is found,

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Zero pivots of gaps that have been moved.
Liam R. Howlett [Wed, 4 Mar 2020 17:00:33 +0000 (12:00 -0500)]
maple_tree: Zero pivots of gaps that have been moved.

This doesn't seem totally correct and should really use a new node.
A solution for low mem is needed too.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Combine gaps with retry entries.
Liam R. Howlett [Tue, 3 Mar 2020 17:03:47 +0000 (12:03 -0500)]
maple_tree: Combine gaps with retry entries.

When a retry entry is hit, combine it into the gap as it was relocated
to where the gap exists now.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Clean up mas_data_end interface.
Liam R. Howlett [Tue, 3 Mar 2020 13:19:30 +0000 (08:19 -0500)]
maple_tree: Clean up mas_data_end interface.

Some places don't care about coalesce and the last pivot, so provide a
cleaner way to get just the end to clean up that code.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: whitespace fix.
Liam R. Howlett [Tue, 3 Mar 2020 13:18:51 +0000 (08:18 -0500)]
maple_tree: whitespace fix.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix rcu_dereference usages
Matthew Wilcox (Oracle) [Mon, 2 Mar 2020 21:16:00 +0000 (16:16 -0500)]
maple_tree: Fix rcu_dereference usages

Enabling CONFIG_PROVE_LOCKING reveals some compilation errors and
running it shows that loading the root pointer needs to be done with
rcu_dereference_protected() (which will permit the load if the lock is
held) instead of a plain rcu_dereference() (which permits the load if
the rcu read lock is held).

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomaple_tree: no need to rcu_dereference in mtree_empty()
Matthew Wilcox (Oracle) [Mon, 2 Mar 2020 21:09:00 +0000 (16:09 -0500)]
maple_tree: no need to rcu_dereference in mtree_empty()

Since we're only comparing the value of the pointer to NULL, we
don't need to use rcu_dereference().  This is explicitly documented
in Documentation/RCU/rcu_dereference.rst.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomm: Fix compilation warnings
Matthew Wilcox (Oracle) [Mon, 2 Mar 2020 21:24:19 +0000 (16:24 -0500)]
mm: Fix compilation warnings

Nothing terribly interesting here.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomaple_tree: Fix lock_dep calls to use pointers.
Liam R. Howlett [Tue, 3 Mar 2020 03:33:28 +0000 (22:33 -0500)]
maple_tree: Fix lock_dep calls to use pointers.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Move variable declaring prior to code.
Liam R. Howlett [Tue, 3 Mar 2020 03:32:23 +0000 (22:32 -0500)]
mm/mmap: Move variable declaring prior to code.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix overwritten slot in mas during __mas_add
Liam R. Howlett [Tue, 3 Mar 2020 03:21:37 +0000 (22:21 -0500)]
maple_tree: Fix overwritten slot in mas during __mas_add

Overwriting the slot in the ma state caused issues later on.  Restore
the value and fix the code in mas_may_move_gap to also detect such
scenarios.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Small code cleanup, white spaces etc.
Liam R. Howlett [Mon, 2 Mar 2020 19:54:06 +0000 (14:54 -0500)]
maple_tree: Small code cleanup, white spaces etc.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agoMAINTAINERS: Add maple tree
Liam R. Howlett [Mon, 2 Mar 2020 18:45:42 +0000 (13:45 -0500)]
MAINTAINERS: Add maple tree

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Add support for combining gaps.
Liam R. Howlett [Mon, 2 Mar 2020 18:31:17 +0000 (13:31 -0500)]
maple_tree: Add support for combining gaps.

When gaps touch but are not in the same node, move them to the right
node.  This allows for searches to find the desired gap.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agoextra debug
Matthew Wilcox (Oracle) [Fri, 28 Feb 2020 20:46:27 +0000 (15:46 -0500)]
extra debug

4 years agomaple_tree: Fix RCU reads to use rcu_dereference_check and writes to use
Liam R. Howlett [Mon, 2 Mar 2020 16:22:53 +0000 (11:22 -0500)]
maple_tree: Fix RCU reads to use rcu_dereference_check and writes to use
rcu_assign_pointer

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix placement of data during add operation during certain
Liam R. Howlett [Mon, 2 Mar 2020 15:43:00 +0000 (10:43 -0500)]
maple_tree: Fix placement of data during add operation during certain
conditions.

When partially overwriting the sources end slot and coalescing data
during the copy operation, there was a potential for an overflow during
a store operation.  Avoid the overflow by using the new node end instead
of the slot passed in as the destination.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm: Get rid of maple tree whitespace changes
Matthew Wilcox (Oracle) [Thu, 27 Feb 2020 19:57:32 +0000 (14:57 -0500)]
mm: Get rid of maple tree whitespace changes

Nothing here makes any difference to the generated code.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomaple_tree: Clean up debug infrastructure
Matthew Wilcox (Oracle) [Thu, 27 Feb 2020 15:47:07 +0000 (10:47 -0500)]
maple_tree: Clean up debug infrastructure

making tests_run & tests_passed static means there's one copy of them in
every file that includes maple_tree.h.  Make them extern, prefix them
with maple_tree_, move them to maple_tree.c and export them so that
test_maple_tree can be built as a module.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomaple_tree: Move xa_get_alloc_size
Matthew Wilcox (Oracle) [Thu, 27 Feb 2020 15:16:09 +0000 (10:16 -0500)]
maple_tree: Move xa_get_alloc_size

... into ma_xa_benchmark.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agomm/mmap: Remove maple tree erase call in __vma_unlink_common
Liam R. Howlett [Fri, 28 Feb 2020 20:33:24 +0000 (15:33 -0500)]
mm/mmap: Remove maple tree erase call in __vma_unlink_common

__vma_unlink_common is used when overwriting the next vma entry.  Maple
tree overwrites these entries on the store of the vma itself.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Maple tree update for validate_mm_mt and comments
Liam R. Howlett [Fri, 28 Feb 2020 20:19:07 +0000 (15:19 -0500)]
mm/mmap: Maple tree update for validate_mm_mt and comments

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agommap: Write changes to next to the maple tree.
Liam R. Howlett [Fri, 28 Feb 2020 17:09:32 +0000 (12:09 -0500)]
mmap: Write changes to next to the maple tree.

When mprotect case 4 is hit (expand next back over vma), you have to
write the changes to the maple tree or there will be a missing mapping.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Initial documentation straw man.
Liam R. Howlett [Thu, 27 Feb 2020 03:39:36 +0000 (22:39 -0500)]
maple_tree: Initial documentation straw man.

Just add the file and some headers.  Details need to come from Thoughts.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agoRenumber XA.*ENTRY constants
Matthew Wilcox (Oracle) [Wed, 26 Feb 2020 19:00:43 +0000 (14:00 -0500)]
Renumber XA.*ENTRY constants

Entries below 256 are reserved for siblings, so renumber the RETRY
entry back to 256.  Entries which are ZERO and higher are allowed to
be inserted into the XArray, so renumber ZERO to 259, and slot SKIP and
DELETED in at 257 and 258.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
4 years agoRevert "maple_tree: Rework node split calculation for better non-leaf node split"
Liam R. Howlett [Tue, 25 Feb 2020 16:45:28 +0000 (11:45 -0500)]
Revert "maple_tree: Rework node split calculation for better non-leaf node split"

Efficient splitting is causing issues in certain scenarios with regards
to allocation trees.  Revisit later.

This reverts commit 4a0a2dd623fae22f2823a0711193aafef3479e71.

4 years agomaple_tree: Fix off by one on mas_prev when going to previous node.
Liam R. Howlett [Tue, 25 Feb 2020 16:18:51 +0000 (11:18 -0500)]
maple_tree: Fix off by one on mas_prev when going to previous node.

mas_prev_nentry decrements the slot prior to checking for an entry, so
don't decrement the slot in mas_prev loop on new nodes.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap: Don't adjust next for maple tree operations.
Liam R. Howlett [Tue, 25 Feb 2020 02:36:03 +0000 (21:36 -0500)]
mm/mmap: Don't adjust next for maple tree operations.

As maple tree store operation will alter the start location of the next
node if it they overlap, there is no need to erase and store the same
VMA.  In fact, since the start location is now occupied by the current
VMA, the erase operation will remove the wrong entry.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Set slot in mas_prev_slot to get the pivot
Liam R. Howlett [Tue, 25 Feb 2020 02:35:05 +0000 (21:35 -0500)]
maple_tree: Set slot in mas_prev_slot to get the pivot

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Rework node split calculation for better non-leaf node split
Liam R. Howlett [Mon, 24 Feb 2020 15:14:18 +0000 (10:14 -0500)]
maple_tree: Rework node split calculation for better non-leaf node split
usage.

When calculating where to split non-leaf nodes, assume the minimum span
is 8 in each entry, so 8*8.  This still needs work as we could figure
out the level from a leaf and keep going up in the minimum span to
better utilize more levels of the tree.

There is also the issue of the right-most entry (ULONG_MAX) which ends
up wasting a slot in the linear allocation case.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Always split regardless of spanning node boundaries or not.
Liam R. Howlett [Mon, 24 Feb 2020 15:11:39 +0000 (10:11 -0500)]
maple_tree: Always split regardless of spanning node boundaries or not.

Spanning node boundaries are now considered when calculating the number
of elements in a node, so if the count is larger than what the node will
hold, the node needs to be split.

set20 in test_maple_tree caught this issue.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_prev issue with parent slot & loop at root.
Liam R. Howlett [Sat, 22 Feb 2020 04:00:32 +0000 (23:00 -0500)]
maple_tree: Fix mas_prev issue with parent slot & loop at root.

parent slots were not being set correctly for the first ascend.  This
caused data to be skipped.

There was also an infinite loop if this was the first entry in a deep
tree.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix finding the end of a node when the node ends in a NULL.
Liam R. Howlett [Sat, 22 Feb 2020 02:49:55 +0000 (21:49 -0500)]
maple_tree: Fix finding the end of a node when the node ends in a NULL.
Also fix the limit calculation on gaps when searches backwards goes into
adjacent nodes during the search.

Ignoring the end null may cause gaps to be skipped when searching
backwards.

Adjacent nodes caused the max limit to be reset to the parent but never
set if the very next entry also had a potential gap that would work.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix limit updating when rewinding nodes during reverse
Liam R. Howlett [Fri, 21 Feb 2020 18:19:21 +0000 (13:19 -0500)]
maple_tree: Fix limit updating when rewinding nodes during reverse
walks.

When walking backwards in a node that sat in slot 0 of the parent, the
limit would not be set correctly.  The fix is not to set the limits
until descending into the node.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap and mm/mprotect: Alter mmap erase method.
Liam R. Howlett [Thu, 20 Feb 2020 21:39:36 +0000 (16:39 -0500)]
mm/mmap and mm/mprotect: Alter mmap erase method.

Can't call erase every time the rbtree erases as the maple tree doesn't
allow overlaps, so it's not necessary.

mprotect was too noisy.

mmap also had debug altered and verify changed in this commit.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix off-by-one on append_entry
Liam R. Howlett [Thu, 20 Feb 2020 21:36:16 +0000 (16:36 -0500)]
maple_tree: Fix off-by-one on append_entry

When appending an entry, ensure that the previous pivot is one less than
the desired range.

Don't subtraction coalesce from the slot calculation as that is now
taken into account within  _mas_add_slot_cnt itself.

Fix testing to kick out if mas_for_each is in a retry loop.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agotest_maple_tree: Standardize tests on using what was stored into the
Liam R. Howlett [Thu, 20 Feb 2020 20:08:30 +0000 (15:08 -0500)]
test_maple_tree: Standardize tests on using what was stored into the
maple tree

Use [x,y], not [x,y).

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix u64 => unsigned long
Liam R. Howlett [Thu, 20 Feb 2020 20:06:48 +0000 (15:06 -0500)]
maple_tree: Fix u64 => unsigned long

Incorrect types fixed.  This will need to be revisited for different
arch and also u16/u32 one day.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix append_entry for NULL appending, fix append for retry
Liam R. Howlett [Thu, 20 Feb 2020 16:28:50 +0000 (11:28 -0500)]
maple_tree: Fix append_entry for NULL appending, fix append for retry
entries, fix split appending on coalesce.

Add some testcases for the above fixes.

Also fix an off-by-one error in spanning_add.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm/mmap and maple_tree: Fix mt_for_each interface, get_unmapped_area_rev
Liam R. Howlett [Tue, 18 Feb 2020 15:56:41 +0000 (10:56 -0500)]
mm/mmap and maple_tree: Fix mt_for_each interface, get_unmapped_area_rev

mt_for_each interface simplification for external users.

get_unampped_area_rev was not getting the right answer.  Fix it and
clean up the condensed and unused interface internal to the maple tree.

Fix associated tests as well.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agommap/fork/mm.h: Add maple tree support.
Liam R. Howlett [Fri, 14 Feb 2020 17:04:34 +0000 (12:04 -0500)]
mmap/fork/mm.h: Add maple tree support.

When forking, init the maple tree and add entries.

mmap: Clean up prints.

mm: Export vma_store for adding things to mt in fork.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Thoughts, fix whitespace, fix compile issue
Liam R. Howlett [Fri, 14 Feb 2020 16:39:56 +0000 (11:39 -0500)]
maple_tree: Thoughts, fix whitespace, fix compile issue

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_rev_awalk to check if the entry is empty.
Liam R. Howlett [Fri, 14 Feb 2020 16:36:50 +0000 (11:36 -0500)]
maple_tree: Fix mas_rev_awalk to check if the entry is empty.

When checking of an entry is empty, ensure delete is considered empty.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_for_each retry incorrectly setting mas->last
Liam R. Howlett [Thu, 13 Feb 2020 15:56:17 +0000 (10:56 -0500)]
maple_tree: Fix mas_for_each retry incorrectly setting mas->last

mas->last was being skipped when initially run or retry was hit.  Ensure
it is set correctly.

Also, fix retry skipping during initial load of mas_for_each.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_set_rev_index, _mas_get_unmapped_area, and code cleanup
Liam R. Howlett [Thu, 13 Feb 2020 02:42:24 +0000 (21:42 -0500)]
maple_tree: Fix mas_set_rev_index, _mas_get_unmapped_area, and code cleanup

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Reduce recursion and fix set10 testcase.
Liam R. Howlett [Tue, 11 Feb 2020 02:35:09 +0000 (21:35 -0500)]
maple_tree:  Reduce recursion and fix set10 testcase.

1. Remove ma_cp/mas_copy in favour of mas_append and friends.
  It turns out it is cleaner to append nodes together than to try and
  copy parts and glue them together as initially designed.

2. Clean up debug/test code and BUG_ON statements.

3. Add *mte_get_rcu_sanitized() to return NULL if it will be coalesced.

4. mas_set_safe_pivot is no longer recursive.

5. mas_data_end has been altered numerous times.

6. Add mas_get_range() - get the range of a given slot.

7. Drop mas_ma_update_gap/mas_ma_cp in favour of the above mentioned
appending operations.

8. mas_parent_gap() is no longer recursive.

9. mas_update_gap() has been updated to use new mas_parent_gap.

10. mas_split() uses mas_append and friends.

11. __mas_add_slot_cnt() is used to calculate the slots needed when
adding a value - much reliable than mas_data_end for this usecase.

12. mas_rebalance() is no longer recursive.

13. Added validation code for parent slot

14. Doubled testcases and fixed a missing mas_destroy() call.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomm: Add maple tree to init-mm,mmap, mprotect, mm_types
Liam R. Howlett [Thu, 16 Jan 2020 16:06:42 +0000 (11:06 -0500)]
mm: Add maple tree to init-mm,mmap, mprotect, mm_types

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Drop BUG_ON and add set9 to tests
Liam R. Howlett [Thu, 16 Jan 2020 16:05:57 +0000 (11:05 -0500)]
maple_tree: Drop BUG_ON and add set9 to tests

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Thoughts updated for coalescing/rebuilding
Liam R. Howlett [Thu, 16 Jan 2020 16:05:33 +0000 (11:05 -0500)]
maple_tree: Thoughts updated for coalescing/rebuilding

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix prev_node, change split balancing during inactive.
Liam R. Howlett [Thu, 16 Jan 2020 15:59:08 +0000 (10:59 -0500)]
maple_tree: Fix prev_node, change split balancing during inactive.

Also change the real world testcases to use an alloc tree.

Note: set9 fails due to attempt to get 140 nodes allocated.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: fix setting parent during split.
Liam R. Howlett [Tue, 14 Jan 2020 17:34:47 +0000 (12:34 -0500)]
maple_tree: fix setting parent during split.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: cleanup
Liam R. Howlett [Tue, 14 Jan 2020 16:22:21 +0000 (11:22 -0500)]
maple_tree: cleanup

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: cleanup
Liam R. Howlett [Tue, 14 Jan 2020 16:22:05 +0000 (11:22 -0500)]
maple_tree: cleanup

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Zero stack struct
Liam R. Howlett [Tue, 14 Jan 2020 04:11:15 +0000 (23:11 -0500)]
maple_tree: Zero stack struct

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, almost there. maple_tree: 653130 of 653130 tests passed
Liam R. Howlett [Mon, 13 Jan 2020 15:35:30 +0000 (10:35 -0500)]
maple_tree: WIP, almost there. maple_tree: 653130 of 653130 tests passed

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, error in delete path when allocations fail.
Liam R. Howlett [Mon, 6 Jan 2020 18:39:36 +0000 (13:39 -0500)]
maple_tree: WIP, error in delete path when allocations fail.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, fixes mas_rebalance pivot promotion to avoid adding to non-leafs...
Liam R. Howlett [Sun, 5 Jan 2020 09:50:01 +0000 (04:50 -0500)]
maple_tree: WIP, fixes mas_rebalance pivot promotion to avoid adding to non-leafs, fixes end detection in corner case, still hosed at 584531

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, fixed mas_awalk for full nodes and fill nodes, still hosed at 78381
Liam R. Howlett [Fri, 3 Jan 2020 20:39:17 +0000 (15:39 -0500)]
maple_tree: WIP, fixed mas_awalk for full nodes and fill nodes, still hosed at 78381

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, still hosed.. Pass: 583922 Run:583923
Liam R. Howlett [Thu, 2 Jan 2020 21:07:02 +0000 (16:07 -0500)]
maple_tree: WIP, still hosed.. Pass: 583922 Run:583923

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP, so very broken coalesce/rebalance
Liam R. Howlett [Thu, 2 Jan 2020 19:30:25 +0000 (14:30 -0500)]
maple_tree: WIP, so very broken coalesce/rebalance

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_find to skip empty nodes and set mas.index correctly
Liam R. Howlett [Thu, 19 Dec 2019 16:32:14 +0000 (11:32 -0500)]
maple_tree: Fix mas_find to skip empty nodes and set mas.index correctly

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: wip, rework of split and such
Liam R. Howlett [Thu, 19 Dec 2019 15:56:33 +0000 (10:56 -0500)]
maple_tree: wip, rework of split and such

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: WIP on kvm tests
Liam R. Howlett [Wed, 18 Dec 2019 17:11:27 +0000 (12:11 -0500)]
maple_tree: WIP on kvm tests

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mas_first_entry return value.
Liam R. Howlett [Mon, 16 Dec 2019 01:05:40 +0000 (20:05 -0500)]
maple_tree: Fix mas_first_entry return value.

This was returning the wrong pivot value which resulted in skipping
tree entries in mas_for_each loops.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix empty pivot when appending to a perfect fit.
Liam R. Howlett [Fri, 13 Dec 2019 21:13:55 +0000 (16:13 -0500)]
maple_tree: Fix empty pivot when appending to a perfect fit.

When appending data to the end of a node which fits perfectly in the
range, it may be that the pivot is 0 but the implied pivot is mas->max.
This would result in a walk operation not finding the value.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Continue fixing fallout from mas_data_end changes.
Liam R. Howlett [Fri, 13 Dec 2019 20:07:04 +0000 (15:07 -0500)]
maple_tree:   Continue fixing fallout from mas_data_end changes.

Rewrite mas_node_push and mas_next_alloc and add test cases to stress
test.

Fix mas_split calculations to use correct pivots.

Reuse null at the end of a node to avoid splitting

Fix mas_next_slot on root node running off the end of the node.

Fix _mas_awalk when there are deleted entries which caused a step over
the end.

Set slot to 0 on descend in __mas_awalk.

Only use 4 for node calculations on mas_replace_tree.

Fix testcase inserting 0 to use xa_mk_value to avoid coalescing NULL
entries.

Add set 4 to check_erase_testcase2 from KVM testing.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Rewrite mas_data_end to return slot not occupied count.
Liam R. Howlett [Thu, 12 Dec 2019 16:18:29 +0000 (11:18 -0500)]
maple_tree: Rewrite mas_data_end to return slot not occupied count.

Rewrite mas_data_end to return slot, not occupied count and fix coalesce
calculation for a run of NULLs, etc

Move MT_BUG_ON for use in verification functions.

Add mas_mn for easier mas->node enode to node conversion.

Drop __mte_get_rcu_slot as the dead_node detect doesn't work right.

Make sure hard_data doesn't return a negative.

Fix ma_state on calls to mas_update_gaps

Fix end pivots on the right side of a split.

Fix number of slots being occupied calculation when _mas_add is using
the last slot and the new range doesn't run to mas->max.

Fix mas_rebalance when right node is empty and fix mas_data_end uses.

Rewrite mas_coalesce for new mas_data_end uses.

Fix mt_find overflow of index when there is a valuse at ULONG_MAX.

Add a testcase for mt_find overflow.

Fix mas_rev_awalk to check for errors prior to trying to walk.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Drop mas.last setting in mt_find and add tests.
Liam R. Howlett [Thu, 5 Dec 2019 04:46:21 +0000 (23:46 -0500)]
maple_tree: Drop mas.last setting in mt_find and add tests.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix mt_find, mas_find, add with deleted slot, __mas_next
Liam R. Howlett [Wed, 4 Dec 2019 23:19:49 +0000 (18:19 -0500)]
maple_tree: Fix mt_find, mas_find, add with deleted slot, __mas_next

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Fix compile warnings during kernel build
Liam R. Howlett [Thu, 28 Nov 2019 18:27:53 +0000 (13:27 -0500)]
maple_tree: Fix compile warnings during kernel build

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
4 years agomaple_tree: Add mas_get_unmapped_area and mas_get_unmapped_area_rev
Liam R. Howlett [Tue, 26 Nov 2019 18:54:29 +0000 (13:54 -0500)]
maple_tree: Add mas_get_unmapped_area and mas_get_unmapped_area_rev

This adds an interface which was missing for the drop-in replacement for
the mmap code.

It also fixes two issues:

1. Range checking for the upper bounds during a forward allocation walk
in _awalk
2. Checking if the ma_state is in error state during the loop in awalk
prior to calling _awalk.  The order was incorrect and could have caused
issues.

I've exposed mas_prev, and mtree_store_range for the mmap code in this
commit as well.

I've renamed a few missed ma_state functions to mas_ instead of ma_.
I've also reorder the header a bit.

Along with the new mas_get_unmapped_area{_rev}, I've added testcases for
them.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>