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 B8EB1C71153 for ; Mon, 11 Sep 2023 20:21:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FB6E6B02F3; Mon, 11 Sep 2023 16:21:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AB626B02F4; Mon, 11 Sep 2023 16:21:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 172AB6B02F5; Mon, 11 Sep 2023 16:21:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 080E16B02F3 for ; Mon, 11 Sep 2023 16:21:30 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CADD51A0A7E for ; Mon, 11 Sep 2023 20:21:29 +0000 (UTC) X-FDA: 81225436698.01.C2EEC51 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf24.hostedemail.com (Postfix) with ESMTP id F022D18000A for ; Mon, 11 Sep 2023 20:21:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=TlT50o4E; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf24.hostedemail.com: domain of htejun@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=htejun@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694463688; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=djFVbSPSCUqIznFcytjoMNrEsFpZVt4WCJe34ZTsb1w=; b=0uHgIwalLY3xSGBvvvv4z/0+5/p6JInU4+9iqRM4Fur012KNdohy8KNmSjibXNrQAaGgHv J9HBGKA51RYpcY77AC/c84W3MzVgTTy/w9/E1GXSW/IKciO4KqxKwW1zEeoMoMO2vDdnqV 939F7ysLaPwVLLcKKiDtrFuroLS2DUQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=TlT50o4E; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf24.hostedemail.com: domain of htejun@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=htejun@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694463688; a=rsa-sha256; cv=none; b=YswL9ncUyD5bU+RueEp2rXaNjogerYRwhsa1RGD7alxOtiJseftpylSqRadl3ifiU3St5k GooTDPIrk58MzavDAI2JrxkO1Br4i0wpB1m5JvPxoUibltXIhEsBPOZuKUaxcTjLoKCmmp FSimGhjIu8l2sbQXly2uBCfGVzJpCys= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1c1e3a4a06fso34347615ad.3 for ; Mon, 11 Sep 2023 13:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694463687; x=1695068487; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=djFVbSPSCUqIznFcytjoMNrEsFpZVt4WCJe34ZTsb1w=; b=TlT50o4E+SWQT2xiq1R5UaycjXS8tQnjb40aoI0Ir3wAHGTLkZaIGNE2We1/MKD5Vx dUpJzgsgvreWcCqKwSEm7fp4iy2A1X9aLGjcvY/2/vPYTSQqSduGO3Yb0KysdlCYZIvy fDJDsbrYqVwB0zuyO93cqA1QFidXVuOm/ORdXtkgyUmm+3HgOBZxQR2WBoEDnffe7HGR PebEZqNnmJrfNccgmpw6q+E8O4/cqZP3YTmf/1g+BNsU0ZKQtjXpgxprHt+B3tDyRhcO iXcfl/RGFk2wWObd0t8unq5URKHj4I/xr/atSKkdVQneSise6Mq4oq/oUd13eCwpAWIU MUaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694463687; x=1695068487; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=djFVbSPSCUqIznFcytjoMNrEsFpZVt4WCJe34ZTsb1w=; b=RxzAvGmd6b9vdMc7Svmp6++hytdXcFeOXI2RcjJYIxsOlrwsbTvw9a+7omBrxaLUfQ lUzzaLl/TglA4JWCHSi107fXORLTtQ5MiEfMQc6eLjwYW3E8vDy8GJm6VDad+UJCv9u4 WQkdj27+ZHalV37rSpT8fuwkdFzumRLJ5JWaBFPFpJi9axI1L30B2mZsLAUCPTAdc6OV OCilf/+o7+awfXa69bMduubPl6XtWyQF5AFZhsv/HPgbeiPfdKvjSB3Q73Qw2/C50ZPh dJj6PV8oAloGi+4Gmwv9kOFXr4SuNSfsozVP0RiByGDYm5vB2t4KeWXRtw0nkiRXLzq2 wSTA== X-Gm-Message-State: AOJu0Ywe58dA5xgtn4kwfTBezm7mYWfgpj5mgFyJd11j/VKSbHYvC3tN 1ftj0dQBWK/S+cHNWGr2Y9I= X-Google-Smtp-Source: AGHT+IFm3ORyZOdteaHbLXIuoVa/NrrR2S6J5B8bPeL3jC8guAY4KfF9nPYEgzTFr2rj3NbEjiNNWQ== X-Received: by 2002:a17:902:e811:b0:1c3:2df4:8791 with SMTP id u17-20020a170902e81100b001c32df48791mr10280357plg.27.1694463686599; Mon, 11 Sep 2023 13:21:26 -0700 (PDT) Received: from localhost (dhcp-72-235-13-41.hawaiiantel.net. [72.235.13.41]) by smtp.gmail.com with ESMTPSA id h8-20020a170902748800b001b8b2b95068sm6827631pll.204.2023.09.11.13.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 13:21:26 -0700 (PDT) Date: Mon, 11 Sep 2023 10:21:24 -1000 From: Tejun Heo To: Wei Xu Cc: Michal Hocko , Yosry Ahmed , Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Michal =?iso-8859-1?Q?Koutn=FD?= , Waiman Long , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Thelen Subject: Re: [PATCH v4 4/4] mm: memcg: use non-unified stats flushing for userspace reads Message-ID: References: <20230831165611.2610118-1-yosryahmed@google.com> <20230831165611.2610118-5-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: F022D18000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 7g5ezojxfzcw185774ppqhhdffyx5mjo X-HE-Tag: 1694463687-1688 X-HE-Meta: U2FsdGVkX1+ahXd5FLs62rTrIMW7D9WbPcLqcLDroXOlLKZ/2k0R2988gguSfpGbv2KdFqu7sDPLAd3PPtDVUb7Uj82LSpkuQnrZgBzGh8ZUgmmXEDcp7gRM1Zp9PqVFzRFcWbpiCDkk8AH+F9FF/384kkFSZh4YA/v933kyP1Num6fpT4JZUSIDM7wOjTDQtHfgz6tDsWWKqky3ShIQkMQN6Zk3GQl6buDD77njLUZ7QpYMp4pxw/wlbYlPIWhUYBT7fc+WVMl65Fdt7C6g3cAskKd1Ai49QV0dVK0wV3KYO19WZPqXCQk4GCeipXQWGM8386MfmnltCEgmqFQ4JE+h+MSlgtn4zGk0TM/RyvlCovCT7a2whgwigAHCuC4QrW7PPyE9ufaC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FVC19Tj6KGNlxrmUPkv6KaiGxfeAe1MoJAORhw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello, On Mon, Sep 11, 2023 at 01:01:25PM -0700, Wei Xu wrote: > Yes, it is the same test (10K contending readers). The kernel change > is to remove stats_user_flush_mutex from mem_cgroup_user_flush_stats() > so that the concurrent mem_cgroup_user_flush_stats() requests directly > contend on cgroup_rstat_lock in cgroup_rstat_flush(). I don't think it'd be a good idea to twist rstat and other kernel internal code to accommodate 10k parallel readers. If we want to support that, let's explicitly support that by implementing better batching in the read path. The only guarantee you need is that there has been at least one flush since the read attempt started, so we can do sth like the following in the read path: 1. Grab a waiter lock. Remember the current timestamp. 2. Try lock flush mutex. If obtained, drop the waiter lock, flush. Regrab the waiter lock, update the latest flush time to my start time, wake up waiters on the waitqueue (maybe do custom wakeups based on start time?). 3. Release the waiter lock and sleep on the waitqueue. 4. When woken up, regarb the waiter lock, compare whether the latest flush timestamp is later than my start time, if so, return the latest result. If not go back to #2. Maybe the above isn't the best way to do it but you get the general idea. When you have that many concurrent readers, most of them won't need to actually flush. Thanks. -- tejun