Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1379989rdg; Fri, 11 Aug 2023 21:53:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0h2BDDnLqSeBsHRpmgcIMG/0XxESkMyzE1T3ASY+V9hgrZlfz4wAGiuSsx8mXPPdPFwui X-Received: by 2002:a05:6402:395:b0:521:8d64:df1c with SMTP id o21-20020a056402039500b005218d64df1cmr3328531edv.0.1691816010860; Fri, 11 Aug 2023 21:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691816010; cv=none; d=google.com; s=arc-20160816; b=E2qBPtfqME3PoY4laMrPRAViYPN6ZLUoqNH03sgUhlXvcO7p0DrDuH/dH08Ik0sjq2 BLLR/LgGOW20z9IHUbsSerEV8LuPJqII75qxE5cglaWEp+TTLSwF4E+k7xI5KiR/a1v/ ttWorhS/M/3uIOfxsk64qJuoQzuIRAwh1HOErdmka2r+Dc2qc6esAdiAfIbhB1L0vCYN ojcWPpj04y+bHDh/lOgZA7NhKZUdi+SGGs9QiV7JapqJIVgqhOhVFH3xASOSMfqiSbXq 1obQJPpOIqVMX3l4gMKz6o42ZeG9agZ+9nsrhyizrxHMD3S8aXfga7C5iHnYGA4rXJUz gMqA== 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=JAmOXeQ0VHSXwwCpVm3J8YOQijq+7iGoLz/Vka2YTMk=; fh=G7ZlAr70Yaaswd0lSBdeWTut9nH9lGr4t2urRXsbfDI=; b=nugTyIl2NTYwwPvzxgXIlm7VCZ90PzWF0YzOJZy7Xo90iQGPP3P83MW3FSnDGxY4k0 nXdN7IOmJlLeB5PJjFF5rKf0x4nqNBrppNIKHr85XtWYnpAuL3ObDdc53LTl6dB/DHxZ M8UjOgn4rJ8Dm+DETHg2KIBm+j/Kk0hPoEJxLZ/CoykFyCOOmOw8ngQehjXCQXOsPbXg I3De91Y+1niFd9cvRZn7TepAhhpXHolitLrwEF6fIkmJRwA3jZA3AUzDmOn0qXuBMF28 UrXL36Fnu7pgiZU2DT5GaVrxG71Ran5XuxnTIS5Myw8G/Pc9xjw+RjUNDPthLMnwEamQ cjkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=dL5mRwRg; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020aa7cb43000000b005236afdc062si4723645edt.209.2023.08.11.21.52.52; Fri, 11 Aug 2023 21:53:30 -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=@google.com header.s=20221208 header.b=dL5mRwRg; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbjHLCMX (ORCPT + 99 others); Fri, 11 Aug 2023 22:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjHLCMW (ORCPT ); Fri, 11 Aug 2023 22:12:22 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FCD2712 for ; Fri, 11 Aug 2023 19:12:22 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-99c1f6f3884so351063466b.0 for ; Fri, 11 Aug 2023 19:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691806340; x=1692411140; 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=JAmOXeQ0VHSXwwCpVm3J8YOQijq+7iGoLz/Vka2YTMk=; b=dL5mRwRgcxjtqEDoIfRVMPS7RQHFXTHE2dp81+2iSyKXxXmt4p7Hsdcs/WW6OzCHr8 Y+xyvdJtwyK3FfdlwZaw/9Oa+tVjzhIK9ZpIYGIKTttzLEdfTgucXs5GlYa6o3PjHK4u kSBkUqpRxu+rx5jjYWx87+cxT1jssYONnzxfCbyWKZwB+wH+NnC+tBkidjKeFqT6RD5Z e7l2yuGfipD3XpnSOnDhKFMWcwXAehVpQ07p8xZ/bz0+NuI8JvWRtiEU3NapnlmZfpMP mJ2KxJGQLN6DjHjWVqh+mvYjfymau+k6k/smOk9HuULcU+wGkNjjR64SI5hB4UdvRJj/ DzKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691806340; x=1692411140; 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=JAmOXeQ0VHSXwwCpVm3J8YOQijq+7iGoLz/Vka2YTMk=; b=G+z+bhWdvPZfHuRCivXA9R3BoM6+cjMhd/cY3NP3ljkwtdpN+xDgZaV63LlkXeT84r QlGOim49lgPn9tYGuLuFSHWzve8nqlsMSVVaXrwxwqrTe97GVB0CpLIQyzwpxovQYfzd yf33ryL53Y1ilsbNh/LpzyUpNSMFNHQwhuXG+A9jpBGgvpAeRmBt6j72gF8LMNEN2nVb nE/bsJ508+7IPbg08rj1m7gYY/fvFzZbxsZyd99XbXQ4KG5k78Ftl/gQvA78uqapMioy roHzfKl5D4ooexX9EKmjTrLxNYjAg4JQEZGbqg3iliMkncmiaqGGl2P2iEEcp461YUdk 54Ug== X-Gm-Message-State: AOJu0YzhQGJYS9w/7zlG+Y/dRpZHTSYby2H2JPzPqlBrxQW7MGE4V9cM TPCurFJU0R7AGPcr+V9IF/kzNlud+unzgzRu2Behqw== X-Received: by 2002:a17:906:de:b0:99b:f49c:fcfa with SMTP id 30-20020a17090600de00b0099bf49cfcfamr3069435eji.21.1691806340376; Fri, 11 Aug 2023 19:12:20 -0700 (PDT) MIME-Version: 1.0 References: <20230809045810.1659356-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 11 Aug 2023 19:11:43 -0700 Message-ID: Subject: Re: [PATCH] mm: memcg: provide accurate stats for userspace reads To: Shakeel Butt Cc: Michal Hocko , Johannes Weiner , Roman Gushchin , Andrew Morton , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Aug 11, 2023 at 7:08=E2=80=AFPM Shakeel Butt = wrote: > > Hi all, > > (sorry for late response as I was away) > > On Fri, Aug 11, 2023 at 1:40=E2=80=AFPM Yosry Ahmed wrote: > > > [...] > > > > > > > > > > Last note, for /proc/vmstat we have /proc/sys/vm/stat_refresh to = trigger > > > > > an explicit refresh. For those users who really need more accurat= e > > > > > numbers we might consider interface like that. Or allow to write = to stat > > > > > file and do that in the write handler. > > > > > > > > This wouldn't be my first option, but if that's the only way to get > > > > accurate stats I'll take it. > > > > > > To be honest, this would be my preferable option because of 2 reasons= . > > > a) we do not want to guarantee to much on the precision front because > > > that would just makes maintainability much more harder with different > > > people having a different opinion of how much precision is enough and= b) > > > it makes the more rare (need precise) case the special case rather th= an > > > the default. > > > > How about we go with the proposed approach in this patch (or the mutex > > approach as it's much cleaner), and if someone complains about slow > > reads we revert the change and introduce the refresh API? We might > > just get away with making all reads accurate and avoid the hassle of > > updating some userspace readers to do write-then-read. We don't know > > for sure that something will regress. > > > > What do you think? > > Actually I am with Michal on this one. As I see multiple regression > reports for reading the stats, I am inclined towards rate limiting the > sync stats flushing from user readable interfaces (through > mem_cgroup_flush_stats_ratelimited()) and providing a separate > interface as suggested by Michal to explicitly flush the stats for > users ok with the cost. Since we flush the stats every 2 seconds, most > of the users should be fine and the users who care about accuracy can > pay for it. I am worried that writing to a stat for flushing then reading will increase the staleness window which we are trying to reduce here. Would it be acceptable to add a separate interface to explicitly read flushed stats without having to write first? If the distinction disappears in the future we can just short-circuit both interfaces.