Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. C++ & Thinking about SSD & wear level

C++ & Thinking about SSD & wear level

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++comdata-structuresjsontutorial
10 Posts 4 Posters 24 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • raddevusR Online
    raddevusR Online
    raddevus
    wrote on last edited by
    #1

    I was thinking about the SSD in my wife's laptop. 120GB and it's been running for 4-5 years. Kind of fell down a rabbit hole... A Windows App?: Not really I started looking for apps to tell me the situation. Found an article that explains some things: Find out how much longer your SSD will last - CNET[^] The article mentions this app: Crystal Disk Mark -- not great[^] All Comes Down to Reads & Writes Basically the article tells you that most likely it will take you 15 years to wear a good SSD out so don't worry too much. Found Some Sample Code Then I found a sample program that makes some API calls and tells you how many bytes you've read and written since the OS was started. Here's the output for my wife's computer that has been running for over 16 days without rebooting: http://i.stack.imgur.com/3jTsD.png[^] Compare those read/write bytes to mine that has only been running[^] for a little over 2 hours. Here's the code (alterations by me) from c++ - How to get global Windows I/O statistics? - Stack Overflow[^] NOTE: hard-coded to check only the C:\ drive Update: Updated method to display the number of days computer has been running.

    #include #include #include #include std::__cxx11::string displayValue(LONGLONG);
    void getOsRunTime();

    int main() {
    HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
    FILE_READ_ATTRIBUTES,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    0,
    NULL);

    DISK\_PERFORMANCE disk\_info { };
    
    P D D 4 Replies Last reply
    0
    • raddevusR raddevus

      I was thinking about the SSD in my wife's laptop. 120GB and it's been running for 4-5 years. Kind of fell down a rabbit hole... A Windows App?: Not really I started looking for apps to tell me the situation. Found an article that explains some things: Find out how much longer your SSD will last - CNET[^] The article mentions this app: Crystal Disk Mark -- not great[^] All Comes Down to Reads & Writes Basically the article tells you that most likely it will take you 15 years to wear a good SSD out so don't worry too much. Found Some Sample Code Then I found a sample program that makes some API calls and tells you how many bytes you've read and written since the OS was started. Here's the output for my wife's computer that has been running for over 16 days without rebooting: http://i.stack.imgur.com/3jTsD.png[^] Compare those read/write bytes to mine that has only been running[^] for a little over 2 hours. Here's the code (alterations by me) from c++ - How to get global Windows I/O statistics? - Stack Overflow[^] NOTE: hard-coded to check only the C:\ drive Update: Updated method to display the number of days computer has been running.

      #include #include #include #include std::__cxx11::string displayValue(LONGLONG);
      void getOsRunTime();

      int main() {
      HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
      FILE_READ_ATTRIBUTES,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      0,
      NULL);

      DISK\_PERFORMANCE disk\_info { };
      
      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      What ARE you guys doing? Writing over 1GB/hr! My linux laptops (not doing a lot, I admit) are running much much less than that. (sorry I had a bit of a hiccup getting reliable stats. I'll update a bit later.) Installing Audacity on one (and running it a bit) put a 150MB/50MB lump in its stats. Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      raddevusR 1 Reply Last reply
      0
      • P Peter_in_2780

        What ARE you guys doing? Writing over 1GB/hr! My linux laptops (not doing a lot, I admit) are running much much less than that. (sorry I had a bit of a hiccup getting reliable stats. I'll update a bit later.) Installing Audacity on one (and running it a bit) put a 150MB/50MB lump in its stats. Cheers, Peter

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        raddevusR Online
        raddevusR Online
        raddevus
        wrote on last edited by
        #3

        Peter_in_2780 wrote:

        What ARE you guys doing? Writing over 1GB/hr!

        I know. It's crazy on Win10. I run Win10 on this new laptop but I run Ubuntu 20.04 on my main desktop that I use daily and it performs so much better than win10. Win10 reads and writes to disk constantly. Check it out. Here's an updated snapshot of what my laptop has done since that last one[^]. I haven't even been on this laptop for hours now, but it's written another 1.1GB and read another 1GB. I noticed this with Win10 when it first came out because I could no longer run an HDD -- win10 eats so much I/O that the machine would get overwhelmed. Had to switch to SSDs or win10 kills performance.

        D 1 Reply Last reply
        0
        • raddevusR raddevus

          Peter_in_2780 wrote:

          What ARE you guys doing? Writing over 1GB/hr!

          I know. It's crazy on Win10. I run Win10 on this new laptop but I run Ubuntu 20.04 on my main desktop that I use daily and it performs so much better than win10. Win10 reads and writes to disk constantly. Check it out. Here's an updated snapshot of what my laptop has done since that last one[^]. I haven't even been on this laptop for hours now, but it's written another 1.1GB and read another 1GB. I noticed this with Win10 when it first came out because I could no longer run an HDD -- win10 eats so much I/O that the machine would get overwhelmed. Had to switch to SSDs or win10 kills performance.

          D Offline
          D Offline
          David ONeil
          wrote on last edited by
          #4

          How much memory do you have on the box? If 8 GB or less, probably doing a lot of swapping to disk as part of the figures you are seeing.

          The Science of King David's Court | Object Oriented Programming with C++

          raddevusR 1 Reply Last reply
          0
          • D David ONeil

            How much memory do you have on the box? If 8 GB or less, probably doing a lot of swapping to disk as part of the figures you are seeing.

            The Science of King David's Court | Object Oriented Programming with C++

            raddevusR Online
            raddevusR Online
            raddevus
            wrote on last edited by
            #5

            16GB on mine and 8GB checked hers and it is actually 4GB. Here are the updated stats on mine after sitting idle all night[^].

            1 Reply Last reply
            0
            • raddevusR raddevus

              I was thinking about the SSD in my wife's laptop. 120GB and it's been running for 4-5 years. Kind of fell down a rabbit hole... A Windows App?: Not really I started looking for apps to tell me the situation. Found an article that explains some things: Find out how much longer your SSD will last - CNET[^] The article mentions this app: Crystal Disk Mark -- not great[^] All Comes Down to Reads & Writes Basically the article tells you that most likely it will take you 15 years to wear a good SSD out so don't worry too much. Found Some Sample Code Then I found a sample program that makes some API calls and tells you how many bytes you've read and written since the OS was started. Here's the output for my wife's computer that has been running for over 16 days without rebooting: http://i.stack.imgur.com/3jTsD.png[^] Compare those read/write bytes to mine that has only been running[^] for a little over 2 hours. Here's the code (alterations by me) from c++ - How to get global Windows I/O statistics? - Stack Overflow[^] NOTE: hard-coded to check only the C:\ drive Update: Updated method to display the number of days computer has been running.

              #include #include #include #include std::__cxx11::string displayValue(LONGLONG);
              void getOsRunTime();

              int main() {
              HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
              FILE_READ_ATTRIBUTES,
              FILE_SHARE_READ | FILE_SHARE_WRITE,
              NULL,
              OPEN_EXISTING,
              0,
              NULL);

              DISK\_PERFORMANCE disk\_info { };
              
              D Offline
              D Offline
              David ONeil
              wrote on last edited by
              #6

              Is std::__cxx11 a GCC-only namespace? I've never seen it used in Visual Studio, and it gives an error.

              The Science of King David's Court | Object Oriented Programming with C++

              raddevusR 1 Reply Last reply
              0
              • D David ONeil

                Is std::__cxx11 a GCC-only namespace? I've never seen it used in Visual Studio, and it gives an error.

                The Science of King David's Court | Object Oriented Programming with C++

                raddevusR Online
                raddevusR Online
                raddevus
                wrote on last edited by
                #7

                It probably is. My C/C++ skills are very rusty and I was just trying the quickest way to return a string and found that type. Sorry for the inconvenience. I didn't want to install Visual Studio on my machine so I'm using Visual Studio Code and MinGW. I kind of blindly stumbled my way through to get that code working. :-O

                David O'Neil wrote:

                Is std::__cxx11 a GCC-only namespace?

                1 Reply Last reply
                0
                • raddevusR raddevus

                  I was thinking about the SSD in my wife's laptop. 120GB and it's been running for 4-5 years. Kind of fell down a rabbit hole... A Windows App?: Not really I started looking for apps to tell me the situation. Found an article that explains some things: Find out how much longer your SSD will last - CNET[^] The article mentions this app: Crystal Disk Mark -- not great[^] All Comes Down to Reads & Writes Basically the article tells you that most likely it will take you 15 years to wear a good SSD out so don't worry too much. Found Some Sample Code Then I found a sample program that makes some API calls and tells you how many bytes you've read and written since the OS was started. Here's the output for my wife's computer that has been running for over 16 days without rebooting: http://i.stack.imgur.com/3jTsD.png[^] Compare those read/write bytes to mine that has only been running[^] for a little over 2 hours. Here's the code (alterations by me) from c++ - How to get global Windows I/O statistics? - Stack Overflow[^] NOTE: hard-coded to check only the C:\ drive Update: Updated method to display the number of days computer has been running.

                  #include #include #include #include std::__cxx11::string displayValue(LONGLONG);
                  void getOsRunTime();

                  int main() {
                  HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
                  FILE_READ_ATTRIBUTES,
                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                  NULL,
                  OPEN_EXISTING,
                  0,
                  NULL);

                  DISK\_PERFORMANCE disk\_info { };
                  
                  D Offline
                  D Offline
                  David ONeil
                  wrote on last edited by
                  #8

                  Here's a version without the GCC specific code, and a more C++ approach to the thousands separator (not that I care for that - I always have to look it up and it is a pain). For those who use it, you will need to set your project to Multi-byte.

                  #include <windows.h>
                  #include <iostream>
                  #include <locale>
                  #include <sysinfoapi.h>

                  void getOsRunTime();

                  struct threes : std::numpunct<char> {
                  std::string do_grouping() const { return "\3"; }
                  // note: comma is provided by std::numpunct<char>
                  };

                  int main() {
                  HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
                  FILE_READ_ATTRIBUTES,
                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                  NULL,
                  OPEN_EXISTING,
                  0,
                  NULL);

                  DISK\_PERFORMANCE disk\_info { };
                  DWORD bytes;
                  
                  if (dev == INVALID\_HANDLE\_VALUE) {
                      std::cerr << "Error opening disk\\n";
                      return 1;
                  }
                  
                  if (!DeviceIoControl(dev, 
                          IOCTL\_DISK\_PERFORMANCE, 
                          NULL, 
                          0, 
                          &disk\_info, 
                          sizeof(disk\_info), 
                          &bytes, 
                          NULL))
                  {
                      std::cerr << "Failure in DeviceIoControl\\n";
                      return 1;
                  }
                  std::cout.imbue(std::locale(std::cout.getloc(), new threes));
                  std::cout << "Bytes read: " << disk\_info.BytesRead.QuadPart << "\\n";
                  std::cout << "Bytes read: " << disk\_info.BytesRead.QuadPart << "\\n";
                  std::cout << "Bytes written: " << disk\_info.BytesWritten.QuadPart << "\\n";
                  getOsRunTime();
                  

                  }

                  void getOsRunTime(){
                  ULONGLONG milli = GetTickCount64();
                  //3600000 milliseconds in an hour
                  long days = milli / (ULONGLONG)(3600000 *24);
                  milli = milli - ((ULONGLONG)3600000 *24) * days;
                  long hr = milli / 3600000;
                  milli = milli - (ULONGLONG)3600000 * hr;
                  //60000 milliseconds in a minute
                  long min = milli / 60000;
                  milli = milli - (ULONGLONG)60000 * min;

                  //1000 milliseconds in a second
                  long sec = milli / 1000;
                  milli = milli - (ULONGLONG)1000 \* sec;
                  std::cout << "OS has been running " << days << " days " << hr << " hours " << min << " minutes " << sec << " seconds " << milli << " ms." << std::endl;
                  

                  }

                  The Science of King David's Court |

                  raddevusR 1 Reply Last reply
                  0
                  • D David ONeil

                    Here's a version without the GCC specific code, and a more C++ approach to the thousands separator (not that I care for that - I always have to look it up and it is a pain). For those who use it, you will need to set your project to Multi-byte.

                    #include <windows.h>
                    #include <iostream>
                    #include <locale>
                    #include <sysinfoapi.h>

                    void getOsRunTime();

                    struct threes : std::numpunct<char> {
                    std::string do_grouping() const { return "\3"; }
                    // note: comma is provided by std::numpunct<char>
                    };

                    int main() {
                    HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
                    FILE_READ_ATTRIBUTES,
                    FILE_SHARE_READ | FILE_SHARE_WRITE,
                    NULL,
                    OPEN_EXISTING,
                    0,
                    NULL);

                    DISK\_PERFORMANCE disk\_info { };
                    DWORD bytes;
                    
                    if (dev == INVALID\_HANDLE\_VALUE) {
                        std::cerr << "Error opening disk\\n";
                        return 1;
                    }
                    
                    if (!DeviceIoControl(dev, 
                            IOCTL\_DISK\_PERFORMANCE, 
                            NULL, 
                            0, 
                            &disk\_info, 
                            sizeof(disk\_info), 
                            &bytes, 
                            NULL))
                    {
                        std::cerr << "Failure in DeviceIoControl\\n";
                        return 1;
                    }
                    std::cout.imbue(std::locale(std::cout.getloc(), new threes));
                    std::cout << "Bytes read: " << disk\_info.BytesRead.QuadPart << "\\n";
                    std::cout << "Bytes read: " << disk\_info.BytesRead.QuadPart << "\\n";
                    std::cout << "Bytes written: " << disk\_info.BytesWritten.QuadPart << "\\n";
                    getOsRunTime();
                    

                    }

                    void getOsRunTime(){
                    ULONGLONG milli = GetTickCount64();
                    //3600000 milliseconds in an hour
                    long days = milli / (ULONGLONG)(3600000 *24);
                    milli = milli - ((ULONGLONG)3600000 *24) * days;
                    long hr = milli / 3600000;
                    milli = milli - (ULONGLONG)3600000 * hr;
                    //60000 milliseconds in a minute
                    long min = milli / 60000;
                    milli = milli - (ULONGLONG)60000 * min;

                    //1000 milliseconds in a second
                    long sec = milli / 1000;
                    milli = milli - (ULONGLONG)1000 \* sec;
                    std::cout << "OS has been running " << days << " days " << hr << " hours " << min << " minutes " << sec << " seconds " << milli << " ms." << std::endl;
                    

                    }

                    The Science of King David's Court |

                    raddevusR Online
                    raddevusR Online
                    raddevus
                    wrote on last edited by
                    #9

                    That's great stuff. Thanks for sharing. I also cleaned up the code and made it so you can provide a drive letter (just the letter) as a command-line arg and it will scan the drive. Unfortunately I couldn't get it quite right for mapped drives, there is something odd there. Also I now use std::string as I should. You can get the code at my github repo: GitHub - raddevus/wearlevel: wearlevel project that checks 1) how long OS has been running, 2) how many bytes read and written during uptime.[^] Also, here's one more thing. I put a micro sd card in the laptop slot and ran it on d:

                    c:\>wearlevel d

                    See the snapshot[^]. Interesting that windows writes 61,440 bytes to the newly attached drive. And, oh yeah, 61440 / 4096 = 15. But I have no idea why or what that means. :~

                    1 Reply Last reply
                    0
                    • raddevusR raddevus

                      I was thinking about the SSD in my wife's laptop. 120GB and it's been running for 4-5 years. Kind of fell down a rabbit hole... A Windows App?: Not really I started looking for apps to tell me the situation. Found an article that explains some things: Find out how much longer your SSD will last - CNET[^] The article mentions this app: Crystal Disk Mark -- not great[^] All Comes Down to Reads & Writes Basically the article tells you that most likely it will take you 15 years to wear a good SSD out so don't worry too much. Found Some Sample Code Then I found a sample program that makes some API calls and tells you how many bytes you've read and written since the OS was started. Here's the output for my wife's computer that has been running for over 16 days without rebooting: http://i.stack.imgur.com/3jTsD.png[^] Compare those read/write bytes to mine that has only been running[^] for a little over 2 hours. Here's the code (alterations by me) from c++ - How to get global Windows I/O statistics? - Stack Overflow[^] NOTE: hard-coded to check only the C:\ drive Update: Updated method to display the number of days computer has been running.

                      #include #include #include #include std::__cxx11::string displayValue(LONGLONG);
                      void getOsRunTime();

                      int main() {
                      HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"),
                      FILE_READ_ATTRIBUTES,
                      FILE_SHARE_READ | FILE_SHARE_WRITE,
                      NULL,
                      OPEN_EXISTING,
                      0,
                      NULL);

                      DISK\_PERFORMANCE disk\_info { };
                      
                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #10

                      If you're just concerned about how close your SSD thinks it is to being worn out any diagnostic tool that can pull SMART values can give the wear out value.

                      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups