Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2841202rdb; Tue, 12 Sep 2023 13:56:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoIp7tbYcJxrG+B0dj/GyZ5pDwnakcBWFfPTVi84IjAGEZblmyITx0IpOdcgh+Nyc7a0pn X-Received: by 2002:a05:6a21:328c:b0:13e:1d49:7249 with SMTP id yt12-20020a056a21328c00b0013e1d497249mr652365pzb.2.1694552204329; Tue, 12 Sep 2023 13:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694552204; cv=none; d=google.com; s=arc-20160816; b=Fc7lYrEf7Skh9tR/lC/dVeBHYy8May7j27OZk39PEBjIUOTutMwSa153Wtw5Gz5lMq 89LkAF/Cwtat9q0k3ib+PZRE1J4Q+NvHPswih2VXR33An3df/JDJxCYcshZYvSaqgoJX ubYVjtF6PqXHxdp+N7nz9RAuzfqZTq7hs8QbkkcRXlYwK967zv753qlgE1aZfPxtvYNh WyMoXPOHJV+vdUBlFwusQUA4i8j1yDR+bC5Zsw5djOVR96lWbmrb3s5hY6reym+KCaI8 4lB34Nwi6SlclW+/EUOguYhAMNZh9LjWs7NEf09zseXmYzYTVKdem2yVJW+ZFs4u/+nR SDag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2Sq0fA/VatZ++ayfpGlQL3susC/RviepPCleB3baLTw=; fh=IuCNfyNmVT/V9ovZLdMHj7KNnFUbhaHXb0FntOupVmY=; b=G65psyRd0W3KJAswmCcw8uL6nFGfY1nJGtiFtSo1PPAwTFAHZIADsbDOcmhmYSd9z8 C8JrSHa0r52knOlrKAXE2jNmZ31aq898oEuloJ1EOXMKEmTMQ4a2KQx3ImKbpoCv1b6I crvLtssAdNb12tQKlFUrLTaFmKgCOdLPAd7A5GPNFNlRSfGs/KHSq4949rU+9YULXXoT KNEWmuru4hWrpPoIi4Z1HiX+6pCP5xj9EjmY1c+vSGMavm1zgWDkTntebZCd4Dz34TiJ EbbFMkAJTtf9BqEtACHlPz9+DfSLdzOj4Qh3i5cq4cwcBfRv+Lgk9plyrGoUTuMhEsvR fH/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ibueTLkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id r24-20020a635158000000b00573e5539422si8710628pgl.890.2023.09.12.13.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 13:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ibueTLkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 69FAA8036EA2; Tue, 12 Sep 2023 04:12:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234569AbjILLMI (ORCPT + 99 others); Tue, 12 Sep 2023 07:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234663AbjILLLL (ORCPT ); Tue, 12 Sep 2023 07:11:11 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA192172C for ; Tue, 12 Sep 2023 04:10:09 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-523100882f2so7051926a12.2 for ; Tue, 12 Sep 2023 04:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694517007; x=1695121807; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2Sq0fA/VatZ++ayfpGlQL3susC/RviepPCleB3baLTw=; b=ibueTLkYyDcakKnfmNNANAP0ZaZtuoHKt8ZiLX4Me5YTXK4m40JAcqFjJH463s68gA BCzfDROkDsS8eC4dlXWZ6nMWOJH12ce/HKdjFOmBD2wBBnHH11x9rNDPvb2ZfHfEqC+r 4xgJML+gnriCrUO2Lb05RoDLr7IISXXtjM2NCh02a1hMd8zO6Pff0hR3XwylXCh3VAZJ F9+m07hsjzGA3YSAPQaTn4ZH/uXbhNGFO4fn0fDjlGqpRsMKCLwOmAeXvIThiBR94yJz zPRx3x8EjVpr+Cxj9xWR50hXpdArrUp0Ur0Dq1tNUbzCtPYzck+m2C1fd1v62U+LInqW cOoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694517007; x=1695121807; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Sq0fA/VatZ++ayfpGlQL3susC/RviepPCleB3baLTw=; b=drz8EZWCJwKP0rF+gm4i4YcHRT9rG6UzUOcHIMZ3Mbx67dY/JjMmKqvcFNjbTBn+3i 3t7FspyqpxSaD2+S2KLxW9BJ71pcu7zsx2MNHfxQ4CyC0nNfNSrANt469S1+2W4IPj5m bGpIu0qI4So02vZK9CbQrIPHvQelPQy7G8mC3EedQKGPoIVPTHnmIC/o0Gd+KG9l6gIB 9bEEg/f0Clb+kAWX5BzHd1OXUtrlQO20ldzxdQE3mEfilZZoLxDmFmNkudu5Acl1U0ov 3cALiIPalrde+u0NqnpI7acqrtShOGaBVlIasuJxYqDjHFYZ4aGtQidY48KAZAla0O01 wMzw== X-Gm-Message-State: AOJu0YzPUmMCtPD3o/D6+W2HnUamCgcYHWftiAFXSZZrZ66v32GFehwP 3pEgR+tdg+SkZ9KmL9oAN3kb+A9vALLZDSo2t6KRTQ== X-Received: by 2002:a17:906:10dc:b0:99c:f47a:2354 with SMTP id v28-20020a17090610dc00b0099cf47a2354mr12544637ejv.70.1694517007270; Tue, 12 Sep 2023 04:10:07 -0700 (PDT) MIME-Version: 1.0 References: <20230831165611.2610118-1-yosryahmed@google.com> <20230831165611.2610118-5-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 12 Sep 2023 04:09:28 -0700 Message-ID: Subject: Re: [PATCH v4 4/4] mm: memcg: use non-unified stats flushing for userspace reads To: Michal Hocko Cc: Tejun Heo , Wei Xu , Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Waiman Long , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Thelen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:12:18 -0700 (PDT) On Tue, Sep 12, 2023 at 4:03=E2=80=AFAM Michal Hocko wrot= e: > > On Mon 11-09-23 10:21:24, Tejun Heo wrote: > > 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 directl= y > > > 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 inter= nal > > code to accommodate 10k parallel readers. > > I didn't mean to suggest optimizing for this specific scenario. I was > mostly curious whether the pathological case of unbound high latency due > to lock dropping is easy to trigger by huge number of readers. It seems > it is not and the mutex might not be really needed as a prevention. > > > If we want to support that, let's > > explicitly support that by implementing better batching in the read pat= h. > > Well, we need to be able to handle those situations because stat files > are generally readable and we do not want unrelated workloads to > influence each other heavily through this path. I am working on a complete rework of this series based on the feedback I got from Wei and the discussions here. I think I have something simpler and more generic, and doesn't proliferate the number of flushing variants we have. I am running some tests right now and will share it as soon as I can. It should address the high concurrency use case without adding a lot of complexity. It basically involves a fast path where we only flush the needed subtree if there's no contention, and a slow path where we coalesce all flushing requests, and everyone just waits for a single flush to complete (without spinning or contending on any locks). I am trying to use this generic mechanism for both userspace reads and in-kernel flushers. I am making sure in-kernel flushers do not regress. > > [...] > > > When you have that many concurrent readers, most of them won't need to > > actually flush. > > Agreed! > -- > Michal Hocko > SUSE Labs