From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7B44C27C40 for ; Thu, 24 Aug 2023 07:13:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B6818E0011; Thu, 24 Aug 2023 03:13:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 417DE2800A9; Thu, 24 Aug 2023 03:13:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DF988E0016; Thu, 24 Aug 2023 03:13:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 220448E0011 for ; Thu, 24 Aug 2023 03:13:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E771540204 for ; Thu, 24 Aug 2023 07:13:53 +0000 (UTC) X-FDA: 81158133546.02.1064B1D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf19.hostedemail.com (Postfix) with ESMTP id DE4A31A0018 for ; Thu, 24 Aug 2023 07:13:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=qb8NuamN; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf19.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692861232; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cL+xkHg3gVScj/qvNoq2aVyQCfwu6YNOsJXQogUGOQI=; b=3BtE4q+25E7Ny+pJkl07mqaneTNb9lV3m4p3AiUzpkhHT/B+gtq1jSWs0emnAZPtYwpG8T NdVSDQI4VBMnHt1/eoAHcQ6ekXX4jL1TMkTi7td57b7Z9AzuweUt+NqUoiQQ0V4H2d3lqq yfFfXRMzT/eRYMLxtA3HE5hKF/VA7ug= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=qb8NuamN; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf19.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692861232; a=rsa-sha256; cv=none; b=KWqonSa6gM++i5GR5b9nktrwtdbXURSk+Lh4IzVVCzO1Q9Pb1nab7tih6Mfoa4Re0ck42c NiHeeuoPJwMutKCJXoa+EQ+9Gfu9+zdGqjLKB55MEXmtvA9VMcYoWrIm0wjRa6DaYffaVJ g1cZSLt8vTP+L7EymsUUivXAjb03DKs= 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-out1.suse.de (Postfix) with ESMTPS id D13A922C73; Thu, 24 Aug 2023 07:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1692861228; 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: in-reply-to:in-reply-to:references:references; bh=cL+xkHg3gVScj/qvNoq2aVyQCfwu6YNOsJXQogUGOQI=; b=qb8NuamNvZBFYTTN0FOFT3Ibgam1CmlB83kK5rDCRNJ33KCnGr21xK0VtE/ya4rUb/TBQF Octr+nFbz3nKd9GIf+gxbBOanAltvASnflTM5oIEWXbXNsTw55b1+9NG4YtLwiDoecBWWH XRQcqtauBjN1w1a6QfonjTxSnwFUhTo= 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 B513F138FB; Thu, 24 Aug 2023 07:13:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kYj3KSwD52QZHQAAMHmgww (envelope-from ); Thu, 24 Aug 2023 07:13:48 +0000 Date: Thu, 24 Aug 2023 09:13:48 +0200 From: Michal Hocko To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] mm: memcg: use non-unified stats flushing for userspace reads Message-ID: References: <20230821205458.1764662-1-yosryahmed@google.com> <20230821205458.1764662-4-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DE4A31A0018 X-Stat-Signature: en8cdzo6uc1kzhoq18ntyzxxzqsdyfwf X-Rspam-User: X-HE-Tag: 1692861231-887601 X-HE-Meta: U2FsdGVkX1+AtIvcvlGIzI0POmCixek5jiNS0ozjSrItBL4a+9sb7JUyDoit4MuAtsDtnlUn/rjcpYiP0d2IRZf060hblaepwVjSTPZlJwWw8sLj7bPF57ONobYxbmXUiCLZRh8uH2gNrF1VLxOTL59C+Z2TJa48oY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: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed 23-08-23 07:55:40, Yosry Ahmed wrote: > On Wed, Aug 23, 2023 at 12:33 AM Michal Hocko wrote: > > > > On Tue 22-08-23 08:30:05, Yosry Ahmed wrote: > > > On Tue, Aug 22, 2023 at 2:06 AM Michal Hocko wrote: > > > > > > > > On Mon 21-08-23 20:54:58, Yosry Ahmed wrote: > > [...] > > > So to answer your question, I don't think a random user can really > > > affect the system in a significant way by constantly flushing. In > > > fact, in the test script (which I am now attaching, in case you're > > > interested), there are hundreds of threads that are reading stats of > > > different cgroups every 1s, and I don't see any negative effects on > > > in-kernel flushers in this case (reclaimers). > > > > I suspect you have missed my point. > > I suspect you are right :) > > > > Maybe I am just misunderstanding > > the code but it seems to me that the lock dropping inside > > cgroup_rstat_flush_locked effectivelly allows unbounded number of > > contenders which is really dangerous when it is triggerable from the > > userspace. The number of spinners at a moment is always bound by the > > number CPUs but depending on timing many potential spinners might be > > cond_rescheded and the worst time latency to complete can be really > > high. Makes more sense? > > I think I understand better now. So basically because we might drop > the lock and resched, there can be nr_cpus spinners + other spinners > that are currently scheduled away, so these will need to wait to be > scheduled and then start spinning on the lock. This may happen for one > reader multiple times during its read, which is what can cause a high > worst case latency. > > I hope I understood you correctly this time. Did I? Yes. I would just add that this could also influence the worst case latency for a different reader - so an adversary user can stall others. Exposing a shared global lock in uncontrolable way over generally available user interface is not really a great idea IMHO. -- Michal Hocko SUSE Labs