-
Notifications
You must be signed in to change notification settings - Fork 233
Implement TRIM Support for Dataset Management Command in BBSSD #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replace free() with g_free() to match g_malloc0() allocation.
- Implement NVMe DSM TRIM functionality with FTL integration, range validation, and proper error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for NVMe TRIM (deallocate) operations to the BBSSD FTL path, enabling proper invalidation of logical blocks and improved garbage collection.
- Introduces DSM range fields in
NvmeRequestto carry multi-range TRIM info - Enhances
nvme-io.cto parse, validate, and enqueue DSM commands with cleanup on failure - Implements
ssd_trim()inftl.cand integrates it into the FTL thread dispatch
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| hw/femu/nvme.h | Added dsm_ranges, dsm_nr_ranges, dsm_attributes to NvmeRequest |
| hw/femu/nvme-io.c | Initialized DSM fields, parsed CDWs into ranges, validated and forwarded to FTL, improved error cleanup |
| hw/femu/bbssd/ftl.c | Added ssd_trim() to process multi-range TRIMs, wired into FTL thread loop |
Comments suppressed due to low confidence (1)
hw/femu/bbssd/ftl.c:861
- [nitpick] The new TRIM path exercises multi-range parsing, boundary checks, and bitmap updates. Consider adding unit or integration tests to cover valid trims, out-of-bounds ranges, and empty requests to ensure correctness under diverse conditions.
static uint64_t ssd_trim(struct ssd *ssd, NvmeRequest *req)
| case NVME_CMD_READ: | ||
| lat = ssd_read(ssd, req); | ||
| break; | ||
| case NVME_CMD_DSM: |
Copilot
AI
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latency variable (lat) is not initialized for the DSM case when req->dsm_ranges is empty, leading to undefined behavior. Consider setting lat = 0; before the conditional or restoring the default assignment.
|
|
||
| // If no deallocate attribute, no need to process further for TRIM | ||
| if (!has_deallocate) { | ||
| femu_err("DSM: No deallocate attribute set, skipping\n"); |
Copilot
AI
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Skipping DSM processing when no deallocate attribute is expected; logging this as an error may confuse readers. Use a debug-level log and ensure req->cmd_opcode is set before early returns to keep request routing consistent.
| femu_err("DSM: No deallocate attribute set, skipping\n"); | |
| femu_debug("DSM: No deallocate attribute set, skipping\n"); | |
| req->cmd_opcode = cmd->opcode; |
| int total_out_of_bounds = 0; | ||
|
|
||
| if (!ranges || nr_ranges <= 0) { | ||
| printf("TRIM: Invalid ranges or count\n"); |
Copilot
AI
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using printf in the FTL path is inconsistent with existing ftl_err/ftl_debug logging macros. Consider switching to the project’s logging API for consistency and log filtering.
| printf("TRIM: Invalid ranges or count\n"); | |
| ftl_err("TRIM: Invalid ranges or count\n"); |
| int total_trimmed_pages = 0; | ||
| int total_already_invalid = 0; | ||
| int total_out_of_bounds = 0; |
Copilot
AI
Jul 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The counters total_trimmed_pages, total_already_invalid, and total_out_of_bounds are never used or logged. Remove them or emit a summary log to reduce dead code and improve observability.
| int total_trimmed_pages = 0; | |
| int total_already_invalid = 0; | |
| int total_out_of_bounds = 0; | |
| // Removed unused counters: total_trimmed_pages, total_already_invalid, total_out_of_bounds |
|
Looks good to me! That said, we will need to run more thorough testing. I'm merging this into the master branch now, and we can follow up with additional fixes as needed. Thanks so much for this patch. It’s been a long time coming, and I’m glad to see it finally addressed! 😊 |
Problem Statement
Currently, BBSSD does not properly handle TRIM operations, which can significantly impact performance. Without proper TRIM support, the garbage collection (GC) mechanism cannot efficiently identify invalidated pages, leading to suboptimal storage management and degraded performance in write-intensive workloads.
Experimental Environment
Host System
FEMU Virtual Environment
Performance Impact Analysis
I conducted experiments using fxmark to demonstrate the performance impact:
Experimental Setup
(1) Re-ran dwal experiment
(2) Ran dwol experiment
Performance Results
Experiment (1) - DWAL after TRIM:
→ 2.13x performance improvement
Experiment (2) - DWOL after TRIM:
→ 1.36x performance improvement
These results clearly demonstrate that proper TRIM support enables more efficient garbage collection by accurately reflecting invalidated pages in the mapping table.
Implementation Details
Key Features
Code Changes
Questions for Review
Next Steps
I'd appreciate feedback on the implementation approach, particularly regarding the multi-range handling mechanism. Once approved, I can clean up the commented debug code and address any additional concerns.