回复: [PATCH] mm/compaction: add check mechanism to avoid cma alloc fail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Why the CMA memory can not be migrated? Could you describe in more 
> detail the reasons for the CMA memory migration failure?
When allocate for cma memory by module, the memory used by system in the 
cma buffer will be migrate outside the cma buffer. If the refcount of the 
current page in cma buffer is greater than the mapcount, the migrate will 
fail.
The page that failed to be migrate was not originally in the cma buffer, 
but was migrate in cma buffer after the kernel compaction.
After this memory is kcompacted and placed in the cma buffer, under 
certain special conditions, the refcount may be greater than the mapcount
ex:the current page is being used by fs, and then migrate will fail.

 

 

发件人: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
发送时间: 2024122 14:59
收件人: Haiqiang Gong (龚海强) <Haiqiang.Gong@xxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx
抄送: Mike Zhang (张伟伟) <Mike.Zhang@xxxxxxxxxxxx>; Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>; Matthias Brugger <matthias.bgg@xxxxxxxxx>; AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>; linux-mm@xxxxxxxxx; linux-arm-kernel@xxxxxxxxxxxxxxxxxxx; linux-mediatek@xxxxxxxxxxxxxxxxxxx
主题: Re: [PATCH] mm/compaction: add check mechanism to avoid cma alloc fail

 

External email : Please do not click links or open attachments until you have verified the sender or the content.

 
 
On 1/22/2024 10:23 AM, Haiqiang Gong wrote:
> cma alloc may fail when we doing cma alloc/free test on kernel 5.10/5.15.
 
Do you have a real use case for the cma alloc issue? And have you tried 
it on the new kernel?
 
> We found that the next memory cannot be migrated because of the alloc of
> fs as next backtrace:
> __alloc_pages_nodemask
> pagecache_get_page
> grow_dev_page
> __getblk_gfp
> ext4_sb_breadahead_unmovable
> __ext4_get_inode_loc
> __ext4_iget
> ext4_lookup
> __lookup_slow
> walk_component
> path_lookupat
> filename_lookup
> vfs_statx
> This kind of unmovable memory is not placed in the cma buffer when kernel
> memory alloc but is migrated in by kcompactd when the kernel migration.
> It will cause memory can't be migrate when cma alloc.
 
Why the CMA memory can not be migrated? Could you describe in more 
detail the reasons for the CMA memory migration failure?
 
> Add check mechanism in the compaction_alloc() where kcompaced alloc for
> memory. Will return NULL and give up this memory migration if the
> allocated memory is in the cma buffer and the memory is unmovable.
> 
> Signed-off-by: Haiqiang Gong <Haiqiang.Gong@xxxxxxxxxxxx>
> ---
>   mm/compaction.c | 38 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 38 insertions(+)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 27ada42924d5..29c0661adc22 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -25,6 +25,11 @@
>   #include <linux/psi.h>
>   #include "internal.h"
>   
> +#ifdef CONFIG_CMA
> +#include <linux/cma.h>
> +#include "cma.h"
> +#endif
> +
>   #ifdef CONFIG_COMPACTION
>   /*
>    * Fragmentation score check interval for proactive compaction purposes.
> @@ -1758,6 +1763,33 @@ static void isolate_freepages(struct compact_control *cc)
>   split_map_pages(freelist);
>   }
>   
> +#ifdef CONFIG_CMA
> +static bool is_in_cma_range(struct folio *folio)
> +{
> +int i;
> +unsigned long pfn = 0;
> +struct page *page = folio_page(folio, 0);
> +
> +pfn = page_to_pfn(page);
> +for (i = 0; i < cma_area_count; i++) {
> +struct cma *cma = &cma_areas[i];
> +
> +if (cma->base_pfn <= pfn && (cma->base_pfn + cma->count) > pfn)
> +return true;
> +}
> +
> +return false;
> +}
> +
> +static bool forbid_move_to_cma_range(struct folio *src, struct folio *dst)
> +{
> +if (folio_mapping(src) && is_in_cma_range(dst))
> +return true;
> +
> +return false;
> +}
> +#endif
> +
>   /*
>    * This is a migrate-callback that "allocates" freepages by taking pages
>    * from the isolated freelists in the block we are migrating to.
> @@ -1775,6 +1807,12 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data)
>   }
>   
>   dst = list_entry(cc->freepages.next, struct folio, lru);
> +#ifdef CONFIG_CMA
> +if (forbid_move_to_cma_range(src, dst)) {
> +pr_notice("kcompactd: could not move non-cma memory to cma buffer\n");
> +return NULL;
> +}
> +#endif
>   list_del(&dst->lru);
>   cc->nr_freepages--;
>   
*********** MEDIATEK Confidentiality Notice ***********
The information contained in this e-mail message (including any 
attachments) may be confidential, proprietary, privileged, or 
otherwise exempt from disclosure under applicable laws. It is 
intended to be conveyed only to the designated recipient(s). Any 
use, dissemination, distribution, printing, retaining or copying 
of this e-mail (including its attachments) by unintended recipient(s) 
is strictly prohibited and may be unlawful. If you are not an 
intended recipient of this e-mail, or believe that you have received 
this e-mail in error, please notify the sender immediately 
(by replying to this e-mail), delete any and all copies of this 
e-mail (including any attachments) from your system, and do not 
disclose the content of this e-mail to any other person. Thank you!

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux