From: Muchun Song <muchun.song@linux.dev>
To: Prakash Sangappa <prakash.sangappa@oracle.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: mike.kravetz@oracle.com, akpm@linux-foundation.org
Subject: Re: [PATCH v3] Hugetlb pages should not be reserved by shmat() if SHM_NORESERVE
Date: Wed, 24 Jan 2024 15:03:15 +0800 [thread overview]
Message-ID: <e59c8e4c-c416-4026-9ab9-ee55edafd4b3@linux.dev> (raw)
In-Reply-To: <1706040282-12388-1-git-send-email-prakash.sangappa@oracle.com>
On 2024/1/24 04:04, Prakash Sangappa wrote:
> For shared memory of type SHM_HUGETLB, hugetlb pages are reserved in
> shmget() call. If SHM_NORESERVE flags is specified then the hugetlb
> pages are not reserved. However when the shared memory is attached
> with the shmat() call the hugetlb pages are getting reserved incorrectly
> for SHM_HUGETLB shared memory created with SHM_NORESERVE which is a bug.
>
> -------------------------------
> Following test shows the issue.
>
> $cat shmhtb.c
>
> int main()
> {
> int shmflags = 0660 | IPC_CREAT | SHM_HUGETLB | SHM_NORESERVE;
> int shmid;
>
> shmid = shmget(SKEY, SHMSZ, shmflags);
> if (shmid < 0)
> {
> printf("shmat: shmget() failed, %d\n", errno);
> return 1;
> }
> printf("After shmget()\n");
> system("cat /proc/meminfo | grep -i hugepages_");
>
> shmat(shmid, NULL, 0);
> printf("\nAfter shmat()\n");
> system("cat /proc/meminfo | grep -i hugepages_");
>
> shmctl(shmid, IPC_RMID, NULL);
> return 0;
> }
>
> #sysctl -w vm.nr_hugepages=20
> #./shmhtb
>
> After shmget()
> HugePages_Total: 20
> HugePages_Free: 20
> HugePages_Rsvd: 0
> HugePages_Surp: 0
>
> After shmat()
> HugePages_Total: 20
> HugePages_Free: 20
> HugePages_Rsvd: 5 <--
> HugePages_Surp: 0
> --------------------------------
>
> Fix is to ensure that hugetlb pages are not reserved for SHM_HUGETLB shared
> memory in the shmat() call.
> Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
BTW, it is better to add a Fixes tag to specify which commit
that this commit aims to fix.
Acked-by: Muchun Song <muchun.song@linux.dev>
Thanks.
next prev parent reply other threads:[~2024-01-24 7:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 20:04 Prakash Sangappa
2024-01-24 7:03 ` Muchun Song [this message]
2024-02-08 2:01 ` Andrew Morton
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=e59c8e4c-c416-4026-9ab9-ee55edafd4b3@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=prakash.sangappa@oracle.com \
/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