idoleat
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: CS Master --- # 111/6/8 meeting: DHASH - Dynamic Hash Tables with Non-blocking Regular Operations ## Introduction * Hash table: an array of buckets * One way of dealing with collision: separate chaining, which uses a list for the nodes with same hash value. * Average length of the list: average load factor * In general cases, given a specified average load factor, hash tables offer the advantage of constant-time lookup operations, such that they have been widely used throughout computer systems. * Most existing hash tables are lacking of robustness. Unable to change hash function while **unable to distribute evenly** (no constant time lookup). * Universal hashing (randomly choosing hash function) only works when input is diverse. * This paper: * Change hash function on the fly for even distribution. No more long traversing on lists. * New size and seed as well $\to$ Dynamic * Prior work: * Only non-blocking for regular operation * When redistributing they used locks per bucket $\to$ blocking * Our work: DHash * a new distributing mechanism that can atomically and efficiently distribute each node without needing to acquire any per-bucket mutex locks * Utilize lock-free and wait-free algorithms for buckets * DHash's rebuilding is scalable and paralleled ## DHash algorithm overview * Hazard period: a short time period during which in neither the hash tables can this node be found. * Use a global pointer for nodes in hazard period * old_ht $\to$ global pointer $\to$ new_ht ![](https://hackmd.io/_uploads/rJoTNEEuc.png) ![](https://hackmd.io/_uploads/HyUA44NOc.png) ## DHash implementation Note: we use RCU as synchronization mechanism. Reference counting and hazard pointer could be used with more engineering efforts. ### Preliminaries * `rcu_read_lock() / rcu_read_unlock()`: defines the read-side critical section. * `synchronize_rcu()`: works as a wait-for-readers barrier * `call_rcu()`: an asynchronous version of `synchronize_rcu()`. Call callback when read-side critical section end. ![](https://hackmd.io/_uploads/H1CgvV4Oq.png) Algorithm 1: Structures and API of DHASH’s bucket. ```c=1 struct node {long key; <node *ptr, flag> next}; /* Has been logically removed by delete operation.*/ #define LOGIC_RM (1UL < < 0) /* Is being distributed by rebuild operation.*/ #define IN_HAZARD (1UL < < 1) struct list {node *head}; struct snapshot {node **prev, *cur, *next}; /* Search the node in list htbp.*/ list_find(list *htbp, key, snapshort *sp) /* Insert node htnp into list htbp.*/ list_insert(list *htbp, node *htnp) /* Search the node in list htbp, set the node’s flag, and try to physically delete the node.*/ list_delete(list *htbp, long key, long flag) ``` **Choice of hash function:** We suggest first utilize some widely-used non-cryptographic hash functions (e.g., Jenkins’ hash function). Or fallback to universal hashing. ### Data structures Algorithm 2: Structures and auxiliary functions. ```c=9 struct ht {ht *ht_new; long (*hash)(long key); int nbuckets; list *bkts[]}; /* Global variables.*/ struct node *rebuild_cur; mutex rebuild_lock; #define logically_removed(htnp) (htnp->next & LOGIC_RM) clean_flag(node *htnp, long flag) { atomic_fetch_and(htnp->next, ∼flag); } ht_alloc(ht *htp, int nbuckets, long (*hash)(long key)) { htp->ht_new := NULL; htp->hash := hash; htp->nbuckets := nbuckets; htp->bkts := allocate(nbuckets); } ``` ### Rebuild operation Algorithm 3: Rebuild operation of DHASH ```c=17 Parameters - nbuckets: Size of the bucket array. hash: User-specified hash function. Local variables - struct node *htnp, *htbp, *htbp_new; struct ht *htp_new; void ht_rebuild(ht *htp, nbuckets, hash) { if ( trylock(rebuild_lock) != SUCCESS ) return -EBUSY; if (!rebuild_is_required()) return -EPERM; htp_new := ht_alloc(htp, nbuckets, hash); htp->ht_new := htp_new; /* Wait for operations not aware of htp_new.*/ synchronize_rcu(); for (each bucket htbp in htp) { for (each node htnp in htbp) { rcu_read_lock(); rebuild_cur := htnp; smp_wmb(); key := htnp->key; if (list_delete(htbp, key, IN_HAZARD)!= SUCCESS)//Hflag continue; clean_flag(htnp, IN_HAZARD)/* unHflag*/ htbp_new := htp_new->bkts[htp_new->hash(key)]; if (list_insert(htbp_new, htnp) != SUCCESS) call_rcu(htnp, free_node); smp_wmb(); rebuild_cur := NULL; rcu_read_unlock(); } } /* Wait for operations accessing nodes via htp->bks[]. */ synchronize_rcu(); htp_tmp := htp; htp := htp_new; /* Wait for operations accessing old hash table.*/ synchronize_rcu(); unlock(rebuild_lock); free(htp_tmp); return SUCCESS; } ``` :::danger 為什麼他不先進入 reader CS 再取得 node reference (line28)? 這樣還要再檢查有沒有被 delete (line33) ::: :::danger > line38 invokes call_rcu(), which reclaims the node after currently unfinished operations pointing to this node have been completed. 如果 node 本來就會被移除那就直接移除就好了吧?幹麻先插入再移除?可能連 rcu_lock() 都不用,只要檢查有沒有被設置 LOGIC_RM,有的話就 `continue` ::: * for each node in bucket * move to `rebuild_cur` * can old be delete? If no, left it for clean_flag * insert to new table * One potential issue: it may redirect lookup operations traversing the old hash table to the wrong lists * Use `bkt_id` to record current bucket id and compare everytime * After deleting, before inserting, invokes a `synchronize_rcu()` to wait all regular operation leave RCU read-side CS. Slow down a bit but no need for extra field and compare. $\to$ we use this cause rebuild is infrequent. ### Lookup operation Algorithm 4: Lookup operation of DHASH. ```c Local variables: struct node *cur, *htbp, *htbp_new; struct ht *htp_new; struct snapshot ss; node *ht_lookup(ht *htp, long key) { htbp := htp->bkts[htp->hash(key)]; if (list_find(htbp, key, &ss) = SUCCESS) { return ss.cur }; if (htp->ht_new = NULL) { return -ENOENT }; smp_rmb(); cur := rebuild_cur; if (cur and (cur->key = key) and !logically_removed(cur)) return cur; smp_rmb(); htp_new := htp->ht_new; htbp_new := htp_new->bkts[htp_new->hash(key)]; if (list_find(htbp_new, key, &ss) = SUCCESS) { return ss.cur }; else return -ENOENT; } ``` * Search in the old table $\to$ global pointer $\to$ new table. * Guarantees that lookup operations can always find the node. $Lemma\space1.$ If DHASH contains a node $\alpha$ with the key value of k, the function `ht_lookup(k)` can find $\alpha$, no matter if a rebuild operation is in progress. $proof.$ We assume that the set algorithm used as the implementation of hash table buckets is linearizable. Therefore, `list_find()`, `list_insert()`, and `list_delete()`, can be treated as atomic operations that take place as "point" events. By inspecting the code of `ht_rebuild()` in algorithm 3, ![](https://hackmd.io/_uploads/r100HrNO5.png) By inspecting the code of `ht_lookup()` in Algorithm 4, ![](https://hackmd.io/_uploads/BydzISVO9.png) When the rebuild and the lookup threads are simultaneously accessing the node $\alpha$, there are three types of interleaving between these two threads: * ![](https://hackmd.io/_uploads/r11D8r4_c.png) * ![](https://hackmd.io/_uploads/r1cPIrNOq.png) * ![](https://hackmd.io/_uploads/Hk2uLS4Oq.png)$insert(new,\alpha)$ Combined with the event sequences 1 and 2, we get the following event sequence: ![](https://hackmd.io/_uploads/H1waIB4_q.png) It follows that ![](https://hackmd.io/_uploads/H1V0Lr4Oq.png) Overall, if there is a node with the matching key in DHASH, it is guaranteed that the function `ht_lookup(k)` can find the node and return a pointer to it, no matter if a rebuild operation is in progress. ### Delete operation Algorithm 5: Delete operation of DHASH. ```c=67 Local variables: struct node *cur, *htbp, *htbp_new; struct ht *htp_new; int ht_delete(ht *htp, long key) { htbp := htp->bkts[htp->hash(key)]; if (list_delete(htbp, key, LOGIC_RM) = SUCCESS)/*Rflag*/ return SUCCESS; htp_new := htp->ht_new; if (htp_new = NULL) return -ENOENT; smp_rmb(); //checking if a rebuild operation is in progress cur := rebuild_cur; while (cur and (cur->key = key)) { cur_next := cur->next; if (cur_next & LOGIC_RM) break; if (cas(cur->next, cur_next, cur_next | LOGIC_RM))/*Rflag*/ return SUCCESS; cur := rebuild_cur; } smp_rmb(); htbp_new := htp_new->bkts[htp_new->hash(key)]; if (list_delete(htbp_new, key, LOGIC_RM) = SUCCESS)/*Rflag*/ return SUCCESS; return -ENOENT; } ``` :::danger 論文提到的 The second stage 實際把 node 移除的 psuedo code 和說明怎麼沒寫?怎麼做的?在什麼時候做的? ::: Challenges of deleting a node: * how to find the node * same logic as `ht_lookup()` * how to delete this node which is concurrently being distributed from the old hash table to the new one by the rebuild operation * Logical/physical delete (Common in concurrent program. Sometimes memory don't even get reclaimed) ![](https://hackmd.io/_uploads/rJKp7UEdc.png) $Lemma\space 2.$ No matter where the node is (either in one of the hash tables, or is referenced by rebuild_cur), a delete operation can successfully delete it by setting its LOGIC_RM bit. $Lemma\space 3.$ If DHASH contains a node α with the key k, the function ht_delete(k) can delete the node α by successfully setting its LOGIC_RM bit, no matter if a rebuild operation is in progress. Flag are all set using $cas$ ### Insert operation Algorithm 6: Insert operation of DHASH. ```c Local variables: node *htnp, *htbp, *htbp_new; ht *htp_new; int ht_insert(ht *htp, long key) { retry: htnp := allocate_node(key); htp_new := htp->ht_new; if (htp_new = NULL) { /* IO(k) */ htbp := htp->bkts[htp->hash(key)]; ret := list_insert_dcss(&htp->htp_new, NULL, htbp, htnp) ; if (ret = SUCCESS) return SUCCESS ; else if (ret = -EADDR1) {free(htnp); goto retry (line 91);} } else { /* IN(k)*/ if (ht_lookup(htp, key) = SUCCESS) {free(htnp); return -EEXIST;} htbp_new := htp_new->bkts[htp_new->hash(key)]; if (list_insert(htbp_new, htnp) = SUCCESS) return SUCCESS; } free(htnp); return -EEXIST; } ``` :::danger 又 `if` 又 `dcss` ? 是不想寫 critical section 嗎?檢查兩遍感覺很多餘 ::: :::info line 102 `ht_lookup()` 只是拿來檢查是否有已經存在的 node,如果用 bloom filter 會不會比較快? ::: * When there are no rebuild operations, which is the common case, DHASH inserts new nodes into the only (i.e., old) hash table * Otherwise, new nodes are inserted into the new hash table * IO(k) and IN(k) may exist simultaneously, such that some synchronization mechanisms are required to prevent IO(k) and IN(k) from inserting duplicate nodes in DHASH. * Once a rebuild operation starts, IO(k) stops, by using `dcss` * An IN(k) first checks if any node with key k already exists in the old hash table or is currently referenced by `rebuild_cur` Lemma 4. Once a rebuild operation has started, IO(k) will fail, start over, and then attempt to insert the node into the new hash table; that is, it becomes IN(k). Lemma 5. When IN(k) attempts to insert a node α with key k into the new hash table on line 103, it is guaranteed that (1) the old hash table does not contain any node with key k , and (2) the node referenced by rebuild_cur does not have the key k . Lemma 6. If DH ASH does not contain a node with key k , the function ht_insert(k) can successfully insert a node α with key k in DH ASH; otherwise, the error message `-EEXIST` is returned without changing the hash table, no matter if a rebuild operation is in progress. Overall, DH ASH always attempts to insert new nodes into either the old or the new hash table, depending on whether rebuild operation are absent, ### Parallelizing rebuild operation * Use multiple thread to rebuild. Different bucket can be processed in parallel. * bucket b is assigned to the rebuilding thread i if b % n = i. * rebuild_cur becomes a global, per-thread variable; * To check rebuild_cur, it checks the rebuild_cur pointers of all rebuilding threads. ## Correctness We first prove that DHASH is linearizable to this sequential specification. That is, each of DHASH’s regular operations has specific linearization points, where the operation takes effect and maps the operation in our concurrent implementation to sequential operations so that the histories meet the specification. ### Linearization point 1. Every lookup operation that finds the node with the expected key via `rebuild_cur`, or in the old or the new hash table. We linearize the unsuccessful lookup operation within its execution interval at: * the point immediately before a new node with the expected key is inserted into the old hash table * the point where the search on the new hash table returns -ENOENT 2. every successful delete operation that finds the node with the required key via lookup 3. Every successful IN(k) linearizes in the invocation of `list_insert()`. Unsuccessful IN(k) linearizes on line 101 or 103, depending on where the existing node with the required key is found. $Theorem 1$ DHASH is a linearizable implementation of a sequential set object. **Progress guarantee:** The lookup, insert, and delete operations of DH ASH are non-blocking and can provide lock-free or wait-free progress guarantee, depending on the underlying set algorithm used. * list_find() * list_delete() * list_insert() * call_rcu() In summary, DHASH provides a wait-free framework for regular operations. For the implementation of DHASH utilizing Michael’s lock-free linked list, the lookup, insert, and delete operations are lock-free. However, since DHASH is modular, programmers can instead choose a wait-free linked list and build their own DHASH that provides a stronger progress guarantee. ## Evaluation We want to show DHASH's robustness, efficiency, and scalability. 1. DHASH’s rebuild operation is effective 2. DHASH’s rebuild operation is lightweight and does not noticeably degrade system performance in terms of throughput and response time of concurrent regular operations 3. DHASH’s rebuild operation is fast and scalable * Initial array size 1k, max 64k * An attacker thread continuously insert nodes at 300/s * If list length is larger than the threshold (32), rebuild. ### Effects of Rebuilding ![](https://hackmd.io/_uploads/r1XJ-UE_q.png) ![](https://hackmd.io/_uploads/rJbAgLEOc.png) ### DHash performance * throughput * response time ### Rebuilding efficiency ![](https://hackmd.io/_uploads/SJdEb8VOq.png) ![](https://hackmd.io/_uploads/BkfHb8Nd9.png) ## Conclusion * The core of DH ASH is a novel distributing mechanism that is atomic, non-blocking, and efficient in distributing every node from the old hash table to the new one. * Experimental results indicate that DH ASH is the algorithm of choice for operating systems and applications under service-level agreement (SLA) contracts. ### 鳴謝 * We thank Pedro Ramalhete and ==Paul E. McKenney==, whose detailed suggestions greatly improved this paper. * OSU Open Source Lab and Packet Incorporation for allowing us to access the 16-core PowerPC and the ==96-core ARM64== servers.

    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