Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F72FC05027 for ; Mon, 23 Jan 2023 17:25:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233696AbjAWRZo (ORCPT ); Mon, 23 Jan 2023 12:25:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233671AbjAWRZg (ORCPT ); Mon, 23 Jan 2023 12:25:36 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14182D56 for ; Mon, 23 Jan 2023 09:24:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674494693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AcpFGZVBAo+PLeHItLT4fyc3ui85dDV8jEYUiDgoSi4=; b=Zpq7bnN9tLi9X7iBmQJXQf6EOVZ2csb2GVHNXKKw0iPzGtPgBynYtqV778GTrCi0BT3bth mqFVWt8hJuqmBU0W+5KPr5IXHBlN3B43IhzxrmeccqPV3r2SB2gUVSUPAZaZ5tj1WBISSn rgGhBsjU139rh4qFMCvkj7TSWstxO2Q= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-102-WoVL2F5LPw6gGfNJm4I8uw-1; Mon, 23 Jan 2023 12:24:52 -0500 X-MC-Unique: WoVL2F5LPw6gGfNJm4I8uw-1 Received: by mail-pj1-f70.google.com with SMTP id s22-20020a17090aad9600b002271d094c82so9727907pjq.7 for ; Mon, 23 Jan 2023 09:24:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AcpFGZVBAo+PLeHItLT4fyc3ui85dDV8jEYUiDgoSi4=; b=3LY5xIRn29UYlIT8FCip0z7YWFTw87hNQzVpmkRSiuiH8wiZMQY5FCTVZfsqMtzkyu cWIhmx6eQhkSwTQkQAnfkbGiwY2GuGeoi5TGVFhvAdFQ1kVomuVryTG0Va1rVukoEn4H urq1JrWXNwcCSr5YsUwym3tE3NMjvrKEUdrp2bo22vothCWCTrzRofES6TptchX1zrQG bbqPnVRhL8ZCIwGp1G/72huzV7w14BR7pZMm0znIUAdLmzdn3GwB+BuaBc/1mTxxNV0P 2aCC6EhHShS96iY3iqfXrtTCbM0W39Txxz9fgGY/kmwVi0tQgF9AnNuCjBOcTkT3+EQ8 BjWQ== X-Gm-Message-State: AFqh2kpJJLpticI5I2Ry/RIxI6y5RqOo6MtoOs4o2SyKjOnzbvSkL/eq dL/Tv/4YRhz4CxtsKrhPLC0Ib6buAjAVjbOM9oVdoWYKI5Vmaf9fZqZqfkPq8x3bHPYUUhKzsR/ 1bgprCudNk2+pxSMBLoOkCqCxNvn4ze6Ttr7Xnwn+ X-Received: by 2002:a17:90a:aa0c:b0:229:f43b:507c with SMTP id k12-20020a17090aaa0c00b00229f43b507cmr1582385pjq.127.1674494691385; Mon, 23 Jan 2023 09:24:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDRqhRgXcaJRzBO7+GDJQsqYOFaFrwA91SBnHxbGrGW9iV0z2YJEeEfJj6bK+oBulZRG7jt7H2IFSUX/A3aL8= X-Received: by 2002:a17:90a:aa0c:b0:229:f43b:507c with SMTP id k12-20020a17090aaa0c00b00229f43b507cmr1582367pjq.127.1674494691144; Mon, 23 Jan 2023 09:24:51 -0800 (PST) MIME-Version: 1.0 References: <20230120150246.20797-1-wander@redhat.com> <20230120150246.20797-2-wander@redhat.com> <20230123163002.GB6268@redhat.com> In-Reply-To: <20230123163002.GB6268@redhat.com> From: Wander Lairson Costa Date: Mon, 23 Jan 2023 14:24:40 -0300 Message-ID: Subject: Re: [PATCH v2 1/4] sched/task: Add the put_task_struct_atomic_safe function To: Oleg Nesterov Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , "Eric W. Biederman" , Stafford Horne , Kefeng Wang , Andrew Morton , Thomas Gleixner , Sebastian Andrzej Siewior , Andy Lutomirski , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , open list , Paul McKenney Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 23, 2023 at 1:30 PM Oleg Nesterov wrote: > > On 01/20, Wander Lairson Costa wrote: > > > > +static inline void put_task_struct_atomic_safe(struct task_struct *task) > > +{ > > + if (IS_ENABLED(CONFIG_PREEMPT_RT)) { > > + /* > > + * Decrement the refcount explicitly to avoid unnecessarily > > + * calling call_rcu. > > + */ > > + if (refcount_dec_and_test(&task->usage)) > > + /* > > + * under PREEMPT_RT, we can't call put_task_struct > > + * in atomic context because it will indirectly > > + * acquire sleeping locks. > > + */ > > + call_rcu(&task->rcu, __delayed_put_task_struct); > ^^^^^^^^^ > I am not sure the usage of task->rcu is safe... > > Suppose that, before __delayed_put_task_struct() is called by RCU, this task > does the last schedule and calls put_task_struct_rcu_user(). > > And, can't we simply turn put_task_struct() into something like > > put_task_struct(struct task_struct *t) > { > if (refcount_dec_and_test(&t->usage)) { > if (IS_ENABLED(CONFIG_PREEMPT_RT) > && (in_atomic() || irqs_disabled())) > call_rcu(...); > else > __put_task_struct(t); > } > } > > ? Yeah, that was one approach I thought about. I chose to use an explicit function because I assumed calling __put_task_struct() from a non-preemptable context should be the exception, not the rule. Therefore (if I am correct in my assumption), it would make sense for only some call sites to pay the overhead price for it. But this is just a guess, and I have no evidence to support my claim.