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 E3FF2EB64DD for ; Sat, 12 Aug 2023 02:12:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C7306B0074; Fri, 11 Aug 2023 22:12:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44F326B0078; Fri, 11 Aug 2023 22:12:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CAF86B007B; Fri, 11 Aug 2023 22:12:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 19AA96B0074 for ; Fri, 11 Aug 2023 22:12:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DCABC80302 for ; Sat, 12 Aug 2023 02:12:23 +0000 (UTC) X-FDA: 81113828166.01.38FE4BE Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf18.hostedemail.com (Postfix) with ESMTP id 0D96E1C0009 for ; Sat, 12 Aug 2023 02:12:21 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dL5mRwRg; spf=pass (imf18.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691806342; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JAmOXeQ0VHSXwwCpVm3J8YOQijq+7iGoLz/Vka2YTMk=; b=0Owg+3PIpMPoFz4bknCLYSvLfRvokjq/YRf365gC1tSjQVueeCHXszDa3lVM/DgKfNUg2Q VBZa0dHnrWSjMmP823CR5MkTm/lNrucLCMcDx0vrCWPfwbL8kYqpoCy1/P595bax4oy1t0 wNj59J7iGoQloxTd9Cjgo4CvVtwr2gw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691806342; a=rsa-sha256; cv=none; b=Eb+b/qPVllpHgBYjJ1apRAjR0SoYaaQTQTboh0vFW86wGz4lzu9xDj1r3kYxBUt/9I1LCL 4Kn5WLBPOSff3VDtUXYAcsMFQVSzBLGO7sqRy+kc5J1Mq0zSQA7Iz/rMDzprN+ab4cv4lt O2aV4IrzeK8urqq0HXEl5mCptNKM3GQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=dL5mRwRg; spf=pass (imf18.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-99bed101b70so348619366b.3 for ; Fri, 11 Aug 2023 19:12:21 -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=E6iTRvAT4iPNjM18VtJyVcVo5hifsE0E+3pU86QtO5ohvrGLoY5RiNEv8sxLgPSldn zgMgmFJ2aIkVBIrJvivHtQ9vcKE0xd+By0p03ud/67YClwQgicL6ofcfqVG/XJgNhtha MqRl4IAPS0FEAC1Bud2C9rf1eVHBvmdbwtw1c4NjNczQRKcwnrxPo4FWXnrgqZJsEvR6 Sf9lr7Dlok32572i1bAaGxgHiPHWAyq0dYOUeHCRdv+0dNYlSIyqorfdj2B0rLiAIY/t kjTK0hMpYUst5/tolZC+PxIza35p00oFXXadqhbuysjq4y6+NIXOxLgp7/3w10hPJX0c qAww== X-Gm-Message-State: AOJu0YxFiAj+GMiSnzQJkdaE9dYuh224WogB4FuWH4qr42vFRWpUsjGF eW4MMEgOWT3rviJ6bFLFjg6/JSvAF57pxd3CJ6JiRw== X-Google-Smtp-Source: AGHT+IE2He6oTlb1mSgLv7Sf/Jbk069NPiIARvyAXaubULmw2CYAwt1dcof3RXQ7QiFE0iEHEzRtxm+Y39pwK8Qurz8= 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-Rspamd-Queue-Id: 0D96E1C0009 X-Rspam-User: X-Stat-Signature: moqsggynfujdzn3n44xongctkozc3iqc X-Rspamd-Server: rspam03 X-HE-Tag: 1691806341-723618 X-HE-Meta: U2FsdGVkX1/XYoh+1aGxjgQFRULJz88QzGMmnbK1EZVUKBIoSlPrlUVgHFwbE/X9Dj/SPORxPODChI+q+QxKXhOWk5r9GTUPml+/POawXSXUp7BrDNtYs8BmOEIbF5FD5GB/TZ3Ezq5CCyq3dYNw+B3WE1y6vpc5Kgsj5OiWuOFPYART/RRDhYaeLEAbsV2kFrKCace/cO+vFdImW0nDBSrrrqQyHQyuUUBMy1K0CCDoAjpBJTIqgMnA5apin2enI+UVfkJm8AzwbLfOlsKlTsSIFL+79GrROG8Ip6w7fLbIo4htuuXcoEgsCRM1MCRJHJc9OPb4eLOg+qExhDI2XgvrrH6BDIZiu+isozWO8VBwphu9pINm4PoftTP9/ru37R5XNWXJNF56Tjh9v8oQC8WNLrtu4/1/fNdy2xjvRtz8/pTyBbki+ZBDj0JlTZ6ke3KKcnKk/y1tY8jqh0QhVUu1sC2V7w1CW/tTLzHQf4/z4q1RRO7QYUzgAnWwvpY493DEjD5ftvrTkTo+9qrTx3VS1PQqdnZNIWJogPyfX1xtsbtnFw9b5x3ip+W4e/PR6sjqCnUCWjk2u5fnYeu+Hlwb6s5NLAiiHhoM3xir96uD8ZugXi7UpKCywEnuInKTka3hw5TOQwVhlfiT4rdlOqIwMTG0UDnoxpdQEdw1FGPlIkRMJQ2aWcRSPZzfH7hmsMO5dYkvGiYBBySt91vzA57w6r+CwaeROSHCyt398ne7HrrfBMZWCeggKuooK3S2HUv3bYjd+cQhRPoCmURQ3VuV2Z1S5mbZuN+Nh+vY2MX5ds4rny2VTpsNWqlNSvq7gv8z46M6IeKvIhFJoZiIjGAL3Z0LAtxKbuZdfDnMP4drkX8ehv1sZzbZ/zxD1gBM6aRKApt38Xsbp2iaGPM1n/FUtWvfHjdnnBNCYJIFYuEy5E2ujNNpPaYjhpKPcl9ZvLlEcXGuKMm6arQVSJb NUgtRt/Q GEepaBbEZIQ8AXHltZPyoYboblKhwARzrKgfDyG9snNMU6+s1UmlIbbNd6yIWrtouhMBGXjp/9NcNfXVRxWj7YsoxSfTRi6gThwf9tVCQJLin6NOzIqts8+kZ5tvHEZ+yv6OINN5PS0ePHoMZBUBigIT15X462G5jRW/2Wdrykuxq5wqQxXveD7BCHgcv89a5b9aMsS/cvLTxlde//DUUQqRRNM+T6NsHhTMffEgTowh/BQtfvHM76qHirg== 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: 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.