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 07F7BC433EF for ; Thu, 6 Jan 2022 17:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BB076B0074; Thu, 6 Jan 2022 12:59:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46AE26B0075; Thu, 6 Jan 2022 12:59:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 334086B0078; Thu, 6 Jan 2022 12:59:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 26E2F6B0074 for ; Thu, 6 Jan 2022 12:59:15 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D89D991E4E for ; Thu, 6 Jan 2022 17:59:14 +0000 (UTC) X-FDA: 79000623828.03.FB230BF Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by imf10.hostedemail.com (Postfix) with ESMTP id 3D760C0007 for ; Thu, 6 Jan 2022 17:59:01 +0000 (UTC) Received: by mail-yb1-f176.google.com with SMTP id m19so9678468ybf.9 for ; Thu, 06 Jan 2022 09:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=l2D6EeoYb+b4mvX70XIdFK6lgodBeGTNmqesy1Eurmk=; b=Otbuw240aMoy4oKfiPfJinywWAixSuIX5t04hFFlZb/Gkp2z/CYyQRbHvVL5wFJlHF hX7biY1/3NX0yfxrbuGBftDmhuAgtE7vSo6N6VjjGXwoGCi29Occp6/vCyao1MtYTJIk Shazu2JghNMLGXb7FJrQ2rYkw0oskCwscTLbmrwkfY9cnJGFpk+FT8g2Ej2hHZyvg5KX DU00kz1hGpKv1qfmF4djni55PvkCRxCTv3WBNXmycLE60eew1LW8UllVRreNsx2bXtve dU+xBmTxf00bPYtC/sB3KnYNekcKUMGaUcWLdVtROcKWfJWiw1FpsaKMo9OsxnfB2yu5 1wnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=l2D6EeoYb+b4mvX70XIdFK6lgodBeGTNmqesy1Eurmk=; b=4Z8K7q7qWmDJEtmYnZ4BvdhmF2PZy7zCgwF9lEB/aYKdXBNBleIYZelh56I3rx42Ei D1bGlu0+SkU7yAH581OTaiauDXOpZrXS7QGDxT7ajwcCWqDb2OBQc6UXAmCbUG2qWb1n VFJUo8LzPnWZvoFt6mfubbfqCuaWrevlPwoV1+FVOSgPahkHk/khx+94tJ061hHcDr1y dQKjNXOvJXaBlqeECQlqRjtrDLwRI+w+6CtZIlYv431j+KSqQUgtp91DrXjTkz0gq72t OhJml8IL2HHZkvlLaXSOMdKdswkdjueXLa79aDs/HD3ydNIXgB6Co0ryWA9ppRsl8zja A9Ug== X-Gm-Message-State: AOAM530P0CcyHUQ/7Ow2OZ3q3RIYC67OsNruT3tlZqzHRqOwhMBArIbD vYIcTT9/INyJV4LO2qFP4czwUBw5CC+mr9Xw21w= X-Google-Smtp-Source: ABdhPJw4ocnS9niYedLirta2VK213X3djYSOmZQumrR2qeItR5A/r+UcVzvbK1kz/RVcnhNY4RzTBgSb3bD1E4fFPIo= X-Received: by 2002:a25:6c55:: with SMTP id h82mr78729963ybc.214.1641491953789; Thu, 06 Jan 2022 09:59:13 -0800 (PST) MIME-Version: 1.0 References: <1641483250-18839-1-git-send-email-quic_pintu@quicinc.com> <14316cf852784a32b5214119a9d976cf@AcuMS.aculab.com> In-Reply-To: <14316cf852784a32b5214119a9d976cf@AcuMS.aculab.com> From: Pintu Agarwal Date: Thu, 6 Jan 2022 23:29:02 +0530 Message-ID: Subject: Re: [PATCH] sysinfo: include availram field in sysinfo struct To: David Laight Cc: Cyrill Gorcunov , Pintu Kumar , open list , Andrew Morton , linux-mm , "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" Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Otbuw240; spf=pass (imf10.hostedemail.com: domain of pintu.ping@gmail.com designates 209.85.219.176 as permitted sender) smtp.mailfrom=pintu.ping@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3D760C0007 X-Stat-Signature: fou5ed38ghiadbzorihgtajpmqywwx3p X-HE-Tag: 1641491941-633312 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, 6 Jan 2022 at 23:12, David Laight wrote: > > From: Pintu Agarwal > > Sent: 06 January 2022 16:50 > > > > On Thu, 6 Jan 2022 at 21:41, Cyrill Gorcunov wrote: > > > > > > 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? > > > > Yes, the corresponding user space header /usr/include/linux/sysinfo.h > > also needs to be updated. > > When we generate the kernel header it will be updated automatically. > > You can't add a field in the middle of a UAPI structure. > It breaks compatibility for old binaries. > > Depending on the interface definition you may be able to add one at the end. > oh okay thank you for your feedback. I will move to the end and check again. But my doubt is, whether I should move before this char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; or after this ? Also, I could not understand what this is for ? Do we need to update this since sture is changed ?