linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pintu Agarwal <pintu.ping@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: Pintu Kumar <quic_pintu@quicinc.com>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	 "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	 "ebiederm@xmission.com" <ebiederm@xmission.com>,
	 "christian.brauner@ubuntu.com" <christian.brauner@ubuntu.com>,
	 "sfr@canb.auug.org.au" <sfr@canb.auug.org.au>,
	"legion@kernel.org" <legion@kernel.org>,
	 "sashal@kernel.org" <sashal@kernel.org>,
	"gorcunov@gmail.com" <gorcunov@gmail.com>,
	 "chris.hyser@oracle.com" <chris.hyser@oracle.com>,
	"ccross@google.com" <ccross@google.com>,
	 "pcc@google.com" <pcc@google.com>,
	"dave@stgolabs.net" <dave@stgolabs.net>,
	 "caoxiaofeng@yulong.com" <caoxiaofeng@yulong.com>,
	"david@redhat.com" <david@redhat.com>,
	 "vbabka@suse.cz" <vbabka@suse.cz>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>,
	dhowells@redhat.com
Subject: Re: [PATCH v2] sysinfo: include availram field in sysinfo struct
Date: Sat, 8 Jan 2022 22:23:13 +0530	[thread overview]
Message-ID: <CAOuPNLh-WLxJ7w=_C7zKXArgZLbO7OahHHhuwAyN9E1yZvNTdQ@mail.gmail.com> (raw)
In-Reply-To: <19cce51e24584c2a8090b618c580a0bd@AcuMS.aculab.com>

On Sat, 8 Jan 2022 at 03:52, David Laight <David.Laight@aculab.com> wrote:
>
> From: Pintu Kumar
> > Sent: 07 January 2022 18:08
> >
> > 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.
> >
> ...
> > 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.. */
>
> There are 4 pad bytes here on most 64bit architectures.
>
> > +     __kernel_ulong_t availram;      /* Memory available for allocation */
> > +     char _f[20-3*sizeof(__kernel_ulong_t)-sizeof(__u32)];   /* Padding: libc5 uses this.. */
> >  };
>
> You've not compile-time tested the size of the structure.
>
With "32" instead of "20" in padding I get these size of sysinfo:
In x86-64 kernel, with app 64-bit: Size of sysinfo = 128
In x86-64 kernel, with app 32-bit:: Size of sysinfo = 76
In arm-64 kernel, with app 32-bit: Size of sysinfo = 76

Okay the sys robot reported some issue in 64-bit build.
{{{
>> include/uapi/linux/sysinfo.h:23:14: error: size of array '_f' is too large
>>    23 |         char _f[20-3*sizeof(__kernel_ulong_t)-sizeof(__u32)];   /* Padding: libc5 uses this.. */
>>       |              ^~
}}}

Also, I got the same issue while building for arm64, so I tried to
adjust like this:
char _f[32-3*sizeof(__kernel_ulong_t)-sizeof(__u32)];

With this the build works on both 32/64 but output fails when running
32-bit program on 64-bit kernel.
Also, the free command on 64-bit reports "stack smashing error"..

How do we resolve this issue to make it work on both arch ?
Also, I don't really understand the significance of that number "20"
in padding ?

Thanks,
Pintu


  reply	other threads:[~2022-01-08 16:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 15:34 [PATCH] " Pintu Kumar
2022-01-06 16:11 ` Cyrill Gorcunov
2022-01-06 16:49   ` Pintu Agarwal
2022-01-06 17:27     ` Cyrill Gorcunov
2022-01-07 12:04       ` Christian Brauner
2022-01-07 13:44         ` Pintu Agarwal
2022-01-07 16:58           ` Vlastimil Babka
2022-01-07 17:47             ` Pintu Agarwal
2022-01-07 22:18             ` David Laight
2022-01-07 19:51         ` Cyrill Gorcunov
2022-01-06 17:41     ` David Laight
2022-01-06 17:59       ` Pintu Agarwal
2022-01-06 19:20         ` Eric W. Biederman
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 [this message]
2022-01-08 22:35       ` David Laight
2022-01-10 14:55         ` Pintu Agarwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOuPNLh-WLxJ7w=_C7zKXArgZLbO7OahHHhuwAyN9E1yZvNTdQ@mail.gmail.com' \
    --to=pintu.ping@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=caoxiaofeng@yulong.com \
    --cc=ccross@google.com \
    --cc=chris.hyser@oracle.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=gorcunov@gmail.com \
    --cc=legion@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pcc@google.com \
    --cc=quic_pintu@quicinc.com \
    --cc=sashal@kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox