Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4275695img; Tue, 26 Mar 2019 06:31:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrwCta9MUbSbw7oxoq08PR/xQ8S6/3r8M2TsdKWeeM6lPBTkpEYQFAn4g717LgjJCzkeOn X-Received: by 2002:a63:530e:: with SMTP id h14mr4596806pgb.136.1553607067430; Tue, 26 Mar 2019 06:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553607067; cv=none; d=google.com; s=arc-20160816; b=uJgNIWeroswcmVAr9Ouf3tRI+ooT0RkfBl71twMC6MsoLRLsHb71jt0fRzY9A9thTT wOIzvFZUA1UOOv6y9z38E8mFcJV0CpaYuXUHcQ8lcRGzb1WBo5sJIvW3FSd5OVUJVnCu OY448sHXYCjP+E5LaNCsHS1hg6wm5ausyi/hMCgK3AsA6WJus4cniWHvIUW/7rZvy6L2 3fwIYfmBi5mDwoIHu8tQBSnJSM49zfhvU/T+Z3p33GE8Zo/acNgZqqXoDjgICsp4lTev adMyhh7iX9adSOQl5WiIjnBySmqTypq+2pxCgIVo0/fkvAWhqu6QRDfrGLkHM/1b9fxk 0Y7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=BaXjoPbnVGZvaRr5WlEoqLpuml+embjigfKBi8GHrUI=; b=IsmvjyAfgmXDjrw4z8ceHGTVYmvF+qO7HWyJKfq/fgraDlyuOAIqcHDm+Dw7maIVLR whFYBw3u9bV6CXnzPLf2di3Kdh+hTJTc3uKK8YNSr7t8LzUf/ozZNeE9z77SG4s/fa22 HkFRsYJlqRQ8xdUVhKr/bRa9iInhuSvAkrjvot0c7KxAQeQQEzxNdwnvDe04D8CokXk9 4yPbhpJgaAW1OzP43YWwZ5fLVcztnAJfjsLtEdghPJhfRD2H4FF7QQjKUHeGAhUKmn0Y v6qKqa9c+f1RWjjRRjZOnQQFwbtFgPtM2Uj3Oyrn+W/WA17B2yhCqZk9PU7M7ikR4Hhc V+0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v47si2752974pgn.117.2019.03.26.06.30.51; Tue, 26 Mar 2019 06:31:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727492AbfCZNaP (ORCPT + 99 others); Tue, 26 Mar 2019 09:30:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59924 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfCZNaP (ORCPT ); Tue, 26 Mar 2019 09:30:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CD7383F4C; Tue, 26 Mar 2019 13:30:04 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.68]) by smtp.corp.redhat.com (Postfix) with SMTP id 68DF53843; Tue, 26 Mar 2019 13:29:57 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 26 Mar 2019 14:30:02 +0100 (CET) Date: Tue, 26 Mar 2019 14:29:55 +0100 From: Oleg Nesterov To: Christopher Lameter Cc: Waiman Long , Matthew Wilcox , Andrew Morton , Pekka Enberg , David Rientjes , Joonsoo Kim , linux-kernel@vger.kernel.org, linux-mm@kvack.org, selinux@vger.kernel.org, Paul Moore , Stephen Smalley , Eric Paris , "Peter Zijlstra (Intel)" Subject: Re: [PATCH 2/4] signal: Make flush_sigqueue() use free_q to release memory Message-ID: <20190326132955.GA16837@redhat.com> References: <20190321214512.11524-1-longman@redhat.com> <20190321214512.11524-3-longman@redhat.com> <20190322015208.GD19508@bombadil.infradead.org> <20190322111642.GA28876@redhat.com> <01000169a686689d-bc18fecd-95e1-4b3e-8cd5-dad1b1c570cc-000000@email.amazonses.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01000169a686689d-bc18fecd-95e1-4b3e-8cd5-dad1b1c570cc-000000@email.amazonses.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 26 Mar 2019 13:30:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry, I am sick and can't work, hopefully I'll return tomorrow. On 03/22, Christopher Lameter wrote: > > On Fri, 22 Mar 2019, Waiman Long wrote: > > > I am looking forward to it. > > There is also alrady rcu being used in these paths. kfree_rcu() would not > be enough? It is an estalished mechanism that is mature and well > understood. But why do we want to increase the number of rcu callbacks in flight? For the moment, lets discuss the exiting tasks only. The only reason why flush_sigqueue(&tsk->pending) needs spin_lock_irq() is the race with release_posix_timer()->sigqueue_free() from another thread which can remove a SIGQUEUE_PREALLOC'ed sigqueue from list. With the simple patch below flush_sigqueue() can be called lockless with irqs enabled. However, this change is not enough, we need to do something similar with do_sigaction()->flush_sigqueue_mask(), and this is less simple. So I won't really argue with kfree_rcu() but I am not sure this is the best option. Oleg. --- a/kernel/exit.c +++ b/kernel/exit.c @@ -85,6 +85,17 @@ static void __unhash_process(struct task_struct *p, bool group_dead) list_del_rcu(&p->thread_node); } +// Rename me and move into signal.c +void remove_prealloced(struct sigpending *queue) +{ + struct sigqueue *q, *t; + + list_for_each_entry_safe(q, t, &queue->list, list) { + if (q->flags & SIGQUEUE_PREALLOC) + list_del_init(&q->list); + } +} + /* * This function expects the tasklist_lock write-locked. */ @@ -160,16 +171,15 @@ static void __exit_signal(struct task_struct *tsk) * Do this under ->siglock, we can race with another thread * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals. */ - flush_sigqueue(&tsk->pending); + if (!group_dead) + remove_prealloced(&tsk->pending); tsk->sighand = NULL; spin_unlock(&sighand->siglock); __cleanup_sighand(sighand); clear_tsk_thread_flag(tsk, TIF_SIGPENDING); - if (group_dead) { - flush_sigqueue(&sig->shared_pending); + if (group_dead) tty_kref_put(tty); - } } static void delayed_put_task_struct(struct rcu_head *rhp) @@ -221,6 +231,11 @@ void release_task(struct task_struct *p) write_unlock_irq(&tasklist_lock); cgroup_release(p); release_thread(p); + + flush_sigqueue(&p->pending); + if (thread_group_leader(p)) + flush_sigqueue(&p->signal->shared_pending); + call_rcu(&p->rcu, delayed_put_task_struct); p = leader;