Skip to content

Commit 446e186

Browse files
Peng Zhangakpm00
authored andcommitted
maple_tree: update check_forking() and bench_forking()
Updated check_forking() and bench_forking() to use __mt_dup() to duplicate maple tree. Link: https://lkml.kernel.org/r/20231027033845.90608-9-zhangpeng.00@bytedance.com Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Mateusz Guzik <mjguzik@gmail.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Mike Christie <michael.christie@oracle.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f670fa1 commit 446e186

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

lib/test_maple_tree.c

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,47 +1834,48 @@ static noinline void __init bench_mas_prev(struct maple_tree *mt)
18341834
}
18351835
#endif
18361836
/* check_forking - simulate the kernel forking sequence with the tree. */
1837-
static noinline void __init check_forking(struct maple_tree *mt)
1837+
static noinline void __init check_forking(void)
18381838
{
1839-
1840-
struct maple_tree newmt;
1841-
int i, nr_entries = 134;
1839+
struct maple_tree mt, newmt;
1840+
int i, nr_entries = 134, ret;
18421841
void *val;
1843-
MA_STATE(mas, mt, 0, 0);
1844-
MA_STATE(newmas, mt, 0, 0);
1845-
struct rw_semaphore newmt_lock;
1842+
MA_STATE(mas, &mt, 0, 0);
1843+
MA_STATE(newmas, &newmt, 0, 0);
1844+
struct rw_semaphore mt_lock, newmt_lock;
18461845

1846+
init_rwsem(&mt_lock);
18471847
init_rwsem(&newmt_lock);
18481848

1849-
for (i = 0; i <= nr_entries; i++)
1850-
mtree_store_range(mt, i*10, i*10 + 5,
1851-
xa_mk_value(i), GFP_KERNEL);
1849+
mt_init_flags(&mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN);
1850+
mt_set_external_lock(&mt, &mt_lock);
18521851

1853-
mt_set_non_kernel(99999);
18541852
mt_init_flags(&newmt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN);
18551853
mt_set_external_lock(&newmt, &newmt_lock);
1856-
newmas.tree = &newmt;
1857-
mas_reset(&newmas);
1858-
mas_reset(&mas);
1859-
down_write(&newmt_lock);
1860-
mas.index = 0;
1861-
mas.last = 0;
1862-
if (mas_expected_entries(&newmas, nr_entries)) {
1854+
1855+
down_write(&mt_lock);
1856+
for (i = 0; i <= nr_entries; i++) {
1857+
mas_set_range(&mas, i*10, i*10 + 5);
1858+
mas_store_gfp(&mas, xa_mk_value(i), GFP_KERNEL);
1859+
}
1860+
1861+
down_write_nested(&newmt_lock, SINGLE_DEPTH_NESTING);
1862+
ret = __mt_dup(&mt, &newmt, GFP_KERNEL);
1863+
if (ret) {
18631864
pr_err("OOM!");
18641865
BUG_ON(1);
18651866
}
1866-
rcu_read_lock();
1867-
mas_for_each(&mas, val, ULONG_MAX) {
1868-
newmas.index = mas.index;
1869-
newmas.last = mas.last;
1867+
1868+
mas_set(&newmas, 0);
1869+
mas_for_each(&newmas, val, ULONG_MAX)
18701870
mas_store(&newmas, val);
1871-
}
1872-
rcu_read_unlock();
1871+
18731872
mas_destroy(&newmas);
1873+
mas_destroy(&mas);
18741874
mt_validate(&newmt);
1875-
mt_set_non_kernel(0);
18761875
__mt_destroy(&newmt);
1876+
__mt_destroy(&mt);
18771877
up_write(&newmt_lock);
1878+
up_write(&mt_lock);
18781879
}
18791880

18801881
static noinline void __init check_iteration(struct maple_tree *mt)
@@ -1977,49 +1978,51 @@ static noinline void __init check_mas_store_gfp(struct maple_tree *mt)
19771978
}
19781979

