Re: [External] Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Fri 25-05-18 09:43:09, Huaisheng HS1 Ye wrote: > From: Michal Hocko [mailto:mho...@kernel.org] > Sent: Thursday, May 24, 2018 8:19 PM> > > > Let me try to reply your questions. > > > Exactly, GFP_ZONE_TABLE is too complicated. I think there are two > > > advantages > > > from the series of patches. > > > > > > 1. XOR operation is simple and efficient, GFP_ZONE_TABLE/BAD need to do > > > twice > > > shift operations, the first is for getting a zone_type and the second is > > > for > > > checking the to be returned type is a correct or not. But with these > > > patch XOR > > > operation just needs to use once. Because the bottom 3 bits of GFP > > > bitmask have > > > been used to represent the encoded zone number, we can say there is no > > > bad zone > > > number if all callers could use it without buggy way. Of course, the > > > returned > > > zone type in gfp_zone needs to be no more than ZONE_MOVABLE. > > > > But you are losing the ability to check for wrong usage. And it seems > > that the sad reality is that the existing code do screw up. > > In my opinion, originally there shouldn't be such many wrong > combinations of these bottom 3 bits. For any user, whether or > driver and fs, they should make a decision that which zone is they > preferred. Matthew's idea is great, because with it the user must > offer an unambiguous flag to gfp zone bits. Well, I would argue that those shouldn't really care about any zones at all. All they should carea bout is whether they really need a low mem zone (aka directly accessible to the kernel), highmem or they are the allocation is generally movable. Mixing zones into the picture just makes the whole thing more complicated and error prone. [...] > > That being said. I am not saying that I am in love with GFP_ZONE_TABLE. > > It always makes my head explode when I look there but it seems to work > > with the current code and it is optimized for it. If you want to change > > this then you should make sure you describe reasons _why_ this is an > > improvement. And I would argue that "we can have more zones" is a > > relevant one. > > Yes, GFP_ZONE_TABLE is too complicated. The patches have 4 advantages as > below. > > * The address zone modifiers have new operation method, that is, user should > decide which zone is preferred at first, then give the encoded zone number to > bottom 3 bits in GFP mask. That is much direct and clear than before. > > * No bad zone combination, because user should choose just one address zone > modifier always. > * Better performance and efficiency, current gfp_zone has to take shifting > operation twice for GFP_ZONE_TABLE and GFP_ZONE_BAD. With these patches, > gfp_zone() just needs one XOR. > * Up to 8 zones can be used. At least it isn't a disadvantage, right? This should be a part of the changelog. Please note that you should provide some number if you claim performance benefits. The complexity will always be subjective. -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Fri 25-05-18 05:00:44, Matthew Wilcox wrote: > On Thu, May 24, 2018 at 05:29:43PM +0200, Michal Hocko wrote: > > > ie if we had more, > > > could we solve our pain by making them more generic? > > > > Well, if you have more you will consume more bits in the struct pages, > > right? > > Not necessarily ... the zone number is stored in the struct page > currently, so either two or three bits are used right now. In my > proposal, one can infer the zone of a page from its PFN, except for > ZONE_MOVABLE. So we could trim down to just one bit per struct page > for 32-bit machines while using 3 bits on 64-bit machines, where there > is plenty of space. Just be warned that page_zone is called from many hot paths. I am not sure adding something more complex there is going to fly. > > > it more-or-less sucks that the devices with 28-bit DMA limits are forced > > > to allocate from the low 16MB when they're perfectly capable of using the > > > low 256MB. > > > > Do we actually care all that much about those? If yes then we should > > probably follow the ZONE_DMA (x86) path and use a CMA region for them. > > I mean most devices should be good with very limited addressability or > > below 4G, no? > > Sure. One other thing I meant to mention was the media devices > (TV capture cards and so on) which want a vmalloc_32() allocation. > On 32-bit machines right now, we allocate from LOWMEM, when we really > should be allocating from the 1GB-4GB region. 32-bit machines generally > don't have a ZONE_DMA32 today. Well, _I_ think that vmalloc on 32b is just lost case... -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Thu, May 24, 2018 at 05:29:43PM +0200, Michal Hocko wrote: > > ie if we had more, > > could we solve our pain by making them more generic? > > Well, if you have more you will consume more bits in the struct pages, > right? Not necessarily ... the zone number is stored in the struct page currently, so either two or three bits are used right now. In my proposal, one can infer the zone of a page from its PFN, except for ZONE_MOVABLE. So we could trim down to just one bit per struct page for 32-bit machines while using 3 bits on 64-bit machines, where there is plenty of space. > > it more-or-less sucks that the devices with 28-bit DMA limits are forced > > to allocate from the low 16MB when they're perfectly capable of using the > > low 256MB. > > Do we actually care all that much about those? If yes then we should > probably follow the ZONE_DMA (x86) path and use a CMA region for them. > I mean most devices should be good with very limited addressability or > below 4G, no? Sure. One other thing I meant to mention was the media devices (TV capture cards and so on) which want a vmalloc_32() allocation. On 32-bit machines right now, we allocate from LOWMEM, when we really should be allocating from the 1GB-4GB region. 32-bit machines generally don't have a ZONE_DMA32 today. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [External] Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
From: Michal Hocko [mailto:mho...@kernel.org] Sent: Thursday, May 24, 2018 8:19 PM> > > Let me try to reply your questions. > > Exactly, GFP_ZONE_TABLE is too complicated. I think there are two advantages > > from the series of patches. > > > > 1. XOR operation is simple and efficient, GFP_ZONE_TABLE/BAD need to do > > twice > > shift operations, the first is for getting a zone_type and the second is for > > checking the to be returned type is a correct or not. But with these patch > > XOR > > operation just needs to use once. Because the bottom 3 bits of GFP bitmask > > have > > been used to represent the encoded zone number, we can say there is no bad > > zone > > number if all callers could use it without buggy way. Of course, the > > returned > > zone type in gfp_zone needs to be no more than ZONE_MOVABLE. > > But you are losing the ability to check for wrong usage. And it seems > that the sad reality is that the existing code do screw up. In my opinion, originally there shouldn't be such many wrong combinations of these bottom 3 bits. For any user, whether or driver and fs, they should make a decision that which zone is they preferred. Matthew's idea is great, because with it the user must offer an unambiguous flag to gfp zone bits. Ideally, before any user wants to modify the address zone modifier, they should clear it firstly, then ORing the GFP zone flag which comes from the zone they prefer. With these patches, we can loudly announce that, the bottom 3 bits of zone mask couldn't accept internal ORing operations. The operations like __GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM is illegal. The current GFP_ZONE_TABLE is precisely the root of this problem, that is __GFP_DMA, __GFP_DMA32 and __GFP_HIGHMEM are formatted as 0x1, 0x2 and 0x4. > > > 2. GFP_ZONE_TABLE has limit with the amount of zone types. Current > > GFP_ZONE_TABLE > > is 32 bits, in general, there are 4 zone types for most ofX86_64 platform, > > they > > are ZONE_DMA, ZONE_DMA32, ZONE_NORMAL and ZONE_MOVABLE. If we want to > > expand the > > amount of zone types to larger than 4, the zone shift should be 3. > > But we do not want to expand the number of zones IMHO. The existing zoo > is quite a maint. pain. > > That being said. I am not saying that I am in love with GFP_ZONE_TABLE. > It always makes my head explode when I look there but it seems to work > with the current code and it is optimized for it. If you want to change > this then you should make sure you describe reasons _why_ this is an > improvement. And I would argue that "we can have more zones" is a > relevant one. Yes, GFP_ZONE_TABLE is too complicated. The patches have 4 advantages as below. * The address zone modifiers have new operation method, that is, user should decide which zone is preferred at first, then give the encoded zone number to bottom 3 bits in GFP mask. That is much direct and clear than before. * No bad zone combination, because user should choose just one address zone modifier always. * Better performance and efficiency, current gfp_zone has to take shifting operation twice for GFP_ZONE_TABLE and GFP_ZONE_BAD. With these patches, gfp_zone() just needs one XOR. * Up to 8 zones can be used. At least it isn't a disadvantage, right? Sincerely, Huaisheng Ye -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Thu 24-05-18 08:18:18, Matthew Wilcox wrote: > On Thu, May 24, 2018 at 02:23:23PM +0200, Michal Hocko wrote: > > > If we had eight ZONEs, we could offer: > > > > No, please no more zones. What we have is quite a maint. burden on its > > own. Ideally we should only have lowmem, highmem and special/device > > zones for directly kernel accessible memory, the one that the kernel > > cannot or must not use and completely special memory managed out of > > the page allocator. All the remaining constrains should better be > > implemented on top. > > I believe you when you say that they're a maintenance pain. Is that > maintenance pain because they're so specialised? Well, it used to be LRU balancing which is gone with the node reclaim but that brings new challenges. Now as you say their meaning is not really clear to users and that leads to bugs left and right. > ie if we had more, > could we solve our pain by making them more generic? Well, if you have more you will consume more bits in the struct pages, right? [...] > > But those already do have aproper API, IIUC. So do we really need to > > make our GFP_*/Zone API more complicated than it already is? > > I don't want to change the driver API (setting the DMA mask, etc), > but we don't actually have a good API to the page allocator for the > implementation of dma_alloc_foo() to request pages. More or less, > architectures do: > > if (mask < 4GB) > alloc_page(GFP_DMA) > else if (mask < 64EB) > alloc_page(GFP_DMA32) > else > alloc_page(GFP_HIGHMEM) > > it more-or-less sucks that the devices with 28-bit DMA limits are forced > to allocate from the low 16MB when they're perfectly capable of using the > low 256MB. Do we actually care all that much about those? If yes then we should probably follow the ZONE_DMA (x86) path and use a CMA region for them. I mean most devices should be good with very limited addressability or below 4G, no? -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Thu, May 24, 2018 at 02:23:23PM +0200, Michal Hocko wrote: > > If we had eight ZONEs, we could offer: > > No, please no more zones. What we have is quite a maint. burden on its > own. Ideally we should only have lowmem, highmem and special/device > zones for directly kernel accessible memory, the one that the kernel > cannot or must not use and completely special memory managed out of > the page allocator. All the remaining constrains should better be > implemented on top. I believe you when you say that they're a maintenance pain. Is that maintenance pain because they're so specialised? ie if we had more, could we solve our pain by making them more generic? > > ZONE_16M// 24 bit > > ZONE_256M // 28 bit > > ZONE_LOWMEM // CONFIG_32BIT only > > ZONE_4G // 32 bit > > ZONE_64G// 36 bit > > ZONE_1T // 40 bit > > ZONE_ALL// everything larger > > ZONE_MOVABLE// movable allocations; no physical address guarantees > > > > #ifdef CONFIG_64BIT > > #define ZONE_NORMAL ZONE_ALL > > #else > > #define ZONE_NORMAL ZONE_LOWMEM > > #endif > > > > This would cover most driver DMA mask allocations; we could tweak the > > offered zones based on analysis of what people need. > > But those already do have aproper API, IIUC. So do we really need to > make our GFP_*/Zone API more complicated than it already is? I don't want to change the driver API (setting the DMA mask, etc), but we don't actually have a good API to the page allocator for the implementation of dma_alloc_foo() to request pages. More or less, architectures do: if (mask < 4GB) alloc_page(GFP_DMA) else if (mask < 64EB) alloc_page(GFP_DMA32) else alloc_page(GFP_HIGHMEM) it more-or-less sucks that the devices with 28-bit DMA limits are forced to allocate from the low 16MB when they're perfectly capable of using the low 256MB. Sure, my proposal doesn't help 27 or 26 bit DMA mask devices, but those are pretty rare. I'm sure you don't need reminding what a mess vmalloc_32 is, and the implementation of saa7146_vmalloc_build_pgtable() just hurts. > > #define GFP_HIGHUSER(GFP_USER | ZONE_ALL) > > #define GFP_HIGHUSER_MOVABLE(GFP_USER | ZONE_MOVABLE) > > > > One other thing I want to see is that fallback from zones happens from > > highest to lowest normally (ie if you fail to allocate in 1T, then you > > try to allocate from 64G), but movable allocations hapen from lowest > > to highest. So ZONE_16M ends up full of page cache pages which are > > readily evictable for the rare occasions when we need to allocate memory > > below 16MB. > > > > I'm sure there are lots of good reasons why this won't work, which is > > why I've been hesitant to propose it before now. > > I am worried you are playing with a can of worms... Yes. Me too. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Wed 23-05-18 22:19:19, Matthew Wilcox wrote: > On Tue, May 22, 2018 at 08:37:28PM +0200, Michal Hocko wrote: > > So why is this any better than the current code. Sure I am not a great > > fan of GFP_ZONE_TABLE because of how it is incomprehensible but this > > doesn't look too much better, yet we are losing a check for incompatible > > gfp flags. The diffstat looks really sound but then you just look and > > see that the large part is the comment that at least explained the gfp > > zone modifiers somehow and the debugging code. So what is the selling > > point? > > I have a plan, but it's not exactly fully-formed yet. > > One of the big problems we have today is that we have a lot of users > who have constraints on the physical memory they want to allocate, > but we have very limited abilities to provide them with what they're > asking for. The various different ZONEs have different meanings on > different architectures and are generally a mess. Agreed. > If we had eight ZONEs, we could offer: No, please no more zones. What we have is quite a maint. burden on its own. Ideally we should only have lowmem, highmem and special/device zones for directly kernel accessible memory, the one that the kernel cannot or must not use and completely special memory managed out of the page allocator. All the remaining constrains should better be implemented on top. > ZONE_16M // 24 bit > ZONE_256M // 28 bit > ZONE_LOWMEM // CONFIG_32BIT only > ZONE_4G // 32 bit > ZONE_64G // 36 bit > ZONE_1T // 40 bit > ZONE_ALL // everything larger > ZONE_MOVABLE // movable allocations; no physical address guarantees > > #ifdef CONFIG_64BIT > #define ZONE_NORMAL ZONE_ALL > #else > #define ZONE_NORMAL ZONE_LOWMEM > #endif > > This would cover most driver DMA mask allocations; we could tweak the > offered zones based on analysis of what people need. But those already do have aproper API, IIUC. So do we really need to make our GFP_*/Zone API more complicated than it already is? > #define GFP_HIGHUSER (GFP_USER | ZONE_ALL) > #define GFP_HIGHUSER_MOVABLE (GFP_USER | ZONE_MOVABLE) > > One other thing I want to see is that fallback from zones happens from > highest to lowest normally (ie if you fail to allocate in 1T, then you > try to allocate from 64G), but movable allocations hapen from lowest > to highest. So ZONE_16M ends up full of page cache pages which are > readily evictable for the rare occasions when we need to allocate memory > below 16MB. > > I'm sure there are lots of good reasons why this won't work, which is > why I've been hesitant to propose it before now. I am worried you are playing with a can of worms... -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [External] Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Wed 23-05-18 16:07:16, Huaisheng HS1 Ye wrote: > From: Michal Hocko [mailto:mho...@kernel.org] > Sent: Wednesday, May 23, 2018 2:37 AM > > > > On Mon 21-05-18 23:20:21, Huaisheng Ye wrote: > > > From: Huaisheng Ye> > > > > > 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 > > > > So why is this any better than the current code. Sure I am not a great > > fan of GFP_ZONE_TABLE because of how it is incomprehensible but this > > doesn't look too much better, yet we are losing a check for incompatible > > gfp flags. The diffstat looks really sound but then you just look and > > see that the large part is the comment that at least explained the gfp > > zone modifiers somehow and the debugging code. So what is the selling > > point? > > Dear Michal, > > Let me try to reply your questions. > Exactly, GFP_ZONE_TABLE is too complicated. I think there are two advantages > from the series of patches. > > 1. XOR operation is simple and efficient, GFP_ZONE_TABLE/BAD need to do twice > shift operations, the first is for getting a zone_type and the second is for > checking the to be returned type is a correct or not. But with these patch XOR > operation just needs to use once. Because the bottom 3 bits of GFP bitmask > have > been used to represent the encoded zone number, we can say there is no bad > zone > number if all callers could use it without buggy way. Of course, the returned > zone type in gfp_zone needs to be no more than ZONE_MOVABLE. But you are losing the ability to check for wrong usage. And it seems that the sad reality is that the existing code do screw up. > 2. GFP_ZONE_TABLE has limit with the amount of zone types. Current > GFP_ZONE_TABLE > is 32 bits, in general, there are 4 zone types for most ofX86_64 platform, > they > are ZONE_DMA, ZONE_DMA32, ZONE_NORMAL and ZONE_MOVABLE. If we want to expand > the > amount of zone types to larger than 4, the zone shift should be 3. But we do not want to expand the number of zones IMHO. The existing zoo is quite a maint. pain. That being said. I am not saying that I am in love with GFP_ZONE_TABLE. It always makes my head explode when I look there but it seems to work with the current code and it is optimized for it. If you want to change this then you should make sure you describe reasons _why_ this is an improvement. And I would argue that "we can have more zones" is a relevant one. -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Tue, May 22, 2018 at 08:37:28PM +0200, Michal Hocko wrote: > So why is this any better than the current code. Sure I am not a great > fan of GFP_ZONE_TABLE because of how it is incomprehensible but this > doesn't look too much better, yet we are losing a check for incompatible > gfp flags. The diffstat looks really sound but then you just look and > see that the large part is the comment that at least explained the gfp > zone modifiers somehow and the debugging code. So what is the selling > point? I have a plan, but it's not exactly fully-formed yet. One of the big problems we have today is that we have a lot of users who have constraints on the physical memory they want to allocate, but we have very limited abilities to provide them with what they're asking for. The various different ZONEs have different meanings on different architectures and are generally a mess. If we had eight ZONEs, we could offer: ZONE_16M// 24 bit ZONE_256M // 28 bit ZONE_LOWMEM // CONFIG_32BIT only ZONE_4G // 32 bit ZONE_64G// 36 bit ZONE_1T // 40 bit ZONE_ALL// everything larger ZONE_MOVABLE// movable allocations; no physical address guarantees #ifdef CONFIG_64BIT #define ZONE_NORMAL ZONE_ALL #else #define ZONE_NORMAL ZONE_LOWMEM #endif This would cover most driver DMA mask allocations; we could tweak the offered zones based on analysis of what people need. #define GFP_HIGHUSER(GFP_USER | ZONE_ALL) #define GFP_HIGHUSER_MOVABLE(GFP_USER | ZONE_MOVABLE) One other thing I want to see is that fallback from zones happens from highest to lowest normally (ie if you fail to allocate in 1T, then you try to allocate from 64G), but movable allocations hapen from lowest to highest. So ZONE_16M ends up full of page cache pages which are readily evictable for the rare occasions when we need to allocate memory below 16MB. I'm sure there are lots of good reasons why this won't work, which is why I've been hesitant to propose it before now. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [External] Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
From: Michal Hocko [mailto:mho...@kernel.org] Sent: Wednesday, May 23, 2018 2:37 AM > > On Mon 21-05-18 23:20:21, Huaisheng Ye wrote: > > From: Huaisheng Ye> > > > 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 > > So why is this any better than the current code. Sure I am not a great > fan of GFP_ZONE_TABLE because of how it is incomprehensible but this > doesn't look too much better, yet we are losing a check for incompatible > gfp flags. The diffstat looks really sound but then you just look and > see that the large part is the comment that at least explained the gfp > zone modifiers somehow and the debugging code. So what is the selling > point? Dear Michal, Let me try to reply your questions. Exactly, GFP_ZONE_TABLE is too complicated. I think there are two advantages from the series of patches. 1. XOR operation is simple and efficient, GFP_ZONE_TABLE/BAD need to do twice shift operations, the first is for getting a zone_type and the second is for checking the to be returned type is a correct or not. But with these patch XOR operation just needs to use once. Because the bottom 3 bits of GFP bitmask have been used to represent the encoded zone number, we can say there is no bad zone number if all callers could use it without buggy way. Of course, the returned zone type in gfp_zone needs to be no more than ZONE_MOVABLE. 2. GFP_ZONE_TABLE has limit with the amount of zone types. Current GFP_ZONE_TABLE is 32 bits, in general, there are 4 zone types for most ofX86_64 platform, they are ZONE_DMA, ZONE_DMA32, ZONE_NORMAL and ZONE_MOVABLE. If we want to expand the amount of zone types to larger than 4, the zone shift should be 3. That is to say, a 32 bits zone table is not enough to store all zone types. And the most painful thing is that, current GFP bitmasks' space is quite space-constrained it only have four ___GFP_XXX could be used as below, #define ___GFP_DMA 0x01u #define ___GFP_HIGHMEM 0x02u #define ___GFP_DMA320x04u (___GFP_NORMAL equals to 0x00) If we use the implementation of these patches, there is a maximum of 8 zone types could be used. The method of encoding and decoding is quite simple and users could have an intuitive feeling for this as below, and the most important is that, there is no BAD zone types eventually. A ^ B ^ B = A And by the way, our v3 patches are ready, but the smtp of Gmail is quite unstable for some firewall reason in my side, I will try to resend them ASAP. Sincerely, Huaisheng Ye -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
On Mon 21-05-18 23:20:21, Huaisheng Ye wrote: > From: Huaisheng Ye> > 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 So why is this any better than the current code. Sure I am not a great fan of GFP_ZONE_TABLE because of how it is incomprehensible but this doesn't look too much better, yet we are losing a check for incompatible gfp flags. The diffstat looks really sound but then you just look and see that the large part is the comment that at least explained the gfp zone modifiers somehow and the debugging code. So what is the selling point? > 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 > -- Michal Hocko SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
From: owner-linux...@kvack.org On Behalf Of Christoph Hellwig > This seems to be missing patch 1 and generally be in somewhat odd format. > Can you try to resend it with git-send-email and against current Linus' > tree? > Sure, I will rebase them to current mainline ASAP. > Also I'd suggest you do cleanups like adding and using __GFP_ZONE_MASK > at the beginning of the series before doing any real changes. Ok, thanks for your suggestion. Sincerely, Huaisheng Ye -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
This seems to be missing patch 1 and generally be in somewhat odd format. Can you try to resend it with git-send-email and against current Linus' tree? Also I'd suggest you do cleanups like adding and using __GFP_ZONE_MASK at the beginning of the series before doing any real changes. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFC PATCH v2 00/12] get rid of GFP_ZONE_TABLE/BAD
From: Huaisheng YeReplace 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 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html