Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mm: Add pending configuration for mm node struct and precding #15484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

W-M-R
Copy link
Contributor

@W-M-R W-M-R commented Jan 10, 2025

pending memory block node precding and the entire struct, after turning on this bit, the size of each memory block wil be aligned to MM_ALIGN

Note: Please adhere to Contributing Guidelines.

Summary

pending memory block node precding and the entire struct, after turning on this bit, the size of each memory block wil be aligned to MM_ALIGN.Adding this alignment can solve this problem

Impact

The new feature arm64 MTE is added, "#15461" requires that the allocated block address must be 16-byte aligned and the size must also be 16-byte aligned. Our current memory management does not meet the requirements.

Testing

Update this section with details on how did you verify the change,
what Host was used for build (OS, CPU, compiler, ..), what Target was
used for verification (arch, board:config, ..), etc. Providing build
and runtime logs from before and after change is highly appreciated.

@github-actions github-actions bot added Area: Memory Management Memory Management issues Size: S The size of the change in this PR is small labels Jan 10, 2025
@nuttxpr
Copy link

nuttxpr commented Jan 10, 2025

[Experimental Bot, please feedback here]

This PR does not fully meet the NuttX requirements yet. While it provides a basic description of the change, it lacks crucial details in the Impact and Testing sections.

Here's a breakdown of what's missing:

  • Summary: While it describes what is changed, it's missing why. What problem does aligning memory blocks to MM_ALIGN solve? Is this a performance optimization, a bug fix, or something else? It needs more context. Mention any related issues.

  • Impact: This section is essentially empty. It needs to be filled out completely. Consider the following:

    • Is this a new feature? If so, explicitly state that.
    • User Impact: Will users need to change any configuration options? Will existing applications break?
    • Build Impact: Will users need to change anything in their build system?
    • Hardware Impact: Does this change affect specific architectures or boards?
    • Documentation Impact: Does the documentation need to be updated to reflect this change? If so, has the documentation been updated in this PR or another?
    • Security Impact: Are there any potential security implications of this change? Even if the answer is no, explicitly state that.
    • Compatibility Impact: Does this change break backwards compatibility?
  • Testing: This section is also largely empty. It needs concrete details:

    • Build Host: Specify the operating system, CPU architecture, and compiler version used. (e.g., "Linux x86_64, GCC 12.1")
    • Target: Specify the architecture and board/configuration tested. (e.g., "sim:qemu-arm")
    • Logs: Provide actual logs from before and after the change. These logs should demonstrate that the change has the intended effect. Show how memory allocation behaves differently now. Don't just leave the placeholder text.

In short, the PR needs to be significantly more detailed before it can be properly reviewed. Filling in the missing information in the Impact and Testing sections is crucial. The Summary section could also benefit from more context.

@yamt
Copy link
Contributor

yamt commented Jan 10, 2025

what are you trying to fix with this?

@W-M-R
Copy link
Contributor Author

W-M-R commented Jan 10, 2025

what are you trying to fix with this?

The new feature arm64 MTE is added, "#15461" requires that the allocated block address must be 16-byte aligned and the size must also be 16-byte aligned. Our current memory management does not meet the requirements.Adding this alignment can solve this problem

#ifdef CONFIG_MM_NODE_PENDING
union
{
mmsize_t preceding; /* Physical preceding chunk size */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simplify to:

mmsize_t preceding aligned_data(MM_ALIGN);

Copy link
Contributor Author

@W-M-R W-M-R Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is invalid to do aligned_data(MM_ALIGN) on precding alone.

#include <stdio.h>


struct st0
{
    char a;
    char b;
}__attribute__((aligned(16)));

struct st1
{
    char a __attribute__((aligned(16)));
    char b;
};

struct st2
{
    char a;
    char b __attribute__((aligned(16)));
};

struct st3
{
    char a __attribute__((aligned(16)));
    char b __attribute__((aligned(16)));
    char d[15];
}__attribute__((aligned(16)));

struct st4
{
    union
    {
        char a;
        char a_align[16];
    };

    union
    {
        char b;
        char b_align[16];
    };
};

#define OFFSET(struct, member) (&(((struct *)0)->member))

#define PRINTF_STRUCT(struct) \
    printf("%s: ", #struct); \
    printf("size: %d\n", sizeof(struct)); \
    printf("member a: %d\n", OFFSET(struct, a)); \
    printf("member b: %d\n", OFFSET(struct, b));

int main()
{
    PRINTF_STRUCT(struct st0);
    PRINTF_STRUCT(struct st1);
    PRINTF_STRUCT(struct st2);
    PRINTF_STRUCT(struct st3);
    PRINTF_STRUCT(struct st4);
}


struct st0: size: 16
member a: 0
member b: 1
struct st1: size: 16
member a: 0
member b: 1
struct st2: size: 32
member a: 0
member b: 16
struct st3: size: 32
member a: 0
member b: 16
struct st4: size: 32
member a: 0
member b: 16

My understanding is that the alignment of attribute((aligned(16))) is more about the alignment of the size of the entire structure, and the alignment of a single member is limited to the alignment of access, not size.Therefore, using union is the only effective way to align the size

mm/mm_heap/mm.h Show resolved Hide resolved
mm/mm_heap/mm.h Outdated
@@ -182,13 +201,22 @@ struct mm_allocnode_s
FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */
# endif
#endif
};
}MM_NODE_STRUCT_PENDING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need

Copy link
Contributor Author

@W-M-R W-M-R Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uploading 20250113-121535.png…
The ptr that the user gets is the size of our node plus the size of the entire result body, so the entire structure must also be aligned

mm/mm_heap/mm.h Outdated Show resolved Hide resolved
@W-M-R W-M-R force-pushed the mm-pending branch 9 times, most recently from df13122 to b45cc31 Compare January 13, 2025 05:16
pending memory block node precding and the entire struct, after turning on this bit, the size of each memory block wil be aligned to MM_ALIGN

Signed-off-by: wangmingrong1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Memory Management Memory Management issues Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants