From patchwork Sat Nov 4 00:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 161507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1397425vqu; Fri, 3 Nov 2023 17:58:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfZPCv7xegFf51HCAnaP6fAkhb+EjnKGpfzhJrTz/3Vio9iKxlRXCAyJ8Yg1btaP4M+xR7 X-Received: by 2002:a05:6a21:35c4:b0:181:1d71:7e0f with SMTP id ba4-20020a056a2135c400b001811d717e0fmr12170589pzc.61.1699059486539; Fri, 03 Nov 2023 17:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699059486; cv=none; d=google.com; s=arc-20160816; b=TXaq26pr8ckJonpzYq9UjrZbS/VD3gkpD37KKVQK3jWPfwZKaHncBTwQHkqwtNiTlF lVnoTE08xta/L/Z1/Fmb4SPbniLxfQntxYzhblRPn/Jibc5jWyZ1eC3iqePvVhI5EVGs fvy4SN0aiyfgRiJFPjLxteawT2BFIWRiNPFDG671oxAtxzyooee9JeBfbhUWnn6JeN3F 3A6QmOYoViClTNsRu6/w7i9gBFInu6USut5cLQGjNz7aqY2VxySlWjE1nY2CnOBqZR+A HhH822SoMjyChIUTOe3gWZq6fdINiYNnWeB9jVUlUo+JwoFdD5j4voOCPh/Pw11IvYIU sm7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:mime-version :content-transfer-encoding:content-language:accept-language :in-reply-to:message-id:date:thread-index:thread-topic:subject:cc:to :from:dkim-signature:dkim-filter; bh=1KdTgtYEN2dnWWW2liOHDQAROLy4THOQmqwXWvqVoBg=; fh=ATjfU8IIUJMRKS1BXjl/oCZ/z4wqJuaZwT8Kl1aPZcU=; b=mmWFCb5s251qP9jU+k4wc0pSoSDJPQw2Arz0ueUR07znubgLG4zfYBajV2yjmHoLik KmlOf5Sd3kDUNIbr6Meb44R0AoCdagcGeyahYw0rAMmuKo+7LJpiR28OcnRiU3QMvPpb hPZBWh4tw2P14/kSu4EGhCIGwu/pRx5kjNf/JaJESQAhZAZ9P+jSROv12MzlDzMHZxyN vaJX4mr+wUhpDEMEK6oC1050P9rDubXYzVB9D2pcTuJO2YwQTbE3adnVGvF2Lywj9v0V aa2Wwo7Yq78bwaaqsfxyqnWoEDwT4fBDWXbbpFDlFXrv9761bm8FFcEpjL38szZFcb1U 3JGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=SUcbDIYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z128-20020a633386000000b005bd641c3614si379337pgz.769.2023.11.03.17.58.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 17:58:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=SUcbDIYm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A1D5980260F7; Fri, 3 Nov 2023 17:58:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231618AbjKDA6E (ORCPT + 34 others); Fri, 3 Nov 2023 20:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjKDA6B (ORCPT ); Fri, 3 Nov 2023 20:58:01 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A10BE3 for ; Fri, 3 Nov 2023 17:57:57 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231104005754euoutp012e60a1bedd4d484c750e76b220e5ec87~URZb1op5z1873918739euoutp01M for ; Sat, 4 Nov 2023 00:57:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231104005754euoutp012e60a1bedd4d484c750e76b220e5ec87~URZb1op5z1873918739euoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1699059474; bh=1KdTgtYEN2dnWWW2liOHDQAROLy4THOQmqwXWvqVoBg=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=SUcbDIYmLUZfmeHpoem3N3WYTH3mXMqK5IK/fsr3MMdJT3b0JEfCVpXuWEjHz21wV C4vvMk2RkInPUV8lBUPXAGXtOGs2gA4EbqF1DEakX9N7AxvQykm0xPj2OAfJFTmKki KYIGCFooSRYP2Sbz0jjVLKSLtDF++5xPjvj4wvxY= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20231104005753eucas1p1a92a433419ced42881862ba7643d303d~URZbdRkCt2722627226eucas1p1O; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 0F.9E.42423.11795456; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231104005753eucas1p19e4ec0196f5ea297f59fb86b2a648b53~URZbHLER31996619966eucas1p1p; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231104005753eusmtrp297c5d7c9860fb6d646e7d3309512a88f~URZbGq1Ei0448904489eusmtrp2t; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) X-AuditID: cbfec7f2-a51ff7000002a5b7-38-65459711785b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 31.08.25043.11795456; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231104005753eusmtip1cddf8a9bfb0b96b110e142adafaad76f~URZa8Fzl61908919089eusmtip1Q; Sat, 4 Nov 2023 00:57:53 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 4 Nov 2023 00:57:51 +0000 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Sat, 4 Nov 2023 00:57:51 +0000 From: Daniel Gomez To: "willy@infradead.org" CC: "gost.dev@samsung.com" , "linux-kernel@vger.kernel.org" , Pankaj Raghav , "mcgrof@kernel.org" , Daniel Gomez Subject: [PATCH 1/2] test_xarray: add tests for advanced multi-index use Thread-Topic: [PATCH 1/2] test_xarray: add tests for advanced multi-index use Thread-Index: AQHaDrnvyiy7tu6TLES21e0ZuAEgHQ== Date: Sat, 4 Nov 2023 00:57:50 +0000 Message-ID: <20231104005747.1389762-2-da.gomez@samsung.com> In-Reply-To: <20231104005747.1389762-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [106.110.32.103] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42LZduznOV3B6a6pBrdvK1pc3jWHzeLGhKeM Fr9/zGFzYPbYvELLY9OqTjaPz5vkApijuGxSUnMyy1KL9O0SuDL+729hL3irXrHoylHWBsb5 Cl2MnBwSAiYSn0/OYu1i5OIQEljBKLG1cSozhPOFUeLJxcdMEM5nRomFP28ww7Q83j2NDcQW ElgO1HJOCa5o4915UO2nGSUO3D+DMHja1Olg7WwCmhL7Tm5iB7FFBPQlVl46ywhSxCzwilHi 3dGJLCAJYQEPiS37z7NBFPlLTNz6iBXC1pP40H4XrIZFQEXiwYS1YHFeAWuJ5sUPmUBsTgEb iT2r14MtYBSQlXi08heYzSwgLnHryXwmiB8EJRbN3gP1j5jEv10P2SBsHYmz158wQtgGEluX 7mOBsJUk/nQsZISYoydxY+oUNghbW2LZwtfMEDcISpyc+YQF5BkJgcmcEruubGGFaHaRWPV5 CdRQYYlXx7ewQ9gyEv93zmeawKg9C8l9s5DsmIVkxywkOxYwsqxiFE8tLc5NTy02zEst1ytO zC0uzUvXS87P3cQITCin/x3/tINx7quPeocYmTgYDzFKcDArifA6erukCvGmJFZWpRblxxeV 5qQWH2KU5mBREudVTZFPFRJITyxJzU5NLUgtgskycXBKNTCFXeWstH7uut7l6xyLr1UTmXfV 2Fx97bvT5P6NWY4eMb/fftAICb/d5/zvY9TJryzZWquOM17qzFgkPGGK6CGF/9fNk1UE5Sy/ HVSpPX1rSfYEddtEhWcG03Z+lJB+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pr9u6a2vl4hd/lLleaFY6Hvvu3fc2Fugcux6cvEeXMba6ebfbNvs66x28Do7m+ju+Gh 0dp/PMJ5t62VzF5OvFgscTwh735X9YuTPb6reRlu6l3tuSM4MfPfxAkih43tXSb5v/5lLJP5 7cNGJ59NtSkR0yR8tB435Mn9uf4kmsfdJK5dp/nFKcnEb7lHf7dI/WD4NS+da35BEy/D1i1M P2sXmHT63bQ9ksZowqQoe1nCjfdaA5dffnC89A2duu75F57wWwcsOHuf/VXHTtc/3gcslViK MxINtZiLihMBl6/+0JMDAAA= X-CMS-MailID: 20231104005753eucas1p19e4ec0196f5ea297f59fb86b2a648b53 X-Msg-Generator: CA X-RootMTR: 20231104005753eucas1p19e4ec0196f5ea297f59fb86b2a648b53 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231104005753eucas1p19e4ec0196f5ea297f59fb86b2a648b53 References: <20231104005747.1389762-1-da.gomez@samsung.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 17:58:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781592999967022965 X-GMAIL-MSGID: 1781592999967022965 From: 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. Signed-off-by: Luis Chamberlain Tested-by: Daniel Gomez --- lib/test_xarray.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index e77d4856442c..0572a3ec2cf8 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -674,6 +674,139 @@ static noinline void check_multi_store(struct xarray *xa) #endif } +#ifdef CONFIG_XARRAY_MULTI +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); + + 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)); +} + +static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + unsigned int nrpages = 1UL << order; + unsigned long base = round_down(index, nrpages); + XA_STATE(xas, xa, base); + + xas_set_order(&xas, base, order); + xas_store(&xas, NULL); + xas_init_marks(&xas); +} + +static unsigned long some_val = 0xdeadbeef; +static unsigned long some_val_2 = 0xdeaddead; + +/* mimics the page cache */ +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, xa_load(xa, base + i) != &some_val); + + XA_BUG_ON(xa, xa_load(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, xa_load(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, xa_load(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, xa_load(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_index + i) != &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(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, xa_load(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(xa, next_index + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, xa_load(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 +1937,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);