Skip to contentSkip to conversation

percpu: clean up of schunk->map[] assignment in pcpu_setup_first_chunk

PATCH In review Baoquan He 3 participants 20 messages Jul 20, 2015 – Jul 23, 2015

Subsystems (2)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

PATCH 1/3 percpu: clean up of schunk->map[] assignment in pcpu_setup_first_chunk

The original assignment is a little redundent.

---
 mm/percpu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/percpu.c +2 -3
index 2dd7448..a63b4d8 100644
@@ -1668,9 +1668,8 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 	schunk->map[1] = ai->static_size;
 	schunk->map_used = 1;
 	if (schunk->free_size)
-		schunk->map[++schunk->map_used] = 1 | (ai->static_size + schunk->free_size);
-	else
-		schunk->map[1] |= 1;
+		schunk->map[++schunk->map_used] = ai->static_size + schunk->free_size;
+	schunk->map[schunk->map_used] |= 1;
 
 	/* init dynamic chunk if necessary */
 	if (dyn_size) {
Signature · 7 lines
1.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw

PATCH 2/3 perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In pcpu_setup_first_chunk() pcpu_reserved_chunk is assigned to point to static chunk. While pcpu_first_chunk is got from below code:

	pcpu_first_chunk = dchunk ?: schunk;

Then it could point to static chunk too if dynamic chunk doesn't exist. So in this patch adding a check in percpu_init_late() to see if pcpu_first_chunk is equal to pcpu_reserved_chunk. Only if they are not equal we add pcpu_reserved_chunk to the target array.

---
 mm/percpu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
mm/percpu.c +8 -1
index a63b4d8..f7e02c0 100644
@@ -2260,11 +2260,18 @@ void __init setup_per_cpu_areas(void)
 void __init percpu_init_late(void)
 {
 	struct pcpu_chunk *target_chunks[] =
-		{ pcpu_first_chunk, pcpu_reserved_chunk, NULL };
+		{ pcpu_first_chunk, NULL, NULL };
 	struct pcpu_chunk *chunk;
 	unsigned long flags;
 	int i;
 
+	/*
+	 * pcpu_first_chunk could be the same as pcpu_reserved_chunk, add it to the
+	 * target array only if pcpu_first_chunk is not equal to pcpu_reserved_chunk.
+	 */
+	if (pcpu_first_chunk != pcpu_reserved_chunk)
+		target_chunks[1] = pcpu_reserved_chunk;
+
 	for (i = 0; (chunk = target_chunks[i]); i++) {
 		int *map;
 		const size_t size = PERCPU_DYNAMIC_EARLY_SLOTS * sizeof(map[0]);
Signature · 7 lines
1.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#9 lore raw

PATCH 3/3 percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_CHUNK_AREA_IN_USE and use it as the in-use flag to replace all magic number '1'.

---
 mm/percpu.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
mm/percpu.c +10 -8
index f7e02c0..2f99073 100644
@@ -80,6 +80,7 @@
 #define PCPU_ATOMIC_MAP_MARGIN_HIGH	64
 #define PCPU_EMPTY_POP_PAGES_LOW	2
 #define PCPU_EMPTY_POP_PAGES_HIGH	4
+#define PCPU_CHUNK_AREA_IN_USE		1
 
 #ifdef CONFIG_SMP
 /* default addr <-> pcpu_ptr mapping, override in asm/percpu.h if necessary */
@@ -328,8 +329,8 @@ static void pcpu_mem_free(void *ptr, size_t size)
  */
 static int pcpu_count_occupied_pages(struct pcpu_chunk *chunk, int i)
 {
-	int off = chunk->map[i] & ~1;
-	int end = chunk->map[i + 1] & ~1;
+	int off = chunk->map[i] & ~PCPU_CHUNK_AREA_IN_USE;
+	int end = chunk->map[i + 1] & ~PCPU_CHUNK_AREA_IN_USE;
 
 	if (!PAGE_ALIGNED(off) && i > 0) {
 		int prev = chunk->map[i - 1];
@@ -340,7 +341,7 @@ static int pcpu_count_occupied_pages(struct pcpu_chunk *chunk, int i)
 
 	if (!PAGE_ALIGNED(end) && i + 1 < chunk->map_used) {
 		int next = chunk->map[i + 1];
-		int nend = chunk->map[i + 2] & ~1;
+		int nend = chunk->map[i + 2] & ~PCPU_CHUNK_AREA_IN_USE;
 
 		if (!(next & 1) && nend >= round_up(end, PAGE_SIZE))
 			end = round_up(end, PAGE_SIZE);
@@ -738,7 +739,7 @@ static struct pcpu_chunk *pcpu_alloc_chunk(void)
 
 	chunk->map_alloc = PCPU_DFL_MAP_ALLOC;
 	chunk->map[0] = 0;
-	chunk->map[1] = pcpu_unit_size | 1;
+	chunk->map[1] = pcpu_unit_size | PCPU_CHUNK_AREA_IN_USE;
 	chunk->map_used = 1;
 
 	INIT_LIST_HEAD(&chunk->list);
@@ -1664,12 +1665,12 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 	}
 	schunk->contig_hint = schunk->free_size;
 
-	schunk->map[0] = 1;
+	schunk->map[0] = PCPU_CHUNK_AREA_IN_USE;
 	schunk->map[1] = ai->static_size;
 	schunk->map_used = 1;
 	if (schunk->free_size)
 		schunk->map[++schunk->map_used] = ai->static_size + schunk->free_size;
-	schunk->map[schunk->map_used] |= 1;
+	schunk->map[schunk->map_used] |= PCPU_CHUNK_AREA_IN_USE;
 
 	/* init dynamic chunk if necessary */
 	if (dyn_size) {
@@ -1684,9 +1685,10 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 		dchunk->nr_populated = pcpu_unit_pages;
 
 		dchunk->contig_hint = dchunk->free_size = dyn_size;
-		dchunk->map[0] = 1;
+		dchunk->map[0] = PCPU_CHUNK_AREA_IN_USE;
 		dchunk->map[1] = pcpu_reserved_chunk_limit;
-		dchunk->map[2] = (pcpu_reserved_chunk_limit + dchunk->free_size) | 1;
+		dchunk->map[2] = (pcpu_reserved_chunk_limit + dchunk->free_size)
+					| PCPU_CHUNK_AREA_IN_USE;
 		dchunk->map_used = 2;
 	}
 
Signature · 7 lines
1.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Baoquan He
Quoted 3 lines · Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_CHUNK_AREA_IN_USE and use it as the in-use flag to replace all magic number '1'.

Hmmm... This is a bitflag and the code now looks like there is some sort of bitmask that were are using. Use bitops or something else that clearly implies that a bit is flipped instead?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#2 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In reply to Baoquan He
Quoted 9 lines · Baoquan He

In pcpu_setup_first_chunk() pcpu_reserved_chunk is assigned to point to static chunk. While pcpu_first_chunk is got from below code:

	pcpu_first_chunk = dchunk ?: schunk;

Then it could point to static chunk too if dynamic chunk doesn't exist. So in this patch adding a check in percpu_init_late() to see if pcpu_first_chunk is equal to pcpu_reserved_chunk. Only if they are not equal we add pcpu_reserved_chunk to the target array.

So, I don't think this is actually possible. dyn_size can't be zero so if reserved chunk is created, dyn chunk is also always created and thus first chunk can't equal reserved chunk. It might be useful to add some comments explaining this or maybe WARN_ON() but I don't think this path is necessary.

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#12 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Baoquan He
Quoted 5 lines · Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_CHUNK_AREA_IN_USE and use it as the in-use flag to replace all magic number '1'.

idk, maybe. Can you at least go for something shorter? PCPU_MAP_BUSY or whatever?

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#18 lore raw
In reply to Baoquan He
Quoted 3 lines · Baoquan He

The original assignment is a little redundent.

Heh, I'm not sure this is actually better. Anyways, applied to percpu/for-4.3. In general tho, I don't really think this level of micro cleanup patches are worthwhile. If something around it changes, sure, take the chance and clean it up but as standalone patches these aren't that readily justifiable.

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#3 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In reply to Tejun Heo

Hi Tejun,

Quoted 11 lines · Tejun Heo
Quoted 9 lines · Baoquan He

In pcpu_setup_first_chunk() pcpu_reserved_chunk is assigned to point to static chunk. While pcpu_first_chunk is got from below code:

	pcpu_first_chunk = dchunk ?: schunk;

Then it could point to static chunk too if dynamic chunk doesn't exist. So in this patch adding a check in percpu_init_late() to see if pcpu_first_chunk is equal to pcpu_reserved_chunk. Only if they are not equal we add pcpu_reserved_chunk to the target array.

Quoted 5 lines

So, I don't think this is actually possible. dyn_size can't be zero so if reserved chunk is created, dyn chunk is also always created and thus first chunk can't equal reserved chunk. It might be useful to add some comments explaining this or maybe WARN_ON() but I don't think this path is necessary.

Thanks for your reviewing.

Yes, dyn_size can't be zero. But in pcpu_setup_first_chunk(), the local variable dyn_size could be zero caused by below code:

if (ai->reserved_size) {
                schunk->free_size = ai->reserved_size;
                pcpu_reserved_chunk = schunk;
                pcpu_reserved_chunk_limit = ai->static_size +
ai->reserved_size;
        } else {
                schunk->free_size = dyn_size;
                dyn_size = 0;                   /* dynamic area covered
*/
        }

So if no reserved_size dyn_size is assigned to zero, and is checked to see if dchunk need be created in below code:

	/* init dynamic chunk if necessary */
        if (dyn_size) {
		...
	}

I think v1 patch is a little ugly, so made a v2 like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

author
#11 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Christoph Lameter

Hi Christoph,

Quoted 9 lines · Christoph Lameter
Quoted 3 lines · Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_CHUNK_AREA_IN_USE and use it as the in-use flag to replace all magic number '1'.

Hmmm... This is a bitflag and the code now looks like there is some sort of bitmask that were are using. Use bitops or something else that clearly implies that a bit is flipped instead?

Thanks for your reviewing and suggesting.

I tried your suggestion and changed to use set_bit/clear_bit to do instead. It's like this:

@@ -328,8 +329,10 @@ static void pcpu_mem_free(void *ptr, size_t size)
*/
static int pcpu_count_occupied_pages(struct pcpu_chunk *chunk, int i) {

-       int off = chunk->map[i] & ~1;
-       int end = chunk->map[i + 1] & ~1;
+       int off = chunk->map[i];
+       int end = chunk->map[i + 1];
+       clear_bit(PCPU_CHUNK_AREA_IN_USE_BIT, &chunk->map[i]);
+       clear_bit(PCPU_CHUNK_AREA_IN_USE_BIT, &chunk->map[i + 1]);

Looks like code becomes a little redundent. If several different bits in chunk->map[] have different usage and need several different flags, bitops maybe better. While now only the lowest bit need be handle, use bitops kindof too much and can make code a little messy.

You and Tejun may be a little struggled on this change since it make code longer. Tejun has suggested that at least use a shorter name, like PCPU_MAP_BUSY. I am going to post v2 to see if it's better.

Thanks
Baoquan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#13 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Tejun Heo

Hi Tejun,

Quoted 9 lines · Tejun Heo
Quoted 5 lines · Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_CHUNK_AREA_IN_USE and use it as the in-use flag to replace all magic number '1'.

idk, maybe. Can you at least go for something shorter? PCPU_MAP_BUSY or whatever?

Thanks for suggestion.

I know this change makes code longer. PCPU_MAP_BUSY is better, I am gonna repost with it.

Thanks
Baoquan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#19 lore raw
In reply to Tejun Heo
Quoted 10 lines · Tejun Heo
Quoted 3 lines · Baoquan He

The original assignment is a little redundent.

Heh, I'm not sure this is actually better. Anyways, applied to percpu/for-4.3. In general tho, I don't really think this level of micro cleanup patches are worthwhile. If something around it changes, sure, take the chance and clean it up but as standalone patches these aren't that readily justifiable.

Understood. They are very tiny cleanups, not inprovement. Just when trying to fix a kdump corrupted header bug where cpu information is stored in percpu variable I tried to understand the whole percpu implementation and found these. Didn't put them together because that change is kdump only in kernel/kexec.c and that patch is testing by customers on big server. Understanding percpu code is always in my TODO list, now it's done. I am fine if patch like patch 3/3 makes code messy and should not be applied.

Thanks for your reviewing and suggestion.

Thanks
Baoquan

maintainer
#4 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In reply to Baoquan He

Hello,

Quoted 14 lines · Baoquan He

Yes, dyn_size can't be zero. But in pcpu_setup_first_chunk(), the local variable dyn_size could be zero caused by below code:

if (ai->reserved_size) {
                schunk->free_size = ai->reserved_size;
                pcpu_reserved_chunk = schunk;
                pcpu_reserved_chunk_limit = ai->static_size +
ai->reserved_size;
        } else {
                schunk->free_size = dyn_size;
                dyn_size = 0;                   /* dynamic area covered
*/
        }
Quoted 2 lines

So if no reserved_size dyn_size is assigned to zero, and is checked to see if dchunk need be created in below code:

Hmmm... but then pcpu_reserved_chunk is NULL so there still is no duplicate on the list, no?

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#14 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Baoquan He

Hello,

Quoted 2 lines · Baoquan He

I know this change makes code longer. PCPU_MAP_BUSY is better, I am gonna repost with it.

While at it, can you also please add comment on top of the definition of PCPU_MAP_BUSY explaining what's going on?

Thanks.

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#5 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In reply to Tejun Heo
Quoted 17 lines · Tejun Heo

Hello,

Quoted 14 lines · Baoquan He

Yes, dyn_size can't be zero. But in pcpu_setup_first_chunk(), the local variable dyn_size could be zero caused by below code:

if (ai->reserved_size) {
                schunk->free_size = ai->reserved_size;
                pcpu_reserved_chunk = schunk;
                pcpu_reserved_chunk_limit = ai->static_size +
ai->reserved_size;
        } else {
                schunk->free_size = dyn_size;
                dyn_size = 0;                   /* dynamic area covered
*/
        }
Quoted 5 lines
Quoted 2 lines

So if no reserved_size dyn_size is assigned to zero, and is checked to see if dchunk need be created in below code:

Hmmm... but then pcpu_reserved_chunk is NULL so there still is no duplicate on the list, no?

Yes, you are quite right. I was mistaken. So NACK this patch.

Thanks a lot.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#6 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

Quoted 7 lines · Baoquan He
Quoted 5 lines
Quoted 2 lines

So if no reserved_size dyn_size is assigned to zero, and is checked to see if dchunk need be created in below code:

Hmmm... but then pcpu_reserved_chunk is NULL so there still is no duplicate on the list, no?

Yes, you are quite right. I was mistaken. So NACK this patch.

But, yeah, it'd be great if we can add a WARN_ON() to ensure that this really doesn't happen along with some comments.

Thanks!

Signature · 7 lines
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#16 lore raw

PATCH v2 3/3 percpu: add macro PCPU_MAP_BUSY

In reply to Baoquan He

chunk->map[] contains <offset|in-use flag> of each area. Now add a new macro PCPU_MAP_BUSY and use it as the in-use flag to replace all magic number '1'.

---
 mm/percpu.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
mm/percpu.c +18 -8
index a63b4d8..8cf18dc 100644
@@ -81,6 +81,15 @@
 #define PCPU_EMPTY_POP_PAGES_LOW	2
 #define PCPU_EMPTY_POP_PAGES_HIGH	4
 
+/* we use int array chunk->map[] to describe each area of chunk. Each array
+ * element is represented by one int - contains offset|1 for <offset, in use>
+ * or offset for <ofset, free> (offset need be guaranteed to be even). In the
+ * end there's a sentry entry - <total size, in-use>. So the size of the N-th
+ * area would be the offset of (N+1)-th - the offset of N-th, namely
+ * SIZEn = chunk->map[N+1]&~1 - chunk->map[N]&~1
+ * For more read-able code define PCPU_MAP_BUSY to represent in-use flag.*/
+#define PCPU_MAP_BUSY			1
+
 #ifdef CONFIG_SMP
 /* default addr <-> pcpu_ptr mapping, override in asm/percpu.h if necessary */
 #ifndef __addr_to_pcpu_ptr
@@ -328,8 +337,8 @@ static void pcpu_mem_free(void *ptr, size_t size)
  */
 static int pcpu_count_occupied_pages(struct pcpu_chunk *chunk, int i)
 {
-	int off = chunk->map[i] & ~1;
-	int end = chunk->map[i + 1] & ~1;
+	int off = chunk->map[i] & ~PCPU_MAP_BUSY;
+	int end = chunk->map[i + 1] & ~PCPU_MAP_BUSY;
 
 	if (!PAGE_ALIGNED(off) && i > 0) {
 		int prev = chunk->map[i - 1];
@@ -340,7 +349,7 @@ static int pcpu_count_occupied_pages(struct pcpu_chunk *chunk, int i)
 
 	if (!PAGE_ALIGNED(end) && i + 1 < chunk->map_used) {
 		int next = chunk->map[i + 1];
-		int nend = chunk->map[i + 2] & ~1;
+		int nend = chunk->map[i + 2] & ~PCPU_MAP_BUSY;
 
 		if (!(next & 1) && nend >= round_up(end, PAGE_SIZE))
 			end = round_up(end, PAGE_SIZE);
@@ -738,7 +747,7 @@ static struct pcpu_chunk *pcpu_alloc_chunk(void)
 
 	chunk->map_alloc = PCPU_DFL_MAP_ALLOC;
 	chunk->map[0] = 0;
-	chunk->map[1] = pcpu_unit_size | 1;
+	chunk->map[1] = pcpu_unit_size | PCPU_MAP_BUSY;
 	chunk->map_used = 1;
 
 	INIT_LIST_HEAD(&chunk->list);
@@ -1664,12 +1673,12 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 	}
 	schunk->contig_hint = schunk->free_size;
 
-	schunk->map[0] = 1;
+	schunk->map[0] = PCPU_MAP_BUSY;
 	schunk->map[1] = ai->static_size;
 	schunk->map_used = 1;
 	if (schunk->free_size)
 		schunk->map[++schunk->map_used] = ai->static_size + schunk->free_size;
-	schunk->map[schunk->map_used] |= 1;
+	schunk->map[schunk->map_used] |= PCPU_MAP_BUSY;
 
 	/* init dynamic chunk if necessary */
 	if (dyn_size) {
@@ -1684,9 +1693,10 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 		dchunk->nr_populated = pcpu_unit_pages;
 
 		dchunk->contig_hint = dchunk->free_size = dyn_size;
-		dchunk->map[0] = 1;
+		dchunk->map[0] = PCPU_MAP_BUSY;
 		dchunk->map[1] = pcpu_reserved_chunk_limit;
-		dchunk->map[2] = (pcpu_reserved_chunk_limit + dchunk->free_size) | 1;
+		dchunk->map[2] = (pcpu_reserved_chunk_limit + dchunk->free_size)
+					| PCPU_MAP_BUSY;
 		dchunk->map_used = 2;
 	}
 
Signature · 1 line
2.4.3
author
#8 lore raw

PATCH v3 2/3 percpu: Add WARN_ON into percpu_init_late

In reply to Baoquan He

In pcpu_setup_first_chunk() pcpu_reserved_chunk is assigned to point to static chunk. While pcpu_first_chunk is got from below code:

	pcpu_first_chunk = dchunk ?: schunk;

pcpu_first_chunk might point to static chunk too with possibility. Add a WARN_ON here to yell out if that happened.*/

---
 mm/percpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/percpu.c +7 -0
index 8cf18dc..974600b 100644
@@ -2275,6 +2275,13 @@ void __init percpu_init_late(void)
 	unsigned long flags;
 	int i;
 
+	/* In pcpu_setup_first_chunk() pcpu_reserved_chunk is assigned to point to
+	 * static chunk. While pcpu_first_chunk is got from below code:
+	 * 		pcpu_first_chunk = dchunk ?: schunk;
+	 * pcpu_first_chunk might point to static chunk too with possibility. Add a
+	 * WARN_ON here to yell out if that happened.*/
+	WARN_ON(pcpu_first_chunk == pcpu_reserved_chunk);
+
 	for (i = 0; (chunk = target_chunks[i]); i++) {
 		int *map;
 		const size_t size = PERCPU_DYNAMIC_EARLY_SLOTS * sizeof(map[0]);
Signature · 1 line
2.4.3
author
#15 lore raw

Re: [PATCH 3/3] percpu: add macro PCPU_CHUNK_AREA_IN_USE

In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

Hello,

Quoted 2 lines · Baoquan He

I know this change makes code longer. PCPU_MAP_BUSY is better, I am gonna repost with it.

While at it, can you also please add comment on top of the definition of PCPU_MAP_BUSY explaining what's going on?

Posted [patch v2 3/3] as you suggested.

Thanks a lot.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#7 lore raw

Re: [PATCH 2/3] perpuc: check pcpu_first_chunk and pcpu_reserved_chunk to avoid handling them twice

In reply to Tejun Heo
Quoted 11 lines · Tejun Heo
Quoted 7 lines · Baoquan He
Quoted 5 lines
Quoted 2 lines

So if no reserved_size dyn_size is assigned to zero, and is checked to see if dchunk need be created in below code:

Hmmm... but then pcpu_reserved_chunk is NULL so there still is no duplicate on the list, no?

Yes, you are quite right. I was mistaken. So NACK this patch.

But, yeah, it'd be great if we can add a WARN_ON() to ensure that this really doesn't happen along with some comments.

Posted [patch v3 2/3] as you suggested.

Thanks a lot!