Skip to content

Conversation

wswsmao
Copy link
Contributor

@wswsmao wswsmao commented Jan 6, 2025

During the testing of passthrough with large images, we observed that the containerd-stargz-grpc process was terminated. The reason for this issue is that the content to be merged is currently stored in bufPool, which poses a risk of memory exhaustion.

This commit modifies the implementation to directly write the chunks obtained from prefetchEntireFile to disk, thereby mitigating the risk of running out of memory.

@ktock
Copy link
Member

ktock commented Jan 6, 2025

Could you rebase this on the latest main branch to enable CI?

@wswsmao
Copy link
Contributor Author

wswsmao commented Jan 7, 2025

Could you rebase this on the latest main branch to enable CI?

done, and this #1905 also has finished rebase and ready to be merged

return fmt.Errorf("failed to seek to end of file: %w", err)
}

if _, err := file.Write(ip); err != nil {
Copy link
Member

@ktock ktock Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blobs in the cache shouldn't be modified directly. The blob should be added to the cache after the entire contents becoming available.

Copy link
Contributor Author

@wswsmao wswsmao Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blobs in the cache shouldn't be modified directly. The blob should be added to the cache after the entire contents becoming available.

I have considered two potential solutions:

  1. Cache all chunks locally using cacheData, and then merge them into a single file by using cache.Get -> ReadAt -> file.Write. However, this approach incurs significant overhead and results in redundant files.

  2. Limit the specifications of the images being used. Before calling combinedBuffer.Write, we can check for potential OOM risks. If such a risk is detected, we can immediately report an error and exit.

I was wondering if there are any other solutions you would recommend?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache.BlobCache.Add() returns a writer and you can write chunks to that writer. Once the entire data is written to that writer, you can call cache.Writer.Commit() method then that blob is added to the cache. So can we use cache.Writer instead of *os.File?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
defer w.Close()

seeker, ok := w.(io.Seeker)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to seek? If it's guaranteed that we only append data to the cached blob, can we do this without seeking? Or are there other reasons to do seeking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, indeed, I made a small mistake, and I have fixed it, done

@wswsmao wswsmao closed this Jan 8, 2025
@wswsmao wswsmao reopened this Jan 8, 2025
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ktock ktock merged commit 6b0021f into containerd:main Jan 8, 2025
61 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants