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 0D1FBCE7AEB for ; Thu, 28 Sep 2023 03:03:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 417AF8D0055; Wed, 27 Sep 2023 23:03:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39FA08D0002; Wed, 27 Sep 2023 23:03:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 240638D0055; Wed, 27 Sep 2023 23:03:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0F0958D0002 for ; Wed, 27 Sep 2023 23:03:33 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D406F1A02F4 for ; Thu, 28 Sep 2023 03:03:32 +0000 (UTC) X-FDA: 81284510664.03.C5B7A04 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf02.hostedemail.com (Postfix) with ESMTP id E60768000E for ; Thu, 28 Sep 2023 03:03:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b="Rz/9T2Cq"; dmarc=pass (policy=reject) header.from=shopee.com; spf=pass (imf02.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=haifeng.xu@shopee.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695870211; 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=DVp3VI4K1tI9SqzvKTAU71U5E0qC9V90AnWjuaLY+n0=; b=FS87HASpBJZAmm7MH5kjVHdwhTZWiQ38JAzqL+9OW+Nv52JdfNoI/4ToDSB0hmmL5SIEbs xycCRz8Rqib92+XH/XWSB4lmz1NRLoXDoocB6aKwIHc6qIyzVmPSrWPySQGhzZOnrkpw8T EgNB0cPS0Ct+gB+3HnxMzqvP8LcM4io= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=shopee.com header.s=shopee.com header.b="Rz/9T2Cq"; dmarc=pass (policy=reject) header.from=shopee.com; spf=pass (imf02.hostedemail.com: domain of haifeng.xu@shopee.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=haifeng.xu@shopee.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695870211; a=rsa-sha256; cv=none; b=m2szfO7kMznBdktfCxHjfZrhxupSb9MVDug+aXQyUxUAr3cJpdopH/Rax7Lw6f1T6cTvAk Ubkkcc0NzdCbKjb4MoM8cAqRAa9DuzMqPzvTkrvbzmZ2SFxdsicRZxkn/W7kL5WORaPj6H g3HWT5tQ3lCoXpeccv89IROvwYY8iT4= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5809d5fe7f7so5969220a12.3 for ; Wed, 27 Sep 2023 20:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopee.com; s=shopee.com; t=1695870209; x=1696475009; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DVp3VI4K1tI9SqzvKTAU71U5E0qC9V90AnWjuaLY+n0=; b=Rz/9T2CqcYixZ+BAGv7v2K1fPPSDE78xGV7ncNR/TCxV1jKQQw4H/lomLepeqp8MGY rnx14tkNsYJpjCX8teh4q2HEoE1e4l/xDovbz4xzXMLKibwUHDtTxMwLDh1IEFgrn7L6 BExd9fnkjTVkeI+qrUT8jiwW1PijlLlwb8pe84iEwjc8g4Z2r3rvX+VWj+6KAFCei8TG f3dfire227Qj2D+m4Yyo2TyUnAwDgLL873J4ixkpOqre3j2ZZXe0LVCPDjHwz9xnjFc/ KjFmG+iF/IlMvnghcIjUkM35/z/kYA8ORTxxBbhVgvbuZPq6A+0oiaH8Qr2jvZ+IPn0p MdCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695870209; x=1696475009; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=DVp3VI4K1tI9SqzvKTAU71U5E0qC9V90AnWjuaLY+n0=; b=AfYi6nbDOnYUv7WPwZTcePfRY6LKJlGNfGV2IMQZQSUL17uHYLnHzmf7YWofZTlKkL PTZJgwsVnLigNMgVdqjTDCqteEjeJ1LOG4WZD83t1oX6ecBcEj8XXhyjlUCNG+hpM2+8 2/J785orR9XWOD47YhkTgS7s1J08BQFzcAd57EVMbq1JpySJl8TCqECOGPb0fpy1V8ID qVON1Yo6perYbgrRCHzVbKn043UT6UXC3yQIClUaqH1B1gnG3x0uf9NIVq7yPJjBcGeM oQXFEoQmJqVjARsDQPGnTLLgnuAFb9E/9lisJNUF9we0VRmV8mUoHA3gMbodMVsBioXb hiKQ== X-Gm-Message-State: AOJu0Yx+ku1DOcLTh6OYHwtv5keJgAc6xlBq2fO5zXhugOc09EpuRFvP BmVv2Xz1m3whMOhz+3jB0KYXBg== X-Google-Smtp-Source: AGHT+IGvIh+DVVXT4Vgsra6G3wWuOvOrgvQvGGBf6PALSSJvSJKEcN+WnYghw13AeOn3cwjWdbPnOQ== X-Received: by 2002:a05:6a21:6da4:b0:14c:e4d9:de46 with SMTP id wl36-20020a056a216da400b0014ce4d9de46mr16585pzb.39.1695870209638; Wed, 27 Sep 2023 20:03:29 -0700 (PDT) Received: from [10.54.24.10] ([143.92.118.3]) by smtp.gmail.com with ESMTPSA id j12-20020a170902c3cc00b001c72d5e16acsm775522plj.57.2023.09.27.20.03.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Sep 2023 20:03:29 -0700 (PDT) Message-ID: <9b463e7e-4a89-f218-ec5c-7f6c16b685ea@shopee.com> Date: Thu, 28 Sep 2023 11:03:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 1/2] memcg, oom: unmark under_oom after the oom killer is done To: Michal Hocko Cc: hannes@cmpxchg.org, roman.gushchin@linux.dev, shakeelb@google.com, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20230922070529.362202-1-haifeng.xu@shopee.com> <6b7af68c-2cfb-b789-4239-204be7c8ad7e@shopee.com> <94b7ed1d-9ca8-7d34-a0f4-c46bc995a3d2@shopee.com> From: Haifeng Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: E60768000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ifr9edkfinmtx4oks8pc7mhzi4b3e5rr X-HE-Tag: 1695870210-733314 X-HE-Meta: U2FsdGVkX19TliqPuatqk0fXfyZGmJdVdX7EWfom3/9OJ6rwDUyA6h9Rz+MUtI+OUVNsxS4v1amvkeyEK3KXTRlE5lV7RPImTobyuml5lArwwGwwb9drEoKDzKLbNNYwKMe26NLtoGhQsC4cHHWUEqV3Z+mLXDTwOX1XS0r+rWqhJUzLj8HwA5tRPpPhsXsNceONq/GfPozRH9mRYRY6OnIT1ozhPPDSVll8xFYMV05Dw0oITbqwto15Q4iOyRBj2lZvmZb/gVtqHu6bcRh6Jty7SJ2QEXgrD8jAT6rCRKqbGTQcJPW77RqdcjTfQ0nd+YTl5v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, 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 2023/9/27 21:36, Michal Hocko wrote: > On Tue 26-09-23 22:39:11, Haifeng Xu wrote: >> >> >> On 2023/9/25 20:37, Michal Hocko wrote: >>> On Mon 25-09-23 20:28:02, Haifeng Xu wrote: >>>> >>>> >>>> On 2023/9/25 19:38, Michal Hocko wrote: >>>>> On Mon 25-09-23 17:03:05, Haifeng Xu wrote: >>>>>> >>>>>> >>>>>> On 2023/9/25 15:57, Michal Hocko wrote: >>>>>>> On Fri 22-09-23 07:05:28, Haifeng Xu wrote: >>>>>>>> When application in userland receives oom notification from kernel >>>>>>>> and reads the oom_control file, it's confusing that under_oom is 0 >>>>>>>> though the omm killer hasn't finished. The reason is that under_oom >>>>>>>> is cleared before invoking mem_cgroup_out_of_memory(), so move the >>>>>>>> action that unmark under_oom after completing oom handling. Therefore, >>>>>>>> the value of under_oom won't mislead users. >>>>>>> >>>>>>> I do not really remember why are we doing it this way but trying to track >>>>>>> this down shows that we have been doing that since fb2a6fc56be6 ("mm: >>>>>>> memcg: rework and document OOM waiting and wakeup"). So this is an >>>>>>> established behavior for 10 years now. Do we really need to change it >>>>>>> now? The interface is legacy and hopefully no new workloads are >>>>>>> emerging. >>>>>>> >>>>>>> I agree that the placement is surprising but I would rather not change >>>>>>> that unless there is a very good reason for that. Do you have any actual >>>>>>> workload which depends on the ordering? And if yes, how do you deal with >>>>>>> timing when the consumer of the notification just gets woken up after >>>>>>> mem_cgroup_out_of_memory completes? >>>>>> >>>>>> yes, when the oom event is triggered, we check the under_oom every 10 seconds. If it >>>>>> is cleared, then we create a new process with less memory allocation to avoid oom again. >>>>> >>>>> OK, I do understand what you mean and I could have made myself >>>>> more clear previously. Even if the state is cleared _after_ >>>>> mem_cgroup_out_of_memory then you won't get what you need I am >>>>> afraid. The memcg stays under OOM until a memory is freed (uncharged) >>>>> from that memcg. mem_cgroup_out_of_memory itself doesn't really free >>>>> any memory on its own. It relies on the task to wake up and die or >>>>> oom_reaper to do the work on its behalf. All of that is time dependent. >>>>> under_oom would have to be reimplemented to be cleared when a memory is >>>>> unchanrged to meet your demands. Something that has never really been >>>>> the semantic. >>>>> >>>> >>>> yes, but at least before we create the new process, it has more chance to get some memory freed. >>> >>> The time window we are talking about is the call of >>> mem_cgroup_out_of_memory which, depending on the number of evaluated >>> processes, could be a very short time. So what kind of practical >>> difference does this have on your workload? Is this measurable in any >>> way. >> >> The oom events in this group seems less than before. > > Let me see if I follow. You are launching new workloads after oom > happens as soon as under_oom becomes 0. With the patch applied you see > fewer oom invocations which imlies that fewer re-launchings hit the > stil-under-oom situations? I would also expect that those are compared > over the same time period. Do you have any actual numbers to present? > Are they statistically representative? > > I really have to say that I am skeptical over the presented usecase. > Optimizing over oom events seems just like a very wrong way to scale the > workload. Timing of oom handling is a subject to change at any time and > what you are optimizing for might change. I think the improvement may because of that, if we see under_oom is 1, we'll sleep for 10s and check again. And the sleep time is enough to complete oom handling, So the size of time window is much larger than the time spending on mem_cgroup_out_of_memory(). > > That being said, I do not see any obvious problem with the patch. IMO we > should rather not apply it because it is slighly changing a long term > behavior for something that is in a legacy mode now. But I will not Nack > it either as it is just a trivial thing. I just do not like an idea we > would be changing the timing of under_oom clearing just to fine tune > some workloads. > >>>>> Btw. is this something new that you are developing on top of v1? And if >>>>> yes, why don't you use v2? >>>>> >>>> >>>> yes, v2 doesn't have the "cgroup.event_control" file. >>> >>> Yes, it doesn't. But why is it necessary? Relying on v1 just for this is >>> far from ideal as v1 is deprecated and mostly frozen. Why do you need to >>> rely on the oom notifications (or oom behavior in general) in the first >>> place? Could you share more about your workload and your requirements? >>> >> >> for example, we want to run processes in the group but those parametes related to >> memory allocation is hard to decide, so use the notifications to inform us that we >> need to adjust the paramters automatically and we don't need to create the new processes >> manually. > > I do understand that but OOM is just way too late to tune anything > upon. Cgroup v2 has a notion of high limit which can throttle memory > allocations way before the hard limit is set and this along with PSI > metrics could give you a much better insight on the memory pressure > in a memcg. > Thank you for your suggestion. We will try to use memory.high instead.