Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:58:11+00:00 2026-06-17T02:58:11+00:00

In Linux kernel source code, there are many memory barrier(smp_mb() and so on). But

  • 0

In Linux kernel source code, there are many memory barrier(smp_mb() and so on).

But in redis’s source,I didn’t see it. In the Makefile of redis, gcc optimize option is -O2, so it should be reorder these instruction. Why it not use mb() for insure the correct behavior?

Added:

For example:
In Linux kernel’s kfifo:

unsigned int __kfifo_put(struct kfifo *fifo,unsigned char *buffer, unsigned int len)   
{   
  unsigned int l;   
  len = min(len, fifo->size - fifo->in + fifo->out);
  smp_mb();
  l = min(len, fifo->size - (fifo->in & (fifo->size - 1)));   
  memcpy(fifo->buffer + (fifo->in & (fifo->size - 1)), buffer, l);
  ...
  smp_wmb();
  fifo->in += len;
  ...
}

In Redis source, I research the whole project, cann’t find memory barriers:
for example:

zskiplistNode *zslInsert(zskiplist *zsl, double score, robj *obj) {
  zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;
  unsigned int rank[ZSKIPLIST_MAXLEVEL];
  int i, level;
  ...
  level = zslRandomLevel();
  if (level > zsl->level) {
    for (i = zsl->level; i < level; i++) {
      rank[i] = 0;
      update[i] = zsl->header;
/////need a mb() ???
      update[i]->level[i].span = zsl->length;
    }
    zsl->level = level;
  }
  ...
}

is it special that why in redis there is no memory barriers?
I think it probably that my understand for mb() is immature, thanks for comment…

added:

But in above two pieces of code displayed, the kfifo in linux kernel uses mb(). it just changes variables allocated in thread’s stack space and also user mb() between r/w operation. So it should not totally relevent to multi-threading… (although redis is single thread)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:58:12+00:00Added an answer on June 17, 2026 at 2:58 am

    Redis is single threaded, so there’s no need for memory barriers.

    They’re only relevant if you have multiple execution paths (e.g. in a multithreaded application). Even with multithreaded user space applications, you would normally not need your own memory barriers, as libraries (e.g. pthreads) contains memory barriers in the synchronization APIs, (such as mutexes, semaphores, condition variables and so on).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in Linux kernel source code, I find below code: h++; pending >>= 1; It
I'm studying linux slab allocation. Following to linux kernel source code mm/slab.c , it
I know that the source code of linux kernel is licensed under GNU GPL
I'm studying about Linux kernel and I have a problem. I see many Linux
I am trying to find the linux 2.4 kernel source code. It seems that
typedef void (*work_func_t)(struct work_struct *work); I found above typedef in Linux kernel source code,
In the Linux kernel source code I found this function: static int __init clk_disable_unused(void)
I recently downloaded new linux kernel source code and compiled on ubuntu. After my
I have some raw open-source code for a modified version of the linux kernel.
I have an ARM kit beside me and a Linux kernel source code patched

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.