19791980
#if defined(BENCH_FORK)
1980-
static noinline void __init bench_forking(struct maple_tree *mt)
1981+
static noinline void __init bench_forking(void)
19811982
{
1982-
1983-
struct maple_tree newmt;
1984-
int i, nr_entries = 134, nr_fork = 80000;
1983+
struct maple_tree mt, newmt;
1984+
int i, nr_entries = 134, nr_fork = 80000, ret;
19851985
void *val;
1986-
MA_STATE(mas, mt, 0, 0);
1987-
MA_STATE(newmas, mt, 0, 0);
1988-
struct rw_semaphore newmt_lock;
1986+
MA_STATE(mas, &mt, 0, 0);
1987+
MA_STATE(newmas, &newmt, 0, 0);
1988+
struct rw_semaphore mt_lock, newmt_lock;
19891989

1990+
init_rwsem(&mt_lock);
19901991
init_rwsem(&newmt_lock);
1991-
mt_set_external_lock(&newmt, &newmt_lock);
19921992

1993-
for (i = 0; i <= nr_entries; i++)
1994-
mtree_store_range(mt, i*10, i*10 + 5,
1995-
xa_mk_value(i), GFP_KERNEL);
1993+
mt_init_flags(&mt, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN);
1994+
mt_set_external_lock(&mt, &mt_lock);
1995+
1996+
down_write(&mt_lock);
1997+
for (i = 0; i <= nr_entries; i++) {
1998+
mas_set_range(&mas, i*10, i*10 + 5);
1999+
mas_store_gfp(&mas, xa_mk_value(i), GFP_KERNEL);
2000+
}
19962001

19972002
for (i = 0; i < nr_fork; i++) {
1998-
mt_set_non_kernel(99999);
1999-
mt_init_flags(&newmt, MT_FLAGS_ALLOC_RANGE);
2000-
newmas.tree = &newmt;
2001-
mas_reset(&newmas);
2002-
mas_reset(&mas);
2003-
mas.index = 0;
2004-
mas.last = 0;
2005-
rcu_read_lock();
2006-
down_write(&newmt_lock);
2007-
if (mas_expected_entries(&newmas, nr_entries)) {
2008-
printk("OOM!");
2003+
mt_init_flags(&newmt,
2004+
MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN);
2005+
mt_set_external_lock(&newmt, &newmt_lock);
2006+
2007+
down_write_nested(&newmt_lock, SINGLE_DEPTH_NESTING);
2008+
ret = __mt_dup(&mt, &newmt, GFP_KERNEL);
2009+
if (ret) {
2010+
pr_err("OOM!");
20092011
BUG_ON(1);
20102012
}
2011-
mas_for_each(&mas, val, ULONG_MAX) {
2012-
newmas.index = mas.index;
2013-
newmas.last = mas.last;
2013+
2014+
mas_set(&newmas, 0);
2015+
mas_for_each(&newmas, val, ULONG_MAX)
20142016
mas_store(&newmas, val);
2015-
}
2017+
20162018
mas_destroy(&newmas);
2017-
rcu_read_unlock();
20182019
mt_validate(&newmt);
2019-
mt_set_non_kernel(0);
20202020
__mt_destroy(&newmt);
20212021
up_write(&newmt_lock);
20222022
}
2023+
mas_destroy(&mas);
2024+
__mt_destroy(&mt);
2025+
up_write(&mt_lock);
20232026
}
20242027
#endif
20252028

@@ -3615,9 +3618,7 @@ static int __init maple_tree_seed(void)
36153618
#endif
36163619
#if defined(BENCH_FORK)
36173620
#define BENCH
3618-
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
3619-
bench_forking(&tree);
3620-
mtree_destroy(&tree);
3621+
bench_forking();
36213622
goto skip;
36223623
#endif
36233624
#if defined(BENCH_MT_FOR_EACH)
@@ -3650,9 +3651,7 @@ static int __init maple_tree_seed(void)
36503651
check_iteration(&tree);
36513652
mtree_destroy(&tree);
36523653

3653-
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
3654-
check_forking(&tree);
3655-
mtree_destroy(&tree);
3654+
check_forking();
36563655

36573656
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
36583657
check_mas_store_gfp(&tree);

tools/include/linux/rwsem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ static inline int up_write(struct rw_semaphore *sem)
3737
{
3838
return pthread_rwlock_unlock(&sem->lock);
3939
}
40+
41+
#define down_read_nested(sem, subclass) down_read(sem)
42+
#define down_write_nested(sem, subclass) down_write(sem)
43+
4044
#endif /* _TOOLS_RWSEM_H */

0 commit comments

Comments
 (0)