<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akshay Siwal</title>
    <description>The latest articles on DEV Community by Akshay Siwal (@akshaysiwal).</description>
    <link>https://dev.to/akshaysiwal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F228543%2Fd8cb2c15-fd7e-4500-9564-c9781ab75bfe.png</url>
      <title>DEV Community: Akshay Siwal</title>
      <link>https://dev.to/akshaysiwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akshaysiwal"/>
    <language>en</language>
    <item>
      <title>Interview Question: How to Analyze iostat Output</title>
      <dc:creator>Akshay Siwal</dc:creator>
      <pubDate>Tue, 17 Dec 2024 21:04:54 +0000</pubDate>
      <link>https://dev.to/akshaysiwal/interview-question-how-to-analyze-iostat-output-54lm</link>
      <guid>https://dev.to/akshaysiwal/interview-question-how-to-analyze-iostat-output-54lm</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Scenario:&lt;/strong&gt; Diagnosing Disk I/O Latency
&lt;/h2&gt;

&lt;p&gt;You suspect that a disk is experiencing high latency during peak traffic. To monitor real-time disk performance, you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iostat &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; 5 3  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;avg-cpu:  %user   %nice %system %iowait  %steal   %idle  
           1.50    0.00    0.40    0.10    0.00   98.00  

Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  
sda                 0.00     1.00    10.00   20.00     0.50     1.00    100.00     0.50   25.00    20.00    30.00   5.00   15.00  

avg-cpu:  %user   %nice %system %iowait  %steal   %idle  
           2.00    0.00    0.50    0.20    0.00   97.30  

Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  
sda                 0.00     2.00    15.00   25.00     0.75     1.25    120.00     0.60   30.00    25.00    35.00   6.00   20.00  

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is iostat?
&lt;/h2&gt;

&lt;p&gt;iostat is a Linux/Unix command-line utility that provides detailed statistics about CPU usage and input/output (I/O) performance of storage devices (disks, partitions, or logical volumes). It is part of the sysstat package and is widely used by system administrators and SREs to diagnose performance bottlenecks related to disk I/O and CPU utilization.&lt;/p&gt;

