Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: cma: kill cma_pages_valid()

Kill cma_pages_valid() which only used in cma_release(), also cleanup code
duplication between cma pages valid checking and cma memrange finding.

Link: https://lkml.kernel.org/r/20260109093136.1491549-4-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Jane Chu <jane.chu@oracle.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kefeng Wang and committed by
Andrew Morton
6c08cc64 a9deb800

+11 -38
-1
include/linux/cma.h
··· 49 49 struct cma **res_cma); 50 50 extern struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned int align, 51 51 bool no_warn); 52 - extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned long count); 53 52 extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count); 54 53 55 54 extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data);
+11 -37
mm/cma.c
··· 942 942 return page ? page_folio(page) : NULL; 943 943 } 944 944 945 - bool cma_pages_valid(struct cma *cma, const struct page *pages, 946 - unsigned long count) 947 - { 948 - unsigned long pfn, end; 949 - int r; 950 - struct cma_memrange *cmr; 951 - bool ret; 952 - 953 - if (!cma || !pages || count > cma->count) 954 - return false; 955 - 956 - pfn = page_to_pfn(pages); 957 - ret = false; 958 - 959 - for (r = 0; r < cma->nranges; r++) { 960 - cmr = &cma->ranges[r]; 961 - end = cmr->base_pfn + cmr->count; 962 - if (pfn >= cmr->base_pfn && pfn < end) { 963 - ret = pfn + count <= end; 964 - break; 965 - } 966 - } 967 - 968 - if (!ret) 969 - pr_debug("%s(page %p, count %lu)\n", 970 - __func__, (void *)pages, count); 971 - 972 - return ret; 973 - } 974 - 975 945 /** 976 946 * cma_release() - release allocated pages 977 947 * @cma: Contiguous memory region for which the allocation is performed. ··· 961 991 962 992 pr_debug("%s(page %p, count %lu)\n", __func__, (void *)pages, count); 963 993 964 - if (!cma_pages_valid(cma, pages, count)) 994 + if (!cma || !pages || count > cma->count) 965 995 return false; 966 996 967 997 pfn = page_to_pfn(pages); 968 - end_pfn = pfn + count; 969 998 970 999 for (r = 0; r < cma->nranges; r++) { 971 1000 cmr = &cma->ranges[r]; 972 - if (pfn >= cmr->base_pfn && 973 - pfn < (cmr->base_pfn + cmr->count)) { 974 - VM_BUG_ON(end_pfn > cmr->base_pfn + cmr->count); 975 - break; 1001 + end_pfn = cmr->base_pfn + cmr->count; 1002 + if (pfn >= cmr->base_pfn && pfn < end_pfn) { 1003 + if (pfn + count <= end_pfn) 1004 + break; 1005 + 1006 + VM_WARN_ON_ONCE(1); 976 1007 } 977 1008 } 978 1009 979 - if (r == cma->nranges) 1010 + if (r == cma->nranges) { 1011 + pr_debug("%s(page %p, count %lu, no cma range matches the page range)\n", 1012 + __func__, (void *)pages, count); 980 1013 return false; 1014 + } 981 1015 982 1016 free_contig_range(pfn, count); 983 1017 cma_clear_bitmap(cma, cmr, pfn, count);