Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp2054418rdb; Wed, 31 Jan 2024 18:53:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFutX4gwak/vRi7WHDAA6VTw1JPXD1yx/jBaX4i5S7HwFH+A/1krW5tIIjMJtnfdw15JJdn X-Received: by 2002:a17:902:dace:b0:1d8:d02c:c692 with SMTP id q14-20020a170902dace00b001d8d02cc692mr3451793plx.10.1706756021146; Wed, 31 Jan 2024 18:53:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706756021; cv=pass; d=google.com; s=arc-20160816; b=PfPXnyyM4xeSsY6hUryZEGYkpgfggFNFSp85l6ZbVKKgNkLU3FJzuXuKVueyhZV9pS iXa755lPcQDOxE/L2honNxio8KaUuMbSwEDlKM6yuIQBbCG5UUSXEnufFPkMiH7zwjgU aGgHWs+N/vjJASlNeiVMEMl5am6RdYfWHvHO2N9I8WMWk/ngPYbRQc8AqnK7nmVGsXyX dx9O4IbMwOADhDvAAyvVs7oCwLMwRKD18ktWEWV9vRLi8gQzcvjxEoKCT1hrA8fkmQWk wk2sQvSRoBJKzoY+YqnXO5S4MBzR3sryHNUk1hMjN4/Gz9tSzV3eLrXZpl/uD6f901/M 1D7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VHDS8XfeqrJJCoN72ANJz9/5fJVypoPtMt3FLrR4fJQ=; fh=8LL10nbRTZBFQPEjo581cjf8r29XyhOq7dyJUkSSqBY=; b=CeFXWOm9jKyn3kudaT4ysYU5lEq6Uedn468n65Csl+ebIh85fnDCPjYmsG25L7LQbQ gxPQO+MOl6vjNgGZ9+QJiWddO0XJMEYaITbnQQiPiZaN5DoMD8keZtZ2dPthQt27Mg5u Pxa+B+7V637hiyg3GU1f656q1oHF48DouINrOaN6D5EtvIvjfttnDzKKQ9QY5kElgjlm 1qe8L/xQl/VnoEsHjySOrQw6KdZ3Z1nS+om7Ox482D/DeTxGwsSOHrTBFo9kiX4gG8B/ X4rQKeYomZDgFL30IDmjOWvDmCrgDP1j0PvHC60zz8t/PI9LCScjnPOxpki85VQdZc2w tZ2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=RRFaCJ4U; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-47280-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47280-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUQksK3XRUEMGfEsEkv5qcgAQxZ54BcdrFPd0CpFEPHnWDXfeo2968nQz4BqXsm55evq88bHu7cFFqI1slX4dpqw6KTVheX17OYqBa0VA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a20-20020a170902b59400b001d75eef04e1si10823471pls.73.2024.01.31.18.53.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 18:53:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47280-linux.lists.archive=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=@infradead.org header.s=bombadil.20210309 header.b=RRFaCJ4U; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-47280-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47280-linux.lists.archive=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 E8E67B2864A for ; Wed, 31 Jan 2024 22:52:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9B7D3B197; Wed, 31 Jan 2024 22:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RRFaCJ4U" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3A1E83AC14; Wed, 31 Jan 2024 22:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741491; cv=none; b=ryCQbNzfQakr5R9cfKKsCsCjyqwcM/sUPJUffjTNEbPTlFWTr/6aBUK6ogWV3u3g9hFN+YYWGdnhzWDoU3E+UENQaLitvptMsKI2RpYNsVEHumQfn2Zp+CzaJngXv8SwCNm/9Lc1ChQ+0RKYxXJOudrNTnmlRCbdtXazo6mpCOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706741491; c=relaxed/simple; bh=nUkzR12xy1p2FiXOVo6YSxE3TENbyX/bzQKcNKNH2Jw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c5bMEdkPx0AUhNGzLVGp8Hk7sZh3aB7/P7YqPkD3wg5cguTPFAx7kTDBlF6k5sfUfuSYLIUoYPwQPmwxUu1aGhiY8ba4uBc6bBxAm9/khmAlmhygCJFXUHHAScl9mI9IRTTTPF9k9LUVcRAWS6/Nii5bc48h8ixG6gbqe2N0AtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=RRFaCJ4U; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=VHDS8XfeqrJJCoN72ANJz9/5fJVypoPtMt3FLrR4fJQ=; b=RRFaCJ4USpY0kDnPaF2Gol/eCH uSXwm4FGSYKqQL6L2LaiKlthJCk+UXmcoNd1huvU87/ebEx4N9F6NuJ6Xr6wmSsYva88XNpFNk6Jl 8VonDVWqHqa3NtjMQblemeLe2bJBWdLZIn/YwiXRHJ2yXZehrKiXuK6Cl8FowK0RCaEFrzF9medG7 8PgaWqykDIabwdxryzoDPb7BtJQOZ2Xwd6zmtJ5tKsvE5DoyhNEu2vzdTaWxcNJlubQV+gJFxTmtz 5bW2px9kQeGRUnIKNiFdPrrD3gER30HYudTQofdG5jkhHiqrNHXq3m6LCOzlu+ap8tr+BzqIVixew i3855xlQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVJQW-00000005kZC-3y0I; Wed, 31 Jan 2024 22:51:28 +0000 From: Luis Chamberlain To: willy@infradead.org, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, hare@suse.com, p.raghav@samsung.com, da.gomez@samsung.com, djwong@kernel.org, david@fromorbit.com, mcgrof@kernel.org Subject: [PATCH v2 1/2] test_xarray: add tests for advanced multi-index use Date: Wed, 31 Jan 2024 14:51:24 -0800 Message-ID: <20240131225125.1370598-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131225125.1370598-1-mcgrof@kernel.org> References: <20240131225125.1370598-1-mcgrof@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain The multi index selftests are great but they don't replicate how we deal with the page cache exactly, which makes it a bit hard to follow as the page cache uses the advanced API. Add tests which use the advanced API, mimicking what we do in the page cache, while at it, extend the example to do what is needed for min order support. Tested-by: Daniel Gomez Signed-off-by: Luis Chamberlain --- lib/test_xarray.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index e77d4856442c..8b23481f0e8f 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -674,6 +674,169 @@ static noinline void check_multi_store(struct xarray *xa) #endif } +#ifdef CONFIG_XARRAY_MULTI +/* mimics page cache __filemap_add_folio() */ +static noinline void check_xa_multi_store_adv_add(struct xarray *xa, + unsigned long index, + unsigned int order, + void *p) +{ + XA_STATE(xas, xa, index); + unsigned int nrpages = 1UL << order; + + /* users are responsible for index alignemnt to the order when adding */ + XA_BUG_ON(xa, index & (nrpages - 1)); + + xas_set_order(&xas, index, order); + + do { + xas_lock_irq(&xas); + + xas_store(&xas, p); + XA_BUG_ON(xa, xas_error(&xas)); + XA_BUG_ON(xa, xa_load(xa, index) != p); + + xas_unlock_irq(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); + + XA_BUG_ON(xa, xas_error(&xas)); +} + +/* mimics page_cache_delete() */ +static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + XA_STATE(xas, xa, index); + + xas_set_order(&xas, index, order); + xas_store(&xas, NULL); + xas_init_marks(&xas); +} + +static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + xa_lock_irq(xa); + check_xa_multi_store_adv_del_entry(xa, index, order); + xa_unlock_irq(xa); +} + +/* mimics page cache filemap_get_entry() */ +static noinline void *test_get_entry(struct xarray *xa, unsigned long index) +{ + XA_STATE(xas, xa, index); + void *p; + + rcu_read_lock(); +repeat: + xas_reset(&xas); + p = xas_load(&xas); + if (xas_retry(&xas, p)) + goto repeat; + rcu_read_unlock(); + + return p; +} + +static unsigned long some_val = 0xdeadbeef; +static unsigned long some_val_2 = 0xdeaddead; + +/* mimics the page cache usage */ +static noinline void check_xa_multi_store_adv(struct xarray *xa, + unsigned long pos, + unsigned int order) +{ + unsigned int nrpages = 1UL << order; + unsigned long index, base, next_index, next_next_index; + unsigned int i; + + index = pos >> PAGE_SHIFT; + base = round_down(index, nrpages); + next_index = round_down(base + nrpages, nrpages); + next_next_index = round_down(next_index + nrpages, nrpages); + + check_xa_multi_store_adv_add(xa, base, order, &some_val); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val); + + XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL); + + /* Use order 0 for the next item */ + check_xa_multi_store_adv_add(xa, next_index, 0, &some_val_2); + XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2); + + /* Remove the next item */ + check_xa_multi_store_adv_delete(xa, next_index, 0); + + /* Now use order for a new pointer */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_index, order); + check_xa_multi_store_adv_delete(xa, base, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* starting fresh again */ + + /* let's test some holes now */ + + /* hole at base and next_next */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL); + + check_xa_multi_store_adv_delete(xa, next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* hole at base and next */ + + check_xa_multi_store_adv_add(xa, next_next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); +} +#endif + +static noinline void check_multi_store_advanced(struct xarray *xa) +{ +#ifdef CONFIG_XARRAY_MULTI + unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; + unsigned long end = ULONG_MAX/2; + unsigned long pos, i; + + /* + * About 117 million tests below. + */ + for (pos = 7; pos < end; pos = (pos * pos) + 564) { + for (i = 0; i < max_order; i++) { + check_xa_multi_store_adv(xa, pos, i); + check_xa_multi_store_adv(xa, pos + 157, i); + } + } +#endif +} + static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) { int i; @@ -1804,6 +1967,7 @@ static int xarray_checks(void) check_reserve(&array); check_reserve(&xa0); check_multi_store(&array); + check_multi_store_advanced(&array); check_get_order(&array); check_xa_alloc(); check_find(&array); -- 2.43.0