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 13E9FC3DA4A for ; Tue, 30 Jul 2024 02:38:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 982566B007B; Mon, 29 Jul 2024 22:38:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 932636B0083; Mon, 29 Jul 2024 22:38:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FA2C6B0085; Mon, 29 Jul 2024 22:38:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 60D006B007B for ; Mon, 29 Jul 2024 22:38:52 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C403E140164 for ; Tue, 30 Jul 2024 02:38:51 +0000 (UTC) X-FDA: 82394861262.24.CACA2B0 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf07.hostedemail.com (Postfix) with ESMTP id BFC604001A for ; Tue, 30 Jul 2024 02:38:49 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=zQ+lHVaE; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf07.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722307069; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PyUDu60PCAuM2zRNcpq+Dc/3a1+n03wqWjS5ucpFVHU=; b=atm/o2P8edw1eDTVQV00Te9io+sUlcG+PoIavFc0D39NqYvXwvgr60WiB4EyK2JvYxubh/ aGq5ysBhKvYSqnLOmZXAn3hARLsaK4Mx1XjBTYMwFfR1vebpdSYqLIGokCOvDcwU33GO0w IwzrzP7IFdhJnKjb0FQIPG9cUpziUck= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722307069; a=rsa-sha256; cv=none; b=6auPRkH0lIRIcZUjhJ9IGsigRfCPDU8qVdaap7XbaNv5LAPJHMB8lxPaICJAKnMYM6NiRR 0pwgLjND0BKy2y3UFL3o2QXeoBYxTW5RRFnS9DaSu31CHLNYOC14wRveN32K2rULxky0vj vrlZhx1q2XqrfVYZHNgWz430II0cfDA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=zQ+lHVaE; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf07.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7a1d7bc07b7so253217585a.0 for ; Mon, 29 Jul 2024 19:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1722307129; x=1722911929; darn=kvack.org; 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=PyUDu60PCAuM2zRNcpq+Dc/3a1+n03wqWjS5ucpFVHU=; b=zQ+lHVaEGcCZPnn3xOASicfA5o8r8ZzcZBrw57rtKnNA6kfqpCBAO9Vhu6wrtJXWgN so9zjkOHRZCN601qyTHUKhRDtLv02xve2KwUrkPah10WX5Y4es+mLC/N8Hq1zrp/vYrp 34wlfSzc9GW2W5GNrSQ7Eao2X/+wkpOqDI0qgPHn28CQ9/sXnmC/ljw2XkLJ3/HJqFBc NpLSODLNqcjgAVKFkb5XF9KGxWiTT1qVG05NjYWWQM+QXo7ofMZXo6Y2rrW9IRWBQ/sw /lYhYyz0S5AFkag/wvwVlIWT19Qgvkl0ezmd4PfkhhsNLB/HZK6E1oNrAIx3fnNDbTjX BFIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722307129; x=1722911929; 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=PyUDu60PCAuM2zRNcpq+Dc/3a1+n03wqWjS5ucpFVHU=; b=sa3jV/uuUSgdl53/rcRLC2ajiOkY2pQ+lNhokdUtVP3WEERJc5T8vBlDWeJro8QlPl F6iWmVO2c0nvM1pBN3WByZ4V5J812TpZh1s+JKPmrVlrpUY7seVsXHXR0mCT7Z6A5sql stoKIB2Z7sg+872aYfhWkniFZiewVwI5I4b4x1srRdpDN1wbuu0QLXMqWt2ZwmCJ/mk1 UJj0SEarR45yaQHa+5yXSz7OVddYtu0J7Xu2ajtxfuAI5uChHah93IRSa4ob9va6Jvzg 7wdW9IGclG+RHTImtecBRWh6afDun5j7WLphVK+Jyr5k+nFiD4OhSZF0N9v4sCBRoHxu OfgA== X-Forwarded-Encrypted: i=1; AJvYcCXxfJvUbG3Kxh0xo5cwNJ1h2UY/ptoEB/7hr/dqMFTpMVMjRYU2Vo8UUj76Sq3nK5rMuW/3tl5/W/PHGVN7ZyrTKos= X-Gm-Message-State: AOJu0YwDJ/UfX/3KZz3aecCeWbPYH13f7S1Qp0rIB8QWsrbP6bAxZH7n cxg3HtbwYbpz+Vy8eLFBy+5s1zL9Hygjx2zqSkArlSfrDe0S9bWY7TyDTLMgUlc= X-Google-Smtp-Source: AGHT+IFUGolmZq/G9ttSj13GVAYbDNH+XIHcDQUS+VIQDesWEnVNI2yCkrS+idWQDi7u+ZKdaSWM4Q== X-Received: by 2002:a05:620a:1a1f:b0:79f:709:a38e with SMTP id af79cd13be357-7a1e524c72bmr1260215585a.19.1722307128647; Mon, 29 Jul 2024 19:38:48 -0700 (PDT) Received: from localhost ([2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a1d7435509sm592811485a.84.2024.07.29.19.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 19:38:48 -0700 (PDT) Date: Mon, 29 Jul 2024 22:38:47 -0400 From: Johannes Weiner To: David Finkel Cc: Muchun Song , Tejun Heo , Roman Gushchin , Andrew Morton , core-services@vimeo.com, Jonathan Corbet , Michal Hocko , Shakeel Butt , Shuah Khan , Zefan Li , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Michal =?iso-8859-1?Q?Koutn=FD?= , Waiman Long Subject: Re: [PATCH v6 1/2] mm, memcg: cg2 memory{.swap,}.peak write handlers Message-ID: <20240730023847.GA2866591@cmpxchg.org> References: <20240729143743.34236-1-davidf@vimeo.com> <20240729143743.34236-2-davidf@vimeo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240729143743.34236-2-davidf@vimeo.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BFC604001A X-Stat-Signature: otudg7ehfrnrh9hxnn6wgwofuecr6d94 X-Rspam-User: X-HE-Tag: 1722307129-610425 X-HE-Meta: U2FsdGVkX19oy6jBeRqkCQhCNsbi7rwFuvaFl7Zn8GA7w3kg3kEzcUJzvURYJza6Floeu1Ui6kdooZVzy3Z8suISXx0/7lXn2PPmO/UKJkfci+0xCh2dGcDtOkD+Ca6o9erL/DAgcrJougtSeGmzioTzeGp2mQz3PJ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vadHli6fJmUqmI6NS3BA3ImQehgQWv2gK/131v4haGvO4igY6xy0Ak9LritCHsj9z6vvC2OpcFDK+zk7jVpi1bX8C8k1Ni5GBYR6Bsi2nBJDHRgaLcnOAT5ZV5eWpwWmKuKO89C+bsTD4AYb5H2X0RLhBnmNyod+l4cZXhIOoyeCP1hNmBQl532OdXU7DeDv1jPBVO8k8uarOxvzOQsUr2yPUb3xijkU+3RaUpVyTQqShgJuDKDyl7 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: List-Subscribe: List-Unsubscribe: On Mon, Jul 29, 2024 at 10:37:42AM -0400, David Finkel wrote: > Other mechanisms for querying the peak memory usage of either a process > or v1 memory cgroup allow for resetting the high watermark. Restore > parity with those mechanisms, but with a less racy API. > > For example: > - Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets > the high watermark. > - writing "5" to the clear_refs pseudo-file in a processes's proc > directory resets the peak RSS. > > This change is an evolution of a previous patch, which mostly copied the > cgroup v1 behavior, however, there were concerns about races/ownership > issues with a global reset, so instead this change makes the reset > filedescriptor-local. > > Writing any non-empty string to the memory.peak and memory.swap.peak > pseudo-files reset the high watermark to the current usage for > subsequent reads through that same FD. > > Notably, following Johannes's suggestion, this implementation moves the > O(FDs that have written) behavior onto the FD write(2) path. Instead, on > the page-allocation path, we simply add one additional watermark to > conditionally bump per-hierarchy level in the page-counter. > > Additionally, this takes Longman's suggestion of nesting the > page-charging-path checks for the two watermarks to reduce the number of > common-case comparisons. > > This behavior is particularly useful for work scheduling systems that > need to track memory usage of worker processes/cgroups per-work-item. > Since memory can't be squeezed like CPU can (the OOM-killer has > opinions), these systems need to track the peak memory usage to compute > system/container fullness when binpacking workitems. > > Most notably, Vimeo's use-case involves a system that's doing global > binpacking across many Kubernetes pods/containers, and while we can use > PSI for some local decisions about overload, we strive to avoid packing > workloads too tightly in the first place. To facilitate this, we track > the peak memory usage. However, since we run with long-lived workers (to > amortize startup costs) we need a way to track the high watermark while > a work-item is executing. Polling runs the risk of missing short spikes > that last for timescales below the polling interval, and peak memory > tracking at the cgroup level is otherwise perfect for this use-case. > > As this data is used to ensure that binpacked work ends up with > sufficient headroom, this use-case mostly avoids the inaccuracies > surrounding reclaimable memory. > > Suggested-by: Johannes Weiner > Suggested-by: Waiman Long > Signed-off-by: David Finkel Acked-by: Johannes Weiner