moonchen commented on code in PR #13380:
URL: https://github.com/apache/trafficserver/pull/13380#discussion_r3915349507
##########
src/iocore/cache/RamCacheLRU.cc:
##########
@@ -213,6 +218,26 @@ RamCacheLRU::put(CryptoHash *key, IOBufferData *data,
[[maybe_unused]] uint32_t
if (e->auxkey == auxkey) {
lru.remove(e);
lru.enqueue(e);
+ if (copy) {
Review Comment:
Please guard this with `copy && !e->copy`.
When two requests both get a RAM-cache miss, both read the same object from
disk, and then both try to fill the RAM cache, whichever finishes first inserts
a private copy. The other request finds that entry resident and currently
allocates and copies the entire object again. Both requests allocate a
RAM-cache buffer, but only the first allocation is necessary.
If `e->copy` is already true, the stored buffer is private and `get()` never
exposes it directly, so replacing it is unnecessary. The guard preserves the
shared-to-private transition while avoiding the redundant allocation and
memcpy. The same applies to the corresponding resident-refresh block in S3-FIFO.
--
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]