Skip to contentSkip to conversation

mm/vmalloc: make sure to traverse from the beginning when overflow occur

RFC PATCH In review Liu Song 3 participants 4 messages Apr 12, 2020 – Apr 14, 2020

Subsystems (2)
lore
Share & tools
lore

Liu Song

author
#0 lore raw

RFC PATCH 1/1 mm/vmalloc: make sure to traverse from the beginning when overflow occur

From: Liu Song <[email protected]>

If overflow, should ensure that "free_vmap_cache" is set to NULL, so as to ensure that it can be traversed from the beginning.

---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmalloc.c +1 -1
index d8e877365f9f..2638a20d36ce 100644
@@ -441,7 +441,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	if (!free_vmap_cache ||
 			size < cached_hole_size ||
 			vstart < cached_vstart ||
-			align < cached_align) {
+			align < cached_align || purged) {
 nocache:
 		cached_hole_size = 0;
 		free_vmap_cache = NULL;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 2 lines · Liu Song

If overflow, should ensure that "free_vmap_cache" is set to NULL, so as to ensure that it can be traversed from the beginning.

This changelog is a bit sparse.

Does this fix a demonstrated problem? Or was it just discovered via code review and assumed to help a theoretical problem?

Which tree is it against? 'free_vmap_cache' doesn't show up in Linus's tree.

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 447

Quoted 13 lines
mm/vmalloc.c +1 -1
index d8e877365f9f..2638a20d36ce 100644
@@ -441,7 +441,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	if (!free_vmap_cache ||
 			size < cached_hole_size ||
 			vstart < cached_vstart ||
-			align < cached_align) {
+			align < cached_align || purged) {
 nocache:
 		cached_hole_size = 0;
 		free_vmap_cache = NULL;

Is 'purged' the right way to do this?

There is a path through the overflow code that also sets purged=0. Does 'free_vmap_cache' *not* need to get reset in that case?

It also seems more natural to me that the code mucking with the rbtree would be the one to reset the cache.

author
#2 lore raw
Quoted 27 lines · Liu Song
Quoted 2 lines

If overflow, should ensure that "free_vmap_cache" is set to NULL, so as to ensure that it can be traversed from the beginning.

This changelog is a bit sparse.

Does this fix a demonstrated problem? Or was it just discovered via code review and assumed to help a theoretical problem?

Which tree is it against? 'free_vmap_cache' doesn't show up in Linus's tree.

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 447

Quoted 13 lines
mm/vmalloc.c +1 -1
index d8e877365f9f..2638a20d36ce 100644
@@ -441,7 +441,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
  if (!free_vmap_cache ||
    size < cached_hole_size ||
    vstart < cached_vstart ||
-   align < cached_align) {
+   align < cached_align || purged) {
 nocache:
   cached_hole_size = 0;
   free_vmap_cache = NULL;

Is 'purged' the right way to do this?

Quoted 5 lines

There is a path through the overflow code that also sets purged=0. Does 'free_vmap_cache' *not* need to get reset in that case?

It also seems more natural to me that the code mucking with the rbtree would be the one to reset the cache.

Hi,
Thanks for your reply, there is indeed a problem with this patch submission. I neglected the cache clearing process, so I mistakenly thought that the cache should be cleared after "purged". I will not issue such unconsidered patches anymore, to avoid unnecessary trouble for everyone. *_^

Thanks

maintainer
#3 lore raw
In reply to Dave Hansen
Quoted 11 lines · Dave Hansen
Quoted 2 lines · Liu Song

If overflow, should ensure that "free_vmap_cache" is set to NULL, so as to ensure that it can be traversed from the beginning.

This changelog is a bit sparse.

Does this fix a demonstrated problem? Or was it just discovered via code review and assumed to help a theoretical problem?

Which tree is it against? 'free_vmap_cache' doesn't show up in Linus's tree.

Quoted 14 lines
Quoted 6 lines
mm/vmalloc.c +0 -0
index d8e877365f9f..2638a20d36ce 100644

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 447

Quoted 8 lines
mm/vmalloc.c +1 -1
@@ -441,7 +441,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 	if (!free_vmap_cache ||
 			size < cached_hole_size ||
 			vstart < cached_vstart ||
-			align < cached_align) {
+			align < cached_align || purged) {
 nocache:
 		cached_hole_size = 0;
 		free_vmap_cache = NULL;

We do not have such code since 5.2 kernel or so, nor things like cached_hole_size, free_vmap_cache and so on. It was totally reworked.

--
Vlad Rezki