&lt;p&gt;Let’s go through the full output of iostat step by step, explaining each section and metric in detail..&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Command Used&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iostat &lt;span class="nt"&gt;-x&lt;/span&gt; 5 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-x&lt;/code&gt;&lt;/strong&gt;: Displays extended statistics for devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;5&lt;/code&gt;&lt;/strong&gt;: Interval in seconds between reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;2&lt;/code&gt;&lt;/strong&gt;: Number of reports (including the first one).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Example Output&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Linux 5.15.0-73-generic (hostname)   12/18/2024  _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.50    0.00    1.00    5.00    0.00   91.50

Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util
sda                 0.00     1.00    10.00   20.00     0.50     1.00    100.00     0.50   25.00    20.00    30.00   5.00   15.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.00    0.00    1.50    4.00    0.00   91.50

Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util
sda                 0.00     2.00    15.00   25.00     0.75     1.25    120.00     0.60   30.00    25.00    35.00   6.00   20.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Section 1: CPU Statistics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first section of the output shows &lt;strong&gt;CPU utilization&lt;/strong&gt; metrics.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Header:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avg-cpu:  %user   %nice %system %iowait  %steal   %idle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Metrics Explained:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;%user&lt;/strong&gt;: Percentage of CPU time spent on user processes (non-kernel processes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%nice&lt;/strong&gt;: Percentage of CPU time spent on user processes with a "nice" priority (low-priority tasks).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%system&lt;/strong&gt;: Percentage of CPU time spent on kernel/system processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%iowait&lt;/strong&gt;: Percentage of CPU time spent waiting for I/O operations (e.g., disk or network) to complete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%steal&lt;/strong&gt;: Percentage of CPU time "stolen" by the hypervisor for other virtual machines (in virtualized environments).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%idle&lt;/strong&gt;: Percentage of CPU time spent idle (not doing any work).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Example:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.50    0.00    1.00    5.00    0.00   91.50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interpretation:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;2.5% of the CPU is being used by user processes.&lt;/li&gt;
&lt;li&gt;1% is being used by system/kernel processes.&lt;/li&gt;
&lt;li&gt;5% of the CPU is waiting for I/O operations to complete (this is significant and could indicate a disk bottleneck).&lt;/li&gt;
&lt;li&gt;91.5% of the CPU is idle, meaning there is plenty of CPU capacity available.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Section 2: Device I/O Statistics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The second section provides detailed statistics for each storage device (e.g., &lt;code&gt;/dev/sda&lt;/code&gt;).&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Header:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Metrics Explained:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Device&lt;/strong&gt;: The name of the storage device (e.g., &lt;code&gt;sda&lt;/code&gt;, &lt;code&gt;nvme0n1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rrqm/s&lt;/strong&gt;: The number of read requests merged per second. If multiple read requests are queued for the same block, they are merged into one request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wrqm/s&lt;/strong&gt;: The number of write requests merged per second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;r/s&lt;/strong&gt;: The number of read requests completed per second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w/s&lt;/strong&gt;: The number of write requests completed per second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rMB/s&lt;/strong&gt;: The amount of data read from the device per second (in megabytes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wMB/s&lt;/strong&gt;: The amount of data written to the device per second (in megabytes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;avgrq-sz&lt;/strong&gt;: The average size of I/O requests (in sectors). Larger values indicate larger I/O operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;avgqu-sz&lt;/strong&gt;: The average number of I/O requests in the queue. Higher values indicate more queuing and potential contention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;await&lt;/strong&gt;: The average time (in milliseconds) for I/O requests to be completed, including both queue time and service time.

&lt;ul&gt;
&lt;li&gt;High &lt;code&gt;await&lt;/code&gt; values indicate that I/O operations are taking too long, which could be due to disk contention or slow storage.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;r_await&lt;/strong&gt;: The average time (in milliseconds) for read requests to be completed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w_await&lt;/strong&gt;: The average time (in milliseconds) for write requests to be completed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;svctm&lt;/strong&gt;: The average service time (in milliseconds) for I/O requests. This is the time the device spends servicing requests, excluding queue time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%util&lt;/strong&gt;: The percentage of time the device was busy handling I/O requests. If this value is close to 100%, the device is saturated and may be a bottleneck.&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Example:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util
sda                 0.00     1.00    10.00   20.00     0.50     1.00    100.00     0.50   25.00    20.00    30.00   5.00   15.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interpretation:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;rrqm/s&lt;/strong&gt; and &lt;strong&gt;wrqm/s&lt;/strong&gt;: Very low values (0.00 and 1.00), meaning there is little merging of I/O requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;r/s&lt;/strong&gt; and &lt;strong&gt;w/s&lt;/strong&gt;: The device is handling 10 read requests and 20 write requests per second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rMB/s&lt;/strong&gt; and &lt;strong&gt;wMB/s&lt;/strong&gt;: The device is reading 0.5 MB/s and writing 1 MB/s.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;avgrq-sz&lt;/strong&gt;: The average request size is 100 sectors (50 KB per request, as 1 sector = 512 bytes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;avgqu-sz&lt;/strong&gt;: The average queue size is 0.5, meaning there is some queuing but not excessive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;await&lt;/strong&gt;: The average time for I/O requests is 25 ms, which is relatively high and could indicate a performance issue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;r_await&lt;/strong&gt;: Read requests take 20 ms on average.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w_await&lt;/strong&gt;: Write requests take 30 ms on average.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;svctm&lt;/strong&gt;: The service time is 5 ms, meaning the device itself is fast, but the queuing time is causing delays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%util&lt;/strong&gt;: The device is 15% utilized, so it is not saturated.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Second Report&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The second report shows updated statistics after 5 seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util
sda                 0.00     2.00    15.00   25.00     0.75     1.25    120.00     0.60   30.00    25.00    35.00   6.00   20.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Changes:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;r/s&lt;/strong&gt; and &lt;strong&gt;w/s&lt;/strong&gt;: Read and write requests have increased to 15 and 25 per second, respectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rMB/s&lt;/strong&gt; and &lt;strong&gt;wMB/s&lt;/strong&gt;: Read and write throughput have increased to 0.75 MB/s and 1.25 MB/s.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;await&lt;/strong&gt;: The average time for I/O requests has increased to 30 ms, indicating worsening performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%util&lt;/strong&gt;: The device utilization has increased to 20%, meaning the disk is busier.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;How to Use This Data&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;High &lt;code&gt;await&lt;/code&gt; and &lt;code&gt;%util&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;await&lt;/code&gt; is high and &lt;code&gt;%util&lt;/code&gt; is close to 100%, the disk is likely a bottleneck.&lt;/li&gt;
&lt;li&gt;Solution: Upgrade to faster storage (e.g., SSDs) or optimize the application to reduce disk I/O.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;High &lt;code&gt;avgqu-sz&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;avgqu-sz&lt;/code&gt; is high, it indicates queuing, which could be due to contention or insufficient IOPS.&lt;/li&gt;
&lt;li&gt;Solution: Increase IOPS (e.g., provisioned IOPS on AWS EBS) or reduce the number of concurrent I/O operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Low &lt;code&gt;svctm&lt;/code&gt; but High &lt;code&gt;await&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;svctm&lt;/code&gt; is low but &lt;code&gt;await&lt;/code&gt; is high, the delay is in the queue rather than the device itself.&lt;/li&gt;
&lt;li&gt;Solution: Investigate the application or workload causing excessive I/O.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;High &lt;code&gt;r_await&lt;/code&gt; or &lt;code&gt;w_await&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If read or write latency is significantly higher than the other, it could indicate a specific issue with read or write operations.&lt;/li&gt;
&lt;li&gt;Solution: Optimize the workload (e.g., caching for reads, batching for writes).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;iostat&lt;/code&gt; command provides a wealth of information about CPU and disk performance. By understanding the metrics and their relationships, you can diagnose performance bottlenecks and take corrective actions. In this example, the high &lt;code&gt;await&lt;/code&gt; values and increasing &lt;code&gt;%util&lt;/code&gt; suggest that the disk is becoming a bottleneck, and further investigation or optimization is needed.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tech Interview Series: What Happens When You malloc 2 GB but Don't Use It?</title>
      <dc:creator>Akshay Siwal</dc:creator>
      <pubDate>Tue, 17 Dec 2024 14:41:23 +0000</pubDate>
      <link>https://dev.to/akshaysiwal/tech-interview-series-what-happens-when-you-malloc-2-gb-but-dont-use-it-2m4c</link>
      <guid>https://dev.to/akshaysiwal/tech-interview-series-what-happens-when-you-malloc-2-gb-but-dont-use-it-2m4c</guid>
      <description>&lt;h2&gt;
  
  
  What Happens When You malloc 2 GB but Don’t Use It?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;malloc&lt;/code&gt; reserves virtual memory, not physical memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you call &lt;code&gt;malloc(2GB)&lt;/code&gt;, the operating system reserves 2 GB of address space for your process in the virtual memory.&lt;/li&gt;
&lt;li&gt;No physical RAM is allocated yet because you haven’t accessed (touched) the memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;RES&lt;/code&gt; and &lt;code&gt;VIRT&lt;/code&gt; behavior:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;VIRT&lt;/code&gt; will increase by 2 GB because the reserved memory adds to your process's virtual address space.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RES&lt;/code&gt; will not increase at this point because physical memory (RAM) has not been allocated.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When does &lt;code&gt;RES&lt;/code&gt; increase?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Physical memory is only allocated when you touch (read/write) the memory.

&lt;ul&gt;
&lt;li&gt;For example, if you write to a page of the allocated memory, the kernel will allocate a physical RAM page to your process. This will reflect in the &lt;code&gt;RES&lt;/code&gt; size.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Question:
&lt;/h2&gt;

&lt;p&gt;If I malloc &lt;code&gt;2 GB&lt;/code&gt; of memory but don’t use it (i.e., the &lt;code&gt;pages&lt;/code&gt; are allocated virtually but not yet touched), will it count toward the &lt;code&gt;RES&lt;/code&gt; (resident memory)? And since the memory hasn't been touched, can other processes still use that space?&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. If I &lt;code&gt;malloc&lt;/code&gt; 2 GB and do not use it, will it be counted in &lt;code&gt;RES&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No, it will not be counted in &lt;code&gt;RES&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you call &lt;code&gt;malloc(2GB)&lt;/code&gt;, the operating system reserves virtual address space for the requested memory.&lt;/li&gt;
&lt;li&gt;However, &lt;strong&gt;no physical memory (RAM) is allocated&lt;/strong&gt; until you actually access or "touch" those pages.&lt;/li&gt;
&lt;li&gt;This is due to the &lt;strong&gt;lazy allocation strategy&lt;/strong&gt; used by modern operating systems. Pages are only backed by physical memory (loaded into RAM) when they are accessed for the first time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;code&gt;top&lt;/code&gt; command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;VIRT&lt;/code&gt; will increase by 2 GB because the virtual memory address space has been reserved.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RES&lt;/code&gt; will remain unchanged because no physical memory is used yet.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;2. What happens when you “touch” the memory?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first time you write to a page in the allocated memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The operating system generates a &lt;strong&gt;page fault&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It assigns a physical page (RAM) to the virtual address space.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;That page now counts towards the RES value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, &lt;strong&gt;RES only grows as you actually use the memory&lt;/strong&gt;.&lt;/p&gt;





&lt;p&gt;&lt;strong&gt;3. Can other processes use the unallocated memory (from &lt;code&gt;malloc&lt;/code&gt;)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, absolutely.&lt;/p&gt;

&lt;p&gt;Here’s why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you call &lt;code&gt;malloc&lt;/code&gt;, you are only &lt;strong&gt;reserving virtual address space&lt;/strong&gt; in your process. The physical memory (RAM) is &lt;strong&gt;not yet allocated&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Since the physical RAM is &lt;strong&gt;not committed&lt;/strong&gt; to your process, it remains &lt;strong&gt;free for other processes&lt;/strong&gt; to use.&lt;/li&gt;
&lt;li&gt;Until you “touch” the memory (write to it), the operating system doesn’t allocate RAM to it.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Analogy to Simplify
&lt;/h2&gt;

&lt;p&gt;Think of the OS as a hotel manager and memory as rooms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Address Space:&lt;/strong&gt; You’ve “booked” 2 GB of rooms (via malloc), but the hotel manager only writes your name in the reservation book.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Physical Memory:&lt;/strong&gt; Rooms in the hotel (RAM). The manager doesn’t hand over any rooms to you yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Touching Memory:&lt;/strong&gt; When you enter the rooms (write to the memory), the manager actually allocates rooms (physical memory) for you.&lt;/li&gt;
&lt;li&gt;Until you use the rooms, they are &lt;strong&gt;still available&lt;/strong&gt; for other guests (processes).&lt;/li&gt;
&lt;li&gt;Your name in the reservation book (&lt;code&gt;VIRT&lt;/code&gt;) just says you’ve reserved them &lt;strong&gt;if needed&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Quick Example with Code
&lt;/h2&gt;

&lt;p&gt;Here’s a C example to test this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;

int main() {
    printf("PID: %d\n", getpid());
    printf("Allocating 2 GB using malloc...\n");

    char *ptr = malloc(2L * 1024 * 1024 * 1024); // Allocate 2 GB
    if (!ptr) {
        perror("malloc failed");
        return 1;
    }

    printf("Press Enter to touch memory...\n");
    getchar(); // Pause to check top command before touching

    for (long i = 0; i &amp;lt; 2L * 1024 * 1024 * 1024; i += 4096) {
        ptr[i] = 0; // Touch memory 4KB at a time
    }

    printf("Memory touched. Press Enter to exit...\n");
    getchar(); // Pause to check top command after touching

    free(ptr);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Steps to Test:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Compile and run the program: gcc test.c -o test &amp;amp;&amp;amp; ./test&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note the PID and check the top command output:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Before touching memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;VIRT&lt;/code&gt; increases by 2 GB.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RES&lt;/code&gt; remains small.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;After touching memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RES increases to reflect the actual physical memory used.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;malloc&lt;/code&gt; without usage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increases &lt;code&gt;VIRT&lt;/code&gt;, but not &lt;code&gt;RES&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Physical RAM is &lt;strong&gt;not allocated&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Other processes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The unallocated memory is still free for other processes to use.&lt;/li&gt;
&lt;li&gt;Physical RAM is only committed to your process when you "touch" the memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Key Point: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;malloced&lt;/code&gt; but unused memory increases &lt;code&gt;VIRT&lt;/code&gt; but not &lt;code&gt;RES&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Virtual memory reservation (&lt;code&gt;VIRT&lt;/code&gt;) does not mean physical memory usage (&lt;code&gt;RES&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Physical memory is allocated lazily&lt;/strong&gt; – only when you &lt;strong&gt;access&lt;/strong&gt; the memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Let me know if you'd like further clarification! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Choose the Right AWS Region: Key Factors and Real-Life Lessons</title>
      <dc:creator>Akshay Siwal</dc:creator>
      <pubDate>Mon, 28 Oct 2024 00:31:27 +0000</pubDate>
      <link>https://dev.to/akshaysiwal/how-to-choose-the-right-aws-region-key-factors-and-real-life-lessons-3mg4</link>
      <guid>https://dev.to/akshaysiwal/how-to-choose-the-right-aws-region-key-factors-and-real-life-lessons-3mg4</guid>
      <description>&lt;h2&gt;
  
  
  How to Choose the Right AWS Region: Key Factors and Real-Life Lessons
&lt;/h2&gt;

&lt;p&gt;Picking an AWS Region may seem like a small detail at first, but it's one of the most impactful decisions you can make in setting up your cloud infrastructure. Getting it right means better performance, compliance, and cost savings; getting it wrong can lead to unforeseen challenges. Here's a straightforward guide to the top factors you should consider, with real-life examples of companies who've nailed it - or learned the hard way.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Stay Compliant with Data Laws and Governance Rules
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Choosing an AWS Region means deciding where your data is stored. For industries with tight data residency laws, like finance or healthcare, this decision is critical. AWS Regions keep your data in specific locations, so it won't leave the region without your approval.&lt;br&gt;
&lt;strong&gt;When It Works:&lt;/strong&gt; &lt;strong&gt;Salesforce&lt;/strong&gt; leveraged AWS to launch its Hyperforce infrastructure, which allows the company to deploy its services in various regions while ensuring compliance with local data residency regulations. This strategic move enables Salesforce to quickly adapt to data sovereignty laws in different countries. &lt;a href="https://aws.amazon.com/solutions/case-studies/salesforce-hyperforce-video-case-study/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;When It Doesn't:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Google&lt;/strong&gt; found itself in hot water when it didn't offer similar regional storage flexibility, which led to regulatory pushback in Europe. They faced hefty fines and damage to user trust. &lt;a href="https://www.politico.eu/article/france-hits-google-with-e50-million-fine-for-gdpr-violation/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Meta&lt;/strong&gt; (Facebook) incurred a €1.2 billion fine for non-compliance with GDPR, highlighting the importance of choosing the right AWS region to avoid legal repercussions. &lt;a href="https://www.bbc.com/news/technology-65669839" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Pro Tip:&lt;/strong&gt; Before choosing your region, check in with your legal or compliance team to ensure you're aligning with any local regulations.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Choose a Region Close to Your Customers for Faster Performance
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Just like how having a warehouse near your customers reduces delivery times, placing your servers close to users reduces the time it takes for data to travel. This leads to smoother, faster user experiences.&lt;br&gt;
&lt;strong&gt;When It Works:&lt;/strong&gt; &lt;strong&gt;Netflix&lt;/strong&gt; does this well, hosting data near key user populations across the globe to minimize buffering and keep viewers engaged. &lt;a href="https://aws.amazon.com/solutions/case-studies/innovators/netflix/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;When It Doesn't:&lt;/strong&gt; &lt;strong&gt;Snapchat&lt;/strong&gt; struggled initially due to geographical distance from users, resulting in high latency and frustrating app performance. &lt;a href="https://aws.amazon.com/solutions/case-studies/snap-dynamodb/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Pro Tip:&lt;/strong&gt; Use &lt;a href="https://docs.aws.amazon.com/whitepapers/latest/best-practices-deploying-amazon-workspaces/how-to-check-latency-to-the-closest-aws-region.html" rel="noopener noreferrer"&gt;AWS's network tools&lt;/a&gt; to test latency for different regions, and choose one close to your main users to ensure great performance.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Ensure the Services You Need Are Available in Your Region
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Not every AWS service is available in every region. Sometimes, new or niche services, like machine learning or real-time applications, are only offered in select regions first.&lt;br&gt;
&lt;strong&gt;When It Works:&lt;/strong&gt; Airbnb chose AWS Regions where all the services it needed were ready and fully supported, allowing them to offer a seamless experience for travelers without delays. &lt;a href="https://aws.amazon.com/solutions/case-studies/innovators/airbnb/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;When It Doesn't:&lt;/strong&gt; Some startups in Europe faced delays when their chosen AWS region lacked essential services, driving up costs and slowing projects.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Pro Tip:&lt;/strong&gt; The &lt;a href="https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/" rel="noopener noreferrer"&gt;AWS Regional Service Availability Guide&lt;/a&gt; is an excellent resource for finding the AWS services you need and verifying their availability in your selected region.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Check the Regional Pricing Differences
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; AWS costs vary by region due to factors like local operating expenses. Just like some cities are pricier to live in than others, some AWS Regions are pricier to run in.&lt;br&gt;
&lt;strong&gt;When It Works:&lt;/strong&gt; Expedia made use of regional pricing differences by selecting regions where they could maximize cost savings without compromising on quality. &lt;a href="https://aws.amazon.com/solutions/case-studies/expedia/" rel="noopener noreferrer"&gt;Read more here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;When It Doesn't:&lt;/strong&gt; Smaller companies have learned this lesson the hard way, finding themselves over budget after choosing pricier regions and later moving to less costly options for sustainability.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Pro Tip:&lt;/strong&gt; The &lt;a href="https://calculator.aws/#/" rel="noopener noreferrer"&gt;AWS Pricing Calculator&lt;/a&gt; is a great tool to compare costs by region and help you choose a budget-friendly option.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Choosing an AWS Region is a strategic decision that will impact your project for years to come. From compliance and latency to service availability and cost, each factor affects your application's performance and your bottom line. By carefully weighing each of these aspects and learning from the experiences of others, you can make the best choice for your business and your users.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Stay Informed:&lt;/em&gt;&lt;/strong&gt; Check AWS's &lt;a href="https://aws.amazon.com/about-aws/global-infrastructure/" rel="noopener noreferrer"&gt;global infrastructure updates&lt;/a&gt; to track new region launches and service availability for optimal planning.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Is Your Data Really Safe in the Cloud?</title>
      <dc:creator>Akshay Siwal</dc:creator>
      <pubDate>Wed, 22 Jul 2020 01:13:26 +0000</pubDate>
      <link>https://dev.to/akshaysiwal/is-your-data-really-safe-in-the-cloud-44lc</link>
      <guid>https://dev.to/akshaysiwal/is-your-data-really-safe-in-the-cloud-44lc</guid>
      <description>&lt;p&gt;I am sure you or the company you work for never want to see such a message on the website of the company. Unfortunately, for some companies, this worst nightmare has come to reality, and few out of them were almost on the verge of losing business until they recovered or negotiated with hackers.&lt;/p&gt;

&lt;h1&gt;
  
  
  One sad story
&lt;/h1&gt;

&lt;p&gt;Ashley Madison, which got hacked on 15 July 2015 by a group called "The Impact Team" and threatened to expose users' identities, if its parent company, Avid Life Media, did not shut down Ashley Madison and its sister site, Established Men. Few users committed suicide as their highly personal data was made public on torrent. The story does not end here. It is 2020 now, and Ashley Madison users are still being blackmailed.&lt;/p&gt;

&lt;p&gt;After being attacked depending on what a company does, consequences may vary, but one side effect is always there.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Any guesses?&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Yes, You are correct. The company loses its customers' trust, which does not come in one day.&lt;/p&gt;

&lt;p&gt;Enough of this sad story. Let us end it here and think about how you can prevent this from happening with your product. These days most of the companies are offering SAAS and are on Cloud because being on Cloud gives much flexibility. However, just like all good things come with some side effects, the Cloud is no exception. It has a side effect of inadvertently exposing Cloud resources to the public.&lt;/p&gt;

&lt;p&gt;We already know how much damage a publically exposed resources can cause to a company, that is why every company has a security team that proactively keeps scanning for unauthorized access or resources that one accidentally let open to the world and bombards with a lot of JIRAs for explanations.&lt;/p&gt;

&lt;p&gt;In my opinion, security is just perception, and no product is 100% secure. It is either hard or easy to hack. Now it depends upon how hard we can make our product to be hacked.&lt;/p&gt;

&lt;p&gt;Coming to the main point that motivated me to write this blog, my very first blog on medium.com was &lt;a href="https://www.youtube.com/watch?v=77qLAl-lRpo"&gt;AWS EBS&lt;/a&gt;. One day my manager paged me to find out all the EC2 instances with unencrypted EBS volume and to encrypt them as soon as possible without affecting any production service and without making any changes in EC2 private IP. While working on this task out of curiosity, I ended up Googling hacks that had happened because of unencrypted EBS, and results were scary. The case I highlighted above was one of them where people at AshleyMadison made two mistakes. First, they hardcode secrets in source code, and second, all this critical information was unencrypted. If EBS were encrypted, hackers would have had a hard time getting this data even if the snapshot of EBS was publicly accessible until a hacker gets access to its KMS keys.&lt;/p&gt;

&lt;p&gt;Let me tell you one unencrypted publicly accessible snapshot can make you live your worst nightmare. Public Snapshot! Now, if you might think I am an Idiot, who does that? Right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--83ZwqBxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/umig1hdo829nn641bjfa.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--83ZwqBxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/umig1hdo829nn641bjfa.gif" alt="Alt Text" width="500" height="375"&gt;&lt;/a&gt;&lt;br&gt;
Wait. Do not judge too early read this report written on Ben Morris's findings, which he presented at DEF CON 27 in August 2019. Several major private companies and even federal agencies unknowingly exposing their sensitive data like admin passwords, application keys, and VPN configuration, which can be exploited to tunnel to their corporate network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://techcrunch.com/2019/08/09/aws-ebs-cloud-backups-leak/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aMbj5RY0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t97kcce7u2vyxucg83mm.png" alt="Report" width="737" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  This nightmare is real
&lt;/h1&gt;

&lt;p&gt;This nightmare is real. Most of the time, we are just one misconfiguration away from a potential hack. If you are still not convinced, read this interesting comment from "Hacker News" which enlighten a case when a user needs to share an EBS snapshot between two AWS accounts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yuqL8qba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zt99wmgcm1s96o1auihl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yuqL8qba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zt99wmgcm1s96o1auihl.png" alt="Alt Text" width="880" height="208"&gt;&lt;/a&gt;&lt;br&gt;
If someone exposes snapshot publically for just a couple of minutes, there are bots planted by Hackers in every region looking for such exposed snapshots and copy as soon as they see it. Hackers can create EBS volume out of it and attach to an EC2 instance to view its data and if there are any secrets or hardcoded API keys present in this then.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9dLMQ-IU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d75h6bds3zepexm29045.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9dLMQ-IU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d75h6bds3zepexm29045.gif" alt="Alt Text" width="480" height="270"&gt;&lt;/a&gt;&lt;br&gt;
Now, consider a scenario where you have a use-case that requires you to share a snapshot with other accounts. While implementing this use-case, you realize that EBS volume contains confidential information and you deleted this sensitive information from EBS before creating a snapshot. SMART!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p0vpjn2p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/er1jf4kov0pfbjrtwhiz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p0vpjn2p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/er1jf4kov0pfbjrtwhiz.gif" alt="Alt Text" width="480" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What if I tell you that others can still see the file you have deleted before creating a snapshot. They can still see your sensitive information. Scary! Isn't it?
&lt;/h4&gt;

&lt;h1&gt;
  
  
  Here is proof of what I have just said
&lt;/h1&gt;

&lt;p&gt;I created an EC2 instance with Ubuntu AMI &lt;code&gt;ami-0caae0b310f01ff33&lt;/code&gt;, which had an EBS volume of 8 GB. For the demonstration, I created a file &lt;code&gt;production.json&lt;/code&gt; with some fake credentials under the &lt;code&gt;/home/ubuntu/test_directory&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uwv-Hfos--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd549o2l71say4rlyhrf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uwv-Hfos--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd549o2l71say4rlyhrf.png" alt="Alt Text" width="692" height="518"&gt;&lt;/a&gt;&lt;br&gt;
To prove the point, I deleted &lt;code&gt;production.json&lt;/code&gt; and created a snapshot of this EBS volume. Let's say I accidentally shared it with unintended person or made it public.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CjKiwkl1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/86ie3azwgji4ay5y4rtz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CjKiwkl1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/86ie3azwgji4ay5y4rtz.png" alt="Alt Text" width="880" height="233"&gt;&lt;/a&gt;&lt;br&gt;
To simulate hackers, I created an EBS volume from the snapshot &lt;code&gt;snap-0f4a66cec80757&lt;/code&gt;, which I created after deleting &lt;code&gt;production.json&lt;/code&gt; and attached this volume to another EC2 instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9uWNSWi5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d0noxph4tb7po64yoxly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9uWNSWi5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d0noxph4tb7po64yoxly.png" alt="Alt Text" width="880" height="77"&gt;&lt;/a&gt;&lt;br&gt;
On the new EC2 instance, I ran &lt;code&gt;lsblk&lt;/code&gt; command to see the device name of the new volume, which is &lt;code&gt;nvme1n1&lt;/code&gt; in this case, and mounted it to &lt;code&gt;/data_from_snapshot&lt;/code&gt; directory. Once it is mounted &lt;code&gt;/data_from_snapshot&lt;/code&gt; will appear in the output of &lt;code&gt;df&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ewOj4-gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6a7g3auo14qk9qc6w5es.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ewOj4-gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6a7g3auo14qk9qc6w5es.png" alt="Alt Text" width="696" height="250"&gt;&lt;/a&gt;&lt;br&gt;
Now we are almost set to steal victim's confidential data. All we need is a utility like &lt;code&gt;extundelete&lt;/code&gt; or &lt;code&gt;testdisk&lt;/code&gt; based on the underlying filesystem, which can recover deleted data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T9zviLkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5zwg0qg787apim8g0kdr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T9zviLkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5zwg0qg787apim8g0kdr.png" alt="Alt Text" width="698" height="402"&gt;&lt;/a&gt;&lt;br&gt;
I used &lt;code&gt;extundelete&lt;/code&gt; as my test EC2 has &lt;code&gt;ext4&lt;/code&gt; filesystem. &lt;code&gt;extundelete&lt;/code&gt; puts all recovered files in a directory called &lt;code&gt;RECOVERED_FILES&lt;/code&gt; with a similar directory structure as of the original volume. Therefore &lt;code&gt;RECOVERED_FILES&lt;/code&gt; directory is all that I need to examine to see deleted files.&lt;/p&gt;

&lt;p&gt;In this example, we already know we deleted file &lt;code&gt;production.json&lt;/code&gt; containing secrets under &lt;code&gt;/home/ubuntu/test_directory&lt;/code&gt; directory, so we should check a similar directory structure inside the &lt;code&gt;RECOVERED_FILES&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h23Ia4Ib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iu7hsey5io0apaq51gn7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h23Ia4Ib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iu7hsey5io0apaq51gn7.png" alt="Alt Text" width="701" height="875"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XMh23m3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7deyjxzklyfd2rzwqn6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XMh23m3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7deyjxzklyfd2rzwqn6s.png" alt="Alt Text" width="880" height="215"&gt;&lt;/a&gt;&lt;br&gt;
Voilà! Now I can see the password and other secrets of the file &lt;code&gt;production.json&lt;/code&gt;, which was not even present when the snapshot was created. This means information can leak from not just currently available files on EBS but also from old deleted files. Therefore never share a snapshot if your EBS ever had any confidential data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why can Hacker see it?
&lt;/h1&gt;

&lt;p&gt;When we delete a file, it only gets unlinked. Delete command only breaks the link between name and inode and marks the inode as unused so that it can be used again. It does not wipe out data from filesystem blocks. If data blocks are not overwritten by new data, then it is possible to recover data based on the underlying filesystem. There are lots of details on how the operating system and filesystem works behind the scene when we delete a file and what all things it checks. I will discuss these things in detail in my future blogs.&lt;/p&gt;

&lt;h1&gt;
  
  
  What can we do to avoid such scenarios?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BN9Oexb2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/usuqm2rb64yykqvnkkcc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BN9Oexb2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/usuqm2rb64yykqvnkkcc.png" alt="Alt Text" width="263" height="264"&gt;&lt;/a&gt;&lt;br&gt;
AWS has provided a straightforward solution, which is nothing but encrypted EBS volume, So even if you accidentally share an encrypted EBS snapshot with unintended user or AWS accounts, only users with appropriate permission on KMS key used for encryption can see what is inside it. Data is encrypted before it leaves the EC2 instance, which ensures security of data-at-rest as well as data-in-transit between an instance and its attached EBS storage.&lt;br&gt;
I will share how you can automatically find and encrypt unencrypted-volumes without impacting your production services in my future blogs.&lt;/p&gt;

&lt;h1&gt;
  
  
  Impact on performance
&lt;/h1&gt;

&lt;p&gt;As per AWS, encrypted EBS volume has the same IOPS performance as unencrypted EBS volume. However, encryption does add some overhead on I/O requests since data get encrypted before it leaves the EC2 instance. To minimize overhead on I/O latency, the EBS encryption feature is available on only a few instances type.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Note
&lt;/h1&gt;

&lt;p&gt;Always use encrypted EBS volumes as encrypted volumes automatically create encrypted snapshots and never share a snapshot with sensitive data with anyone or whom you do not trust until you have any unavoidable use-case. Even if you have use-case, always think twice because you are just one mistake away from being hacked.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Additional Links —&lt;br&gt;
&lt;a href="https://inshorts.com/en/news/hundreds-of-amazon-cloud-backups-leaking-sensitive-data-report-1565503231724"&gt;inshorts.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theregister.co.uk/2015/09/08/ashley_madison_made_dumb_security_mistakes_researcher_says/"&gt;www.theregister.co.uk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://krebsonsecurity.com/2015/07/online-cheating-site-ashleymadison-hacked/"&gt;krebsonsecurity.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.forbes.com/sites/zakdoffman/2020/02/01/ashley-madison-hack-returns-to-haunt-its-victims-32-million-users-now-have-to-watch-and-wait/#337a353c5677"&gt;www.forbes.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>cloud</category>
      <category>aws</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
