Skip to content

Commit bc9d654

Browse files
XuNeoxiaoxiang781216
authored andcommitted
mm: call sched_note within mm lock
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
1 parent 5397a58 commit bc9d654

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

mm/mm_heap/mm_initialize.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,9 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
206206

207207
mm_addfreechunk(heap, node);
208208
heap->mm_curused += 2 * MM_SIZEOF_ALLOCNODE;
209-
mm_unlock(heap);
210-
211209
sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize,
212210
heap->mm_curused);
211+
mm_unlock(heap);
213212
}
214213

215214
/****************************************************************************

mm/mm_heap/mm_malloc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,19 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
321321
}
322322

323323
DEBUGASSERT(ret == NULL || mm_heapmember(heap, ret));
324+
325+
if (ret)
326+
{
327+
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
328+
heap->mm_curused);
329+
}
330+
324331
mm_unlock(heap);
325332

326333
if (ret)
327334
{
328335
MM_ADD_BACKTRACE(heap, node);
329336
ret = kasan_unpoison(ret, nodesize - MM_ALLOCNODE_OVERHEAD);
330-
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
331-
heap->mm_curused);
332337
#ifdef CONFIG_MM_FILL_ALLOCATIONS
333338
memset(ret, MM_ALLOC_MAGIC, alignsize - MM_ALLOCNODE_OVERHEAD);
334339
#endif

mm/mm_heap/mm_memalign.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
277277
heap->mm_maxused = heap->mm_curused;
278278
}
279279

280+
sched_note_heap(NOTE_HEAP_ALLOC, heap, (FAR void *)alignedchunk, size,
281+
heap->mm_curused);
282+
280283
mm_unlock(heap);
281284

282285
MM_ADD_BACKTRACE(heap, node);
283286

284287
alignedchunk = (uintptr_t)kasan_unpoison((FAR const void *)alignedchunk,
285288
size - MM_ALLOCNODE_OVERHEAD);
286-
sched_note_heap(NOTE_HEAP_ALLOC, heap, (FAR void *)alignedchunk, size,
287-
heap->mm_curused);
288-
289289
DEBUGASSERT(alignedchunk % alignment == 0);
290290
return (FAR void *)alignedchunk;
291291
}

mm/tlsf/mm_tlsf.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,9 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
699699
/* Add memory to the tlsf pool */
700700

701701
tlsf_add_pool(heap->mm_tlsf, heapstart, heapsize);
702-
mm_unlock(heap);
703-
704702
sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize,
705703
heap->mm_curused);
704+
mm_unlock(heap);
706705
}
707706

708707
/****************************************************************************
@@ -1333,6 +1332,12 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
13331332
heap->mm_maxused = heap->mm_curused;
13341333
}
13351334

1335+
if (ret)
1336+
{
1337+
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
1338+
heap->mm_curused);
1339+
}
1340+
13361341
mm_unlock(heap);
13371342

13381343
if (ret)
@@ -1344,8 +1349,6 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
13441349
#endif
13451350

13461351
ret = kasan_unpoison(ret, nodesize);
1347-
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
1348-
heap->mm_curused);
13491352

13501353
#ifdef CONFIG_MM_FILL_ALLOCATIONS
13511354
memset(ret, 0xaa, nodesize);
@@ -1415,6 +1418,12 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
14151418
heap->mm_maxused = heap->mm_curused;
14161419
}
14171420

1421+
if (ret)
1422+
{
1423+
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
1424+
heap->mm_curused);
1425+
}
1426+
14181427
mm_unlock(heap);
14191428

14201429
if (ret)
@@ -1425,8 +1434,6 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
14251434
memdump_backtrace(heap, buf);
14261435
#endif
14271436
ret = kasan_unpoison(ret, nodesize);
1428-
sched_note_heap(NOTE_HEAP_ALLOC, heap, ret, nodesize,
1429-
heap->mm_curused);
14301437
}
14311438

14321439
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
@@ -1545,6 +1552,14 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
15451552
heap->mm_maxused = heap->mm_curused;
15461553
}
15471554

1555+
if (newmem)
1556+
{
1557+
sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize,
1558+
heap->mm_curused - newsize);
1559+
sched_note_heap(NOTE_HEAP_ALLOC, heap, newmem, newsize,
1560+
heap->mm_curused);
1561+
}
1562+
15481563
mm_unlock(heap);
15491564

15501565
if (newmem)
@@ -1553,11 +1568,6 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
15531568
FAR struct memdump_backtrace_s *buf = newmem + newsize;
15541569
memdump_backtrace(heap, buf);
15551570
#endif
1556-
1557-
sched_note_heap(NOTE_HEAP_FREE, heap, oldmem, oldsize,
1558-
heap->mm_curused - newsize);
1559-
sched_note_heap(NOTE_HEAP_ALLOC, heap, newmem, newsize,
1560-
heap->mm_curused);
15611571
}
15621572

15631573
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0

0 commit comments

Comments
 (0)