[PATCH] dma-mapping: remove unused attrs parameter to dma_common_get_sgtable
From: Huaisheng Ye dma_common_get_sgtable has parameter attrs which is not used at all. Remove it. Signed-off-by: Huaisheng Ye Acked-by: Stefano Stabellini --- drivers/xen/swiotlb-xen.c | 2 +- include/linux/dma-mapping.h | 2 +- kernel/dma/mapping.c| 6 ++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 989cf87..b8cb1da 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -677,7 +677,7 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, handle, size, attrs); } #endif - return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size, attrs); + return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size); } const struct dma_map_ops xen_swiotlb_dma_ops = { diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index ba521d5..f9e7c2a 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -523,7 +523,7 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, - dma_addr_t dma_addr, size_t size, unsigned long attrs); + dma_addr_t dma_addr, size_t size); int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t dma_addr, size_t size, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index d7c34d2..0c28b71 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -203,8 +203,7 @@ void dmam_release_declared_memory(struct device *dev) * Create scatter-list for the already allocated DMA buffer. */ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, -void *cpu_addr, dma_addr_t dma_addr, size_t size, -unsigned long attrs) +void *cpu_addr, dma_addr_t dma_addr, size_t size) { struct page *page; int ret; @@ -234,8 +233,7 @@ int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, if (!dma_is_direct(ops) && ops->get_sgtable) return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size, attrs); - return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size, - attrs); + return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size); } EXPORT_SYMBOL(dma_get_sgtable_attrs); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v1] arch/x86/kernel/pci-dma: Remove useless parameter of arch_dma_alloc_attrs
From: Huaisheng Ye <ye...@lenovo.com> arch_dma_alloc_attrs has parameter gfp which is not used at all. Remove it. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Christoph Hellwig <h...@lst.de> Cc: Marek Szyprowski <m.szyprow...@samsung.com> Cc: Robin Murphy <robin.mur...@arm.com> Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Tom Lendacky <thomas.lenda...@amd.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Randy Dunlap <rdun...@infradead.org> Cc: Michal Hocko <mho...@suse.com> --- arch/x86/include/asm/dma-mapping.h | 2 +- arch/x86/kernel/pci-dma.c | 2 +- include/linux/dma-mapping.h| 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 89ce4bf..ef59747 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -33,7 +33,7 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) int arch_dma_supported(struct device *dev, u64 mask); #define arch_dma_supported arch_dma_supported -bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp); +bool arch_dma_alloc_attrs(struct device **dev); #define arch_dma_alloc_attrs arch_dma_alloc_attrs #endif diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 77625b6..94d1a49 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -76,7 +76,7 @@ void __init pci_iommu_alloc(void) } } -bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp) +bool arch_dma_alloc_attrs(struct device **dev) { if (!*dev) *dev = _dma_fallback_dev; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f8ab1c0..c80bb09 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -502,7 +502,7 @@ void *dma_common_pages_remap(struct page **pages, size_t size, #define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0) #ifndef arch_dma_alloc_attrs -#define arch_dma_alloc_attrs(dev, flag)(true) +#define arch_dma_alloc_attrs(dev) (true) #endif static inline void *dma_alloc_attrs(struct device *dev, size_t size, @@ -521,7 +521,7 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, /* let the implementation decide on the zone to allocate from: */ flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); - if (!arch_dma_alloc_attrs(, )) + if (!arch_dma_alloc_attrs()) return NULL; if (!ops->alloc) return NULL; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 6/9] mm/vmpressure: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, replace (__GFP_HIGHMEM | __GFP_MOVABLE) with __GFP_ZONE_MOVABLE. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: zhongjiang <zhongji...@huawei.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: David Rientjes <rient...@google.com> Cc: Christoph Hellwig <h...@infradead.org> --- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmpressure.c b/mm/vmpressure.c index 85350ce..30a40e2 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -256,7 +256,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, * Indirect reclaim (kswapd) sets sc->gfp_mask to GFP_KERNEL, so * we account it too. */ - if (!(gfp & (__GFP_HIGHMEM | __GFP_MOVABLE | __GFP_IO | __GFP_FS))) + if (!(gfp & (__GFP_ZONE_MOVABLE | __GFP_IO | __GFP_FS))) return; /* -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 5/9] drivers/block/zram/zram_drv: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, replace (__GFP_HIGHMEM | __GFP_MOVABLE) with __GFP_ZONE_MOVABLE. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Nitin Gupta <ngu...@vflare.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com> Cc: Christoph Hellwig <h...@infradead.org> --- drivers/block/zram/zram_drv.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 0f3fadd..1bb5ca8 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1004,14 +1004,12 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, handle = zs_malloc(zram->mem_pool, comp_len, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | - __GFP_HIGHMEM | - __GFP_MOVABLE); + __GFP_ZONE_MOVABLE); if (!handle) { zcomp_stream_put(zram->comp); atomic64_inc(>stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, - GFP_NOIO | __GFP_HIGHMEM | - __GFP_MOVABLE); + GFP_NOIO | __GFP_ZONE_MOVABLE); if (handle) goto compress_again; return -ENOMEM; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 9/9] arch/x86/include/asm/page.h: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: x...@kernel.org <x...@kernel.org> Cc: Philippe Ombredanne <pombreda...@nexb.com> Cc: Christoph Hellwig <h...@infradead.org> --- arch/x86/include/asm/page.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 7555b48..a47f42d 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -35,7 +35,8 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, } #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ - alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) + alloc_page_vma((movableflags ? GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER) \ + | __GFP_ZERO, vma, vaddr) #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE #ifndef __pa -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 8/9] include/linux/highmem.h: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Philippe Ombredanne <pombreda...@nexb.com> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/highmem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 0690679..5383c9e 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -159,8 +159,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr) struct vm_area_struct *vma, unsigned long vaddr) { - struct page *page = alloc_page_vma(GFP_HIGHUSER | movableflags, - vma, vaddr); + struct page *page = alloc_page_vma(movableflags ? + GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER, vma, vaddr); if (page) clear_user_highpage(page, vaddr); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 7/9] mm/zsmalloc: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, Use GFP_NORMAL_UNMOVABLE() to clear bottom 4 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Nitin Gupta <ngu...@vflare.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com> Cc: Christoph Hellwig <h...@infradead.org> --- mm/zsmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 61cb05d..e250c69 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -345,7 +345,7 @@ static void destroy_cache(struct zs_pool *pool) static unsigned long cache_alloc_handle(struct zs_pool *pool, gfp_t gfp) { return (unsigned long)kmem_cache_alloc(pool->handle_cachep, - gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + GFP_NORMAL_UNMOVABLE(gfp)); } static void cache_free_handle(struct zs_pool *pool, unsigned long handle) @@ -356,7 +356,7 @@ static void cache_free_handle(struct zs_pool *pool, unsigned long handle) static struct zspage *cache_alloc_zspage(struct zs_pool *pool, gfp_t flags) { return kmem_cache_alloc(pool->zspage_cachep, - flags & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + GFP_NORMAL_UNMOVABLE(flags)); } static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage) -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 4/9] fs/btrfs/extent_io: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA32 | __GFP_HIGHMEM). In function alloc_extent_state, it is obvious that __GFP_DMA is not the expecting zone type. ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Chris Mason <c...@fb.com> Cc: Josef Bacik <jba...@fb.com> Cc: David Sterba <dste...@suse.com> Cc: Christoph Hellwig <h...@infradead.org> --- fs/btrfs/extent_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index e99b329..f41fc61 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -220,7 +220,7 @@ static struct extent_state *alloc_extent_state(gfp_t mask) * The given mask might be not appropriate for the slab allocator, * drop the unsupported bits */ - mask &= ~(__GFP_DMA32|__GFP_HIGHMEM); + mask = GFP_NORMAL(mask); state = kmem_cache_alloc(extent_state_cache, mask); if (!state) return state; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 3/9] drivers/xen/swiotlb-xen: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM). In function xen_swiotlb_alloc_coherent, it is obvious that __GFP_DMA32 is not the expecting zone type. ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com> Cc: Boris Ostrovsky <boris.ostrov...@oracle.com> Cc: Juergen Gross <jgr...@suse.com> Cc: Christoph Hellwig <h...@infradead.org> --- drivers/xen/swiotlb-xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index e1c6089..359 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -301,7 +301,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) * machine physical layout. We can't allocate highmem * because we can't return a pointer to it. */ - flags &= ~(__GFP_DMA | __GFP_HIGHMEM); + flags = GFP_NORMAL(flags); /* On ARM this function returns an ioremap'ped virtual address for * which virt_to_phys doesn't return the corresponding physical -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 2/9] include/linux/dma-mapping: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Christoph Hellwig <h...@lst.de> Cc: Marek Szyprowski <m.szyprow...@samsung.com> Cc: Robin Murphy <robin.mur...@arm.com> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/dma-mapping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f8ab1c0..8fe524d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -519,7 +519,7 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, return cpu_addr; /* let the implementation decide on the zone to allocate from: */ - flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); + flag = GFP_NORMAL(flag); if (!arch_dma_alloc_attrs(, )) return NULL; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 1/9] include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All subsystems should use GFP_HIGHUSER_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Suggested-by: Matthew Wilcox <wi...@infradead.org> Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Vlastimil Babka <vba...@suse.cz> Cc: Michal Hocko <mho...@suse.com> Cc: Mel Gorman <mgor...@techsingularity.net> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: "Levin, Alexander (Sasha Levin)" <alexander.le...@verizon.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/gfp.h | 107 ++-- 1 file changed, 20 insertions(+), 87 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 1a4582b..f76ccd76 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -16,9 +16,7 @@ */ /* Plain integer GFP bitmasks. Do not use this directly. */ -#define ___GFP_DMA 0x01u -#define ___GFP_HIGHMEM 0x02u -#define ___GFP_DMA32 0x04u +#define ___GFP_ZONE_MASK 0x07u #define ___GFP_MOVABLE 0x08u #define ___GFP_RECLAIMABLE 0x10u #define ___GFP_HIGH0x20u @@ -53,11 +51,15 @@ * without the underscores and use them consistently. The definitions here may * be used in bit comparisons. */ -#define __GFP_DMA ((__force gfp_t)___GFP_DMA) -#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) -#define __GFP_DMA32((__force gfp_t)___GFP_DMA32) +#define __GFP_DMA ((__force gfp_t)OPT_ZONE_DMA ^ ZONE_NORMAL) +#define __GFP_HIGHMEM ((__force gfp_t)OPT_ZONE_HIGHMEM ^ ZONE_NORMAL) +#define __GFP_DMA32((__force gfp_t)OPT_ZONE_DMA32 ^ ZONE_NORMAL) #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ -#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) +#define GFP_ZONEMASK ((__force gfp_t)___GFP_ZONE_MASK | ___GFP_MOVABLE) +/* bottom 3 bits of GFP bitmasks are used for zone number encoded*/ +#define __GFP_ZONE_MASK ((__force gfp_t)___GFP_ZONE_MASK) +#define __GFP_ZONE_MOVABLE \ + ((__force gfp_t)(ZONE_MOVABLE ^ ZONE_NORMAL) | ___GFP_MOVABLE) /* * Page mobility and placement hints @@ -268,6 +270,13 @@ * available and will not wake kswapd/kcompactd on failure. The _LIGHT * version does not attempt reclaim/compaction at all and is by default used * in page fault path, while the non-light is used by khugepaged. + * + * GFP_NORMAL() is used to clear bottom 3 bits of GFP bitmask. Actually it + * returns encoded ZONE_NORMAL bits. + * + * GFP_NORMAL_UNMOVABLE() is similar to GFP_NORMAL, but it clear bottom 4 bits + * of GFP bitmask. Excepting the encoded ZONE_NORMAL bits, it clears MOVABLE + * flags as well. */ #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) @@ -279,10 +288,12 @@ #define GFP_DMA__GFP_DMA #define GFP_DMA32 __GFP_DMA32 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE) +#define GFP_HIGHUSER_MOVABLE (GFP_USER | __GFP_ZONE_MOVABLE) #define GFP_TRANSHUGE_LIGHT((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) +#define GFP_NORMAL(gfp)((gfp) & ~__GFP_ZONE_MASK) +#define GFP_NORMAL_UNMOVABLE(gfp) ((gfp) & ~GFP_ZONEMASK) /* Convert GFP flags to their corresponding migrate type */ #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE) @@ -326,87 +337,9 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) #define OPT_ZONE_DMA32 ZONE_NORMAL #endif -/* - * GFP_ZONE_TABLE is a wor
[RFC PATCH v3 0/9] get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Changes since v2: [2] * According to Christoph's suggestion, rebase patches to current mainline from v4.16. * Follow the advice of Matthew, create macros like GFP_NORMAL and GFP_NORMAL_UNMOVABLE to clear bottom 3 and 4 bits of GFP bitmask. * Delete some patches because of kernel updating. [2]: https://marc.info/?l=linux-mm=152691610014027=2 Tested by Lenovo Thinksystem server. Initmem setup node 0 [mem 0x1000-0x00043fff] [0.00] On node 0 totalpages: 4111666 [0.00] DMA zone: 64 pages used for memmap [0.00] DMA zone: 23 pages reserved [0.00] DMA zone: 3999 pages, LIFO batch:0 [0.00] mminit::memmap_init Initialising map node 0 zone 0 pfns 1 -> 4096 [0.00] DMA32 zone: 10935 pages used for memmap [0.00] DMA32 zone: 699795 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 0 zone 1 pfns 4096 -> 1048576 [0.00] Normal zone: 53248 pages used for memmap [0.00] Normal zone: 3407872 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 0 zone 2 pfns 1048576 -> 4456448 [0.00] mminit::memmap_init Initialising map node 0 zone 3 pfns 1 -> 4456448 [0.00] Initmem setup node 1 [mem 0x00238000-0x00277fff] [0.00] On node 1 totalpages: 4194304 [0.00] Normal zone: 65536 pages used for memmap [0.00] Normal zone: 4194304 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 1 zone 2 pfns 37224448 -> 41418752 [0.00] mminit::memmap_init Initialising map node 1 zone 3 pfns 37224448 -> 41418752 ... [0.00] mminit::zonelist general 0:DMA = 0:DMA [0.00] mminit::zonelist general 0:DMA32 = 0:DMA32 0:DMA [0.00] mminit::zonelist general 0:Normal = 0:Normal 0:DMA32 0:DMA 1:Normal [0.00] mminit::zonelist thisnode 0:DMA = 0:DMA [0.00] mminit::zonelist thisnode 0:DMA32 = 0:DMA32 0:DMA [0.00] mminit::zonelist thisnode 0:Normal = 0:Normal 0:DMA32 0:DMA [0.00] mminit::zonelist general 1:Normal = 1:Normal 0:Normal 0:DMA32 0:DMA [0.00] mminit::zonelist thisnode 1:Normal = 1:Normal [0.00] Built 2 zonelists, mobility grouping on. Total pages: 8176164 [0.00] Policy zone: Normal [0.00] Kernel command line: BOOT_IMAGE=/vmlinuz-4.17.0-rc6-gfp09+ root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap debug LANG=en_US.UTF-8 mminit_loglevel=4 console=tty0 console=ttyS0,115200n8 memblock=debug earlyprintk=serial,0x3f8,115200 --- Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All callers should use GFP_HIGHUSER_MOVABLE or __GFP_ZONE_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Changes since v1:[1] * Create __GFP_ZONE_MOVABLE and modify GFP_HIGHUSER_MOVABLE to help callers to get ZONE_MOVABLE. Try to create __GFP_ZONE_MASK to mask lowest 3 bits of GFP bitmasks. * Modify some callers' gfp flag to update usage of address zone modifiers. * Modify inline function gfp_zone to get better performance according to Matthew's suggestion. [1]: https://marc.info/?l=linux-mm=152596791931266=2 --- Huaisheng Ye (9): include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD include/linux/dma-mapping: update usage of zone modifiers drivers/xen/swiotlb-xen: update usage of zone modifiers fs/btrfs/extent_io: update usage of zone modifiers drivers/block/zram/zram_drv: update usage of zone modifiers mm/vmpressure: update usage of zone modifiers mm/zsmalloc: update usage of zone modifiers include/linux/highmem.h: update usage of movableflags arch/x86/include/asm/page.h: update usage of movableflags arch/x86/include/asm/page.h | 3 +- drivers/block/zram/zram_drv.c | 6 +-- drivers/xen/swiotlb-xen.c | 2 +- fs/btrfs/extent_io.c | 2 +- include/linux/dma-mapping.h | 2 +- include/lin
[RFC PATCH v3 9/9] arch/x86/include/asm/page.h: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: x...@kernel.org <x...@kernel.org> Cc: Philippe Ombredanne <pombreda...@nexb.com> Cc: Christoph Hellwig <h...@infradead.org> --- arch/x86/include/asm/page.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 7555b48..a47f42d 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -35,7 +35,8 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, } #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ - alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) + alloc_page_vma((movableflags ? GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER) \ + | __GFP_ZERO, vma, vaddr) #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE #ifndef __pa -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 8/9] include/linux/highmem.h: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Philippe Ombredanne <pombreda...@nexb.com> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/highmem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 0690679..5383c9e 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -159,8 +159,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr) struct vm_area_struct *vma, unsigned long vaddr) { - struct page *page = alloc_page_vma(GFP_HIGHUSER | movableflags, - vma, vaddr); + struct page *page = alloc_page_vma(movableflags ? + GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER, vma, vaddr); if (page) clear_user_highpage(page, vaddr); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 4/9] fs/btrfs/extent_io: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA32 | __GFP_HIGHMEM). In function alloc_extent_state, it is obvious that __GFP_DMA is not the expecting zone type. ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Chris Mason <c...@fb.com> Cc: Josef Bacik <jba...@fb.com> Cc: David Sterba <dste...@suse.com> Cc: Christoph Hellwig <h...@infradead.org> --- fs/btrfs/extent_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index e99b329..f41fc61 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -220,7 +220,7 @@ static struct extent_state *alloc_extent_state(gfp_t mask) * The given mask might be not appropriate for the slab allocator, * drop the unsupported bits */ - mask &= ~(__GFP_DMA32|__GFP_HIGHMEM); + mask = GFP_NORMAL(mask); state = kmem_cache_alloc(extent_state_cache, mask); if (!state) return state; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 1/9] include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All subsystems should use GFP_HIGHUSER_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Suggested-by: Matthew Wilcox <wi...@infradead.org> Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Vlastimil Babka <vba...@suse.cz> Cc: Michal Hocko <mho...@suse.com> Cc: Mel Gorman <mgor...@techsingularity.net> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: "Levin, Alexander (Sasha Levin)" <alexander.le...@verizon.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/gfp.h | 107 ++-- 1 file changed, 20 insertions(+), 87 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 1a4582b..f76ccd76 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -16,9 +16,7 @@ */ /* Plain integer GFP bitmasks. Do not use this directly. */ -#define ___GFP_DMA 0x01u -#define ___GFP_HIGHMEM 0x02u -#define ___GFP_DMA32 0x04u +#define ___GFP_ZONE_MASK 0x07u #define ___GFP_MOVABLE 0x08u #define ___GFP_RECLAIMABLE 0x10u #define ___GFP_HIGH0x20u @@ -53,11 +51,15 @@ * without the underscores and use them consistently. The definitions here may * be used in bit comparisons. */ -#define __GFP_DMA ((__force gfp_t)___GFP_DMA) -#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) -#define __GFP_DMA32((__force gfp_t)___GFP_DMA32) +#define __GFP_DMA ((__force gfp_t)OPT_ZONE_DMA ^ ZONE_NORMAL) +#define __GFP_HIGHMEM ((__force gfp_t)OPT_ZONE_HIGHMEM ^ ZONE_NORMAL) +#define __GFP_DMA32((__force gfp_t)OPT_ZONE_DMA32 ^ ZONE_NORMAL) #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ -#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) +#define GFP_ZONEMASK ((__force gfp_t)___GFP_ZONE_MASK | ___GFP_MOVABLE) +/* bottom 3 bits of GFP bitmasks are used for zone number encoded*/ +#define __GFP_ZONE_MASK ((__force gfp_t)___GFP_ZONE_MASK) +#define __GFP_ZONE_MOVABLE \ + ((__force gfp_t)(ZONE_MOVABLE ^ ZONE_NORMAL) | ___GFP_MOVABLE) /* * Page mobility and placement hints @@ -268,6 +270,13 @@ * available and will not wake kswapd/kcompactd on failure. The _LIGHT * version does not attempt reclaim/compaction at all and is by default used * in page fault path, while the non-light is used by khugepaged. + * + * GFP_NORMAL() is used to clear bottom 3 bits of GFP bitmask. Actually it + * returns encoded ZONE_NORMAL bits. + * + * GFP_NORMAL_UNMOVABLE() is similar to GFP_NORMAL, but it clear bottom 4 bits + * of GFP bitmask. Excepting the encoded ZONE_NORMAL bits, it clears MOVABLE + * flags as well. */ #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) @@ -279,10 +288,12 @@ #define GFP_DMA__GFP_DMA #define GFP_DMA32 __GFP_DMA32 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE) +#define GFP_HIGHUSER_MOVABLE (GFP_USER | __GFP_ZONE_MOVABLE) #define GFP_TRANSHUGE_LIGHT((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) +#define GFP_NORMAL(gfp)((gfp) & ~__GFP_ZONE_MASK) +#define GFP_NORMAL_UNMOVABLE(gfp) ((gfp) & ~GFP_ZONEMASK) /* Convert GFP flags to their corresponding migrate type */ #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE) @@ -326,87 +337,9 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) #define OPT_ZONE_DMA32 ZONE_NORMAL #endif -/* - * GFP_ZONE_TABLE is a wor
[RFC PATCH v3 2/9] include/linux/dma-mapping: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Christoph Hellwig <h...@lst.de> Cc: Marek Szyprowski <m.szyprow...@samsung.com> Cc: Robin Murphy <robin.mur...@arm.com> Cc: Christoph Hellwig <h...@infradead.org> --- include/linux/dma-mapping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f8ab1c0..8fe524d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -519,7 +519,7 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, return cpu_addr; /* let the implementation decide on the zone to allocate from: */ - flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); + flag = GFP_NORMAL(flag); if (!arch_dma_alloc_attrs(, )) return NULL; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 5/9] drivers/block/zram/zram_drv: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, replace (__GFP_HIGHMEM | __GFP_MOVABLE) with __GFP_ZONE_MOVABLE. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Nitin Gupta <ngu...@vflare.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com> Cc: Christoph Hellwig <h...@infradead.org> --- drivers/block/zram/zram_drv.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 0f3fadd..1bb5ca8 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1004,14 +1004,12 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, handle = zs_malloc(zram->mem_pool, comp_len, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | - __GFP_HIGHMEM | - __GFP_MOVABLE); + __GFP_ZONE_MOVABLE); if (!handle) { zcomp_stream_put(zram->comp); atomic64_inc(>stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, - GFP_NOIO | __GFP_HIGHMEM | - __GFP_MOVABLE); + GFP_NOIO | __GFP_ZONE_MOVABLE); if (handle) goto compress_again; return -ENOMEM; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 7/9] mm/zsmalloc: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, Use GFP_NORMAL_UNMOVABLE() to clear bottom 4 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Nitin Gupta <ngu...@vflare.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com> Cc: Christoph Hellwig <h...@infradead.org> --- mm/zsmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 61cb05d..e250c69 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -345,7 +345,7 @@ static void destroy_cache(struct zs_pool *pool) static unsigned long cache_alloc_handle(struct zs_pool *pool, gfp_t gfp) { return (unsigned long)kmem_cache_alloc(pool->handle_cachep, - gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + GFP_NORMAL_UNMOVABLE(gfp)); } static void cache_free_handle(struct zs_pool *pool, unsigned long handle) @@ -356,7 +356,7 @@ static void cache_free_handle(struct zs_pool *pool, unsigned long handle) static struct zspage *cache_alloc_zspage(struct zs_pool *pool, gfp_t flags) { return kmem_cache_alloc(pool->zspage_cachep, - flags & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + GFP_NORMAL_UNMOVABLE(flags)); } static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage) -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 6/9] mm/vmpressure: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, replace (__GFP_HIGHMEM | __GFP_MOVABLE) with __GFP_ZONE_MOVABLE. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: zhongjiang <zhongji...@huawei.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: David Rientjes <rient...@google.com> Cc: Christoph Hellwig <h...@infradead.org> --- mm/vmpressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmpressure.c b/mm/vmpressure.c index 85350ce..30a40e2 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -256,7 +256,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, * Indirect reclaim (kswapd) sets sc->gfp_mask to GFP_KERNEL, so * we account it too. */ - if (!(gfp & (__GFP_HIGHMEM | __GFP_MOVABLE | __GFP_IO | __GFP_FS))) + if (!(gfp & (__GFP_ZONE_MOVABLE | __GFP_IO | __GFP_FS))) return; /* -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 3/9] drivers/xen/swiotlb-xen: update usage of zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM). In function xen_swiotlb_alloc_coherent, it is obvious that __GFP_DMA32 is not the expecting zone type. ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Use GFP_NORMAL() to clear bottom 3 bits of GFP bitmaks. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com> Cc: Boris Ostrovsky <boris.ostrov...@oracle.com> Cc: Juergen Gross <jgr...@suse.com> Cc: Christoph Hellwig <h...@infradead.org> --- drivers/xen/swiotlb-xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index e1c6089..359 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -301,7 +301,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) * machine physical layout. We can't allocate highmem * because we can't return a pointer to it. */ - flags &= ~(__GFP_DMA | __GFP_HIGHMEM); + flags = GFP_NORMAL(flags); /* On ARM this function returns an ioremap'ped virtual address for * which virt_to_phys doesn't return the corresponding physical -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v3 0/9] get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Changes since v2: [2] * According to Christoph's suggestion, rebase patches to current mainline from v4.16. * Follow the advice of Matthew, create macros like GFP_NORMAL and GFP_NORMAL_UNMOVABLE to clear bottom 3 and 4 bits of GFP bitmask. * Delete some patches because of kernel updating. [2]: https://marc.info/?l=linux-mm=152691610014027=2 Tested by Lenovo Thinksystem server. Initmem setup node 0 [mem 0x1000-0x00043fff] [0.00] On node 0 totalpages: 4111666 [0.00] DMA zone: 64 pages used for memmap [0.00] DMA zone: 23 pages reserved [0.00] DMA zone: 3999 pages, LIFO batch:0 [0.00] mminit::memmap_init Initialising map node 0 zone 0 pfns 1 -> 4096 [0.00] DMA32 zone: 10935 pages used for memmap [0.00] DMA32 zone: 699795 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 0 zone 1 pfns 4096 -> 1048576 [0.00] Normal zone: 53248 pages used for memmap [0.00] Normal zone: 3407872 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 0 zone 2 pfns 1048576 -> 4456448 [0.00] mminit::memmap_init Initialising map node 0 zone 3 pfns 1 -> 4456448 [0.00] Initmem setup node 1 [mem 0x00238000-0x00277fff] [0.00] On node 1 totalpages: 4194304 [0.00] Normal zone: 65536 pages used for memmap [0.00] Normal zone: 4194304 pages, LIFO batch:31 [0.00] mminit::memmap_init Initialising map node 1 zone 2 pfns 37224448 -> 41418752 [0.00] mminit::memmap_init Initialising map node 1 zone 3 pfns 37224448 -> 41418752 ... [0.00] mminit::zonelist general 0:DMA = 0:DMA [0.00] mminit::zonelist general 0:DMA32 = 0:DMA32 0:DMA [0.00] mminit::zonelist general 0:Normal = 0:Normal 0:DMA32 0:DMA 1:Normal [0.00] mminit::zonelist thisnode 0:DMA = 0:DMA [0.00] mminit::zonelist thisnode 0:DMA32 = 0:DMA32 0:DMA [0.00] mminit::zonelist thisnode 0:Normal = 0:Normal 0:DMA32 0:DMA [0.00] mminit::zonelist general 1:Normal = 1:Normal 0:Normal 0:DMA32 0:DMA [0.00] mminit::zonelist thisnode 1:Normal = 1:Normal [0.00] Built 2 zonelists, mobility grouping on. Total pages: 8176164 [0.00] Policy zone: Normal [0.00] Kernel command line: BOOT_IMAGE=/vmlinuz-4.17.0-rc6-gfp09+ root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap debug LANG=en_US.UTF-8 mminit_loglevel=4 console=tty0 console=ttyS0,115200n8 memblock=debug earlyprintk=serial,0x3f8,115200 --- Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All callers should use GFP_HIGHUSER_MOVABLE or __GFP_ZONE_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Changes since v1:[1] * Create __GFP_ZONE_MOVABLE and modify GFP_HIGHUSER_MOVABLE to help callers to get ZONE_MOVABLE. Try to create __GFP_ZONE_MASK to mask lowest 3 bits of GFP bitmasks. * Modify some callers' gfp flag to update usage of address zone modifiers. * Modify inline function gfp_zone to get better performance according to Matthew's suggestion. [1]: https://marc.info/?l=linux-mm=152596791931266=2 --- Huaisheng Ye (9): include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD include/linux/dma-mapping: update usage of zone modifiers drivers/xen/swiotlb-xen: update usage of zone modifiers fs/btrfs/extent_io: update usage of zone modifiers drivers/block/zram/zram_drv: update usage of zone modifiers mm/vmpressure: update usage of zone modifiers mm/zsmalloc: update usage of zone modifiers include/linux/highmem.h: update usage of movableflags arch/x86/include/asm/page.h: update usage of movableflags arch/x86/include/asm/page.h | 3 +- drivers/block/zram/zram_drv.c | 6 +-- drivers/xen/swiotlb-xen.c | 2 +- fs/btrfs/extent_io.c | 2 +- include/linux/dma-mapping.h | 2 +- include/lin
[RFC PATCH v2 12/12] arch/x86/include/asm/page.h: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: x...@kernel.org <x...@kernel.org> Cc: Philippe Ombredanne <pombreda...@nexb.com> --- arch/x86/include/asm/page.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 7555b48..a47f42d 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -35,7 +35,8 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, } #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ - alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) + alloc_page_vma((movableflags ? GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER) \ + | __GFP_ZERO, vma, vaddr) #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE #ifndef __pa -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 11/12] include/linux/highmem: update usage of movableflags
From: Huaisheng Ye <ye...@lenovo.com> GFP_HIGHUSER_MOVABLE doesn't equal to GFP_HIGHUSER | __GFP_MOVABLE, modify it to adapt patch of getting rid of GFP_ZONE_TABLE/BAD. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Philippe Ombredanne <pombreda...@nexb.com> --- include/linux/highmem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 776f90f..da34260 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -159,8 +159,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr) struct vm_area_struct *vma, unsigned long vaddr) { - struct page *page = alloc_page_vma(GFP_HIGHUSER | movableflags, - vma, vaddr); + struct page *page = alloc_page_vma(movableflags ? + GFP_HIGHUSER_MOVABLE : GFP_HIGHUSER, vma, vaddr); if (page) clear_user_highpage(page, vaddr); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 10/12] mm/zsmalloc: update usage of address zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MOVABLE to replace (__GFP_HIGHMEM | __GFP_MOVABLE). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_ZONE_MOVABLE contains encoded ZONE_MOVABLE and __GFP_MOVABLE flag. With GFP_ZONE_TABLE, __GFP_HIGHMEM ORing __GFP_MOVABLE means gfp_zone should return ZONE_MOVABLE. In order to keep that compatible with GFP_ZONE_TABLE, replace (__GFP_HIGHMEM | __GFP_MOVABLE) with __GFP_ZONE_MOVABLE. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Minchan Kim <minc...@kernel.org> Cc: Nitin Gupta <ngu...@vflare.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.w...@gmail.com> --- mm/zsmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index c301350..06b2902 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -343,7 +343,7 @@ static void destroy_cache(struct zs_pool *pool) static unsigned long cache_alloc_handle(struct zs_pool *pool, gfp_t gfp) { return (unsigned long)kmem_cache_alloc(pool->handle_cachep, - gfp & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + gfp & ~__GFP_ZONE_MOVABLE); } static void cache_free_handle(struct zs_pool *pool, unsigned long handle) @@ -354,7 +354,7 @@ static void cache_free_handle(struct zs_pool *pool, unsigned long handle) static struct zspage *cache_alloc_zspage(struct zs_pool *pool, gfp_t flags) { return kmem_cache_alloc(pool->zspage_cachep, - flags & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); + flags & ~__GFP_ZONE_MOVABLE); } static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage) -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 05/12] include/linux/dma-mapping: update usage of address zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated with each others by OR. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Christoph Hellwig <h...@lst.de> Cc: Marek Szyprowski <m.szyprow...@samsung.com> Cc: Robin Murphy <robin.mur...@arm.com> --- include/linux/dma-mapping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index eb9eab4..3da0293 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -523,7 +523,7 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size, * decide on the way of zeroing the memory given that the memory * returned should always be zeroed. */ - flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO); + flag &= ~(__GFP_ZONE_MASK | __GFP_ZERO); if (!arch_dma_alloc_attrs(, )) return NULL; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 04/12] drivers/iommu/amd_iommu: update usage of address zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated by OR. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Joerg Roedel <j...@8bytes.org> --- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 74788fd..3921d53 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2614,7 +2614,7 @@ static void *alloc_coherent(struct device *dev, size_t size, dma_dom = to_dma_ops_domain(domain); size = PAGE_ALIGN(size); dma_mask = dev->coherent_dma_mask; - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); + flag &= ~__GFP_ZONE_MASK; flag |= __GFP_ZERO; page = alloc_pages(flag | __GFP_NOWARN, get_order(size)); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 03/12] arch/x86/kernel/pci-calgary_64: update usage of address zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated by OR. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Muli Ben-Yehuda <mu...@mulix.org> Cc: Jon Mason <jdma...@kudzu.us> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> --- arch/x86/kernel/pci-calgary_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c index 35c461f..c89717d 100644 --- a/arch/x86/kernel/pci-calgary_64.c +++ b/arch/x86/kernel/pci-calgary_64.c @@ -445,7 +445,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size, npages = size >> PAGE_SHIFT; order = get_order(size); - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); + flag &= ~__GFP_ZONE_MASK; /* alloc enough pages (and possibly more) */ ret = (void *)__get_free_pages(flag, order); -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 02/12] arch/x86/kernel/amd_gart_64: update usage of address zone modifiers
From: Huaisheng Ye <ye...@lenovo.com> Use __GFP_ZONE_MASK to replace (__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32). ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 have been deleted from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. __GFP_DMA, __GFP_HIGHMEM and __GFP_DMA32 should not be operated by OR. Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Ingo Molnar <mi...@redhat.com> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Robin Murphy <robin.mur...@arm.com> --- arch/x86/kernel/amd_gart_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c index ecd486c..1dd6971 100644 --- a/arch/x86/kernel/amd_gart_64.c +++ b/arch/x86/kernel/amd_gart_64.c @@ -485,7 +485,7 @@ static int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, struct page *page; if (force_iommu && !(flag & GFP_DMA)) { - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); + flag &= ~__GFP_ZONE_MASK; page = alloc_pages(flag | __GFP_ZERO, get_order(size)); if (!page) return NULL; -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[RFC PATCH v2 01/12] include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All subsystems should use GFP_HIGHUSER_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Suggested-by: Matthew Wilcox <wi...@infradead.org> Signed-off-by: Huaisheng Ye <ye...@lenovo.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Vlastimil Babka <vba...@suse.cz> Cc: Michal Hocko <mho...@suse.com> Cc: Mel Gorman <mgor...@techsingularity.net> Cc: Kate Stewart <kstew...@linuxfoundation.org> Cc: "Levin, Alexander (Sasha Levin)" <alexander.le...@verizon.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> --- include/linux/gfp.h | 98 ++--- 1 file changed, 11 insertions(+), 87 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 1a4582b..ab0fb7f 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -16,9 +16,7 @@ */ /* Plain integer GFP bitmasks. Do not use this directly. */ -#define ___GFP_DMA 0x01u -#define ___GFP_HIGHMEM 0x02u -#define ___GFP_DMA32 0x04u +#define ___GFP_ZONE_MASK 0x07u #define ___GFP_MOVABLE 0x08u #define ___GFP_RECLAIMABLE 0x10u #define ___GFP_HIGH0x20u @@ -53,11 +51,15 @@ * without the underscores and use them consistently. The definitions here may * be used in bit comparisons. */ -#define __GFP_DMA ((__force gfp_t)___GFP_DMA) -#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) -#define __GFP_DMA32((__force gfp_t)___GFP_DMA32) +#define __GFP_DMA ((__force gfp_t)OPT_ZONE_DMA ^ ZONE_NORMAL) +#define __GFP_HIGHMEM ((__force gfp_t)OPT_ZONE_HIGHMEM ^ ZONE_NORMAL) +#define __GFP_DMA32((__force gfp_t)OPT_ZONE_DMA32 ^ ZONE_NORMAL) #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ -#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) +#define GFP_ZONEMASK ((__force gfp_t)___GFP_ZONE_MASK | ___GFP_MOVABLE) +/* bottom 3 bits of GFP bitmasks are used for zone number encoded*/ +#define __GFP_ZONE_MASK ((__force gfp_t)___GFP_ZONE_MASK) +#define __GFP_ZONE_MOVABLE \ + ((__force gfp_t)(ZONE_MOVABLE ^ ZONE_NORMAL) | ___GFP_MOVABLE) /* * Page mobility and placement hints @@ -279,7 +281,7 @@ #define GFP_DMA__GFP_DMA #define GFP_DMA32 __GFP_DMA32 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE) +#define GFP_HIGHUSER_MOVABLE (GFP_USER | __GFP_ZONE_MOVABLE) #define GFP_TRANSHUGE_LIGHT((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) @@ -326,87 +328,9 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) #define OPT_ZONE_DMA32 ZONE_NORMAL #endif -/* - * GFP_ZONE_TABLE is a word size bitstring that is used for looking up the - * zone to use given the lowest 4 bits of gfp_t. Entries are GFP_ZONES_SHIFT - * bits long and there are 16 of them to cover all possible combinations of - * __GFP_DMA, __GFP_DMA32, __GFP_MOVABLE and __GFP_HIGHMEM. - * - * The zone fallback order is MOVABLE=>HIGHMEM=>NORMAL=>DMA32=>DMA. - * But GFP_MOVABLE is not only a zone specifier but also an allocation - * policy. Therefore __GFP_MOVABLE plus another zone selector is valid. - * Only 1 bit of the lowest 3 bits (DMA,DMA32,HIGHMEM) can be set to "1". - * - * bit result - * = - * 0x0=> NORMAL - * 0x1=> DMA or NORMAL - * 0x2=> HIGHMEM or NORMAL - * 0x3=> BAD (DMA+HIGHMEM) - * 0x4=> DMA32 or DMA or NORMAL - * 0x5=> BAD (DMA+DMA32) - * 0x6=> BAD (HIGHMEM+DMA32) - * 0x7=> BAD (HIGHMEM+DMA32+DMA) - * 0x8=> NORMA
[RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng Ye <ye...@lenovo.com> Replace GFP_ZONE_TABLE and GFP_ZONE_BAD with encoded zone number. Delete ___GFP_DMA, ___GFP_HIGHMEM and ___GFP_DMA32 from GFP bitmasks, the bottom three bits of GFP mask is reserved for storing encoded zone number. The encoding method is XOR. Get zone number from enum zone_type, then encode the number with ZONE_NORMAL by XOR operation. The goal is to make sure ZONE_NORMAL can be encoded to zero. So, the compatibility can be guaranteed, such as GFP_KERNEL and GFP_ATOMIC can be used as before. Reserve __GFP_MOVABLE in bit 3, so that it can continue to be used as a flag. Same as before, __GFP_MOVABLE respresents movable migrate type for ZONE_DMA, ZONE_DMA32, and ZONE_NORMAL. But when it is enabled with __GFP_HIGHMEM, ZONE_MOVABLE shall be returned instead of ZONE_HIGHMEM. __GFP_ZONE_MOVABLE is created to realize it. With this patch, just enabling __GFP_MOVABLE and __GFP_HIGHMEM is not enough to get ZONE_MOVABLE from gfp_zone. All callers should use GFP_HIGHUSER_MOVABLE or __GFP_ZONE_MOVABLE directly to achieve that. Decode zone number directly from bottom three bits of flags in gfp_zone. The theory of encoding and decoding is, A ^ B ^ B = A Changes since v1, v2: Add __GFP_ZONE_MOVABLE and modify GFP_HIGHUSER_MOVABLE to help callers to get ZONE_MOVABLE. Add __GFP_ZONE_MASK to mask lowest 3 bits of GFP bitmasks. Modify some callers' gfp flag to update usage of address zone modifiers. Modify inline function gfp_zone to get better performance according to Matthew's suggestion. Link: https://marc.info/?l=linux-mm=152596791931266=2 Huaisheng Ye (12): include/linux/gfp.h: get rid of GFP_ZONE_TABLE/BAD arch/x86/kernel/amd_gart_64: update usage of address zone modifiers arch/x86/kernel/pci-calgary_64: update usage of address zone modifiers drivers/iommu/amd_iommu: update usage of address zone modifiers include/linux/dma-mapping: update usage of address zone modifiers drivers/xen/swiotlb-xen: update usage of address zone modifiers fs/btrfs/extent_io: update usage of address zone modifiers drivers/block/zram/zram_drv: update usage of address zone modifiers mm/vmpressure: update usage of address zone modifiers mm/zsmalloc: update usage of address zone modifiers include/linux/highmem: update usage of movableflags arch/x86/include/asm/page.h: update usage of movableflags arch/x86/include/asm/page.h | 3 +- arch/x86/kernel/amd_gart_64.c| 2 +- arch/x86/kernel/pci-calgary_64.c | 2 +- drivers/block/zram/zram_drv.c| 6 +-- drivers/iommu/amd_iommu.c| 2 +- drivers/xen/swiotlb-xen.c| 2 +- fs/btrfs/extent_io.c | 2 +- include/linux/dma-mapping.h | 2 +- include/linux/gfp.h | 98 +--- include/linux/highmem.h | 4 +- mm/vmpressure.c | 2 +- mm/zsmalloc.c| 4 +- 12 files changed, 26 insertions(+), 103 deletions(-) -- 1.8.3.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu