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 7443467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:02+00:00 2026-05-29T11:20:02+00:00

I have just read the ‘dict.c’ source code file of dict implementation. I have

  • 0

I have just read the ‘dict.c’ source code file of dict implementation. I have got the literal difference between safe/non-safe dict iterator, but don’t yet understand the intent of why introducing the new concept of non-safe iterator.

It’s said by google that ‘the new iterator may perform less useless COW’. But I fail to figure out how it works, so turn to here for help.

Appreciate for any help, an explanation with example would be better.

  • 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-05-29T11:20:03+00:00Added an answer on May 29, 2026 at 11:20 am

    The purpose of safe/non safe iterators is to clearly establish whether iteration occurs on a mutable or immutable data structure. In the dict implementation, it prevents some operations (rehashing for instance) to be done on the dictionary when a safe iteration is on-going.

    Now safe iterators have a downside: they need to increment a reference counter in the iterated object itself, so that the object knows whether safe iteration occurs or not.

    Redis leverages the OS copy-on-write (COW) mechanism to deal with background dump. When a dump occurs, fork is called to clone the Redis instance and create a second process. This process will iterate on the whole data to serialize everything into the dump file. Thanks to the COW mechanism, most pages are shared across the two processes, so Redis does not take twice the RAM while it is dumping the data.

    Now the pages are only shared if they are accessed in read-only mode. When one of the two processes writes something in memory, the corresponding page is automatically duplicated by the OS.

    If a safe iterator was systematically used to iterate on all dictionaries, plenty of pages would be duplicated (because of the reference counter updates). In the cloned process, the data are considered immutable, so using an unsafe iterator makes sense to reduce COW activity. This is mostly relevant when you have a lot of set/hash/zset objects in Redis.

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

Sidebar

Related Questions

I have just read about Guava and checked out its source code but don't
I just got Delphi 2009 and have previously read some articles about modifications that
I have just read this question: Could this code damage my processor? and this
I have just read this interesting article about the implementation details for various languages
In Python, I have just read a line form a text file and I'd
I have just read the following code but do not understand why there is
I have just read the following post on SO; Do you source control your
i have just started using Moq ver (3.1) and i have read blogs and
I have just switched from svn to mercurial and have read some tutorials about
I am new to Java. I just read that class variables in Java have

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.