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 742B5C83F22 for ; Wed, 16 Jul 2025 19:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2E048D0003; Wed, 16 Jul 2025 15:59:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F060E8D0001; Wed, 16 Jul 2025 15:59:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E42BC8D0003; Wed, 16 Jul 2025 15:59:21 -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 D86108D0001 for ; Wed, 16 Jul 2025 15:59:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A8BFC1DA688 for ; Wed, 16 Jul 2025 19:59:21 +0000 (UTC) X-FDA: 83671192122.22.07F515F Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf27.hostedemail.com (Postfix) with ESMTP id AEF4B40014 for ; Wed, 16 Jul 2025 19:59:19 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=frzjju8t; spf=pass (imf27.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752695960; 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=yjMZ6us4TdD9QVBjf4ldOi/koyIhqOXFOROnbj4ANDo=; b=KRihpR2EWQ25tAhPawys4yfeRwS17LUpqNz2w/Id4dV5MNDhKPvaEWfibFeIdEbl6UQRL8 FhHXoEMrnH/XwWV4juM3n4kMsuJounjqLYlHnDf2sTpyhksD5i+jMxkJ01pI8del58QKFE /gRm8W+C5C2BzMhIKujD7Dy/PxiZaEU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752695960; a=rsa-sha256; cv=none; b=AGUX/Nz9Asc5VdpC63+v8LnJpZxo7apKNEV7Fy2V0R5YSvpK4AXjlLeRHPjEQQPQAmfMCP Id8YvnJhpVRvP9kOqOkvrGaKbhOtdKa34P07V1VR7ILKXew5X/DNlV1sz7kr4Toavx4wUd i5PHXw3Gs501nDCYFqlTCHnbNbuRXXc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=frzjju8t; spf=pass (imf27.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Wed, 16 Jul 2025 12:59:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1752695957; h=from:from:reply-to:subject:subject: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=yjMZ6us4TdD9QVBjf4ldOi/koyIhqOXFOROnbj4ANDo=; b=frzjju8ttZeKrvxATp+pFSdGVWg8+e0BSL9jtZTc5IUkrY27447fdYlnuOT3vODdEpjibL wqNk8b8nHJvM0s0JpZJP3EIbJ1OI+sUAmO4Yq68leOh81pWRqN0gwt+wsgcT5SxLvW+so2 FmK84tzICOZXZhEJzh2BpMWxPix7VWQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Kuniyuki Iwashima Cc: Andrew Morton , Johannes Weiner , "David S. Miller" , Vladimir Davydov , Kuniyuki Iwashima , linux-mm@kvack.org, Neal Cardwell Subject: Re: [PATCH] memcg: Keep socket_pressure fresh on 32-bit kernel. Message-ID: <74yeh3tde3uzugxplhpr7mfvrtnoqoek2weqbwujegb53yybcw@lgqtoskse6ef> References: <20250716042925.106239-1-kuniyu@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250716042925.106239-1-kuniyu@google.com> X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: AEF4B40014 X-Rspam-User: X-Rspamd-Server: rspam09 X-Stat-Signature: a9fqwfwk6r8ti8o1ix9d1t6m9ci3zzeg X-HE-Tag: 1752695959-716686 X-HE-Meta: U2FsdGVkX18DRMOPhAze58mwi1Fokf/DxUecDJrdMoiiHgcXOCEZFtDLIN3SILz8J5jd6CCdRI8GF8KvEm9Znlo8vvF/OXim3Ak3cgHesZEaYjoN5aAqKRiedAYtVU1vT3OmBswJlZG4zgcFZcPqsrfRaxQiGq1+uyuQpixrcalQLjs82JxpLryOcmaGfWVrf/dtTRn3q/4Qwj0WKiYy8KaSGywsVhHVBbj3dzdj8EuJiBFQPyAnpW20bth9HBlVuDCMJkm/QlrTpL9N01ONhf7XtoTIxFHDLqE8Mtm/DWleZ9FLGHONA2ysvCkRXsgXQG+HzIgjD6pgJy6uNJbKDQpshJto/eOZUMji1MBJ3k6FbGsxELqO3M1RC1zjfE5dAUFCyPbc+EnUAwddTRbvl/gD9OnVKm7y8DMfZraYUEoBoa3O6HfTq5GD441EvjmDZTIWmC8yzFe1lfJSLS528Kz0zafVjdCeYnl0QT7yY8BeMJNAaLyaFtdMPzpW+zNiLaGBb02XTVmM/BtS4F+YfT17QmWi/W5Liu6fe17XvaXu1AJAwK/MNYCWSlx9oN+dAAnPsY6S8drHP5Mb61ZmLYFOGnuOmLoix1+P1ulQsjnZx5T+TUrWl4yKj9PIV+DBkbv3xfTeEPbZ46+SSUoJ8H3TuU6TPT0avZF2EmSD5uPlzp5OSwUCkGPgnXefLgemmlPbDdXfwRdylqfeyytw5Pqh2go6w7o/BInOfVCDCmLkQ6daBhlLB9gChGViFnRs3k2RRDtE8v04UZ0Exl4x+znqkYdKfZursqd7PLbPGYDu/2DuRreeWSkYOL+igPbemb/qSFWdqPMhpchC8j6jzgBVLaRJNxNqiCt07N/fM1V65TeDA7/IdKEZcKNfZH4e/QHRIEEapqH6lfCskbh43VEpIxOeLGA/H7tf5wIsS+/68m96l1CPELJAOq+tD9SWv6MRAy4X0H7XKX65VC8 jc7P+0RE T5zMJHFMcXbhaPTRfGBWZGOG3ou0vv1JV1DeWuADDH0v2z2vYtQ1EVvNimh+qC/tfgr720Yzc3PR2O+sTJdjU4eiz9Ug6OqeqGGynpsAvYNKYN59biyEkwoc/MtguV/TYJStNJp72/otJzz5TPAwTfhXusSVpJqeF53GZlZ4Ezsv0/jFvNf4uqBVzt8gZTu8Wh0RwsIAVS0UUzfhap5OhcBcNUKqedCAJqam9U7MElazf0JQk7V+9p628c6LbBlpzwP47MdwUuTjOer3YPpqzafVosImzbFCpRvYx1wIECfW1qvC/9OVA8BhRsdZZrj/gITO13iI8StUv5zIk0dyqF29yvFu6JbdwZ3eI 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 Wed, Jul 16, 2025 at 04:29:12AM +0000, Kuniyuki Iwashima wrote: > memcg->socket_pressure is initialised with jiffies when the memcg > is created. > > Once vmpressure detects that the cgroup is under memory pressure, > the field is updated with jiffies + HZ to signal the fact to the > socket layer and suppress memory allocation for one second. > > Otherwise, the field is not updated. > > mem_cgroup_under_socket_pressure() uses time_before() to check if > jiffies is less than memcg->socket_pressure, and this has a bug on > 32-bit kernel. > > if (time_before(jiffies, memcg->socket_pressure)) > return true; > > As time_before() casts the final result to long, the acceptable delta > between two timestamps is 2 ^ (BITS_PER_LONG - 1). > > On 32-bit kernel with CONFIG_HZ=1000, this is about 24 days. > > >>> (2 ** 31) / 1000 / 60 / 60 / 24 > 24.855134814814818 > > Once 24 days have passed since the last update of socket_pressure, > mem_cgroup_under_socket_pressure() starts to lie until the next > 24 days pass. > > Thus, we need to update socket_pressure to a recent timestamp > periodically on 32-bit kernel. > > Let's do that every 24 hours, with a variation of about 0 to 4 hours. > > The variation is to avoid bursting by cgroups created within a small > timeframe, like boot-up. > > The work could be racy but does not take vmpr->sr_lock nor re-evaluate > vmpressure_calc_level() under the assumption that socket_pressure will > get updated soon if under memory pressure, because it persists only > for one second. > > Note that we don't need to worry about 64-bit machines unless they > serve for 300 million years. > > >>> (2 ** 63) / 1000 / 60 / 60 / 24 / 365 > 292471208.6775361 > > Fixes: 8e8ae645249b8 ("mm: memcontrol: hook up vmpressure to socket pressure") > Reported-by: Neal Cardwell > Signed-off-by: Kuniyuki Iwashima Is this a real issue which you have seen in the production? I wonder if we can just reset memcg->socket_pressure in mem_cgroup_under_socket_pressure() for 32 bit systems if we see overflow?