use sendfile/splice implementation to perform DMA (#18411)

sendfile implementation to perform DMA on all platforms

Go stdlib already supports sendfile/splice implementations
for

- Linux
- Windows
- *BSD
- Solaris

Along with this change however O_DIRECT for reads() must be
removed as well since we need to use sendfile() implementation

The main reason to add O_DIRECT for reads was to reduce the
chances of page-cache causing OOMs for MinIO, however it would
seem that avoiding buffer copies from user-space to kernel space
this issue is not a problem anymore.

There is no Go based memory allocation required, and neither
the page-cache is referenced back to MinIO. This page-
cache reference is fully owned by kernel at this point, this
essentially should solve the problem of page-cache build up.

With this now we also support SG - when NIC supports Scatter/Gather
https://en.wikipedia.org/wiki/Gather/scatter_(vector_addressing)
This commit is contained in:
Harshavardhana
2023-11-10 10:10:14 -08:00
committed by GitHub
parent 80adc87a14
commit 91d8bddbd1
5 changed files with 68 additions and 47 deletions

View File

@@ -19,6 +19,7 @@ package http
import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
@@ -29,6 +30,7 @@ import (
// status code and to record the response body
type ResponseRecorder struct {
http.ResponseWriter
io.ReaderFrom
StatusCode int
// Log body of 4xx or 5xx responses
LogErrBody bool
@@ -51,13 +53,27 @@ type ResponseRecorder struct {
// NewResponseRecorder - returns a wrapped response writer to trap
// http status codes for auditing purposes.
func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder {
rf, _ := w.(io.ReaderFrom)
return &ResponseRecorder{
ResponseWriter: w,
ReaderFrom: rf,
StatusCode: http.StatusOK,
StartTime: time.Now().UTC(),
}
}
// ErrNotImplemented when a functionality is not implemented
var ErrNotImplemented = errors.New("not implemented")
// ReadFrom implements support for calling internal io.ReaderFrom implementations
// returns an error if the underlying ResponseWriter does not implement io.ReaderFrom
func (lrw *ResponseRecorder) ReadFrom(r io.Reader) (int64, error) {
if lrw.ReaderFrom != nil {
return lrw.ReaderFrom.ReadFrom(r)
}
return 0, ErrNotImplemented
}
func (lrw *ResponseRecorder) Write(p []byte) (int, error) {
if !lrw.headersLogged {
// We assume the response code to be '200 OK' when WriteHeader() is not called,