Skip to contentSkip to conversation

mm: Redundant const parameter?

QUESTION Dev Jain 3 participants 7 messages May 31, 2024 Memory management

lore
Share & tools
lore

Dev Jain

author
#0 lore raw

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

Please comment.

Thanks

DJ

author
#1 lore raw

I guess it would be better if I send this as a patch and wait for comments.

Quoted 20 lines · Dev Jain

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

Please comment.

Thanks

DJ

#2 lore raw
Quoted 1 line · Dev Jain

I guess it would be better if I send this as a patch and wait for comments.

Ah, you're right. I think it should be:

	return folio_test_workingset(slab_folio(slab));

Right? Don't notice there isn't any build warning about this "const" discard.

Thanks.

Quoted 22 lines · Dev Jain
Quoted 20 lines

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

Please comment.

Thanks

DJ

author
#3 lore raw

Yes; Matthew just did a wider fix:

https://lore.kernel.org/all/[email protected]/

Quoted 31 lines · Chengming Zhou
Quoted 1 line · Dev Jain

I guess it would be better if I send this as a patch and wait for comments.

Ah, you're right. I think it should be:

	return folio_test_workingset(slab_folio(slab));

Right? Don't notice there isn't any build warning about this "const" discard.

Thanks.

Quoted 21 lines · Dev Jain
Quoted 20 lines

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

Please comment.

Thanks

DJ

#4 lore raw
In reply to Chengming Zhou
Quoted 8 lines · Chengming Zhou
Quoted 1 line · Dev Jain

I guess it would be better if I send this as a patch and wait for comments.

Ah, you're right. I think it should be:

	return folio_test_workingset(slab_folio(slab));

Right? Don't notice there isn't any build warning about this "const" discard.

But there used to be! I fixed that in ce3467af6bde dated Feb 27 2024, which took a fair amount of prep work to make happen.

#5 lore raw
In reply to Dev Jain
Quoted 5 lines · Dev Jain

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Quoted 7 lines

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

I have a patch to fix this; hang on a second ...

author
#6 lore raw

I was just about to hit git send-email for a patch-series of 2, I noticed your reply :)

Quoted 14 lines · Matthew Wilcox
Quoted 5 lines · Dev Jain

Hi Chengming,

In mm/slub.c, you had defined slab_test_node_partial() to take a const parameter.

Quoted 7 lines

Is there any point of taking in a const, when you are anyways typecasting it to

a (struct folio *) from (const struct folio *) ? In fact, at the place where you call

slab_test_node_partial(), the struct slab *slab is not const.

I have a patch to fix this; hang on a second ...