From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 495033858C83 for ; Wed, 11 Jan 2023 21:12:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 495033858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673471578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/u1Ht6vBNnZYj9ydDSSY8RuOkxatZujLP3+vrV3NB80=; b=BJLuYg5cMEg+4zX50fSKSdRqWvEwD8auIixiOEyIBbIeQYlvU0fvJuiIp//UJIcFSduM0M MpCbaiZxyaPRJSAku/Jz5fLLOxSfJGZghvANGjjrtQqu2PTlJLCc1lhDjum0K625H6jgfE cUSjdOyX5VU2G7KuPK8Oaz9AjxIdOkc= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-191-IF1MmcyTOKGrTkRiAh4hpw-1; Wed, 11 Jan 2023 16:12:58 -0500 X-MC-Unique: IF1MmcyTOKGrTkRiAh4hpw-1 Received: by mail-il1-f197.google.com with SMTP id h24-20020a056e021d9800b0030be8a5dd68so11849886ila.13 for ; Wed, 11 Jan 2023 13:12:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/u1Ht6vBNnZYj9ydDSSY8RuOkxatZujLP3+vrV3NB80=; b=hvgPDdzn0qTW5+E4XaoyXRwij2+MzNu6Pzhf6X5MwtlD1LMnCwzkGERa8BWCQQtHGg pbxAiStMjRSN+5KwnHEje/Gxd+JtfjsiqfHCuY/yE/TSRfllp+2I6J38122U9RU73JmV 6E5HOFUtZd2hzqrrss9LDfB07tL1X3SAo2SKBiz6p7CeNnXMw01xaUKx3zdo1e5REQEc ZNCmpPUsEvlob9iYADn/+HlPQZfl7KuE/6ll8buiXnLTiAT2lBA+SGW5QJz1NDLuwidX i2/MQR6fjchKmhVxK/BC/t5IGUDHtwT380b5wWIn6chZlaiWTA7BbaPyk6C7rgF4yIWg IO9Q== X-Gm-Message-State: AFqh2kpQeFzZiG/uvEfe8GpoxWhJgEBzwlYgnmBfDo8oQrGN6RfSPAvx 8oefP+UIKxugM27MthSIdJS+WpVl73OJ7nZV/zMGAGyO9KGPxPDQBdDRs+t14lkNyMFCs4RmsTD ZExRqisQ3x/dKyeQ+NmBy X-Received: by 2002:a05:6602:70b:b0:6e0:2763:48fa with SMTP id f11-20020a056602070b00b006e0276348famr49580175iox.1.1673471577092; Wed, 11 Jan 2023 13:12:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsrD53108De1ucT4dyDufotZarNdOiLe0NI/7jS3PxOOOq9JvnEfX8+6ca90McDYg6gyz+Rtg== X-Received: by 2002:a05:6602:70b:b0:6e0:2763:48fa with SMTP id f11-20020a056602070b00b006e0276348famr49580170iox.1.1673471576829; Wed, 11 Jan 2023 13:12:56 -0800 (PST) Received: from [192.168.0.241] (192-0-145-146.cpe.teksavvy.com. [192.0.145.146]) by smtp.gmail.com with ESMTPSA id e14-20020a056602044e00b006de16e510b5sm5343078iov.53.2023.01.11.13.12.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Jan 2023 13:12:56 -0800 (PST) Message-ID: <4b815c7f-613a-9a08-5036-e3ded8336405@redhat.com> Date: Wed, 11 Jan 2023 16:12:55 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v2 9/9] Linux: optimize clone3 internal usage To: Adhemerval Zanella , libc-alpha@sourceware.org, Christian Brauner References: <20220930192613.3491147-1-adhemerval.zanella@linaro.org> <20220930192613.3491147-10-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20220930192613.3491147-10-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 9/30/22 15:26, Adhemerval Zanella via Libc-alpha wrote: > Now that clone3 is used on more architectures, add an optimization > to avoid calling when glibc detects that it is no supported by the > kernel. It also adds __ASSUME_CLONE3, which allows skip this > optimization and issue clone3 syscall directly. Please post v3 with changes. Suggest: Add an optimization to avoid calling clone3 when glibc detects that there is no kernel support. It also adds __ASSUME_CLONE3, which allows skipping this optimization and issuing the clone3 syscall directly. > > It does not handle the the small window between 5.3 and 5.5 for > posix_spawn (CLONE_CLEAR_SIGHAND was added in 5.5). > > Checked on x86_64-linux-gnu. > --- > include/clone_internal.h | 5 +++++ > sysdeps/unix/sysv/linux/clone-internal.c | 24 ++++++++++++++++++++++- > sysdeps/unix/sysv/linux/kernel-features.h | 9 +++++++++ > 3 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/include/clone_internal.h b/include/clone_internal.h > index 320640e64b..385f3c5589 100644 > --- a/include/clone_internal.h > +++ b/include/clone_internal.h > @@ -7,6 +7,11 @@ extern __typeof (clone3) __clone3; > -1 with ENOSYS, fall back to clone or clone2. */ > extern int __clone_internal (struct clone_args *__cl_args, > int (*__func) (void *__arg), void *__arg); > +/* clone3 wrapper with a sticky check to avoid re-issue the syscall if > + it fails with ENOSYS. */ s/re-issue/re-issuing/g > +extern int __clone3_internal (struct clone_args *cl_args, > + int (*func) (void *args), void *arg) > + attribute_hidden; > /* The fallback code which calls clone/clone2 based on clone3 arguments. */ > extern int __clone_internal_fallback (struct clone_args *__cl_args, > int (*__func) (void *__arg), > diff --git a/sysdeps/unix/sysv/linux/clone-internal.c b/sysdeps/unix/sysv/linux/clone-internal.c > index 7bc991e033..39d76733db 100644 > --- a/sysdeps/unix/sysv/linux/clone-internal.c > +++ b/sysdeps/unix/sysv/linux/clone-internal.c > @@ -76,6 +76,28 @@ __clone_internal_fallback (struct clone_args *cl_args, > return ret; > } > > +int > +__clone3_internal (struct clone_args *cl_args, int (*func) (void *args), > + void *arg) > +{ > +#ifdef HAVE_CLONE3_WRAPPER > +# if __ASSUME_CLONE3 > + return __clone3 (cl_args, sizeof (*cl_args), func, arg); > +# else > + static int clone3_supported = 1; > + if (atomic_load_relaxed (&clone3_supported) == 1) > + { > + int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); > + if (ret != -1 || errno != ENOSYS) > + return ret; > + > + atomic_store_relaxed (&clone3_supported, 0); > + } > +# endif > +#endif > + __set_errno (ENOSYS); > + return -1; > +} > > int > __clone_internal (struct clone_args *cl_args, > @@ -83,7 +105,7 @@ __clone_internal (struct clone_args *cl_args, > { > #ifdef HAVE_CLONE3_WRAPPER > int saved_errno = errno; > - int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg); > + int ret = __clone3_internal (cl_args, func, arg); > if (ret != -1 || errno != ENOSYS) > return ret; > > diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h > index 74adc3956b..4ecd08a98f 100644 > --- a/sysdeps/unix/sysv/linux/kernel-features.h > +++ b/sysdeps/unix/sysv/linux/kernel-features.h > @@ -236,4 +236,13 @@ > # define __ASSUME_FUTEX_LOCK_PI2 0 > #endif > > +/* The clone3 system call was introduced across on most architectures in > + Linux 5.3. Not all ports implements it, so it should be used along > + HAVE_CLONE3_WRAPPER define. */ > +#if __LINUX_KERNEL_VERSION >= 0x050300 > +# define __ASSUME_CLONE3 1 > +#else > +# define __ASSUME_CLONE3 0 > +#endif > + > #endif /* kernel-features.h */ -- Cheers, Carlos.