Skip to content

Commit 1b23ff8

Browse files
Baoquan Heakpm00
authored andcommitted
mm/vmalloc: invoke classify_va_fit_type() in adjust_va_to_fit_type()
Patch series "Cleanup patches of vmalloc", v2. Some cleanup patches found when reading vmalloc code. This patch (of 4): adjust_va_to_fit_type() checks all values of passed in fit type, including NOTHING_FIT in the else branch. However, the check of NOTHING_FIT has been done inside adjust_va_to_fit_type() and before it's called in all call sites. In fact, both of these functions are coupled tightly, since classify_va_fit_type() is doing the preparation work for adjust_va_to_fit_type(). So putting invocation of classify_va_fit_type() inside adjust_va_to_fit_type() can simplify code logic and the redundant check of NOTHING_FIT issue will go away. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Baoquan He <[email protected]> Suggested-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent bcc728e commit 1b23ff8

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

mm/vmalloc.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,10 +1335,10 @@ classify_va_fit_type(struct vmap_area *va,
13351335

13361336
static __always_inline int
13371337
adjust_va_to_fit_type(struct vmap_area *va,
1338-
unsigned long nva_start_addr, unsigned long size,
1339-
enum fit_type type)
1338+
unsigned long nva_start_addr, unsigned long size)
13401339
{
13411340
struct vmap_area *lva = NULL;
1341+
enum fit_type type = classify_va_fit_type(va, nva_start_addr, size);
13421342

13431343
if (type == FL_FIT_TYPE) {
13441344
/*
@@ -1444,7 +1444,6 @@ __alloc_vmap_area(unsigned long size, unsigned long align,
14441444
bool adjust_search_size = true;
14451445
unsigned long nva_start_addr;
14461446
struct vmap_area *va;
1447-
enum fit_type type;
14481447
int ret;
14491448

14501449
/*
@@ -1472,14 +1471,9 @@ __alloc_vmap_area(unsigned long size, unsigned long align,
14721471
if (nva_start_addr + size > vend)
14731472
return vend;
14741473

1475-
/* Classify what we have found. */
1476-
type = classify_va_fit_type(va, nva_start_addr, size);
1477-
if (WARN_ON_ONCE(type == NOTHING_FIT))
1478-
return vend;
1479-
14801474
/* Update the free vmap_area. */
1481-
ret = adjust_va_to_fit_type(va, nva_start_addr, size, type);
1482-
if (ret)
1475+
ret = adjust_va_to_fit_type(va, nva_start_addr, size);
1476+
if (WARN_ON_ONCE(ret))
14831477
return vend;
14841478

14851479
#if DEBUG_AUGMENT_LOWEST_MATCH_CHECK
@@ -3735,7 +3729,6 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
37353729
int area, area2, last_area, term_area;
37363730
unsigned long base, start, size, end, last_end, orig_start, orig_end;
37373731
bool purged = false;
3738-
enum fit_type type;
37393732

37403733
/* verify parameters and allocate data structures */
37413734
BUG_ON(offset_in_page(align) || !is_power_of_2(align));
@@ -3846,15 +3839,11 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
38463839
/* It is a BUG(), but trigger recovery instead. */
38473840
goto recovery;
38483841

3849-
type = classify_va_fit_type(va, start, size);
3850-
if (WARN_ON_ONCE(type == NOTHING_FIT))
3842+
ret = adjust_va_to_fit_type(va, start, size);
3843+
if (WARN_ON_ONCE(unlikely(ret)))
38513844
/* It is a BUG(), but trigger recovery instead. */
38523845
goto recovery;
38533846

3854-
ret = adjust_va_to_fit_type(va, start, size, type);
3855-
if (unlikely(ret))
3856-
goto recovery;
3857-
38583847
/* Allocated area. */
38593848
va = vas[area];
38603849
va->va_start = start;

0 commit comments

Comments
 (0)