Files
levelx/common/CMakeLists.txt
Frédéric DesbiensandCopilot bfb39676df Added opt-in lazy sector release to reduce O(N²) deletion (issue #70) (#71)
WARNING: This feature is brand new and has not been tested beyond the
existing regression suite.  It should be thoroughly tested — including
stress, power-loss, and wear-levelling scenarios — before being used in
any production system.

When LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE is defined and free blocks
exceed LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD (default 10), releasing
a sector from a full block defers the copy+erase.  A tombstone page is
written to a freshly-allocated block; the old full block is flagged
COMPACTION_PENDING in its block status and recorded in a new per-LG
compaction table.  Compaction (merge + erase) is triggered lazily:

  * sector_write: before writing to a full block with a pending source
  * block_data_move: intercepts wear-levelling moves for pending LGs
  * defragment: iterates all pending LGs (now actually implemented)
  * block_allocate: emergency compaction when the free list is empty

Reads transparently fall back to the compaction-pending block when the
primary block does not contain the requested sector.

Crash recovery is handled in open_extended:
  - Phase 1: detects COMPACTION_PENDING blocks and either clears the flag
    (crash before mapping update — abort) or rebuilds compaction_table
    (crash after mapping update — resume deferred compaction).
  - Phase 2: erases orphaned ALLOCATED blocks not present in any mapping.

Without the flag, all paths remain unchanged and defragment returns
LX_NOT_SUPPORTED as before.

Fixes: https://github.com/eclipse-threadx/levelx/issues/70

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-02 11:25:12 -04:00

77 lines
4.2 KiB
CMake
Executable File

target_sources(${PROJECT_NAME} PRIVATE
# {{BEGIN_TARGET_SOURCES}}
${CMAKE_CURRENT_LIST_DIR}/src/fx_nand_flash_simulated_driver.c
${CMAKE_CURRENT_LIST_DIR}/src/fx_nor_flash_simulator_driver.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_check.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_256byte_ecc_compute.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_allocate.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_data_move.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_find.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_mapping_set.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_block_status_set.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_close.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_data_page_copy.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_defragment.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erase.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_erased_verify.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_get.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_block_status_set.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_driver_page_erased_verify.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_logical_group_compact.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_memory_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_allocate.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_read.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_release.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sectors_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_read.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_release.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_sector_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_simulator.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_system_error.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_block_reclaim.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_close.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_defragment.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_block_erase.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_read.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_driver_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_extended_cache_enable.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open_extended.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_format.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_read.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_release.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_write.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_simulator.c
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_system_error.c
# {{END_TARGET_SOURCES}}
)
# Add the Common/inc directory to the project include list
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/inc
)