Commit fbbb7f4e authored by Tejun Heo's avatar Tejun Heo

percpu: remove the usage of separate populated bitmap in percpu-vm

percpu-vm uses pcpu_get_pages_and_bitmap() to acquire temp pages array
and populated bitmap and uses the two during [de]population.  The temp
bitmap is used only to build the new bitmap that is copied to
chunk->populated after the operation succeeds; however, the new bitmap
can be trivially set after success without using the temp bitmap.

This patch removes the temp populated bitmap usage from percpu-vm.c.

* pcpu_get_pages_and_bitmap() is renamed to pcpu_get_pages() and no
  longer hands out the temp bitmap.

* @populated arugment is dropped from all the related functions.
  @populated updates in pcpu_[un]map_pages() are dropped.

* Two loops in pcpu_map_pages() are merged.

* pcpu_[de]populated_chunk() modify chunk->populated bitmap directly
  from @page_start and @page_end after success.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarChristoph Lameter <cl@linux.com>
parent 3189eddb
...@@ -20,46 +20,24 @@ static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk, ...@@ -20,46 +20,24 @@ static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
} }
/** /**
* pcpu_get_pages_and_bitmap - get temp pages array and bitmap * pcpu_get_pages - get temp pages array
* @chunk: chunk of interest * @chunk: chunk of interest
* @bitmapp: output parameter for bitmap
* @may_alloc: may allocate the array * @may_alloc: may allocate the array
* *
* Returns pointer to array of pointers to struct page and bitmap, * Returns pointer to array of pointers to struct page which can be indexed
* both of which can be indexed with pcpu_page_idx(). The returned * with pcpu_page_idx(). Note that there is only one array and access
* array is cleared to zero and *@bitmapp is copied from * exclusion is the caller's responsibility.
* @chunk->populated. Note that there is only one array and bitmap
* and access exclusion is the caller's responsibility.
*
* CONTEXT:
* pcpu_alloc_mutex and does GFP_KERNEL allocation if @may_alloc.
* Otherwise, don't care.
* *
* RETURNS: * RETURNS:
* Pointer to temp pages array on success, NULL on failure. * Pointer to temp pages array on success.
*/ */
static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk, static struct page **pcpu_get_pages(struct pcpu_chunk *chunk, bool may_alloc)
unsigned long **bitmapp,
bool may_alloc)
{ {
static struct page **pages; static struct page **pages;
static unsigned long *bitmap;
size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]); size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]);
size_t bitmap_size = BITS_TO_LONGS(pcpu_unit_pages) *
sizeof(unsigned long);
if (!pages || !bitmap) {
if (may_alloc && !pages)
pages = pcpu_mem_zalloc(pages_size);
if (may_alloc && !bitmap)
bitmap = pcpu_mem_zalloc(bitmap_size);
if (!pages || !bitmap)
return NULL;
}
bitmap_copy(bitmap, chunk->populated, pcpu_unit_pages); if (!pages && may_alloc)
pages = pcpu_mem_zalloc(pages_size);
*bitmapp = bitmap;
return pages; return pages;
} }
...@@ -67,7 +45,6 @@ static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk, ...@@ -67,7 +45,6 @@ static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk,
* pcpu_free_pages - free pages which were allocated for @chunk * pcpu_free_pages - free pages which were allocated for @chunk
* @chunk: chunk pages were allocated for * @chunk: chunk pages were allocated for
* @pages: array of pages to be freed, indexed by pcpu_page_idx() * @pages: array of pages to be freed, indexed by pcpu_page_idx()
* @populated: populated bitmap
* @page_start: page index of the first page to be freed * @page_start: page index of the first page to be freed
* @page_end: page index of the last page to be freed + 1 * @page_end: page index of the last page to be freed + 1
* *
...@@ -75,8 +52,7 @@ static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk, ...@@ -75,8 +52,7 @@ static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk,
* The pages were allocated for @chunk. * The pages were allocated for @chunk.
*/ */
static void pcpu_free_pages(struct pcpu_chunk *chunk, static void pcpu_free_pages(struct pcpu_chunk *chunk,
struct page **pages, unsigned long *populated, struct page **pages, int page_start, int page_end)
int page_start, int page_end)
{ {
unsigned int cpu; unsigned int cpu;
int i; int i;
...@@ -95,7 +71,6 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk, ...@@ -95,7 +71,6 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk,
* pcpu_alloc_pages - allocates pages for @chunk * pcpu_alloc_pages - allocates pages for @chunk
* @chunk: target chunk * @chunk: target chunk
* @pages: array to put the allocated pages into, indexed by pcpu_page_idx() * @pages: array to put the allocated pages into, indexed by pcpu_page_idx()
* @populated: populated bitmap
* @page_start: page index of the first page to be allocated * @page_start: page index of the first page to be allocated
* @page_end: page index of the last page to be allocated + 1 * @page_end: page index of the last page to be allocated + 1
* *
...@@ -104,8 +79,7 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk, ...@@ -104,8 +79,7 @@ static void pcpu_free_pages(struct pcpu_chunk *chunk,
* content of @pages and will pass it verbatim to pcpu_map_pages(). * content of @pages and will pass it verbatim to pcpu_map_pages().
*/ */
static int pcpu_alloc_pages(struct pcpu_chunk *chunk, static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
struct page **pages, unsigned long *populated, struct page **pages, int page_start, int page_end)
int page_start, int page_end)
{ {
const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_COLD; const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_COLD;
unsigned int cpu, tcpu; unsigned int cpu, tcpu;
...@@ -164,7 +138,6 @@ static void __pcpu_unmap_pages(unsigned long addr, int nr_pages) ...@@ -164,7 +138,6 @@ static void __pcpu_unmap_pages(unsigned long addr, int nr_pages)
* pcpu_unmap_pages - unmap pages out of a pcpu_chunk * pcpu_unmap_pages - unmap pages out of a pcpu_chunk
* @chunk: chunk of interest * @chunk: chunk of interest
* @pages: pages array which can be used to pass information to free * @pages: pages array which can be used to pass information to free
* @populated: populated bitmap
* @page_start: page index of the first page to unmap * @page_start: page index of the first page to unmap
* @page_end: page index of the last page to unmap + 1 * @page_end: page index of the last page to unmap + 1
* *
...@@ -175,8 +148,7 @@ static void __pcpu_unmap_pages(unsigned long addr, int nr_pages) ...@@ -175,8 +148,7 @@ static void __pcpu_unmap_pages(unsigned long addr, int nr_pages)
* proper pre/post flush functions. * proper pre/post flush functions.
*/ */
static void pcpu_unmap_pages(struct pcpu_chunk *chunk, static void pcpu_unmap_pages(struct pcpu_chunk *chunk,
struct page **pages, unsigned long *populated, struct page **pages, int page_start, int page_end)
int page_start, int page_end)
{ {
unsigned int cpu; unsigned int cpu;
int i; int i;
...@@ -192,8 +164,6 @@ static void pcpu_unmap_pages(struct pcpu_chunk *chunk, ...@@ -192,8 +164,6 @@ static void pcpu_unmap_pages(struct pcpu_chunk *chunk,
__pcpu_unmap_pages(pcpu_chunk_addr(chunk, cpu, page_start), __pcpu_unmap_pages(pcpu_chunk_addr(chunk, cpu, page_start),
page_end - page_start); page_end - page_start);
} }
bitmap_clear(populated, page_start, page_end - page_start);
} }
/** /**
...@@ -228,7 +198,6 @@ static int __pcpu_map_pages(unsigned long addr, struct page **pages, ...@@ -228,7 +198,6 @@ static int __pcpu_map_pages(unsigned long addr, struct page **pages,
* pcpu_map_pages - map pages into a pcpu_chunk * pcpu_map_pages - map pages into a pcpu_chunk
* @chunk: chunk of interest * @chunk: chunk of interest
* @pages: pages array containing pages to be mapped * @pages: pages array containing pages to be mapped
* @populated: populated bitmap
* @page_start: page index of the first page to map * @page_start: page index of the first page to map
* @page_end: page index of the last page to map + 1 * @page_end: page index of the last page to map + 1
* *
...@@ -236,13 +205,11 @@ static int __pcpu_map_pages(unsigned long addr, struct page **pages, ...@@ -236,13 +205,11 @@ static int __pcpu_map_pages(unsigned long addr, struct page **pages,
* caller is responsible for calling pcpu_post_map_flush() after all * caller is responsible for calling pcpu_post_map_flush() after all
* mappings are complete. * mappings are complete.
* *
* This function is responsible for setting corresponding bits in * This function is responsible for setting up whatever is necessary for
* @chunk->populated bitmap and whatever is necessary for reverse * reverse lookup (addr -> chunk).
* lookup (addr -> chunk).
*/ */
static int pcpu_map_pages(struct pcpu_chunk *chunk, static int pcpu_map_pages(struct pcpu_chunk *chunk,
struct page **pages, unsigned long *populated, struct page **pages, int page_start, int page_end)
int page_start, int page_end)
{ {
unsigned int cpu, tcpu; unsigned int cpu, tcpu;
int i, err; int i, err;
...@@ -253,18 +220,12 @@ static int pcpu_map_pages(struct pcpu_chunk *chunk, ...@@ -253,18 +220,12 @@ static int pcpu_map_pages(struct pcpu_chunk *chunk,
page_end - page_start); page_end - page_start);
if (err < 0) if (err < 0)
goto err; goto err;
}
/* mapping successful, link chunk and mark populated */ for (i = page_start; i < page_end; i++)
for (i = page_start; i < page_end; i++) {
for_each_possible_cpu(cpu)
pcpu_set_page_chunk(pages[pcpu_page_idx(cpu, i)], pcpu_set_page_chunk(pages[pcpu_page_idx(cpu, i)],
chunk); chunk);
__set_bit(i, populated);
} }
return 0; return 0;
err: err:
for_each_possible_cpu(tcpu) { for_each_possible_cpu(tcpu) {
if (tcpu == cpu) if (tcpu == cpu)
...@@ -314,7 +275,6 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size) ...@@ -314,7 +275,6 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
int page_end = PFN_UP(off + size); int page_end = PFN_UP(off + size);
int free_end = page_start, unmap_end = page_start; int free_end = page_start, unmap_end = page_start;
struct page **pages; struct page **pages;
unsigned long *populated;
unsigned int cpu; unsigned int cpu;
int rs, re, rc; int rs, re, rc;
...@@ -327,28 +287,27 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size) ...@@ -327,28 +287,27 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
/* need to allocate and map pages, this chunk can't be immutable */ /* need to allocate and map pages, this chunk can't be immutable */
WARN_ON(chunk->immutable); WARN_ON(chunk->immutable);
pages = pcpu_get_pages_and_bitmap(chunk, &populated, true); pages = pcpu_get_pages(chunk, true);
if (!pages) if (!pages)
return -ENOMEM; return -ENOMEM;
/* alloc and map */ /* alloc and map */
pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) { pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
rc = pcpu_alloc_pages(chunk, pages, populated, rs, re); rc = pcpu_alloc_pages(chunk, pages, rs, re);
if (rc) if (rc)
goto err_free; goto err_free;
free_end = re; free_end = re;
} }
pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) { pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
rc = pcpu_map_pages(chunk, pages, populated, rs, re); rc = pcpu_map_pages(chunk, pages, rs, re);
if (rc) if (rc)
goto err_unmap; goto err_unmap;
unmap_end = re; unmap_end = re;
} }
pcpu_post_map_flush(chunk, page_start, page_end); pcpu_post_map_flush(chunk, page_start, page_end);
/* commit new bitmap */ bitmap_set(chunk->populated, page_start, page_end - page_start);
bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
clear: clear:
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size); memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
...@@ -357,11 +316,11 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size) ...@@ -357,11 +316,11 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
err_unmap: err_unmap:
pcpu_pre_unmap_flush(chunk, page_start, unmap_end); pcpu_pre_unmap_flush(chunk, page_start, unmap_end);
pcpu_for_each_unpop_region(chunk, rs, re, page_start, unmap_end) pcpu_for_each_unpop_region(chunk, rs, re, page_start, unmap_end)
pcpu_unmap_pages(chunk, pages, populated, rs, re); pcpu_unmap_pages(chunk, pages, rs, re);
pcpu_post_unmap_tlb_flush(chunk, page_start, unmap_end); pcpu_post_unmap_tlb_flush(chunk, page_start, unmap_end);
err_free: err_free:
pcpu_for_each_unpop_region(chunk, rs, re, page_start, free_end) pcpu_for_each_unpop_region(chunk, rs, re, page_start, free_end)
pcpu_free_pages(chunk, pages, populated, rs, re); pcpu_free_pages(chunk, pages, rs, re);
return rc; return rc;
} }
...@@ -383,7 +342,6 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size) ...@@ -383,7 +342,6 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
int page_start = PFN_DOWN(off); int page_start = PFN_DOWN(off);
int page_end = PFN_UP(off + size); int page_end = PFN_UP(off + size);
struct page **pages; struct page **pages;
unsigned long *populated;
int rs, re; int rs, re;
/* quick path, check whether it's empty already */ /* quick path, check whether it's empty already */
...@@ -400,22 +358,21 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size) ...@@ -400,22 +358,21 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
* successful population attempt so the temp pages array must * successful population attempt so the temp pages array must
* be available now. * be available now.
*/ */
pages = pcpu_get_pages_and_bitmap(chunk, &populated, false); pages = pcpu_get_pages(chunk, false);
BUG_ON(!pages); BUG_ON(!pages);
/* unmap and free */ /* unmap and free */
pcpu_pre_unmap_flush(chunk, page_start, page_end); pcpu_pre_unmap_flush(chunk, page_start, page_end);
pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end) pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
pcpu_unmap_pages(chunk, pages, populated, rs, re); pcpu_unmap_pages(chunk, pages, rs, re);
/* no need to flush tlb, vmalloc will handle it lazily */ /* no need to flush tlb, vmalloc will handle it lazily */
pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end) pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
pcpu_free_pages(chunk, pages, populated, rs, re); pcpu_free_pages(chunk, pages, rs, re);
/* commit new bitmap */ bitmap_clear(chunk->populated, page_start, page_end - page_start);
bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
} }
static struct pcpu_chunk *pcpu_create_chunk(void) static struct pcpu_chunk *pcpu_create_chunk(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment