Message ID | 20231009135811.2627-1-mkoutny@suse.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1887697vqo; Mon, 9 Oct 2023 06:58:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWsUEqmJF/kn6gakzVMdVg/aWHICajH+NBm2mHFNrBlyD5/yVE0A+CRoLtWaxE30QWHk1A X-Received: by 2002:a17:902:d382:b0:1c5:e9a8:dbc0 with SMTP id e2-20020a170902d38200b001c5e9a8dbc0mr15044862pld.51.1696859912628; Mon, 09 Oct 2023 06:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696859912; cv=none; d=google.com; s=arc-20160816; b=GHGTrRS+fQpsNBtxllsgpZnu7BGZWXOWQ6/Eb+NuGeJd4Ri6BQVPsvfEJIP6FYauVg QtBolHFl9QhxQQvYXM8LZe8rdFZ0XFrx/psJzz2NSWbulxG7mCjVl0/8HElkAYED5pio F9HmafArQWw6MPwcwfC84CvjCtxHwnXGoQpL9jojGEOMQ7ILo5bhDBNebjJh3IORPz27 PEtLAd+MSLxW503XADm9fMgjXDK+HdzbcJnwOyjg55ftzdAXobngJUiz7aiNOsWBRbKI /mu158Koit919STIv9cDsncncMzMxKo+oxZeDOAC/tKydvXI5B37vwG4g4MqzzGdSU/H O6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7OgkSL2KmvIM/AbVLqY0l7mLuBK7eG7eLJyEbA5Dmic=; fh=J/29fCZ+rQHCgcVeR4toNoG+r303TryN5hKAEpqe5Rc=; b=FypYOA+aYHDX8SvbxpwYfteHzeUMsRkYDQRBJeQhsnYDWqgLZGux8KJ9Gg0zNyCIqv SIsTIFWZTU92AyEdpGFw+t4+4JQ0GCeOjx/OSV4VnKE89jw9XHSKpgtsZHnGyJ46/i2/ 7DgEBS8utOjhswVfPfzjHr3LCp/57uUaTIv6DBbz4WQLpzAjmChoOQ5OCd/d5jZnDCHG 66Y2M2uAt9918/yo7PWgoyvjvZ1J5qWctvdQDTeF0Sh9q40KUngRkYs5RpHjQq+ev5QJ lmGQHAiM3s1/a0quUxkAP+EtAXshMmu5xl3HNBQooe4CZMLrAXvIOoLrDmRT7BvWd0lZ beVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lIh9JNcN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a10-20020a170902ecca00b001bbad1883d5si10183983plh.293.2023.10.09.06.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 06:58:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lIh9JNcN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7838E80488FF; Mon, 9 Oct 2023 06:58:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377540AbjJIN6T (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Mon, 9 Oct 2023 09:58:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376852AbjJIN6R (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Oct 2023 09:58:17 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00BB199; Mon, 9 Oct 2023 06:58:15 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AEDA81F381; Mon, 9 Oct 2023 13:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1696859894; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7OgkSL2KmvIM/AbVLqY0l7mLuBK7eG7eLJyEbA5Dmic=; b=lIh9JNcNFzDdUWqqH8dgPFjtVoPjAPJ09+D6/ZnUe8PNohHlnvGctLowI4oJOpavAYxv7F ma3yxEFptZfEIw+MDkv0aIq9J4oaFF/RR6rFuDoa+qftptY8yTsVBnCjMIdO7u2fGZYmTx mhr3/E0pYJ26quX4KXWSRf1+fUg5cgQ= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 93BCE13586; Mon, 9 Oct 2023 13:58:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id M2NmI/YGJGV6fAAAMHmgww (envelope-from <mkoutny@suse.com>); Mon, 09 Oct 2023 13:58:14 +0000 From: =?utf-8?q?Michal_Koutn=C3=BD?= <mkoutny@suse.com> To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>, Johannes Weiner <hannes@cmpxchg.org>, Firo Yang <firo.yang@suse.com> Subject: [PATCH] cgroup: Remove duplicates in cgroup v1 tasks file Date: Mon, 9 Oct 2023 15:58:11 +0200 Message-ID: <20231009135811.2627-1-mkoutny@suse.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 06:58:30 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779286579554942023 X-GMAIL-MSGID: 1779286579554942023 |
Series |
cgroup: Remove duplicates in cgroup v1 tasks file
|
|
Commit Message
Michal Koutný
Oct. 9, 2023, 1:58 p.m. UTC
One PID may appear multiple times in a preloaded pidlist. (Possibly due to PID recycling but we have reports of the same task_struct appearing with different PIDs, thus possibly involving transfer of PID via de_thread().) Because v1 seq_file iterator uses PIDs as position, it leads to a message: > seq_file: buggy .next function kernfs_seq_next did not update position index Conservative and quick fix consists of removing duplicates from `tasks` file (as opposed to removing pidlists altogether). It doesn't affect correctness (it's sufficient to show a PID once), performance impact would be hidden by unconditional sorting of the pidlist already in place (asymptotically). Link: https://lore.kernel.org/r/20230823174804.23632-1-mkoutny@suse.com/ Suggested-by: Firo Yang <firo.yang@suse.com> Signed-off-by: Michal Koutný <mkoutny@suse.com> --- kernel/cgroup/cgroup-v1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Comments
On Mon, Oct 09, 2023 at 03:58:11PM +0200, Michal Koutný wrote: > One PID may appear multiple times in a preloaded pidlist. > (Possibly due to PID recycling but we have reports of the same > task_struct appearing with different PIDs, thus possibly involving > transfer of PID via de_thread().) > > Because v1 seq_file iterator uses PIDs as position, it leads to > a message: > > seq_file: buggy .next function kernfs_seq_next did not update position index > > Conservative and quick fix consists of removing duplicates from `tasks` > file (as opposed to removing pidlists altogether). It doesn't affect > correctness (it's sufficient to show a PID once), performance impact > would be hidden by unconditional sorting of the pidlist already in place > (asymptotically). > > Link: https://lore.kernel.org/r/20230823174804.23632-1-mkoutny@suse.com/ > Suggested-by: Firo Yang <firo.yang@suse.com> > Signed-off-by: Michal Koutný <mkoutny@suse.com> Applied to cgroup/for-6.6-fixes. Thanks.
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index c487ffef6652..76db6c67e39a 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -360,10 +360,9 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, } css_task_iter_end(&it); length = n; - /* now sort & (if procs) strip out duplicates */ + /* now sort & strip out duplicates (tgids or recycled thread PIDs) */ sort(array, length, sizeof(pid_t), cmppid, NULL); - if (type == CGROUP_FILE_PROCS) - length = pidlist_uniq(array, length); + length = pidlist_uniq(array, length); l = cgroup_pidlist_find_create(cgrp, type); if (!l) {