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 249E3C001DB for ; Tue, 15 Aug 2023 00:35:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7333900012; Mon, 14 Aug 2023 20:35:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A233F90000B; Mon, 14 Aug 2023 20:35:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EA84900012; Mon, 14 Aug 2023 20:35:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8005B90000B for ; Mon, 14 Aug 2023 20:35:30 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 51DD4140CB0 for ; Tue, 15 Aug 2023 00:35:30 +0000 (UTC) X-FDA: 81124470420.13.5086871 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf20.hostedemail.com (Postfix) with ESMTP id 796B31C0018 for ; Tue, 15 Aug 2023 00:35:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Q3FsTHwS; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf20.hostedemail.com: domain of htejun@gmail.com designates 209.85.214.173 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=1692059728; 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=bfAmkgzB7vT7tpPqvlusS7lhE5MuyQY4MvJWqWEdMxw=; b=pwScHfPwECF7INCHhf64bWfT0fhkOh+6KWVRDo8GrpTaQz4ucC5PAirmWhj2g+Nc+9JEQI ueRiluYUMIZm2rsm9Fxmh8uK1QZVwVDdDJe/Sep9CKLFnmdx76VcA2Zt4vKaCzN8iH9yzu Hx/yHf7wCmci/dfBBiCP1gHq6CuVagw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Q3FsTHwS; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf20.hostedemail.com: domain of htejun@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=htejun@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692059728; a=rsa-sha256; cv=none; b=wN90zZcfNP8Nd+FK4JCj6J+66jE9RwfNlghAXr4ypPhl0E5TjldMxBetdw8iAFHCDCFiII qHZWSOsLHM2pQXjt+8U3bEnc5/ejKMhXTpY3BoZz9ITr1AFeSynxQPd2ARZnjsedrTlcK4 m+YZTkWrGISwmDKNLt0jNFvrd7erTjY= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1bdef6f5449so8233665ad.3 for ; Mon, 14 Aug 2023 17:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692059727; x=1692664527; 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=bfAmkgzB7vT7tpPqvlusS7lhE5MuyQY4MvJWqWEdMxw=; b=Q3FsTHwS9lFILlCZTL+VSW2aBgIikI37LyzDBlO0rg0yAWWl8WiLTTad1Bw93yvH2Z 6+H2tD04Xx312hOQjfVs27DFdL6BpDfUgH3bGOLnXfU6snGVTi+SuseJ4OifnvpGkxDr 7JxqVmNrBAZB0ief7FxYgn9iQKvIGAqQQi5CNmTYRSrxjBEfskBkDsspIzSrAK/aJg7x f2nsQFkayTk8wUfT/jQZzyxeA+3lz1jN9M8+8YF+8FCQmW5s/n9Zuni13dkFGyJoQPYv QmmmIL1K28eb5SymTU5DSEDwbxqSnpm9lF4RfGQ00GO5KnsBKtt5CZPR0kq/u1Kq9JmR OySw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692059727; x=1692664527; 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=bfAmkgzB7vT7tpPqvlusS7lhE5MuyQY4MvJWqWEdMxw=; b=c1g/FOJ1QgiY6REYHmJmteHBKOcwI+wXnnIvxCPRIaAuDwjKsR5p6Jx1nXuXjY0lDr gkLF83l73AYmAHDhcZjFE8o6qVd+qSTIgrHNuOAvbgcA1udAox9MyPGn2TfSCg4XfMzt 3w4tW4vbQZzThZvdV1Q2cajLkMo1eiTVmAGaV9xedsSCUwc+K/NTkDfjdja1zb+HLFrx /oVZBlFM5OFRcqkF3jgc4pG2NYIqRd97jsoASp1AZsIiNJ94w8SJYIx66IfaVQRQUhOa 1za3VuVxSx3jg0dEIl7P51tJm4CHONbASYzmrFblSOrEjCIaYOyIboADtNYK/HQiKXsC zozA== X-Gm-Message-State: AOJu0Yy9e7OX2g99IarJH0BcqUGoF7n3DHxnRyB9fSSSn3ZAcCKCzh3y tlrR/pnRoEOpdP1wzX5Q5Sw= X-Google-Smtp-Source: AGHT+IHI7QnEnuIcrHvGdYK8SghKW3IFtA+uZj3a3P6LJs/SVdXPUY2rHy+foXwaqvyorqLt4HERmQ== X-Received: by 2002:a17:903:22cc:b0:1b6:797d:33fb with SMTP id y12-20020a17090322cc00b001b6797d33fbmr13717283plg.64.1692059727156; Mon, 14 Aug 2023 17:35:27 -0700 (PDT) Received: from localhost ([2620:10d:c090:400::5:93bd]) by smtp.gmail.com with ESMTPSA id bh9-20020a170902a98900b001b89a6164desm9972446plb.118.2023.08.14.17.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 17:35:26 -0700 (PDT) Date: Mon, 14 Aug 2023 14:35:25 -1000 From: Tejun Heo To: Yosry Ahmed Cc: Michal Hocko , Shakeel Butt , Johannes Weiner , Roman Gushchin , Andrew Morton , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: memcg: provide accurate stats for userspace reads Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 796B31C0018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 51ziqbm9srtksi6n9st57qwm7xcd8zgo X-HE-Tag: 1692059728-625083 X-HE-Meta: U2FsdGVkX1/SYuDNHm6LStmVyzI7X1E1eqwtsfnitTEBGehmDxtFFXqRFDERdABc3nKKNeyeILltaPDjGPaEj7EifrR7UNWPQ4mknlUpXNI6MNrrLC9lIvJ0PQO9Jbs9OPycBCjjYGYNtbtNHFurJ/ljp5p0sqSMYWjRxFD6kgoEVtH2F6IHiKLrfdX5dJlwqT+71tcNegIZSXFp7/6M/zTWK63w8RHOiQ6eHfy86HkCGtwIG4BOQaGjM3YCoYNstM/D/NnLTnUDA6W7FLm/b1+BBSjIXnTy1Yn8awfUEu5GIEFl8ftpVLKbXv/w39NsU+6W5FtBBv4w5E0mVYVju+7J2X8bhMXfWqzwVoAaZBRGDOGxvTz0A3ah17brRPP9U0T5QJmxaic6H6esr6HrPWoMB58MCUE4XaukqcrDkzGy8Pvu/X2fkig2l46XzCnPSm8MXmxuIsfeOKCFz6mzcRgcrz07zBXcr9K4RjkFfsnDYpaN/TGHFXe1xxhMH43CojAmuT6ZatalGTnVMAm03N+LZj731bn9FemMZUFBum29qY4/9Svwl2o3M/vWBRNvSbwOYYwobZ7lQJc9tMeGdiA0arUsWaeR4gMyMFGyC6PSnuViHeSkpvzbItFBO/Uetu1AYLgMSI+CaIbOeWpGwYDZw8rSyaB65WhqmDUAOXfUCxlX66MfgkML7joW+uWD1TSruL5Eo0Cka5xAwXzSAjLGwB9r2NPy512WYWICy4v1AUN8Ej2YuKUb3KGPb4iIUrybdT50KeRs/wmCvcn5HDc/z9SHAfAVoURy5w7iPGuBpAtJmcFUaugkqBSWL3TaCOgdqpncNn7+he6wwwt7RGY9squo9uHKsG1j6ntPWZrQ8q8A+dqqvU0O8GvUxc93f4Dtxbh8O+y7E+A7Wh98s31XvKCwjeRzYF/gKdsWoOglGf212cjVshe7XR1pIxti+30gzAwJQtHIT1h0XKK fVLrYNzs PhbEIj8jV/4qcFpAd+m/2nDrXIFuoXB4zV5cT09x0yUXuT4PQe13vfYiWMWomVWa8yB2l3qKm6fEeUiqXc2xbBNgbjmYjCdpMQ/9mbBjCriMKEe7736XVSOnaWfbghzmmwSmHyIqOsjXJLuCp6DnGUxNK4QFuonosOxEp3UAyHhZfK53YjT8NSvCAjnyPNuQPsz4oS+Ea86Zmq5POpku5wUriErO6BVtiJw2x8BspP9opYXIMxmMGQL3HsAjPL3Cs5WUSHZANMFWpH7RAFcX2JVUF25svcO1dpZpP1w1Jl6bRyJFHi8Hb/Y68jVZq4LKx3LaBp9MGkaRVK4de8zhKNRyVLFLGOeNSHulD+vG+/K3uivt8xkXt8CQzC6GtHvXcB0oXEG6QJ+RAwvbLFER2alaWoa2eXQM8Ss6mso6tFJeUOrJmf3eIp0/LOYaVPXVEal4zx+VBtctRkGKdUv9Buh4HfCBrdKQFiBpMjQqNTNgJ161LbFRxdjySd/Q0zm2zcmsi 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, Aug 14, 2023 at 05:28:22PM -0700, Yosry Ahmed wrote: > > So, the original design used mutex for synchronize flushing with the idea > > being that updates are high freq but reads are low freq and can be > > relatively slow. Using rstats for mm internal operations changed this > > assumption quite a bit and we ended up switching that mutex with a lock. > > Naive question, do mutexes handle thundering herd problems better than > spinlocks? I would assume so but I am not sure. I don't know. We can ask Waiman if that becomes a problem. > > * Flush-side, maybe we can break flushing into per-cpu or whatnot but > > there's no avoiding the fact that flushing can take quite a while if there > > are a lot to flush whether locks are split or not. I wonder whether it'd > > be possible to go back to mutex for flushing and update the users to > > either consume the cached values or operate in a sleepable context if > > synchronous read is necessary, which is the right thing to do anyway given > > how long flushes can take. > > Unfortunately it cannot be broken down into per-cpu as all flushers > update the same per-cgroup counters, so we need a bigger locking > scope. Switching to atomics really hurts performance. Breaking down > the lock to be per-cgroup is doable, but since we need to lock both > the parent and the cgroup, flushing top-level cgroups (which I assume > is most common) will lock the root anyway. Plus, there's not much point in flushing in parallel, so I don't feel too enthusiastic about splitting flush locking. > All flushers right now operate in sleepable context, so we can go > again to the mutex if you think this will make things better. The Yes, I think that'd be more sane. > slowness problem reported recently is in a sleepable context, it's > just too slow for userspace if I understand correctly. I mean, there's a certain amount of work to do. There's no way around it if you wanna read the counters synchronously. The only solution there would be using a cached value or having some sort of auto-flushing mechanism so that the amount to flush don't build up too much - e.g. keep a count of the number of entries to flush and trigger flush if it goes over some threshold. Thanks. -- tejun