linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Prakash Sangappa <prakash.sangappa@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"muchun.song@linux.dev" <muchun.song@linux.dev>,
	Mike Kravetz <mike.kravetz@oracle.com>
Subject: Re: [PATCH] Hugetlb pages should not be reserved by shmat() if SHM_NORESERVE
Date: Tue, 23 Jan 2024 02:00:12 +0000	[thread overview]
Message-ID: <EAA37C24-41E0-40DB-9EBB-D207C581DC8F@oracle.com> (raw)
Message-ID: <20240123020012.dzE2R9q_iVbUHNf8YsmPYdPw4nha-Rk-WxaD0S5MuQc@z> (raw)
In-Reply-To: <20240121143207.299f0d3df52ac746224dacd8@linux-foundation.org>



> On Jan 21, 2024, at 2:32 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> On Fri, 19 Jan 2024 17:17:52 -0800 Prakash Sangappa <prakash.sangappa@oracle.com> 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.
>> 
>> Ensure that the hugetlb pages are no reserved for SHM_HUGETLB shared
>> memory in the shmat() call.
> 
> Thanks.

Sent a v2 patch with slightly modified fix.

> 
> What are the userspace-visible effects of this change?

This is a bug. Following test shows the issue

$ cat shmhtb.c
#include <stdlib.h>
#include <sys/mman.h>
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <errno.h>

#define SHMSZ (10*1024*1024)
#define SKEY 41321234

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("After 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

> 
> Based on that, is a -stable backport desirable?

I think so. The issue is reproducible on older kernel versions. Reproduced on v4.18

> 
> And can we please identify a suitable Fixes: target for this?

Should it be mentioned in the patch?

-Prakash

> 


  reply	other threads:[~2024-01-23  2:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-20  1:17 Prakash Sangappa
2024-01-21 22:32 ` Andrew Morton
2024-01-23  2:00   ` Prakash Sangappa [this message]
2024-01-23  2:00     ` Prakash Sangappa

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=EAA37C24-41E0-40DB-9EBB-D207C581DC8F@oracle.com \
    --to=prakash.sangappa@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=muchun.song@linux.dev \
    /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