linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
  • * [PATCH v2] sysinfo: include availram field in sysinfo struct
           [not found] <1641483250-18839-1-git-send-email-quic_pintu@quicinc.com>
           [not found] ` <YdcUttZWaqYQpR1K@grain>
    @ 2022-01-07 18:07 ` Pintu Kumar
      2022-01-07 21:01   ` Cyrill Gorcunov
      2022-01-07 22:22   ` David Laight
      1 sibling, 2 replies; 11+ messages in thread
    From: Pintu Kumar @ 2022-01-07 18:07 UTC (permalink / raw)
      To: linux-kernel, akpm, quic_pintu, linux-mm, ebiederm,
    	christian.brauner, sfr, legion, sashal, gorcunov, chris.hyser,
    	ccross, pcc, dave, caoxiaofeng, david, pintu.ping, vbabka
      Cc: linux-api
    
    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 <quic_pintu@quicinc.com>
    Signed-off-by: Pintu Agarwal <pintu.ping@gmail.com>
    ---
     include/uapi/linux/sysinfo.h | 3 ++-
     kernel/sys.c                 | 4 ++++
     mm/page_alloc.c              | 2 ++
     3 files changed, 8 insertions(+), 1 deletion(-)
    
    diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h
    index 435d5c2..fe84c6a 100644
    --- a/include/uapi/linux/sysinfo.h
    +++ b/include/uapi/linux/sysinfo.h
    @@ -19,7 +19,8 @@ struct sysinfo {
     	__kernel_ulong_t totalhigh;	/* Total high memory size */
     	__kernel_ulong_t freehigh;	/* Available high memory size */
     	__u32 mem_unit;			/* Memory unit size in bytes */
    -	char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];	/* Padding: libc5 uses this.. */
    +	__kernel_ulong_t availram;	/* Memory available for allocation */
    +	char _f[20-3*sizeof(__kernel_ulong_t)-sizeof(__u32)];	/* Padding: libc5 uses this.. */
     };
     
     #endif /* _LINUX_SYSINFO_H */
    diff --git a/kernel/sys.c b/kernel/sys.c
    index ecc4cf0..7059515 100644
    --- a/kernel/sys.c
    +++ b/kernel/sys.c
    @@ -2671,6 +2671,7 @@ static int do_sysinfo(struct sysinfo *info)
     	info->freeram <<= bitcount;
     	info->sharedram <<= bitcount;
     	info->bufferram <<= bitcount;
    +	info->availram <<= bitcount;
     	info->totalswap <<= bitcount;
     	info->freeswap <<= bitcount;
     	info->totalhigh <<= bitcount;
    @@ -2700,6 +2701,7 @@ struct compat_sysinfo {
     	u32 freeram;
     	u32 sharedram;
     	u32 bufferram;
    +	u32 availram;
     	u32 totalswap;
     	u32 freeswap;
     	u16 procs;
    @@ -2732,6 +2734,7 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
     		s.freeram >>= bitcount;
     		s.sharedram >>= bitcount;
     		s.bufferram >>= bitcount;
    +		s.availram >>= bitcount;
     		s.totalswap >>= bitcount;
     		s.freeswap >>= bitcount;
     		s.totalhigh >>= bitcount;
    @@ -2747,6 +2750,7 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
     	s_32.freeram = s.freeram;
     	s_32.sharedram = s.sharedram;
     	s_32.bufferram = s.bufferram;
    +	s_32.availram = s.availram;
     	s_32.totalswap = s.totalswap;
     	s_32.freeswap = s.freeswap;
     	s_32.procs = s.procs;
    diff --git a/mm/page_alloc.c b/mm/page_alloc.c
    index b5d62e1..5013c75 100644
    --- a/mm/page_alloc.c
    +++ b/mm/page_alloc.c
    @@ -5786,6 +5786,7 @@ void si_meminfo(struct sysinfo *val)
     	val->sharedram = global_node_page_state(NR_SHMEM);
     	val->freeram = global_zone_page_state(NR_FREE_PAGES);
     	val->bufferram = nr_blockdev_pages();
    +	val->availram = si_mem_available();
     	val->totalhigh = totalhigh_pages();
     	val->freehigh = nr_free_highpages();
     	val->mem_unit = PAGE_SIZE;
    @@ -5807,6 +5808,7 @@ void si_meminfo_node(struct sysinfo *val, int nid)
     	val->totalram = managed_pages;
     	val->sharedram = node_page_state(pgdat, NR_SHMEM);
     	val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES);
    +	val->availram = si_mem_available();
     #ifdef CONFIG_HIGHMEM
     	for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) {
     		struct zone *zone = &pgdat->node_zones[zone_type];
    -- 
    2.7.4
    
    
    ^ permalink raw reply related	[flat|nested] 11+ messages in thread

  • end of thread, other threads:[~2022-01-10 14:55 UTC | newest]
    
    Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <1641483250-18839-1-git-send-email-quic_pintu@quicinc.com>
         [not found] ` <YdcUttZWaqYQpR1K@grain>
         [not found]   ` <CAOuPNLifYFPU4Gt2+1sOSsYNNLQq7U2aGVaYknrhaMc-CVx8vg@mail.gmail.com>
         [not found]     ` <Ydcmk+WaBWKlLkAw@grain>
         [not found]       ` <20220107120451.z2eqru2tm5mlhla3@wittgenstein>
         [not found]         ` <CAOuPNLiJZu_HJQ+Hf5BJOgmT+v7DT96VLkiXrfx0MJQrkD3rSw@mail.gmail.com>
    2022-01-07 16:58           ` [PATCH] sysinfo: include availram field in sysinfo struct Vlastimil Babka
    2022-01-07 17:47             ` Pintu Agarwal
    2022-01-07 22:18             ` David Laight
    2022-01-07 18:07 ` [PATCH v2] " Pintu Kumar
    2022-01-07 21:01   ` Cyrill Gorcunov
    2022-01-08 16:24     ` Pintu Agarwal
    2022-01-10  8:11       ` Cyrill Gorcunov
    2022-01-07 22:22   ` David Laight
    2022-01-08 16:53     ` Pintu Agarwal
    2022-01-08 22:35       ` David Laight
    2022-01-10 14:55         ` Pintu Agarwal
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox;
    as well as URLs for NNTP newsgroup(s).