Received: by 10.192.165.148 with SMTP id m20csp313758imm; Fri, 20 Apr 2018 07:13:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49py/GHxiujiKXHl0WsM+hFZZlWjIwwqj2vAwq7PwoirYW+9TmmFASkyk1uceEvmEn+SOvb X-Received: by 2002:a17:902:5389:: with SMTP id c9-v6mr757744pli.143.1524233588786; Fri, 20 Apr 2018 07:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524233588; cv=none; d=google.com; s=arc-20160816; b=f2TCc/GJqQ+NM1N2mtaPPse8VJNWhM0gydtW3NYhyN5WtpraYXuGsckhpuoW43vmhy km7bWuzjrD/krceLRATPS30O6+3bFJDxF1FOROIkmZpEN+crKRkFH4DaWlPA2rQafoGN Fp9VbcpAPC9MdFCh3NZb8ku9yYm/yJ6J6vT8S6pp8CqiiuCnbCCt8RjeWlVMmMNBeCOh DMPr1OVvN6j9/29X4+hgI57hTzk+vt79vdc6ZublyT9AgoV8lzKHm73+Abyg/1Jx+Vcn 7C/SuEIqBavwT53+rZZoGeOTYazfWTeh9FEbJfrJoqEUSQFiqfn8kXfHkvyxqd4ywJPj FCAg== 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:dkim-signature:arc-authentication-results; bh=+u2JQdcsnCEU0FsHPXsEdZLJD40sAfeVQNopvhllrR8=; b=Hz+Gp/Rbl05w7SoVCnLjjBvywoU9IDcbreVUwuiXmtVK6gZftiFozobdjKvFJTw+9d u1ZNuY9MJxJNdotTwTy+qzMWjX4oGY6rd2V5UNd7yTLJIEgJpqfrsqiX30VAlGhvTkpY sG9HLumNwI2dx+YmNpDp5XknvR7CgdTrRd8UiAmtr1/ANnBmLxwuiCvCCsvPlg+MLleC fmfc5dfeZj/lXlkQtkse0FzAfX/jQA/cV6+UNUMJSzl6NjlwpP2pC09kkfgWsXoyvzzB aUpZvnLXnIhyMweeRVmoigSjD/fRZRtcwoLAFq1f3PXHkUwVgNrxxtw6UmiRpdMcXy7g zoJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AATj1dt5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si5085549pgs.51.2018.04.20.07.12.54; Fri, 20 Apr 2018 07:13:08 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AATj1dt5; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755145AbeDTOLu (ORCPT + 99 others); Fri, 20 Apr 2018 10:11:50 -0400 Received: from mail-wr0-f182.google.com ([209.85.128.182]:42359 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754996AbeDTOLt (ORCPT ); Fri, 20 Apr 2018 10:11:49 -0400 Received: by mail-wr0-f182.google.com with SMTP id s18-v6so23396467wrg.9 for ; Fri, 20 Apr 2018 07:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+u2JQdcsnCEU0FsHPXsEdZLJD40sAfeVQNopvhllrR8=; b=AATj1dt5Fqqv33Ya8RW4PXBIOcD93CxaRDqvW7SOzFZEzo4W6dz8/L9N//uk+5P0Zz GIdmsoXS6EBu0EEEFNCLGuazEPHU6wRiPdRya/xVY7FhuLa76e+pSNHe1YVS+xCPxO4B vkdkZBoHgZWrvmeOxuce35ZRIKB2T5/a0BO24l4AWqQavoTpkz1ZaaLO53Hy2Jk6PmqP BOJQU12ZKFclyg90u/c/rIqISyEfsgbOkFXecjTCjnUhpR4odk08JgwvQECe1rEbnLKH c9rnFKq1x9A6o4DBsSvC59OwhNr0TdA7uCb8v6VVBoV8wq53QrNtN5hFp0v70IUGNgi7 rqVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+u2JQdcsnCEU0FsHPXsEdZLJD40sAfeVQNopvhllrR8=; b=aC4EhsZL5CRu1W9pk3WL86P8EmJh2S3xYLUDdyy9TsCrJQktKCP0XYt2LEA1W2Ihud kRUVgIGBj2gjOby5tob5X1PLC7x8PExeSlgmRQ5xhiSYypgpoj1mmLUOlNsH610/6xrW ylFg2AKiIpLooi3tP82tFoyKlV8XvaLSsFpbwCdiw2xhQ+AbwVmT6C8bKtiUUX8PBB/t DAILUaLx3cA+wtRVvXNn3FYC8hdejgaKvCis2RGOOZtUXo+IjQv1+fhBVOB4X/umIOot 56Ph9Ye+XxyEOaV8JFg0Khy1M0AvD2cCTsPUqr6KJOawVIIY+Po2mJoBcirFbp6jWMTm 6ypA== X-Gm-Message-State: ALQs6tD28Pifm0F7ehjeyBK96/7i7yBWQotjVa9IO/QIHiMaE+CY/jjd D8aqMOymi1uiaUWcrEtVzrs= X-Received: by 2002:adf:84e5:: with SMTP id 92-v6mr8559144wrg.46.1524233508011; Fri, 20 Apr 2018 07:11:48 -0700 (PDT) Received: from localhost.localdomain ([151.15.228.118]) by smtp.gmail.com with ESMTPSA id 11sm1803492wmr.16.2018.04.20.07.11.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Apr 2018 07:11:47 -0700 (PDT) Date: Fri, 20 Apr 2018 16:11:45 +0200 From: Juri Lelli To: Kirill Tkhai Cc: mingo@redhat.com, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched/rt: Rework for_each_process_thread() iterations in tg_has_rt_tasks() Message-ID: <20180420141145.GI24599@localhost.localdomain> References: <152415882713.2054.8734093066910722403.stgit@localhost.localdomain> <20180420092540.GG24599@localhost.localdomain> <0d7fbdab-b972-7f86-4090-b49f9315c868@virtuozzo.com> <854a5fb1-a9c1-023f-55ec-17fa14ad07d5@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <854a5fb1-a9c1-023f-55ec-17fa14ad07d5@virtuozzo.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/04/18 13:06, Kirill Tkhai wrote: > From: Kirill Tkhai > > tg_rt_schedulable() iterates over all child task groups, > while tg_has_rt_tasks() iterates over all linked tasks. > In case of systems with big number of tasks, this may > take a lot of time. > > I observed hard LOCKUP on machine with 20000+ processes > after write to "cpu.rt_period_us" of cpu cgroup with > 39 children. The problem occurred because of tasklist_lock > is held for a long time and other processes can't do fork(). > > PID: 1036268 TASK: ffff88766c310000 CPU: 36 COMMAND: "criu" > #0 [ffff887f7f408e48] crash_nmi_callback at ffffffff81050601 > #1 [ffff887f7f408e58] nmi_handle at ffffffff816e0cc7 > #2 [ffff887f7f408eb0] do_nmi at ffffffff816e0fb0 > #3 [ffff887f7f408ef0] end_repeat_nmi at ffffffff816e00b9 > [exception RIP: tg_rt_schedulable+463] > RIP: ffffffff810bf49f RSP: ffff886537ad7d50 RFLAGS: 00000202 > RAX: 0000000000000000 RBX: 000000003b9aca00 RCX: ffff883e9cb4b1b0 > RDX: ffff887d0be43608 RSI: ffff886537ad7dd8 RDI: ffff8840a6ad0000 > RBP: ffff886537ad7d68 R8: ffff887d0be431b0 R9: 00000000000e7ef0 > R10: ffff88164fc39400 R11: 0000000000023380 R12: ffffffff81ef8d00 > R13: ffffffff810bea40 R14: 0000000000000000 R15: ffff8840a6ad0000 > ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 > --- --- > #4 [ffff886537ad7d50] tg_rt_schedulable at ffffffff810bf49f > #5 [ffff886537ad7d70] walk_tg_tree_from at ffffffff810c6c91 > #6 [ffff886537ad7dc0] tg_set_rt_bandwidth at ffffffff810c6dd0 > #7 [ffff886537ad7e28] cpu_rt_period_write_uint at ffffffff810c6eea > #8 [ffff886537ad7e38] cgroup_file_write at ffffffff8111cfd3 > #9 [ffff886537ad7ec8] vfs_write at ffffffff8121eced > #10 [ffff886537ad7f08] sys_write at ffffffff8121faff > #11 [ffff886537ad7f50] system_call_fastpath at ffffffff816e8a7d > > The patch reworks tg_has_rt_tasks() and makes it to iterate over > task group process list instead of iteration over all tasks list. > This makes the function to scale well, and reduces its execution > time. > > Note, that since tasklist_lock doesn't protect a task against > sched_class changing, we don't introduce new races in comparison > to that we had before. This seems to be true. However, I wonder why we are OK with current racy code (against tasks moving between groups). :/ Can't a task join the group while we are iterating and we miss that?