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 8FAF3C19F2D for ; Tue, 9 Aug 2022 10:32:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 251FA8E0002; Tue, 9 Aug 2022 06:32:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DABF6B0072; Tue, 9 Aug 2022 06:32:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 053A98E0002; Tue, 9 Aug 2022 06:32:56 -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 E91C66B0071 for ; Tue, 9 Aug 2022 06:32:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C60DA1C6608 for ; Tue, 9 Aug 2022 10:32:56 +0000 (UTC) X-FDA: 79779691152.20.228A41E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 58A2314017C for ; Tue, 9 Aug 2022 10:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660041174; 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=4/nlumMUczp73apm8CZRUgaBYhutP5eXhEt6NxdNHlY=; b=icA3l7YjBWVy0ssWifm2zAYtQ+x02fQQ1V4zugS/b1uXbySu5Jageq3ZvRxsxjV/6OqNAR bqG6szr8u1XKll1lsmNbRDQxcOqzcnrAtnl4ie8CdphNozLgGisGulPi/dq6GMFeWy2uEr x52gke4d58gA0zDrhKz91S4yi7vHaZk= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-hCXF_7oDNsq6PWCGWLR0hA-1; Tue, 09 Aug 2022 06:32:53 -0400 X-MC-Unique: hCXF_7oDNsq6PWCGWLR0hA-1 Received: by mail-ed1-f69.google.com with SMTP id y16-20020a056402359000b0043db5186943so7034400edc.3 for ; Tue, 09 Aug 2022 03:32:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=4/nlumMUczp73apm8CZRUgaBYhutP5eXhEt6NxdNHlY=; b=U65ekI1bN9zXhjeunuo5Xs5tRal1Yc/ZphCCuu0cK+AxHwJNbcylfiYuyU1V/NSy/L 6X2EJuZtZuJtbY8qhtYHOspmw8jrFZdxU5dGPP0TC9Y2O2tEabZ+HRlDtH68lZm5aQmV 406fKiVMkQ3/bvbSfhYmvd1uquY8WjljenS9xxJTnKD/1AFlQbIpAEtXHqzx+rxGb8IK 7ZlZ/g4ipLx129VNMUCAt2E+R5j8nOzDNMLDnRdkdVWUNd7/pJ7T2a74sr4BhAuYsDM3 A5+ye97RX6rXiwqRd2NXCfcGGaSSUBxV2dGzZSO+TEUaBxnw71Or0DbXhZ7F+J7+EHdp XPKg== X-Gm-Message-State: ACgBeo0Mv0g9FY667++cmIdQ0HHoW5bRBmx1TSqVQTxiWXDfkCamKxvk wQXbOuYtrVrNpPd3K2t+Z7ZNYIAnbTQVyKBPvuvoM//6hfddrZV7Wk6XxilE0ueS3DnD9GTZ0EK qfudS5Qowx3g= X-Received: by 2002:a05:6402:278c:b0:43d:cd35:db25 with SMTP id b12-20020a056402278c00b0043dcd35db25mr21160269ede.44.1660041172537; Tue, 09 Aug 2022 03:32:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR7kHfqy2K3ZZ0VU1/IEtq20+vgUMc90FDejB9zNFwNsrjyA2JfUM7Qy1rx71dvSPaxNUXUPVA== X-Received: by 2002:a05:6402:278c:b0:43d:cd35:db25 with SMTP id b12-20020a056402278c00b0043dcd35db25mr21160248ede.44.1660041172290; Tue, 09 Aug 2022 03:32:52 -0700 (PDT) Received: from redhat.com ([2.52.152.113]) by smtp.gmail.com with ESMTPSA id n6-20020aa7c786000000b0043a554818afsm5801531eds.42.2022.08.09.03.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 03:32:51 -0700 (PDT) Date: Tue, 9 Aug 2022 06:32:47 -0400 From: "Michael S. Tsirkin" To: Alexander Atanasov Cc: Jonathan Corbet , Andrew Morton , kernel@openvz.org, David Hildenbrand , Wei Liu , Nadav Amit , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v1 1/2] Enable balloon drivers to report inflated memory Message-ID: <20220809063111-mutt-send-email-mst@kernel.org> References: <7bfac48d-2e50-641b-6523-662ea4df0240@virtuozzo.com> <20220809094933.2203087-1-alexander.atanasov@virtuozzo.com> MIME-Version: 1.0 In-Reply-To: <20220809094933.2203087-1-alexander.atanasov@virtuozzo.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660041176; a=rsa-sha256; cv=none; b=KVR06Jas2tZvcAUTXigDwdo/WRzCQoFzvlluMdwBkk/uJJKy1hVdd+VtFuR4fCOxM/jn4B W5LR5VO/2RW/gD+6qnG64cp0rMVE41dwShR3DXnY8DrIZXdeCwS+B1/Ab3vC79KSBFfgGi HrQ4XcoUBeU+dvpJRq3ch2qUI3jvQB0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=icA3l7Yj; spf=pass (imf09.hostedemail.com: domain of mst@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mst@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660041176; 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=4/nlumMUczp73apm8CZRUgaBYhutP5eXhEt6NxdNHlY=; b=HH6srv4xXHLt+wjQlLnNF8T8i6pZ2a0Vnx0OTM+KZ7HIOaSiWVrfeUM8aw0YAKyZotR4H1 2FIVuhsJz5m/zBYfmGpeO7jFvsi3UJUVw7CWcsuCIoNrZEiBNi+wiHzITiRDlBXqU3z29V 1t65cx1iYSgKFjBd1ZN3pPjxNABEecw= X-Rspamd-Queue-Id: 58A2314017C X-Rspam-User: X-Rspamd-Server: rspam11 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=icA3l7Yj; spf=pass (imf09.hostedemail.com: domain of mst@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=mst@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: ag7354i4zsd5eegk1gxy4puh4qqkyna9 X-HE-Tag: 1660041175-207454 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 Tue, Aug 09, 2022 at 12:49:32PM +0300, Alexander Atanasov wrote: > Display reported in /proc/meminfo as: > > Inflated(total) or Inflated(free) > > depending on the driver. > > Drivers use the sign bit to indicate where they do account > the inflated memory. > > Amount of inflated memory can be used by: > - as a hint for the oom a killer > - user space software that monitors memory pressure > > Cc: David Hildenbrand > Cc: Wei Liu > Cc: Nadav Amit > > Signed-off-by: Alexander Atanasov > --- > Documentation/filesystems/proc.rst | 5 +++++ > fs/proc/meminfo.c | 11 +++++++++++ > include/linux/mm.h | 4 ++++ > mm/page_alloc.c | 4 ++++ > 4 files changed, 24 insertions(+) > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst > index 1bc91fb8c321..064b5b3d5bd8 100644 > --- a/Documentation/filesystems/proc.rst > +++ b/Documentation/filesystems/proc.rst > @@ -986,6 +986,7 @@ Example output. You may not have all of these fields. > VmallocUsed: 40444 kB > VmallocChunk: 0 kB > Percpu: 29312 kB > + Inflated(total): 2097152 kB > HardwareCorrupted: 0 kB > AnonHugePages: 4149248 kB > ShmemHugePages: 0 kB > @@ -1133,6 +1134,10 @@ VmallocChunk > Percpu > Memory allocated to the percpu allocator used to back percpu > allocations. This stat excludes the cost of metadata. > +Inflated(total) or Inflated(free) > + Amount of memory that is inflated by the balloon driver. > + Due to differences among balloon drivers inflated memory > + is either subtracted from TotalRam or from MemFree. > HardwareCorrupted > The amount of RAM/memory in KB, the kernel identifies as > corrupted. > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c > index 6e89f0e2fd20..ebbe52ccbb93 100644 > --- a/fs/proc/meminfo.c > +++ b/fs/proc/meminfo.c > @@ -38,6 +38,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > unsigned long pages[NR_LRU_LISTS]; > unsigned long sreclaimable, sunreclaim; > int lru; > +#ifdef CONFIG_MEMORY_BALLOON > + long inflated_kb; > +#endif > > si_meminfo(&i); > si_swapinfo(&i); > @@ -153,6 +156,14 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > global_zone_page_state(NR_FREE_CMA_PAGES)); > #endif > > +#ifdef CONFIG_MEMORY_BALLOON > + inflated_kb = atomic_long_read(&mem_balloon_inflated_kb); > + if (inflated_kb >= 0) > + seq_printf(m, "Inflated(total): %8ld kB\n", inflated_kb); > + else > + seq_printf(m, "Inflated(free): %8ld kB\n", -inflated_kb); > +#endif > + > hugetlb_report_meminfo(m); > > arch_report_meminfo(m); This seems too baroque for my taste. Why not just have two counters for the two pruposes? And is there any value in having this atomic? We want a consistent value but just READ_ONCE seems sufficient ... > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 7898e29bcfb5..b190811dc16e 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2582,6 +2582,10 @@ extern int watermark_boost_factor; > extern int watermark_scale_factor; > extern bool arch_has_descending_max_zone_pfns(void); > > +#ifdef CONFIG_MEMORY_BALLOON > +extern atomic_long_t mem_balloon_inflated_kb; > +#endif > + > /* nommu.c */ > extern atomic_long_t mmap_pages_allocated; > extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t); > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index b0bcab50f0a3..12359179a3a2 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -194,6 +194,10 @@ EXPORT_SYMBOL(init_on_alloc); > DEFINE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_FREE_DEFAULT_ON, init_on_free); > EXPORT_SYMBOL(init_on_free); > > +#ifdef CONFIG_MEMORY_BALLOON > +atomic_long_t mem_balloon_inflated_kb = ATOMIC_LONG_INIT(0); > +#endif > + > static bool _init_on_alloc_enabled_early __read_mostly > = IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON); > static int __init early_init_on_alloc(char *buf) > -- > 2.31.1 > >