Unikraft
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: "SMP WG, April 11, 2023" tags: unikraft, smp, synchronization datetime: 2023-04-11T10:00:00+02:00 location: Online, Discord (https://bit.ly/UnikraftDiscord), the `#monkey-business` voice channel teams: - smp participants: - RăzvanD - Marc - Michalis - Sairaj - Simon - RăzvanV - Andra --- ## :dart: Agenda - Status update - Next steps ## :closed_book: Discussions RV: I had some medical issues. I started to look on Friday. RV: The task was to include buddy allocator with the VM API. MR: The most simple step that you can do is to use the nopaging support. Then synchronize the buddy allocator. MR: Then decide where this allocator is getting memory from. MR: Starting with nopaging is easier. Starting with paging you could get on top of the memory allocator and this is more complex. RV: There is already a PR on synchronizing ukallocbuddy, so this is done. MR: Maybe this will synchronize paging operations. First it would work if paging operations use directly `ukvmem`. MR: Even if `ukvmem` is there, you can make paging API calls directly. Of course, then you need to synchronize every level. If we use `ukvmem`, you don't need to sublayers, such as the frame allocator. Since the top-layer is synchronized, everything below that will be synchronized. SK: You said you have a PR for the buddy allocator. Was there something open? RV: Andra, Simon and Sairaj are assigned as reviewers. I need to look into the buddy allocator synchronization PR. RV: I used the SMP API to test it. There is a test inside the PR description. MR: In `ukvmem` you still need to synchornized for internal data structures. MR: Don't just think about correctness, but also about performance. Maybe use reader-writer lock. Play with different approaches to see if there are performance issues. SK: I would look in the DPDK implementation for synchronization primitives around SMP. MR: This is one of the additional topics: lock-free data structures. MR: For now synchronize with standard synchronization primitives. But for the future, we would look into lock-free structures. MR: We have new synchronization primitives. It's more about lock-free data structures. RD/MR: We would have lock-free data structures as a next step. Let's first focus on the synchronizing libraries (such as memory allocation). MR: If, in case of mimalloc, there is a `mmap()` call, leave it like that. You want to keep the code as unmodified as possible, so it is easier to update. RV: We are now patching mimalloc to call the region allocator. MR: As long as you don't have paging enabled, this is OK. MR: How would the ukbuddyalloc will work with paging enabled? Two approaches: 1) Create virtual memory area large enough to include all physical memory. Allocate physical memory by just accessing it and letting demand-paging do its magic. You can release physical memory via `madvise()`. Limitation: Out-of-memory will be a page fault that cannot be resolved. 2) Explicitly manage different areas in the buddy allocator and allocate/release these areas with `ukvmem`. Much like `mimalloc` works. Very explicit out-of-memory behavior during `malloc` if buddy allocator cannot get additional memory from `ukvmem`. Disadvantage: buddy allocator needs to manage multiple regions (there are linear searches in there). MR: Not sure what the best approach is. If multiple regions, there is overhead in managing multiple regions. SK: You're talking about the buddy allocator being paging-aware? MR: Yes, you could use `madvise()` to release memory for the buddy allocator. SK: Something to keep track of is what regions are mapped and what are not mapped. MR: In buddy allocator, you don't need to. It's totally transparent with the amount of memory you have in the system. If you do it explictly, you can ask to prepopulate entries to have the physical memory. And handle in a more elegant manner if you run out of heap. MR: Maybe it could be that it's more costly, depending on how the buddy allocator works behind the scenes. SK: Personally, I would prefer a more explicitly allocate / deallocate. I wouldn't use the `posix-mmap` API, but I would use the underlying `ukvmem` calls. MR: Currently we do it this way: + When we start with `ukvmem`, we create a large enough virtual memory area so that we can use all physical memory + The buddy allocator splits the heap into chunks of $2^n$ size. Whenever we need to allocate a certain size and there is no chunk of that size, we take a larger block and split it recusively until we have a new chunk of the desired size + However, physical memory is not explicitly assigned. Only on the first access to a page via demand-paging. That means, allocation of physical memory is totally transparent to the buddy allocator. Problem 1: out-of-memory behavior = crash on page fault. Problem 2: physical memory is never released Better way to do it: + At start, still allocate a VMA that is large enough to include all physical memory (already done by `ukboot`) + Within the buddy allocator, we add to the block metadata a flag which indicates if the block has physical memory assigned. The flag must be **inherited** if the block is split. + For a configurable order $x$ (i.e., chunk sizes $>= 2^x$) we say that **no** physical memory should be assigned, except if a block of that size or larger has been directly requested. This is to release physical memory when possible while limiting overhead for assigning and freeing physical memory compared to doing it also for sizes $<2^x$. + At the beginning no physical memory is assigned. When we split a block of size $2^x$, we explicitly call `uk_vma_advise()` with `UK_VMA_ADV_WILLNEED` to one of the buddies (it will have size $2^{x-1}$) to assign physical memory to the region. The call will fail if not enough physical memory can be allocated. Since already some physical memory might have been allocated with the attempted advise, a call to `uk_vma_advise()` with `UK_VMA_ADV_DONTNEED` should follow an error to release any partially allocated physical memory again. On success, the flag for the block can be set, indicating that this block has physical memory assigned. The existing flow of allocation within the buddy allocator continues. + If the call to `uk_vma_advise()` fails since there is not enough physical memory, we can still continue to split the block to the desired block size. However, the flag will indicate that **no** physical memory is allocated yet. + Whenever the buddy allocator gives out a block of memory it checks the new flag and performs a `uk_vma_advise()` with `UK_VMA_ADV_WILLNEED` to make sure physical memory is allocated if the flag is not set. This will implicitly handle proper physical memory allocation for direct heap allocations with sizes $>=2^x$. And it will also enable a second attempt of physical memory allocation with a smaller size when we could not allocate a block of size $2^{x-1}$. In case this `uk_vma_advise()` fails, the heap allocation fails (again do a `UK_VMA_ADV_DONTNEED` on the range to make sure no physical memory is partially allocated to it). + When a heap allocation is freed and two buddies can be merged, we check if the order of the new block is $>=x$. In that case we release the physical memory with `UK_VMA_ADV_DONTNEED`. If only one of the buddies has physical memory assigned, release it no matter the order of the target block. The new block would have the flag **not** set. + HINT: Whenever physical memory is released using `UK_VMA_ADV_DONTNEED`, make sure you do not include the metadata in the freed range SjK: The synchronization PR (476) done. SjK: I did a report on the university. MR: There are multiple layers that need synchronization. One are is the frame allocator, because it will be used by multiple cores. MR: There is also the idea of partitioning memory and leave it out of this hot path. And you can ask at some point for extra memory: steal memory. And synchronize that. MR: The ideas is that, irrespective if you do partitioning or not, you require the `ukvmem` synchronization. ## :wrench: TODOs and Decisions Synchronization PR: https://github.com/unikraft/unikraft/pull/476 MR: Review #476 for release 0.13 RV: Keep an eye for the ukalloc PR: https://github.com/unikraft/unikraft/pull/801 RV: Synchronize `ukvmem`. SjK: Research on frame allocation synchronization on different OSes and research papers.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully