Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp84790rwl; Thu, 30 Mar 2023 12:31:20 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8CW5+gbvfnvd2Lzeos+F0NUxobCDM33JoLrIEIdBzSCsbNc6pE2mGqHUUWrXmEVjTLtwZ X-Received: by 2002:a17:906:2098:b0:930:7f40:c1bb with SMTP id 24-20020a170906209800b009307f40c1bbmr2932281ejq.4.1680204680674; Thu, 30 Mar 2023 12:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680204680; cv=none; d=google.com; s=arc-20160816; b=plOlEmMFOLn0v2Cm7cpkjNAHLTZyYImBVlZncuDAvE7/NRYVhug93HBDv/Sdd+iVG2 WFSf1+2ZCSTZECNDAV+ArI1qACaAp0Y+ToQZfafnX0PkB4+HHu4sXq1Csh63iMQLqkYr EiA6NyOwgkUbPajiMdg4/qKHrfMomuKPSaUYljrR6I6+PGFVxmcqrxC3ZIlY5jsPpKYR 6TlaETmXMLC4MqO61uXjIj4xQhr8fADdAiP3FugerfVWM+2vIJvAmsveOlzz6Y8uyOLR rbgvXAZ4qzqvbcKKgWX/FQ7gTjeH8y8mhkBSCEaWWvdnvYel2UwtKbfnv8ahcG84DcRQ 8HzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Khpw7ou3XcOkEyyu20b7pCpZUxpOS3o1zWL8rB8cIWg=; b=iIZ5FpSCkTDbPHK1Xki9p5iuF/ZAJFWxYtbjYYIuZDwkfqWjMaHLZRf7XLNgvBjDM+ nC/QBTlmgJKD3ryh0seslDul5P7LiRqW/cJXaXg4au5G/6fMvYd+dVb8qlOurVfjdQ2y iyJqoticfxZXnvT308z4dGvBDmnQallOK6tQqMgazcbxFgqFr2Y/qFvz+wi6Ugv3tfmB /7q3H4qLJD2A9iB9TzCaGmxSF56A6zVtM9Q3hrHbraQsTsuoI/E+3WAdGZfRYtnixlBf EFL1H7CJjtEz09l8yQmQ8ZBekTBT6s8R5rGlSV88Ql23uGV0u+z1E2yVMP56CMNCgEEX hoyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=EBZ5RSwu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a1709062b8800b0093defbd6270si300825ejg.1015.2023.03.30.12.30.55; Thu, 30 Mar 2023 12:31:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=EBZ5RSwu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232078AbjC3TaW (ORCPT + 99 others); Thu, 30 Mar 2023 15:30:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjC3TaU (ORCPT ); Thu, 30 Mar 2023 15:30:20 -0400 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC4FA5B82 for ; Thu, 30 Mar 2023 12:30:18 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id l7-20020a4abe07000000b0053e1205c84bso2781934oop.9 for ; Thu, 30 Mar 2023 12:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; t=1680204618; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Khpw7ou3XcOkEyyu20b7pCpZUxpOS3o1zWL8rB8cIWg=; b=EBZ5RSwu7qAxwJOxXP+VV5tCHAvd597imHWQHEOpyHjV99Yma2yYj2+GVrBE3CvEYu j8GOYLIo/8V6p01dDFwWDz0SuE7pJ9ps3e/uuV/vrp+Efny6FMlE8BM6+lrA9yui5XXy BP6sOtWFiXcCali8wq+wJ3ZeGb16MFGin5/zucLqAsEfB6IkgmUZYUNLVZS0o4LTsQYV p4WDiyCZ5dD1Xl6y5Lz0GhJWbb1bQHZ85QIJV0Hj8hcm7nUsFbYsfBttw01lkBWhwMDp adaoaJrHF1Tqpn0MyPd0QZKQohCtbf0gRnsrAsPTFufImEuTtaA7mENwlPt7Do/NeuEl 4V8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680204618; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Khpw7ou3XcOkEyyu20b7pCpZUxpOS3o1zWL8rB8cIWg=; b=yydrjn8XEwSmsRGnSD9DrUB5y0C6VsnbyOj+UkAC7rbTvRxDgjP8WPv4QYemzEWiYw kpelKyrDhUYTkM7eHlhYdrbFnr9nN4vWZQR7b5tkY8NQWkJbCQcSkfyC09f6OubIIK0V JW5nYerIVU5aKGTygWKqQRU1WC6vs4HbWlwF9V1XROJMxHfa+bsERCQjXYhlElV1wHMf Ni+DfZBwplPZObSQ1SZpy8cJy4YvM/HCGBlEsPSXnPGccEaxWVoDU4oZaJ+Sljeemk97 TeEY/6bOp4AgNtsP1tvPTqKVGLd1TF76a9pcuUtxBaK+hNep8FLbEFdlt1KKY+vA4r5i TpbQ== X-Gm-Message-State: AO0yUKU1vBFWb1QuvC4KuJ1HwaJqzxx6bD8mh7sxuEr1EJR3OdLbxxUL XszHfnzhh5dbDfTgRteQD0lCwA== X-Received: by 2002:a4a:558f:0:b0:534:c237:eb00 with SMTP id e137-20020a4a558f000000b00534c237eb00mr11810755oob.3.1680204618144; Thu, 30 Mar 2023 12:30:18 -0700 (PDT) Received: from localhost ([107.116.82.97]) by smtp.gmail.com with ESMTPSA id 2-20020a4a0302000000b005251f71250dsm13103ooi.37.2023.03.30.12.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:30:17 -0700 (PDT) Date: Thu, 30 Mar 2023 15:30:13 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Michal =?iso-8859-1?Q?Koutn=FD?= , Vasily Averin , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, Michal Hocko Subject: Re: [PATCH v3 5/8] memcg: sleep during flushing stats in safe contexts Message-ID: References: <20230330191801.1967435-1-yosryahmed@google.com> <20230330191801.1967435-6-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230330191801.1967435-6-yosryahmed@google.com> X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 30, 2023 at 07:17:58PM +0000, Yosry Ahmed wrote: > Currently, all contexts that flush memcg stats do so with sleeping not > allowed. Some of these contexts are perfectly safe to sleep in, such as > reading cgroup files from userspace or the background periodic flusher. > Flushing is an expensive operation that scales with the number of cpus > and the number of cgroups in the system, so avoid doing it atomically > where possible. > > Refactor the code to make mem_cgroup_flush_stats() non-atomic (aka > sleepable), and provide a separate atomic version. The atomic version is > used in reclaim, refault, writeback, and in mem_cgroup_usage(). All > other code paths are left to use the non-atomic version. This includes > callbacks for userspace reads and the periodic flusher. > > Since refault is the only caller of mem_cgroup_flush_stats_ratelimited(), > change it to mem_cgroup_flush_stats_atomic_ratelimited(). Reclaim and > refault code paths are modified to do non-atomic flushing in separate > later patches -- so it will eventually be changed back to > mem_cgroup_flush_stats_ratelimited(). > > Signed-off-by: Yosry Ahmed > Acked-by: Shakeel Butt > Acked-by: Michal Hocko Acked-by: Johannes Weiner