Article View: linux.kernel.git
Article #4184Re: [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time
From: Kaartic Sivaraam
Date: Tue, 01 Dec 2026 08:47
Date: Tue, 01 Dec 2026 08:47
134 lines
15981 bytes
15981 bytes
On 12/1/26 12:52, Patrick Steinhardt wrote:
>> +
>> +acquire_expensive_lock_ () {
>> + local owner waited= tmp="$expensive_lock_.$$" misses=0
>> + mkdir -p "$TEST_RESULTS_DIR" ||
>> + { expensive_lock_unavailable_; return 0; }
>> + # The lock is a hard link to a file that already holds our PID, so
>> + # it never exists without its owner recorded in it. Remove any
>> + # $tmp left by a dead process with our PID first: it may still be
>> + # linked to that process's lock, which writing to it would empty.
>> + rm -f "$tmp"
>
> Nit: it is expected that in most cases this won't do anything, so in the
> expected common case we'll see an error message. Do we want to silence
> this?
>
I guess that was mostly done to keep things consistent as we pretty much
silence everything in this function. So, I tend to prefer keeping the
'-f' on this one too.
>> + echo $$ >"$tmp" ||
>> + { expensive_lock_unavailable_; return 0; }
>
> Nit: It would have been nice to maybe have empty lines in this function
> to make it easier to follow. Right now the reader is presented one huge
> chunk, and they have to figure out by themselves what the logical blocks
> are.
>
Indeed. This is a good one. I've tried to improve things by throwing
newlines in places where it seemed logically better to place them.
>> + while ! ln "$tmp" "$expensive_lock_" 2>/dev/null
>> + do
>> + if ! test -f "$expensive_lock_"
>> + then
>> + # Nobody holds the lock, yet we cannot create it (no
>> + # hard links, disk full, ...). Retry in case it was
>> + # just released, then run anyway rather than wait
>> + # forever.
>> + misses=$((misses + 1))
>> + test $misses -lt 3 && continue
>> + expensive_lock_unavailable_
>> + return 0
>> + fi
>
> I was first thinking that this would trigger after three retries
> unconditionally, so essentially after three seconds. And that would have
> been overly aggressive, as we should expect that expensive tests run
> more than 3 seconds.
>
> But this is only detecting the case where we fail to create the lock due
> to whatever reason. So it's a rather uncommon case.
>
Yep. We won't be retrying when the lock already exists. The comment
should've conveyed this. If you think we could improve it in someway, do
let me know.
>> + misses=0
>> + owner=$(cat "$expensive_lock_" 2>/dev/null)
>> + # A lock carrying our own PID was left by a dead holder whose
>> + # PID we were given again; we know we do not hold it.
>> + if test -n "$owner" &&
>> + { test "$owner" = $$ || ! kill -0 "$owner" 2>/dev/null; }
>> + then
>> + # The holder was killed without releasing the lock.
>> + #
>> + # Another waiter may have taken it over since we
>> + # looked, so only remove it if it is still the same.
>> + if test "$(cat "$expensive_lock_" 2>/dev/null)" = "$owner"
>> + then
>> + rm -f "$expensive_lock_"
>> + fi
>
> I feel like re-checking the lock owner is kind of pointless here. The
> check doesn't fix the race, but it suggests it to the reader. And that
> is overall fine, because the intent now is to fail in a way that we
> prefer to run the test instead of blocking forever.
>
> But it raises the question why we even bother to check again. To me it
> only causes puzzlement.
>
The re-check is present in order to prevent a specific race scenario
pointed out by Junio:
> * T1 holds $expensive_lock_, finishes its last EXPENSIVE test,
> calls release_expensive_lock_ (rm -rf "$expensive_lock_"), and
> exits.
>
> * Waiter T2 read owner=$(cat "$expensive_lock_/pid" 2>/dev/null)
> (obtaining T1's PID) just before T1 removed the directory.
>
> * Waiter T3 runs mkdir "$expensive_lock_", succeeds, writes T3's
> PID to pid, and begins its EXPENSIVE test.
>
> * T2 now checks test -n "$owner" && ! kill -0 "$owner" 2>/dev/null
> against T1's exited PID, finds that T1 is gone, runs rm -rf
> "$expensive_lock_", which deletes T3's active lock. It loops,
> succeeds on mkdir "$expensive_lock_", and runs its EXPENSIVE test
> concurrently with T3.
It talks about the variant that created directories but it applies for
the current linking variant also.
If we could improve the comment above the relevant code in someway, do
let me know. It tries to convey it but I unfortunately couldn't get what
detail it is missing.
>> @@ -1115,6 +1197,7 @@ test_run_ () {
>> test_eval_ "$test_cleanup"
>> teardown_malloc_check
>> fi
>> + release_expensive_lock_
>
> In the other block where we call this function we have this one:
>
>> + release_expensive_lock_
>> + test -z "$expensive_lock_" || rm -f "$expensive_lock_.$$"
>
> And as far as I can see, `release_expensive_lock_` does not also prune
> the PID-file. Do we have to do that here?
>
We ideally reach this only after a normal flow of
acquire_expensive_lock_. We do have 'rm -r "$tmp"' at the end of it
which is intended to do exactly that. So, I think it is not necessary here.
--
Sivaraam
Technical Details
Message-ID:
<17e17015-53a8-4887-9891-7a7f2f16ea6c@gmail.com>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76757-linux-kernel-git=dewy.ruReferences:
<20261128-ks-ci-long-test-hang-fix-v4-0-f117badd2e13@gmail.com> <20261128-ks-ci-long-test-hang-fix-v4-1-f117badd2e13@gmail.com> <aw51wkqQQ8kgXkzI@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76757-linux-kernel-git=dewy.ru
From: kaartic.sivaraam@gmail.com (Kaartic Sivaraam)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time
Date: Tue, 1 Dec 2026 14:17:48 +0530
Organization: Usenet Network
Message-ID: <17e17015-53a8-4887-9891-7a7f2f16ea6c@gmail.com>
References: <20261128-ks-ci-long-test-hang-fix-v4-0-f117badd2e13@gmail.com>
<20261128-ks-ci-long-test-hang-fix-v4-1-f117badd2e13@gmail.com>
<aw51wkqQQ8kgXkzI@pks.im>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="1663891"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YhwVWhucrnmpsrrlp2kccZBLx9U= sha256:DxwJeWo1J2gAJvMAr/d/szsELNYI7ljele+OMMAEQJY=
sha1:CNOs/zHqU9baml2s7MxLwglPY6g= sha256:1p+aHnSe9/vPUT4I5KqxLXmewGtgbAYH1j37I3cZzNU=
Content-Language: en-US
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 820741172D3; Tue, 1 Dec 2026 11:48:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id py1GsQgE7FVp;
Tue, 1 Dec 2026 11:48:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76757-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 25FB011729A; Tue, 1 Dec 2026 11:47:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 3E8032D7EF; Tue, 1 Dec 2026 08:47:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796114873;
b=VxMn17Z+JfCoh9Dl8IW0Rc0GdgUgnHywwqkZsgDqogramV3BfcMd11r7q/vbtaaD1peg
NKOoRNB6D8Z1OxBYSbih8ABPWm7OM1x+Ma+FlW3IDynA4jMEkCC58bMOwq/3PNfU+vLlw
ZOvLOWms6pJ3iAVsYVFPN/38oE1WcpFDaplf+WceV3VYBUceKmLBdTPfaZeFWTqtqQ/OX
kx1E6CrqKLnrNh5dQKJcErjmK+JDKjjfX/L0NzsV5iP7MK+loF74+jMMhFS7i3jXNzOr8
gVoQViIe7/2eiRaTqYqRH6odlKROPnuWj9ZRgpP8GyjKlQ3yoYfVg0GM1D+/ysZFeJg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796114873;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To:
Content-Type:Content-Transfer-Encoding;
bh=UuEhFmJ3Gtl8Sf0ao/PAhx6Luox7aQsF8U/X+ZaWg7M=;
b=WZEcvaKiCKWFczOkKEzbldusgIP35dT4/6/PoqkkO44mDRiPBrBkTt8M7LEFUJ8SM2qD
++eqYKq1/2lz0F5pDBsmVpmYmsPjmb3RVUl6lzKLrqZqYdHDg2EsyqK1RFo/gJxiiuhAu
FFljKCuI2ZuD8uYDlNwGpzuBKmvdpKB1X6ZBC2D7Ygc4ES1wpG9XENKFFw18ahlop9Qdj
FlD5oEBQr4MzQinb9pq7/dHScltuCaJjmqrTHPVEGTdiIh6wcIxbxRBOaW20AfPkoCkVY
ZdQjxqJt3+t9Hgn8TK2FlZa6zV3MG3p7JWftZu6Hg4ghy5ayp5+4q9B0A6YlIL79ZNg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rk4k8ZwV;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ADCE606A334;
Tue, 1 Dec 2026 08:47:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rk4k8ZwV
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.170
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796114872;
b=Z4QyqQ0CjceG+iqp75B4f6UPAeKiFZVcg8d6GoVP3n3Ojdfd070VoRLV1d57Z/Lb5sk6
RsNfmT4tbdzb5KlMFBSvJgslo3ALB2TyJZv6CNFGeIIqNhToweyIHvSpRUXnmLY3ywt93
yFKr7dWVBBL42PxgRAnLPN8JteFEv2LV8LJkcJPPh6MkVTcva0CJ521qejiTNEwpuH950
PwzaubWhb37foZGO9dN6yGB8qywKSni5VlIZrT83DLRIu27P2VvHfLVYJhrRn5ofDetvW
7BUgNuRBfxKjMuHTEJZ2ZMoUMwQlRPUyEZSb5wRoQ6B4Yx4+TeC2QuO8AxnAcFPf8gQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796114872;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-ID:Date:
MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language:
From:In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=UuEhFmJ3Gtl8Sf0ao/PAhx6Luox7aQsF8U/X+ZaWg7M=;
b=nDxnU+gWB1PBtQH6sBmyPbOIv+7+Yqq2T2EeYJsok9L/IAx5P4NSXI9vNrHGAfy4b/HS
3QCpaW5d5AIYpe60TZ5hlvs1fE9yZTRQngMP7l+/m3u8fQRUJF1eM+1IhfKy3mNNSn7aG
wxIb3ZMZRJAcrlC9JdYymD7Nt3CnXB2qCvdmZ6qoLZxCRNaE1RxyYq1n+mDA+8DKylz4d
dge7JLtLog6ikf41V2k/EQfrF6IaATch5Ttfo8X5+WbNDGWN7+r/WnvmorfpKJYC4BPuS
N2Ce5E3BDc9Br/l7DK3Kf2UFfPCl/2QbM+mShvMQKC3d4tCiaEAO76J4D9KQdYxmImw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rk4k8ZwV;
arc=none smtp.remote-ip=209.85.214.170
X-Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BAC5606A32A
for <git@vger.kernel.org>; Tue, 1 Dec 2026 08:47:51 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0BAC5606A32A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2f03920c4a0so70127375ad.3
for <git@vger.kernel.org>; Tue, 01 Dec 2026 00:47:51 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796114871; x=1796719671; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:cc:to:subject:user-agent:mime-version
:date:message-id:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=UuEhFmJ3Gtl8Sf0ao/PAhx6Luox7aQsF8U/X+ZaWg7M=;
b=rk4k8ZwVGunEoJpPk4maT0LurSXMUbhwEgPe9p3U+6ntXc2KeTETSZbnuURcF28P4O
HWz512XTqC/BLKj1w9ta6jthZIpYQzavzH0T2EMuFgezl27SPLFHQGZ/LgLeObw+3oi3
hm66jcriO/Taxh17iBh7I4J6PAUSTr+dfxJK2taZImtL9KU9+xBvfhxWdATbDAYkSuED
E6zsltj1cgfrLblS+Ajw7H+xIxFRb3tcWH+KF6yYwJpDaZNKv1RgO/Oi+/mk28EUfitd
YA+zYLx0OQms8AsNsU/85Cry2veYhbaJj5kKJqMtDu2002Drg7YeGrTqqZKaKtIp8nb+
FekA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796114871; x=1796719671;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:cc:to:subject:user-agent:mime-version
:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=UuEhFmJ3Gtl8Sf0ao/PAhx6Luox7aQsF8U/X+ZaWg7M=;
b=NHZsfhFZjBsXZoMrBFh4bJtPMKy2i0rB6BKShQGqnqVyDqkGMUNcnbzYSDCKhwnafS
5LFhAZ2YG+qpeMAvQ7HIF26Hb7XRiCHoO9+eDeRFpwwNZy2ZFJetrJ9FULCuNxGGnLGC
Wg3lll4uVmvZyOC9xludVmMY63Wl+0VSGgW8dWuLBQlnC40KdY7ooSCHvDkLez94PVsV
DdAvku+NGugpmN8uQJTh7zci6OkVwhB/SfgbXghwktWlOGudQiYI69VMuBzhUBGYSfMQ
QlM7K7NQ7uE7qI6PcPcP+lUYA/SDP7rpruayvP3bEv/4CBCkirj4Bwzzng1zQ5I3ObKQ
f/2g==
X-Gm-Message-State: APuU4Z+wjLdruClOpxyAcGAgU3dbZmCSQeym1woKozJLKSkwrubuCKU1
JfIQeUP3oT8tEhWRDNbLANOyaBUa5rVOafMIwUT4SgarDvEK4Mq9G0ET9BgY6A==
X-Gm-Gg: AZFdTZeeqJaqYP3XtKne14Bmd2Vw5s2I+OSjJq9JtvTAV7QwpZofc5bwrYnnJiwrj5W
2DKpd1JVIZI87T1aqQchaqAIl/q9M/pPaNhFeo/k34mCHHcKVBq/zFQ/qSUTJ6Hou9c9QAxu7o/
fThul7JgT0/DOBimDqlikSkLaSeiJGYmY3ts6AEqCzk+dH19fs395oAhG0Rwlvy62BYBN0zWE8n
ZkaLS0FuVLsqaOWXh+5aiRgsbPI/dHViWFmFuQSHT60h+/dwzRsKcDqESu32Kr/CU2VTxBMedvt
YbAQDhh5EWwSaBI12E/of9IgRkr5zz4dS6MDW0K96PtEPfC9hCTppQk3F3LNCEI1HbfGUP/eeRP
Bq+SsfjemvPSgqTnEEsBPBwsdAajF7y4EuBSbxB66W2SfMzp37bF5j0+MgcUvI2dwln9U3PSxX0
h+OlQeWuDa9rYE0MmJGxDMWDVkL9DF6nejejyrjP5qGarMI/gDwSK3hw8A/W/6m8Qm6b0M8R4xI
CW0y0OvfAxa8eU3LjjZvQ2qIYvmYvDy3YZ38ktjNgAyJfsLSIQ//CPufrqY8ADZJc/vuQk5O5l/
zVSal4K3khah3zt+ztRmHYRep8NqCfDTqnrQFVjjBrxhBcczQwHPKdTRoKMWznA=
X-Received: by 2002:a17:903:98b:b0:2ed:1df2:8b35 with SMTP id d9443c01a7336-2f03f1b8105mr425399715ad.37.1796114871037;
Tue, 01 Dec 2026 00:47:51 -0800 (PST)
X-Received: from [192.168.1.34] ([103.215.237.185])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f147a9esm177991915ad.72.2026.12.01.00.47.49
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Tue, 01 Dec 2026 00:47:50 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Git mailing list <git@vger.kernel.org>,
Harald Nordgren <haraldnordgren@gmail.com>,
Junio C Hamano <gitster@pobox.com>
X-In-Reply-To: <aw51wkqQQ8kgXkzI@pks.im>