devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	hyesoo.yu@samsung.com, willy@infradead.org, david@redhat.com,
	iamjoonsoo.kim@lge.com, vbabka@suse.cz, surenb@google.com,
	pullip.cho@samsung.com, joaodias@google.com, hridya@google.com,
	sumit.semwal@linaro.org, john.stultz@linaro.org,
	Brian.Starkey@arm.com, linux-media@vger.kernel.org,
	devicetree@vger.kernel.org, robh@kernel.org,
	christian.koenig@amd.com, linaro-mm-sig@lists.linaro.org,
	Minchan Kim <minchan@kernel.org>
Subject: [PATCH v2 1/4] mm: introduce alloc_contig_mode
Date: Tue,  1 Dec 2020 09:51:41 -0800	[thread overview]
Message-ID: <20201201175144.3996569-2-minchan@kernel.org> (raw)
In-Reply-To: <20201201175144.3996569-1-minchan@kernel.org>

There are demands to control how hard alloc_contig_range try to
increase allocation success ratio. This patch abstract it by
adding new enum mode parameter in alloc_contig_range.
New API in next patch will add up new mode there to control it.

This patch shouldn't change any existing behavior.

Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 drivers/virtio/virtio_mem.c | 2 +-
 include/linux/gfp.h         | 8 +++++++-
 mm/cma.c                    | 3 ++-
 mm/page_alloc.c             | 6 ++++--
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 9fc9ec4a25f5..5585fc67b65e 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -1148,7 +1148,7 @@ static int virtio_mem_fake_offline(unsigned long pfn, unsigned long nr_pages)
 	 */
 	for (retry_count = 0; retry_count < 5; retry_count++) {
 		rc = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE,
-					GFP_KERNEL);
+					GFP_KERNEL, ALLOC_CONTIG_NORMAL);
 		if (rc == -ENOMEM)
 			/* whoops, out of memory */
 			return rc;
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index c603237e006c..ad5872699692 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -624,9 +624,15 @@ static inline bool pm_suspended_storage(void)
 #endif /* CONFIG_PM_SLEEP */
 
 #ifdef CONFIG_CONTIG_ALLOC
+enum alloc_contig_mode {
+	/* try several ways to increase success ratio of memory allocation */
+	ALLOC_CONTIG_NORMAL,
+};
+
 /* The below functions must be run on a range from a single zone. */
 extern int alloc_contig_range(unsigned long start, unsigned long end,
-			      unsigned migratetype, gfp_t gfp_mask);
+			      unsigned migratetype, gfp_t gfp_mask,
+			      enum alloc_contig_mode mode);
 extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask,
 				       int nid, nodemask_t *nodemask);
 #endif
diff --git a/mm/cma.c b/mm/cma.c
index 3692a34e2353..8010c1ba04b0 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -454,7 +454,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
 
 		pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
 		ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
-				     GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0));
+				     GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0),
+				     ALLOC_CONTIG_NORMAL);
 
 		if (ret == 0) {
 			page = pfn_to_page(pfn);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f91df593bf71..adfbfd95fbc3 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8533,6 +8533,7 @@ static void __alloc_contig_clear_range(unsigned long start_pfn,
  *			be either of the two.
  * @gfp_mask:	GFP mask to use during compaction. __GFP_ZERO clears allocated
  *		pages.
+ * @mode:	how hard it will try to increase allocation success ratio
  *
  * The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
  * aligned.  The PFN range must belong to a single zone.
@@ -8546,7 +8547,8 @@ static void __alloc_contig_clear_range(unsigned long start_pfn,
  * need to be freed with free_contig_range().
  */
 int alloc_contig_range(unsigned long start, unsigned long end,
-		       unsigned migratetype, gfp_t gfp_mask)
+		       unsigned migratetype, gfp_t gfp_mask,
+		       enum alloc_contig_mode mode)
 {
 	unsigned long outer_start, outer_end;
 	unsigned int order;
@@ -8689,7 +8691,7 @@ static int __alloc_contig_pages(unsigned long start_pfn,
 	unsigned long end_pfn = start_pfn + nr_pages;
 
 	return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE,
-				  gfp_mask);
+				  gfp_mask, ALLOC_CONTIG_NORMAL);
 }
 
 static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
-- 
2.29.2.454.gaff20da3a2-goog


  reply	other threads:[~2020-12-01 17:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 17:51 [PATCH v2 0/4] Chunk Heap Support on DMA-HEAP Minchan Kim
2020-12-01 17:51 ` Minchan Kim [this message]
2020-12-01 17:51 ` [PATCH v2 2/4] mm: introduce cma_alloc_bulk API Minchan Kim
2020-12-02  9:14   ` David Hildenbrand
2020-12-02 15:49     ` Michal Hocko
2020-12-02 16:00       ` David Hildenbrand
2020-12-02 16:15       ` Minchan Kim
2020-12-02 16:48         ` Michal Hocko
2020-12-02 17:54           ` Minchan Kim
2020-12-02 18:51             ` Michal Hocko
2020-12-02 19:26               ` Minchan Kim
2020-12-02 20:22                 ` David Hildenbrand
2020-12-02 20:48                   ` Minchan Kim
2020-12-03  8:28                   ` Michal Hocko
2020-12-03  9:47                     ` David Hildenbrand
2020-12-03 11:47                       ` Michal Hocko
2020-12-03 11:57                         ` David Hildenbrand
2020-12-02 16:00     ` Minchan Kim
2020-12-01 17:51 ` [PATCH v2 3/4] dma-buf: add export symbol for dma-heap Minchan Kim
2020-12-02 13:51   ` Christoph Hellwig
2020-12-01 17:51 ` [PATCH v2 4/4] dma-buf: heaps: add chunk heap to dmabuf heaps Minchan Kim
2020-12-01 19:48   ` John Stultz
2020-12-01 22:55     ` Minchan Kim
2020-12-01 23:38       ` John Stultz
2020-12-02  0:13         ` Minchan Kim
2020-12-02  0:33           ` John Stultz
2020-12-02  0:57             ` Minchan Kim
2020-12-02 13:54   ` Christoph Hellwig

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=20201201175144.3996569-2-minchan@kernel.org \
    --to=minchan@kernel.org \
    --cc=Brian.Starkey@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=christian.koenig@amd.com \
    --cc=david@redhat.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hridya@google.com \
    --cc=hyesoo.yu@samsung.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=joaodias@google.com \
    --cc=john.stultz@linaro.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pullip.cho@samsung.com \
    --cc=robh@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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).