From: Igor Stoppa <igor.stoppa@huawei.com>
To: mhocko@suse.com, namhyung@kernel.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Igor Stoppa <igor.stoppa@huawei.com>
Subject: [PATCH 1/1] Remove hardcoding of ___GFP_xxx bitmasks
Date: Wed, 26 Apr 2017 16:35:49 +0300 [thread overview]
Message-ID: <20170426133549.22603-2-igor.stoppa@huawei.com> (raw)
In-Reply-To: <20170426133549.22603-1-igor.stoppa@huawei.com>
The bitmasks used for ___GFP_xxx can be defined in terms of an enum,
which doesn't require manual updates to its values.
As bonus, __GFP_BITS_SHIFT is automatically kept consistent.
Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
---
include/linux/gfp.h | 82 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 55 insertions(+), 27 deletions(-)
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 0fe0b62..2f894c5 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -14,33 +14,62 @@ struct vm_area_struct;
* include/trace/events/mmflags.h and tools/perf/builtin-kmem.c
*/
+enum gfp_bitmask_shift {
+ __GFP_DMA_SHIFT = 0,
+ __GFP_HIGHMEM_SHIFT,
+ __GFP_DMA32_SHIFT,
+ __GFP_MOVABLE_SHIFT,
+ __GFP_RECLAIMABLE_SHIFT,
+ __GFP_HIGH_SHIFT,
+ __GFP_IO_SHIFT,
+ __GFP_FS_SHIFT,
+ __GFP_COLD_SHIFT,
+ __GFP_NOWARN_SHIFT,
+ __GFP_REPEAT_SHIFT,
+ __GFP_NOFAIL_SHIFT,
+ __GFP_NORETRY_SHIFT,
+ __GFP_MEMALLOC_SHIFT,
+ __GFP_COMP_SHIFT,
+ __GFP_ZERO_SHIFT,
+ __GFP_NOMEMALLOC_SHIFT,
+ __GFP_HARDWALL_SHIFT,
+ __GFP_THISNODE_SHIFT,
+ __GFP_ATOMIC_SHIFT,
+ __GFP_ACCOUNT_SHIFT,
+ __GFP_NOTRACK_SHIFT,
+ __GFP_DIRECT_RECLAIM_SHIFT,
+ __GFP_WRITE_SHIFT,
+ __GFP_KSWAPD_RECLAIM_SHIFT,
+ __GFP_BITS_SHIFT
+};
+
+
/* Plain integer GFP bitmasks. Do not use this directly. */
-#define ___GFP_DMA 0x01u
-#define ___GFP_HIGHMEM 0x02u
-#define ___GFP_DMA32 0x04u
-#define ___GFP_MOVABLE 0x08u
-#define ___GFP_RECLAIMABLE 0x10u
-#define ___GFP_HIGH 0x20u
-#define ___GFP_IO 0x40u
-#define ___GFP_FS 0x80u
-#define ___GFP_COLD 0x100u
-#define ___GFP_NOWARN 0x200u
-#define ___GFP_REPEAT 0x400u
-#define ___GFP_NOFAIL 0x800u
-#define ___GFP_NORETRY 0x1000u
-#define ___GFP_MEMALLOC 0x2000u
-#define ___GFP_COMP 0x4000u
-#define ___GFP_ZERO 0x8000u
-#define ___GFP_NOMEMALLOC 0x10000u
-#define ___GFP_HARDWALL 0x20000u
-#define ___GFP_THISNODE 0x40000u
-#define ___GFP_ATOMIC 0x80000u
-#define ___GFP_ACCOUNT 0x100000u
-#define ___GFP_NOTRACK 0x200000u
-#define ___GFP_DIRECT_RECLAIM 0x400000u
-#define ___GFP_WRITE 0x800000u
-#define ___GFP_KSWAPD_RECLAIM 0x1000000u
-/* If the above are modified, __GFP_BITS_SHIFT may need updating */
+#define ___GFP_DMA (1u << __GFP_DMA_SHIFT)
+#define ___GFP_HIGHMEM (1u << __GFP_HIGHMEM_SHIFT)
+#define ___GFP_DMA32 (1u << __GFP_DMA32_SHIFT)
+#define ___GFP_MOVABLE (1u << __GFP_MOVABLE_SHIFT)
+#define ___GFP_RECLAIMABLE (1u << __GFP_RECLAIMABLE_SHIFT)
+#define ___GFP_HIGH (1u << __GFP_HIGH_SHIFT)
+#define ___GFP_IO (1u << __GFP_IO_SHIFT)
+#define ___GFP_FS (1u << __GFP_FS_SHIFT)
+#define ___GFP_COLD (1u << __GFP_COLD_SHIFT)
+#define ___GFP_NOWARN (1u << __GFP_NOWARN_SHIFT)
+#define ___GFP_REPEAT (1u << __GFP_REPEAT_SHIFT)
+#define ___GFP_NOFAIL (1u << __GFP_NOFAIL_SHIFT)
+#define ___GFP_NORETRY (1u << __GFP_NORETRY_SHIFT)
+#define ___GFP_MEMALLOC (1u << __GFP_MEMALLOC_SHIFT)
+#define ___GFP_COMP (1u << __GFP_COMP_SHIFT)
+#define ___GFP_ZERO (1u << __GFP_ZERO_SHIFT)
+#define ___GFP_NOMEMALLOC (1u << __GFP_NOMEMALLOC_SHIFT)
+#define ___GFP_HARDWALL (1u << __GFP_HARDWALL_SHIFT)
+#define ___GFP_THISNODE (1u << __GFP_THISNODE_SHIFT)
+#define ___GFP_ATOMIC (1u << __GFP_ATOMIC_SHIFT)
+#define ___GFP_ACCOUNT (1u << __GFP_ACCOUNT_SHIFT)
+#define ___GFP_NOTRACK (1u << __GFP_NOTRACK_SHIFT)
+#define ___GFP_DIRECT_RECLAIM (1u << __GFP_DIRECT_RECLAIM_SHIFT)
+#define ___GFP_WRITE (1u << __GFP_WRITE_SHIFT)
+#define ___GFP_KSWAPD_RECLAIM (1u << __GFP_KSWAPD_RECLAIM_SHIFT)
/*
* Physical address zone modifiers (see linux/mmzone.h - low four bits)
@@ -180,7 +209,6 @@ struct vm_area_struct;
#define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
/* Room for N __GFP_FOO bits */
-#define __GFP_BITS_SHIFT 25
#define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
/*
--
2.9.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-04-26 13:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-26 13:35 [PATCH 0/1] mm: Improve consistency of ___GFP_xxx masks Igor Stoppa
2017-04-26 13:35 ` Igor Stoppa [this message]
2017-04-26 14:47 ` [PATCH 1/1] Remove hardcoding of ___GFP_xxx bitmasks Michal Hocko
2017-04-26 15:29 ` Igor Stoppa
2017-04-27 12:16 ` Question on ___GFP_NOLOCKDEP - Was: " Igor Stoppa
2017-04-27 13:35 ` Michal Hocko
2017-05-10 15:24 ` Vlastimil Babka
2017-04-27 12:18 ` Igor Stoppa
2017-04-27 13:41 ` Michal Hocko
2017-04-27 14:06 ` Igor Stoppa
2017-04-28 7:40 ` Michal Hocko
2017-04-28 7:43 ` Igor Stoppa
2017-04-28 8:13 ` Igor Stoppa
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=20170426133549.22603-2-igor.stoppa@huawei.com \
--to=igor.stoppa@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=namhyung@kernel.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