Re: Bug#1141670: util-linux: very slow code and undefined behaviour in handle_interrupt

Dirk Gouders <[email protected]> Sun, 12 Jul 2026 11:02:12 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
Hi Chris,

On Sat, Jul 11 2026, Chris Hofstaedtler wrote:

> the following was reported to Debian, regarding the hardlink
> utility. It appears to be an upstream issue. Maybe someone can look at
> it. CC:ing =D0=BD=D0=B0=D0=B1 who seems to have touched the relevant func=
tion last.

it seems, this regression was fixed with:

87831fa19 (hardlink: fix performance regression (inefficient signal evaluat=
ion), 2025-04-29)

The commit message says it improved performance by factor ten.

Regards,

Dirk

> * Marc Lehmann <[email protected]> [260708 07:23]:
>>Version: 2.41-5
>>
>>Dear Maintainer,
>>
>>while strace'ing to find out why hardlink is so slow, IO found it does th=
is sequence between every fstatat call:
>>
>>   gettid()                                =3D 36482
>>   getpid()                                =3D 36482
>>   tgkill(36482, 36482, 0)                 =3D 0
>>
>>this seems to be a pretty weird thing to do in a tighht scanning
>>loop. Looking at the code, handle_interrupt is responsible:
>>
>>   /**
>>    * handle_interrupt - Handle a signal
>>    */
>>   static void handle_interrupt(void)
>>   {
>>           switch (last_signal) {
>>           case SIGUSR1:
>>                   print_stats();
>>                   putchar('\n');
>>                   break;
>>           default:
>>                   signal(last_signal, SIG_DFL);
>>                   raise(last_signal);
>>                   break;
>>           }
>>           last_signal =3D 0;
>>   }
>>
>>this is already a weird function to begin with, but crucially, it calls s=
ignal(0,... and raise(0).
>>
>>it seems to me the former is likely undefined behaviour and the latter is
>>just unnecessartily slow.
>>
>>most likely, handle_interrupt simply should not be called after every fst=
atat, or at all, without last_signal bering set beforehand.
>>