Refactor README for clarity and add coding tasks#1
Open
shivangjhalani wants to merge 1 commit into
Open
Conversation
Updated formatting for clarity and added code tasks for inode exploration and hard-link finding.
There was a problem hiding this comment.
Pull request overview
This PR refactors the lab README to improve clarity and adds new hands-on coding tasks around inodes/hard links, RAID reconstruction, FAT traversal, and page-cache behavior.
Changes:
- Added new C “Code Task” exercises: inode/link exploration, hard-link finder, RAID reconstruct, FAT seek, and a page-cache benchmark.
- Updated markdown formatting/emphasis and adjusted some directory-scaling parameters (e.g., 5000 → 500 files).
- Reworked later sections by removing swap/journaling content and introducing a Page Cache section, plus updated the submission checklist accordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+151
| int fd = open(orig, O_CREAT | O_WRONLY | O_TRUNC, 0644); | ||
| write(fd, "inode exploration\n", 18); | ||
| close(fd); | ||
|
|
Comment on lines
+155
to
+157
| // TODO 1: Create a hard link (link()) from orig → hard. | ||
| // Create a symbolic link (symlink()) from orig → soft. | ||
|
|
| File write path: | ||
| process → write() → copy into page cache (dirty page) → return immediately | ||
| ↓ (background) | ||
| pdflush writes dirty pages to disk |
Comment on lines
+792
to
+793
| # Drop ALL cached file data from RAM, then run immediately | ||
| sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" |
Comment on lines
+740
to
+757
| // TODO: Allocate the read buffer. | ||
| // O_DIRECT requires the buffer address to be aligned to 4096 bytes — | ||
| // use posix_memalign(&buf, 4096, BUF_SIZE). Why does the kernel require | ||
| // this alignment? (Think about how O_DIRECT transfers data to the device.) | ||
| void *buf; | ||
| posix_memalign(&buf, 4096, BUF_SIZE); | ||
|
|
||
| struct timespec t0, t1; | ||
| clock_gettime(CLOCK_MONOTONIC, &t0); | ||
|
|
||
| ssize_t n; | ||
| long total = 0; | ||
| while ((n = read(fd, buf, BUF_SIZE)) > 0) | ||
| total += n; | ||
|
|
||
| clock_gettime(CLOCK_MONOTONIC, &t1); | ||
| close(fd); | ||
| free(buf); |
Comment on lines
+750
to
763
| ssize_t n; | ||
| long total = 0; | ||
| while ((n = read(fd, buf, BUF_SIZE)) > 0) | ||
| total += n; | ||
|
|
||
| clock_gettime(CLOCK_MONOTONIC, &t1); | ||
| close(fd); | ||
| free(buf); | ||
|
|
||
| #define MB (1024UL * 1024) | ||
|
|
||
| int main(void) { | ||
| // Allocate and touch 128 MB to create memory pressure | ||
| char *region = malloc(128 * MB); | ||
| if (!region) { perror("malloc"); return 1; } | ||
| memset(region, 'S', 128 * MB); | ||
|
|
||
| printf("Allocated 128 MB. PID: %d\n", getpid()); | ||
| char cmd[128]; | ||
| snprintf(cmd, sizeof(cmd), | ||
| "grep -E 'VmRSS|VmSwap' /proc/%d/status", getpid()); | ||
| system(cmd); | ||
| printf("\nSwap usage:\n"); | ||
| system("swapon --show"); | ||
|
|
||
| free(region); | ||
| return 0; | ||
| double elapsed = (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9; | ||
| printf(" %ld bytes in %.4f s → %.1f MB/s\n", | ||
| total, elapsed, (total / (1024.0 * 1024.0)) / elapsed); | ||
| return elapsed; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updated formatting for clarity and added code tasks for inode exploration and hard-link finding.