From patchwork Tue Feb 13 21:37:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 200678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp831045dyb; Tue, 13 Feb 2024 14:01:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUzQm7F26Fo/Sm3iFC8aKP9NxQiBFZ3kPIOEVcnEhbH8toSb/K9mVN82x8Xu82HeqWkjzSep7Rp7CCm+WDVAkibJlsIzw== X-Google-Smtp-Source: AGHT+IHKf1vlvmi0+E4FfjytRHl/QMYWK5Yew8YpBniVVcnKGWwc03jqIo4gjy/hhVczFool004R X-Received: by 2002:a05:6359:4c27:b0:179:24b4:41f6 with SMTP id kj39-20020a0563594c2700b0017924b441f6mr634814rwc.7.1707861679863; Tue, 13 Feb 2024 14:01:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707861679; cv=pass; d=google.com; s=arc-20160816; b=fcygHO2OerBx2cr77i8ahVOOq9xfv04deqwjWTviL5p+w3b+ufpO5VbVom3QV324m1 IH8bDRaQ8RrnQTWRjpHYLm+ca8xx3oBpavj1K5VcU//uXS9/AI1FxreQLOJa3pvpwjSO PitKxxb6gnAl1HIOSY4p9JfqQFoqEnxwTfBI328umpSU6lwWKbEBdpb9BrAT3AF8J4w4 MHsADXfJtm10KcBpZyJoS26jCXL6oKWTFlIcLdDxScWzwUuDWFvXk35CHSXtDkggWqo4 86xaxVoBSNCfJ4Elg/33dk/VfdwpZQFcRkI9jMi6ZVua7sbIYwf+pQuhGDO2xypPo0w2 M7Jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:cc:to:from:subject:dkim-signature; bh=dH9/7pSMHgIoq16nk50EO6AL6CLhc0Zg3gckgnzjmrE=; fh=e9TlNvPRSP+k2k9yxWXTkQzW5fHcZwyraIzc9d5mMAk=; b=APw3ZFNR6FXI1nfptp9n2ebrICmuvH3nxeZzaw07hx0oNmgF4Wxs5UQp36IGDYSRwN QLS6VWbpYKpVrV6NCEtZjxsM1rOtTtXv7xRAYgleB/G57cBQCDoZ+H1WOUVy6c225Nq0 TYUhgzVWjDTE42cdYiQ7J/g3iW5JuIwEVB2HhcUEKgfLetFjKVUbDlzNymyun/PgKoGX JQWJK+84Ibev3ioRFBFwyTTTZinjOZZvAkE95tkVjrWuYUvODKON07lRXNTwbD8uSn/c bmXEeOpwcc/MYBuHl4GL0vWzP4SNOgzt8kj9eWOYq/koRy8Gqn0/sgWsdP5R5owjPnii an9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Th8U8xQD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVo9S3tCptgDbmW/Fuep5c4TncbWVcixGK0umY7/99eqKHJk9IIpwXie/Yh3Ow/VdDeJXjyPbyw39wZqGQs07wnVjYFrg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b26-20020a63931a000000b005dc5568b149si2550003pge.297.2024.02.13.14.01.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:01:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Th8U8xQD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64346-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 18B5FB22B75 for ; Tue, 13 Feb 2024 21:39:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E7C8629EE; Tue, 13 Feb 2024 21:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Th8U8xQD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81441627FC; Tue, 13 Feb 2024 21:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860276; cv=none; b=fCSGrRJVznXsHjz1Ns3eyN1Dg6tEu4DFmmabvyET91Vqjpd0KccgvQsp78TJvg/lry3LIZiD0HYwsQdEIVCKXEN3ijVoOXxMbUyQNku9BcNzR0KGHoRq3NFHOe3MldomX2OmK8G/iUVD34EHADQeA39IpOby5PjiYcfXOwIrLRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707860276; c=relaxed/simple; bh=r6dLn2R32hxUVKrwHaR6P90sYMJO3HfuXaP1srQuHsY=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DkXA/J50pGzMakWih6ua2sc/DLzVgRNjo14XddvgEJi76TybHcPRKwMIF9nvVdgRyt+pgdcsgdUphTnOTZOOcGsHXtqL1Cks+jJLIZRF5hsShNe08PtQ3oEJXKlvb1wtWdCywgNEqQtQ+rkWLF+cYDNXhYSXUoheLVnqWTw7Qu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Th8U8xQD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DFACC433F1; Tue, 13 Feb 2024 21:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707860276; bh=r6dLn2R32hxUVKrwHaR6P90sYMJO3HfuXaP1srQuHsY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Th8U8xQDYjqE1oQO4SMhsymZnm2aTPh8ZM7SpIcq4/V3kMtNsQxxEPtEb+A/tXJZf G7CeU83YmDWCAhd/8bx6jK94iSNmgavwSA4WP4N4dJI0dRaDB/zSKquDqTQXzeFO7m nC38c/PXELlpiHWShA/rc3NbKs6cX7/7sxgiSLwa58znNQ1vr0pOGxb0cnwQgQdJbs a8EcruWbXzSxvwZRj8o8Y+0+5a327ukO27y3BcROelsesxB4/7N/jTda8uI3qtQj8A oJsu3SksCpvwru3/pix1RG4ASCwWk4HWxBO5o5oD9ZaLDJTRzKXMbRscRM2tuNVH9G qMSYb7+IbpL7g== Subject: [PATCH RFC 5/7] test_maple_tree: testing the cyclic allocation From: Chuck Lever To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, hughd@google.com, akpm@linux-foundation.org, Liam.Howlett@oracle.com, oliver.sang@intel.com, feng.tang@intel.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Date: Tue, 13 Feb 2024 16:37:54 -0500 Message-ID: <170786027413.11135.7987491534374292548.stgit@91.116.238.104.host.secureserver.net> In-Reply-To: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790822768575181855 X-GMAIL-MSGID: 1790822768575181855 From: Liam R. Howlett This tests the interactions of the cyclic allocations, the maple state index and last, and overflow. Signed-off-by: Liam R. Howlett Signed-off-by: Chuck Lever --- lib/test_maple_tree.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 29185ac5c727..399380db449c 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -3599,6 +3599,45 @@ static noinline void __init check_state_handling(struct maple_tree *mt) mas_unlock(&mas); } +static noinline void __init alloc_cyclic_testing(struct maple_tree *mt) +{ + unsigned long location; + unsigned long next; + int ret = 0; + MA_STATE(mas, mt, 0, 0); + + next = 0; + mtree_lock(mt); + for (int i = 0; i < 100; i++) { + mas_alloc_cyclic(&mas, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MAS_BUG_ON(&mas, i != location - 2); + MAS_BUG_ON(&mas, mas.index != location); + MAS_BUG_ON(&mas, mas.last != location); + MAS_BUG_ON(&mas, i != next - 3); + } + + mtree_unlock(mt); + mtree_destroy(mt); + next = 0; + mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE); + for (int i = 0; i < 100; i++) { + mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, i != location - 2); + MT_BUG_ON(mt, i != next - 3); + MT_BUG_ON(mt, mtree_load(mt, location) != mt); + } + + mtree_destroy(mt); + /* Overflow test */ + next = ULONG_MAX - 1; + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 0); + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 0); + ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL); + MT_BUG_ON(mt, ret != 1); +} + static DEFINE_MTREE(tree); static int __init maple_tree_seed(void) { @@ -3880,6 +3919,11 @@ static int __init maple_tree_seed(void) check_state_handling(&tree); mtree_destroy(&tree); + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + alloc_cyclic_testing(&tree); + mtree_destroy(&tree); + + #if defined(BENCH) skip: #endif