From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Rik van Riel <riel@surriel.com>, Roman Gushchin <guro@fb.com>,
Vlastimil Babka <vbabka@suse.cz>, Joonsoo Kim <js1304@gmail.com>,
Minchan Kim <minchan@kernel.org>,
Chris Goldsworthy <quic_cgoldswo@quicinc.com>,
Georgi Djakov <quic_c_gdjako@quicinc.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm,page_alloc,cma: configurable CMA utilization
Date: Tue, 31 Jan 2023 12:53:25 +0530 [thread overview]
Message-ID: <4f088ff9-d88b-e35b-e8b5-712874b2be8c@arm.com> (raw)
In-Reply-To: <20230131071052.GB19285@hu-sbhattip-lv.qualcomm.com>
On 1/31/23 12:40, Sukadev Bhattiprolu wrote:
>
> Commit 16867664936e ("mm,page_alloc,cma: conditionally prefer cma pageblocks for movable allocations")
> added support to use CMA pages when more than 50% of total free pages in
> the zone are free CMA pages.
>
> However, with multiplatform kernels a single binary is used across different
> targets of varying memory sizes. A low memory target using one such kernel
> would incur allocation failures even when sufficient memory is available in
> the CMA region. On these targets we would want to utilize a higher percentage
> of the CMA region and reduce the allocation failures, even if it means that a
> subsequent cma_alloc() would take longer.
>
> Make the percentage of CMA utilization a configurable parameter to allow
> for such usecases.
>
> Signed-off-by: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>
> ---
> Note: There was a mention about it being the last resort to making this
> percentage configurable (https://lkml.org/lkml/2020/3/12/751). But
> as explained above, multi-platform kernels for varying memory size
> targets would need this to be configurable.
> ---
> include/linux/mm.h | 1 +
> kernel/sysctl.c | 8 ++++++++
> mm/page_alloc.c | 18 +++++++++++++++---
> mm/util.c | 2 ++
> 4 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 8f857163ac89..e4e5d508e9eb 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -203,6 +203,7 @@ extern unsigned long sysctl_admin_reserve_kbytes;
>
> extern int sysctl_overcommit_memory;
> extern int sysctl_overcommit_ratio;
> +extern int sysctl_cma_utilization_ratio;
> extern unsigned long sysctl_overcommit_kbytes;
>
> int overcommit_ratio_handler(struct ctl_table *, int, void *, size_t *,
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 137d4abe3eda..2dce6a908aa6 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2445,6 +2445,14 @@ static struct ctl_table vm_table[] = {
> .extra2 = SYSCTL_ONE,
> },
> #endif
> + {
> + .procname = "cma_utilization_ratio",
> + .data = &sysctl_cma_utilization_ratio,
> + .maxlen = sizeof(sysctl_cma_utilization_ratio),
> + .mode = 0644,
> + .proc_handler = proc_dointvec_minmax,
> + .extra1 = SYSCTL_ONE,
> + },
> { }
> };
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 0745aedebb37..b72db3824687 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3071,6 +3071,20 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype,
>
> }
>
> +static __always_inline bool zone_can_use_cma_pages(struct zone *zone)
> +{
> + unsigned long cma_free_pages;
> + unsigned long zone_free_pages;
> +
> + cma_free_pages = zone_page_state(zone, NR_FREE_CMA_PAGES);
> + zone_free_pages = zone_page_state(zone, NR_FREE_PAGES);
> +
> + if (cma_free_pages > zone_free_pages / sysctl_cma_utilization_ratio)
> + return true;
> +
> + return false;
> +}
> +
> /*
> * Do the hard work of removing an element from the buddy allocator.
> * Call me with the zone->lock already held.
> @@ -3087,9 +3101,7 @@ __rmqueue(struct zone *zone, unsigned int order, int migratetype,
> * allocating from CMA when over half of the zone's free memory
> * is in the CMA area.
> */
> - if (alloc_flags & ALLOC_CMA &&
> - zone_page_state(zone, NR_FREE_CMA_PAGES) >
> - zone_page_state(zone, NR_FREE_PAGES) / 2) {
> + if (alloc_flags & ALLOC_CMA && zone_can_use_cma_pages(zone)) {
> page = __rmqueue_cma_fallback(zone, order);
> if (page)
> return page;
> diff --git a/mm/util.c b/mm/util.c
> index b56c92fb910f..4de81f04b249 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -781,6 +781,8 @@ void folio_copy(struct folio *dst, struct folio *src)
> }
>
> int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS;
> +
> +int sysctl_cma_utilization_ratio __read_mostly = 2;
Make '2' here a macro e.g CMA_UTILIZATION_DEFAULT ? Also it might be a good
opportunity to comment why the default value is '2' i.e 50 %.
> int sysctl_overcommit_ratio __read_mostly = 50;
> unsigned long sysctl_overcommit_kbytes __read_mostly;
> int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
next prev parent reply other threads:[~2023-01-31 7:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 7:10 [PATCH] mm,page_alloc,cma: configurable CMA utilization Sukadev Bhattiprolu
2023-01-31 7:23 ` Anshuman Khandual [this message]
2023-01-31 14:26 ` Georgi Djakov
2023-01-31 18:10 ` Roman Gushchin
2023-01-31 20:10 ` Sukadev Bhattiprolu
2023-01-31 23:59 ` Roman Gushchin
2023-02-01 4:06 ` Chris Goldsworthy
2023-02-01 19:00 ` Roman Gushchin
2023-02-02 20:13 ` Sukadev Bhattiprolu
2023-02-04 0:04 ` Roman Gushchin
2023-02-01 23:47 ` Minchan Kim
2023-02-06 5:22 ` Chris Goldsworthy
2023-02-08 22:00 ` Minchan Kim
2024-01-05 23:46 ` Sukadev Bhattiprolu
2024-01-06 0:05 ` Roman Gushchin
2024-01-08 20:15 ` Sukadev Bhattiprolu
2024-01-09 2:59 ` Roman Gushchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f088ff9-d88b-e35b-e8b5-712874b2be8c@arm.com \
--to=anshuman.khandual@arm.com \
--cc=akpm@linux-foundation.org \
--cc=guro@fb.com \
--cc=js1304@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=quic_c_gdjako@quicinc.com \
--cc=quic_cgoldswo@quicinc.com \
--cc=quic_sukadev@quicinc.com \
--cc=riel@surriel.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).