guyinyou opened a new issue, #10035:
URL: https://github.com/apache/rocketmq/issues/10035

   ### Before Creating the Enhancement Request
   
   - [x] I have confirmed that this should be classified as an enhancement 
rather than a bug/feature.
   
   
   ### Summary
   
   Fix the page alignment logic in DefaultMappedFile to avoid unnecessary 
padding when the message end position is already page-aligned. Currently, when 
endpos is exactly a multiple of UNSAFE_PAGE_SIZE, the calculation results in 
extraAppendSize equal to UNSAFE_PAGE_SIZE, causing an entire page of 
unnecessary padding.
   
   ### Motivation
   
   When writing messages to mapped files, the system aligns the end position to 
page boundaries for optimal memory-mapped I/O performance. However, there's a 
boundary case where if the message end position (endpos) is already aligned to 
UNSAFE_PAGE_SIZE, the current calculation `UNSAFE_PAGE_SIZE - endpos % 
UNSAFE_PAGE_SIZE` results in UNSAFE_PAGE_SIZE instead of 0. This causes 
unnecessary padding of an entire page size, wasting disk space and potentially 
affecting write performance. This enhancement improves the efficiency of the 
page alignment mechanism.
   
   ### Describe the Solution You'd Like
   
   Add a boundary check after calculating extraAppendSize:
   - If extraAppendSize equals UNSAFE_PAGE_SIZE (meaning endpos is already 
page-aligned), set it to 0
   - This ensures no unnecessary padding is added when the position is already 
aligned
   
   Implementation:
   int extraAppendSize = UNSAFE_PAGE_SIZE - endpos % UNSAFE_PAGE_SIZE;
   if (extraAppendSize == UNSAFE_PAGE_SIZE) {
       extraAppendSize = 0;
   }
   
   
   ### Describe Alternatives You've Considered
   
   Using modulo operation differently: Could use (UNSAFE_PAGE_SIZE - endpos % 
UNSAFE_PAGE_SIZE) % UNSAFE_PAGE_SIZE, but this is less readable and the 
explicit check is clearer.
   Pre-checking alignment: Check if endpos % UNSAFE_PAGE_SIZE == 0 before 
calculation, but this requires an extra modulo operation and the current 
solution is more efficient.
   No change: Accept the current behavior, but this wastes disk space 
unnecessarily and doesn't align with the optimization goals of the page 
alignment mechanism.
   
   ### Additional Context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to