mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 16:58:09 +02:00
Always use fallocate() on Linux for SHM creation
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
package shm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func Fallocate_simple(fd int, size int64) (err error) {
|
||||
return unix.ENOSYS
|
||||
return errors.ErrUnsupported
|
||||
}
|
||||
|
||||
@@ -92,16 +92,15 @@ func CreateTemp(pattern string, size uint64) (MMap, error) {
|
||||
return create_temp(pattern, size)
|
||||
}
|
||||
|
||||
var force_use_of_fallocate bool = false
|
||||
|
||||
func truncate_or_unlink(ans *os.File, size uint64) (err error) {
|
||||
fd := int(ans.Fd())
|
||||
if err = Fallocate_simple(fd, int64(size)); err != nil {
|
||||
if force_use_of_fallocate {
|
||||
sz := int64(size)
|
||||
if err = Fallocate_simple(fd, sz); err != nil {
|
||||
if !errors.Is(err, errors.ErrUnsupported) {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
err = unix.Ftruncate(fd, int64(size))
|
||||
err = unix.Ftruncate(fd, sz)
|
||||
if !errors.Is(err, unix.EINTR) {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -9,15 +9,12 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func TestSHM(t *testing.T) {
|
||||
force_use_of_fallocate = runtime.GOOS == "linux"
|
||||
defer func() { force_use_of_fallocate = false }()
|
||||
data := make([]byte, 13347)
|
||||
_, _ = rand.Read(data)
|
||||
mm, err := CreateTemp("test-kitty-shm-", uint64(len(data)))
|
||||
|
||||
Reference in New Issue
Block a user