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 9448AC433EF for ; Thu, 6 Jan 2022 16:11:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F20106B0071; Thu, 6 Jan 2022 11:11:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED08F6B0072; Thu, 6 Jan 2022 11:11:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6F226B0073; Thu, 6 Jan 2022 11:11:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id C79F46B0071 for ; Thu, 6 Jan 2022 11:11:38 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 651D685D7B for ; Thu, 6 Jan 2022 16:11:38 +0000 (UTC) X-FDA: 79000352676.29.C29D8A6 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by imf18.hostedemail.com (Postfix) with ESMTP id 8D3F81C001A for ; Thu, 6 Jan 2022 16:11:25 +0000 (UTC) Received: by mail-lf1-f48.google.com with SMTP id bp20so5987615lfb.6 for ; Thu, 06 Jan 2022 08:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UweD5BJ4DKQCz9vlPdatipHmRP/OHAThtxD90vvKQYs=; b=VMBXuw310pEBE0hRKuhM5FjpdbHWyARebd7bXxHSCQMKbEEfGfHJivVMia0R9uQPCb 2d9aj90JU8m59mfIHl3+hL5Vn4DpsKYdRAtgTLJxYF8ivzTWHLsPxgFqyJ6CXDLEULzd WI5MbRyzIL3jRwV+eplpbRPn4ARPWfHhhh7W7HEXpwDqn2Xn+jgK6aGlP/GUf2r6CsPa zfm0Z18ub2H0ooIFrU/XE/Uz/DOmz+k/e4JgQRIW16TJgOx2ezoJjZr2HWUe7Vo3g22G 87gsDiMSTjrcNetqjQxCoc3XnpWiKblgIN0fIXYP8Ybu8syo2A07wxohzqa4LLeBCfq+ W7iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UweD5BJ4DKQCz9vlPdatipHmRP/OHAThtxD90vvKQYs=; b=6zFds9TrzIMSoSnu6uc4fhDe3mM2f6hS+R6yGhLQ5u4+ghrO/luns/PcbenQwYwcB1 YbvOyP+Ceykg4pH1ZqvIWYBLI4lg1/lDT7WQgWuqTfRR7iEYZdnU9f5zN8HImjijif2c Lcf1n6w9ksXf1Sw6W+slc9V0lc6l4BJCr/yl47223bWk6jh5XHys6Fde8v5xGKQlm4SZ PM954Dt/Ba5Z7cY4sxdPoy5irOebU8kLtHyV0PHBQGj60x+9dFx5EkWjzNfODGk79okJ JgWFURV0qQWZ0NtwNm+28Db/K2IJntOAB1nTbCDkbLjBuyhzaqDwba/gWWPSbEkhBX4d Mvvg== X-Gm-Message-State: AOAM533tqM9UllVFwqF2vDOeArizdaFmeLFE+OlZvQC0Ztpv70UIgqE7 axKyWNC/7Qd2jJ2nVGr9Tx4= X-Google-Smtp-Source: ABdhPJxncGOMXL666kdVArKsvJheKvIRNs4K0S0x16vtIctFIiKdHrJu38Q1dxdsqTcS9HrJe3PQwA== X-Received: by 2002:ac2:46d1:: with SMTP id p17mr54816098lfo.578.1641485496348; Thu, 06 Jan 2022 08:11:36 -0800 (PST) Received: from grain.localdomain ([5.18.251.97]) by smtp.gmail.com with ESMTPSA id u26sm213623lfi.62.2022.01.06.08.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 08:11:34 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 3A60A5A0020; Thu, 6 Jan 2022 19:11:34 +0300 (MSK) Date: Thu, 6 Jan 2022 19:11:34 +0300 From: Cyrill Gorcunov To: Pintu Kumar Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, ebiederm@xmission.com, christian.brauner@ubuntu.com, sfr@canb.auug.org.au, legion@kernel.org, sashal@kernel.org, chris.hyser@oracle.com, ccross@google.com, pcc@google.com, dave@stgolabs.net, caoxiaofeng@yulong.com, david@redhat.com, pintu.ping@gmail.com Subject: Re: [PATCH] sysinfo: include availram field in sysinfo struct Message-ID: References: <1641483250-18839-1-git-send-email-quic_pintu@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1641483250-18839-1-git-send-email-quic_pintu@quicinc.com> User-Agent: Mutt/2.0.7 (2021-05-04) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VMBXuw31; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of gorcunov@gmail.com designates 209.85.167.48 as permitted sender) smtp.mailfrom=gorcunov@gmail.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8D3F81C001A X-Stat-Signature: rsjiod9i1d6iqjyctaptbdhbuq594f4b X-HE-Tag: 1641485485-374351 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 Thu, Jan 06, 2022 at 09:04:10PM +0530, Pintu Kumar wrote: > The sysinfo member does not have any "available ram" field and > the bufferram field is not much helpful either, to get a rough > estimate of available ram needed for allocation. > > One needs to parse MemAvailable field separately from /proc/meminfo > to get this info instead of directly getting if from sysinfo itself. > > Thus, this patch introduce a new field as availram in sysinfo > so that all the info total/free/available can be retrieved from > one place itself. > > There are couple of places in kernel as well where this can be improved. > For example: > In fs/proc/meminfo.c: > meminfo_proc_show: > si_meminfo(&i); > available = si_mem_available(); > Now with this change the second call be avoided. > Thus, we can directly do: > show_val_kb(m, "MemAvailable: ", i.availram); > > Note, this also requires update in procfs for free and other commands. > Like in free command as well we frist call sysinfo then again parse > /proc/meminfo to get available field. > This can be avoided too with higher kernel version. > > A sample output with single sysinfo call is shown below: > Total RAM: 248376 kB > Free RAM: 231540 kB > Avail RAM: 230448 kB > > Signed-off-by: Pintu Kumar > Signed-off-by: Pintu Agarwal > --- > include/uapi/linux/sysinfo.h | 1 + > kernel/sys.c | 4 ++++ > mm/page_alloc.c | 2 ++ > 3 files changed, 7 insertions(+) > > diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h > index 435d5c2..6e77e90 100644 > --- a/include/uapi/linux/sysinfo.h > +++ b/include/uapi/linux/sysinfo.h > @@ -12,6 +12,7 @@ struct sysinfo { > __kernel_ulong_t freeram; /* Available memory size */ > __kernel_ulong_t sharedram; /* Amount of shared memory */ > __kernel_ulong_t bufferram; /* Memory used by buffers */ > + __kernel_ulong_t availram; /* Memory available for allocation */ > __kernel_ulong_t totalswap; /* Total swap space size */ > __kernel_ulong_t freeswap; /* swap space still available */ > __u16 procs; /* Number of current processes */ Hi! Sorry, but I don't understand -- the sysinfo structure seems to be part of user API, no? Don't we break it up here?