From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: Matthew Wilcox <willy@infradead.org>,
akpm@linux-foundation.org, mhocko@suse.com, ak@linux.intel.com,
mtk.manpages@gmail.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>,
khandual@linux.vnet.ibm.com
Subject: Re: [PATCH] mm,hugetlb: compute page_size_log properly
Date: Thu, 13 Apr 2017 11:32:09 +0530 [thread overview]
Message-ID: <87wpaoq1zy.fsf@skywalker.in.ibm.com> (raw)
In-Reply-To: <20170328175408.GD7838@bombadil.infradead.org>
Matthew Wilcox <willy@infradead.org> writes:
> On Tue, Mar 28, 2017 at 09:55:13AM -0700, Davidlohr Bueso wrote:
>> Do we have any consensus here? Keeping SHM_HUGE_* is currently
>> winning 2-1. If there are in fact users out there computing the
>> value manually, then I am ok with keeping it and properly exporting
>> it. Michal?
>
> Well, let's see what it looks like to do that. I went down the rabbit
> hole trying to understand why some of the SHM_ flags had the same value
> as each other until I realised some of them were internal flags, some
> were flags to shmat() and others were flags to shmget(). Hopefully I
> disambiguated them nicely in this patch. I also added 8MB and 16GB sizes.
> Any more architectures with a pet favourite huge/giant page size we
> should add convenience defines for?
>
> diff --git a/include/linux/shm.h b/include/linux/shm.h
> index 04e881829625..cd95243efd1a 100644
> --- a/include/linux/shm.h
> +++ b/include/linux/shm.h
> @@ -24,26 +24,13 @@ struct shmid_kernel /* private to the kernel */
> struct list_head shm_clist; /* list by creator */
> };
>
> -/* shm_mode upper byte flags */
> -#define SHM_DEST 01000 /* segment will be destroyed on last detach */
> -#define SHM_LOCKED 02000 /* segment will not be swapped */
> -#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
> -#define SHM_NORESERVE 010000 /* don't check for reservations */
> -
> -/* Bits [26:31] are reserved */
> -
> /*
> - * When SHM_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
> - * This gives us 6 bits, which is enough until someone invents 128 bit address
> - * spaces.
> - *
> - * Assume these are all power of twos.
> - * When 0 use the default page size.
> + * These flags are used internally; they cannot be specified by the user.
> + * They are masked off in newseg(). These values are used by IPC_CREAT
> + * and IPC_EXCL when calling shmget().
> */
> -#define SHM_HUGE_SHIFT 26
> -#define SHM_HUGE_MASK 0x3f
> -#define SHM_HUGE_2MB (21 << SHM_HUGE_SHIFT)
> -#define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT)
> +#define SHM_DEST 01000 /* segment will be destroyed on last detach */
> +#define SHM_LOCKED 02000 /* segment will not be swapped */
>
> #ifdef CONFIG_SYSVIPC
> struct sysv_shm {
> diff --git a/include/uapi/linux/shm.h b/include/uapi/linux/shm.h
> index 1fbf24ea37fd..44b36cb228d7 100644
> --- a/include/uapi/linux/shm.h
> +++ b/include/uapi/linux/shm.h
> @@ -40,15 +40,34 @@ struct shmid_ds {
> /* Include the definition of shmid64_ds and shminfo64 */
> #include <asm/shmbuf.h>
>
> -/* permission flag for shmget */
> +/* shmget() shmflg values. */
> +/* The bottom nine bits are the same as open(2) mode flags */
> #define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
> #define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
> +/* Bits 9 & 10 are IPC_CREAT and IPC_EXCL */
> +#define SHM_HUGETLB (1 << 11) /* segment will use huge TLB pages */
> +#define SHM_NORESERVE (1 << 12) /* don't check for reservations */
>
> -/* mode for attach */
> -#define SHM_RDONLY 010000 /* read-only access */
> -#define SHM_RND 020000 /* round attach address to SHMLBA boundary */
> -#define SHM_REMAP 040000 /* take-over region on attach */
> -#define SHM_EXEC 0100000 /* execution access */
> +/*
> + * When SHM_HUGETLB is set bits [26:31] encode the log2 of the huge page size.
> + * This gives us 6 bits, which is enough until someone invents 128 bit address
> + * spaces. These match MAP_HUGE_SHIFT and MAP_HUGE_MASK.
> + *
> + * Assume these are all powers of two.
> + * When 0 use the default page size.
> + */
> +#define SHM_HUGE_SHIFT 26
> +#define SHM_HUGE_MASK 0x3f
> +#define SHM_HUGE_2MB (21 << SHM_HUGE_SHIFT)
> +#define SHM_HUGE_8MB (23 << SHM_HUGE_SHIFT)
> +#define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT)
> +#define SHM_HUGE_16GB (34 << SHM_HUGE_SHIFT)
This should be in arch/uapi like MAP_HUGE_2M ? That will let arch add
#defines based on the hugepae size supported by them.
> +
> +/* shmat() shmflg values */
> +#define SHM_RDONLY (1 << 12) /* read-only access */
> +#define SHM_RND (1 << 13) /* round attach address to SHMLBA boundary */
> +#define SHM_REMAP (1 << 14) /* take-over region on attach */
> +#define SHM_EXEC (1 << 15) /* execution access */
>
-aneesh
next prev parent reply other threads:[~2017-04-13 6:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 17:06 [PATCH] mm,hugetlb: compute page_size_log properly Davidlohr Bueso
2017-03-08 19:39 ` Andi Kleen
2017-03-09 3:24 ` Anshuman Khandual
2017-03-09 8:55 ` Michal Hocko
2017-03-28 16:53 ` Davidlohr Bueso
2017-03-28 16:55 ` Davidlohr Bueso
2017-03-28 17:54 ` Matthew Wilcox
2017-03-29 8:06 ` Michal Hocko
2017-03-29 17:45 ` Andi Kleen
2017-03-30 6:12 ` Michal Hocko
2017-04-12 16:18 ` Davidlohr Bueso
2017-04-12 16:30 ` Andi Kleen
2017-04-12 17:21 ` Matthew Wilcox
2017-04-13 6:02 ` Aneesh Kumar K.V [this message]
2017-04-13 12:46 ` Matthew Wilcox
2017-07-17 22:27 ` Mike Kravetz
2017-07-17 22:27 ` [RFC PATCH 1/3] mm:hugetlb: Define system call hugetlb size encodings in single file Mike Kravetz
2017-07-18 0:00 ` Matthew Wilcox
2017-07-26 9:50 ` Michal Hocko
2017-07-17 22:28 ` [RFC PATCH 2/3] mm: arch: Use new hugetlb size encoding definitions Mike Kravetz
2017-07-26 9:52 ` Michal Hocko
2017-07-17 22:28 ` [RFC PATCH 3/3] mm: shm: " Mike Kravetz
2017-07-26 9:53 ` Michal Hocko
2017-07-26 10:07 ` Michal Hocko
2017-07-26 17:39 ` Mike Kravetz
2017-07-26 18:48 ` Matthew Wilcox
2017-07-27 7:50 ` Michal Hocko
2017-07-27 21:18 ` Mike Kravetz
2017-07-28 6:30 ` Michal Hocko
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=87wpaoq1zy.fsf@skywalker.in.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=dbueso@suse.de \
--cc=khandual@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mtk.manpages@gmail.com \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).