Received: by 10.192.165.148 with SMTP id m20csp396845imm; Fri, 20 Apr 2018 08:29:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dL2TPzYGQH1Eic22F/6NbxaiDZ9gWz8Z6ZtN6+qoiodWteg/g4sO6HriEHo80R3/WG+zq X-Received: by 10.98.58.28 with SMTP id h28mr3348389pfa.209.1524238147487; Fri, 20 Apr 2018 08:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524238147; cv=none; d=google.com; s=arc-20160816; b=DJZM9cf+hPRNdvETyULDS4uMKq6GBEGL2x56CYpxPkUqNkWLg2s5CLas/cxNyQFZIE SKZhFIVUUD1MGikv61y8rXu43cY8bswTsX5UWewsSJkLH2FGDh8WrRY1FiqIfXcUH7yi lN4+/m2e0t+4FvRtVcJwFDd3JEVONsAwtVqqGaDufW+P5upjZqa1CZ9RpycypBjaFlJv cBEHaTqV5G5qDf3P4CtDCM71hfx+lClI9P/pCmj8Sg7ZdplsymYoGX2Cx+/fEy9ImKwJ ZQOZtID192JwDNepmOyl6SMyfLcEwqduDNrNXIGlq0jav3BN0niydtb15Q5a0J2c3OBG QctQ== 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=XlLbHZBggTmNEboA2bgZUYlPYKnKse1WJKCwTHvGVoc=; b=w5DLlzqfzdyY21tJKqNxujTCsBpXJt7NNLjQTyCzQix8RCr5sJtJ1MHZfycin8C+3G 5L+wOn+8tRtG8MxlCcVSsLwbSfLq+zfQUWbi19ZwG6ERRK49O7SFsld8CURE3Mxd44Rk siOjWRfhnEQ/Jk1zlJVPjkKAHG7Ec8Ebzo3d0mvBDQY11s3Z3/6W4dVcQGbj1NdUCECi HIuUxUsPBLU+wWTbTme9w2omRVS03RnG0DAsmfKJiwTsBlddyVZa7kEBXyE9Yu3awNIE Yd2vMi5AW5E/PgpQTQZaXcRwnuAv2XxnH+X7hHQPkWgYITYteXLu3sOBdffq5aWzfEdD qgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qmzuxZlI; 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 bb4-v6si1254411plb.169.2018.04.20.08.28.53; Fri, 20 Apr 2018 08:29: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qmzuxZlI; 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 S1755589AbeDTP1k (ORCPT + 99 others); Fri, 20 Apr 2018 11:27:40 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38773 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755550AbeDTP1a (ORCPT ); Fri, 20 Apr 2018 11:27:30 -0400 Received: by mail-wr0-f194.google.com with SMTP id h3-v6so24065184wrh.5 for ; Fri, 20 Apr 2018 08:27:30 -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=XlLbHZBggTmNEboA2bgZUYlPYKnKse1WJKCwTHvGVoc=; b=qmzuxZlISn0tclZLVY/QFtIzBZzUkn5alMDSywBoW/xyyU+M+a6jXKZn63iaYCzIQR FfpMSW3oHDCxFY03dNY7aVSovjZUy8kpbNIZLlbIQX0l4LdRX49JdKFztGipOEF5FZEM kL3mRv1QHHjM1KlmIBHXhlAkSNEjOKvY1yq+86IKG/RZwXa3AHIEsV3TGnrS8+m46ECB PqOirvCFxv5m66FX0B6iWhz0ZZ8i3cdTIbxsmUHODO4QEHnUvBd3Nj3tzl0Yb9zQieJi lT7l3HMPcKTGg22Qk+NjnacJuWYBgaOUeW8pAgNlGQMwsdYUNvGmMS1vooFdKD1SAYJG qLzw== 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=XlLbHZBggTmNEboA2bgZUYlPYKnKse1WJKCwTHvGVoc=; b=kS0s246JMLsqDXX49MHlA+iBkloaOpL26f+Z92ctxZHvkYvG3eWEDhPf20BWkF8C1s GRPezC/ybPf7tYlVWWGwWPYbVSGWrrdVOlue+EPmIGS9XY3pYiTay3aOfKa80Vl6FplU 9Swb0HHz2033L4bunMLY7PpnLyEgbdL0c5fn/QM+2wkicoxIBdoHKMx+/xc/tByMotqZ YIYb5VlSqUBVc26fj7h3ciwrI8TgC7bqd5tQi2zvdsu6O13DIfUFtMr/CqFbxRCV5bMF EQ75+3BvHp7kpQZXgu14F5iFVdENwZmQ5UYuBuImHiIp09lD33yIxyX14GHS8ie97lCm qycg== X-Gm-Message-State: ALQs6tCl09pl/aztUa9ABVNYaj+qRHCT0grCEJH7tpWdkwN5DDpNRPTB BCScP/OUZULT2IvieHX22hY= X-Received: by 2002:adf:ad46:: with SMTP id p64-v6mr7734704wrc.44.1524238049356; Fri, 20 Apr 2018 08:27:29 -0700 (PDT) Received: from localhost.localdomain ([151.15.228.118]) by smtp.gmail.com with ESMTPSA id e202sm1948598wma.43.2018.04.20.08.27.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Apr 2018 08:27:28 -0700 (PDT) Date: Fri, 20 Apr 2018 17:27:26 +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: <20180420152726.GJ24599@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> <20180420141145.GI24599@localhost.localdomain> <5fee2cc2-e6de-6bc2-7644-778ef2185803@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5fee2cc2-e6de-6bc2-7644-778ef2185803@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 17:30, Kirill Tkhai wrote: > On 20.04.2018 17:11, Juri Lelli wrote: > > 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? > > Yes, it can, but I'm not sure either this should be considered as problem, > seeing the race design we already have. It's not a real protection, this > place is to warn a person, he does something wrong. We check for zero written > there, but really written "1" will invent the same problems. Mmm, right. :/