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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFA86C48BE5 for ; Wed, 16 Jun 2021 16:17:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 700B261159 for ; Wed, 16 Jun 2021 16:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 700B261159 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xmission.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1247D6B006E; Wed, 16 Jun 2021 12:17:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D4576B0070; Wed, 16 Jun 2021 12:17:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E69EE6B0071; Wed, 16 Jun 2021 12:17:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id B0C9C6B006E for ; Wed, 16 Jun 2021 12:17:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DF2A08287E13 for ; Wed, 16 Jun 2021 16:17:48 +0000 (UTC) X-FDA: 78260093016.24.638E8D7 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by imf04.hostedemail.com (Postfix) with ESMTP id B82B6369 for ; Wed, 16 Jun 2021 16:17:41 +0000 (UTC) Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ltYEc-009lYc-Aw; Wed, 16 Jun 2021 10:17:46 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ltYEb-000Wks-3W; Wed, 16 Jun 2021 10:17:45 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Shakeel Butt Cc: Alexey Gladkov , Christian Brauner , LKML , Linux Containers , Linux Containers , Linux FS Devel , Linux MM , Andrew Morton , Johannes Weiner , Michal Hocko , Chris Down , Cgroups References: <20210615113222.edzkaqfvrris4nth@wittgenstein> <20210615124715.nzd5we5tl7xc2n2p@example.org> Date: Wed, 16 Jun 2021 11:17:38 -0500 In-Reply-To: (Shakeel Butt's message of "Tue, 15 Jun 2021 18:09:49 -0700") Message-ID: <87zgvpg4wt.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1ltYEb-000Wks-3W;;;mid=<87zgvpg4wt.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/oAPIcVGnPayS1n8LJJbfvRL5ngyGBE/A= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v1] proc: Implement /proc/self/meminfo X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.233 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B82B6369 X-Stat-Signature: cyq6tqbh44tmecamnumradrzuuu9ijay X-HE-Tag: 1623860261-576828 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: Shakeel Butt writes: > On Tue, Jun 15, 2021 at 5:47 AM Alexey Gladkov wrote: >> > [...] >> >> I made the second version of the patch [1], but then I had a conversation >> with Eric W. Biederman offlist. He convinced me that it is a bad idea to >> change all the values in meminfo to accommodate cgroups. But we agreed >> that MemAvailable in /proc/meminfo should respect cgroups limits. This >> field was created to hide implementation details when calculating >> available memory. You can see that it is quite widely used [2]. >> So I want to try to move in that direction. >> >> [1] https://git.kernel.org/pub/scm/linux/kernel/git/legion/linux.git/log/?h=patchset/meminfo/v2.0 >> [2] https://codesearch.debian.net/search?q=MemAvailable%3A >> > > Please see following two links on the previous discussion on having > per-memcg MemAvailable stat. > > [1] https://lore.kernel.org/linux-mm/alpine.DEB.2.22.394.2006281445210.855265@chino.kir.corp.google.com/ > [2] https://lore.kernel.org/linux-mm/alpine.DEB.2.23.453.2007142018150.2667860@chino.kir.corp.google.com/ > > MemAvailable itself is an imprecise metric and involving memcg makes > this metric even more weird. The difference of semantics of swap > accounting of v1 and v2 is one source of this weirdness (I have not > checked your patch if it is handling this weirdness). The lazyfree and > deferred split pages are another source. > > So, I am not sure if complicating an already imprecise metric will > make it more useful. Making a good guess at how much memory can be allocated without triggering swapping or otherwise stressing the system is something that requires understanding our mm internals. To be able to continue changing the mm or even mm policy without introducing regressions in userspace we need to export values that userspace can use. At a first approximation that seems to look like MemAvailable. MemAvailable seems to have a good definition. Roughly the amount of memory that can be allocated without triggering swapping. Updated to include not trigger memory cgroup based swapping and I sounds good. I don't know if it will work in practice but I think it is worth exploring. I do know that hiding the implementation details and providing userspace with information it can directly use seems like the programming model that needs to be explored. Most programs should not care if they are in a memory cgroup, etc. Programs, load management systems, and even balloon drivers have a legitimately interest in how much additional load can be placed on a systems memory. A version of this that I remember working fairly well is free space on compressed filesystems. As I recall compressed filesystems report the amount of uncompressed space that is available (an underestimate). This results in the amount of space consumed going up faster than the free space goes down. We can't do exactly the same thing with our memory usability estimate, but having our estimate be a reliable underestimate might be enough to avoid problems with reporting too much memory as available to userspace. I know that MemAvailable already does that /2 so maybe it is already aiming at being an underestimate. Perhaps we need some additional accounting to help create a useful metric for userspace as well. I don't know the final answer. I do know that not designing an interface that userspace can use to deal with it's legitimate concerns is sticking our collective heads in the sand and wishing the problem will go away. Eric