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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BB5DC6FD18 for ; Wed, 29 Mar 2023 11:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjC2L6y (ORCPT ); Wed, 29 Mar 2023 07:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjC2L6u (ORCPT ); Wed, 29 Mar 2023 07:58:50 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE7ADEA; Wed, 29 Mar 2023 04:58:44 -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-out1.suse.de (Postfix) with ESMTPS id 89907219D6; Wed, 29 Mar 2023 11:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680091123; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yUxNSXHNGER+MCVZDyDV8l5ua3h1BaSz76WjsL0+L3s=; b=Y9IuGtiVAXDxMAHsM6cj7w2mYq2eAbOAWUcGbhruEFj1/tTjy0ED7NrMdnGwksKxLWnPdS 2XErqMm71eFEKSjeeww8JCt/gvAo3MxStIDeQ1v26jeQkUL5w58Wj50wWGD35gsly/pJ7o eNf2oLyQeU11xKNm9lcEWC8qojyK8Qs= 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 6F463138FF; Wed, 29 Mar 2023 11:58:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ecknG/MnJGRBXwAAMHmgww (envelope-from ); Wed, 29 Mar 2023 11:58:43 +0000 Date: Wed, 29 Mar 2023 13:58:43 +0200 From: Michal Hocko To: Yosry Ahmed Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Johannes Weiner , 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 Subject: Re: [PATCH v2 3/9] memcg: do not flush stats in irq context Message-ID: References: <20230328221644.803272-1-yosryahmed@google.com> <20230328221644.803272-4-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230328221644.803272-4-yosryahmed@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 28-03-23 22:16:38, Yosry Ahmed wrote: > Currently, the only context in which we can invoke an rstat flush from > irq context is through mem_cgroup_usage() on the root memcg when called > from memcg_check_events(). An rstat flush is an expensive operation that > should not be done in irq context, so do not flush stats and use the > stale stats in this case. > > Arguably, usage threshold events are not reliable on the root memcg > anyway since its usage is ill-defined. > > Suggested-by: Johannes Weiner > Suggested-by: Shakeel Butt > Signed-off-by: Yosry Ahmed > Acked-by: Shakeel Butt > Acked-by: Johannes Weiner Acked-by: Michal Hocko > --- > mm/memcontrol.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c3b6aae78901..ff39f78f962e 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3669,7 +3669,21 @@ static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap) > unsigned long val; > > if (mem_cgroup_is_root(memcg)) { > - mem_cgroup_flush_stats(); > + /* > + * We can reach here from irq context through: > + * uncharge_batch() > + * |--memcg_check_events() > + * |--mem_cgroup_threshold() > + * |--__mem_cgroup_threshold() > + * |--mem_cgroup_usage > + * > + * rstat flushing is an expensive operation that should not be > + * done from irq context; use stale stats in this case. > + * Arguably, usage threshold events are not reliable on the root > + * memcg anyway since its usage is ill-defined. > + */ > + if (in_task()) > + mem_cgroup_flush_stats(); > val = memcg_page_state(memcg, NR_FILE_PAGES) + > memcg_page_state(memcg, NR_ANON_MAPPED); > if (swap) > -- > 2.40.0.348.gf938b09366-goog -- Michal Hocko SUSE Labs