Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/crypto/scrypt: memory not released after hash is calculated #20000

Closed
awnumar opened this issue Apr 16, 2017 · 1 comment
Closed

x/crypto/scrypt: memory not released after hash is calculated #20000

awnumar opened this issue Apr 16, 2017 · 1 comment

Comments

@awnumar
Copy link
Contributor

awnumar commented Apr 16, 2017

What version of Go are you using?

go version go1.8.1 linux/amd64

What operating system and processor architecture are you using?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/awn/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build015290357=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package main

import (
	"fmt"
	"time"

	"golang.org/x/crypto/scrypt"
)

func main() {
	key, _ := scrypt.Key(
		[]byte(""), // Input data.
		[]byte(""), // Salt.
		1<<18,      // Scrypt parameter N.
		16,         // Scrypt parameter r.
		1,          // Scrypt parameter p.
		64)         // Output hash length.

	fmt.Println(key)

	// Keep the process running.
	time.Sleep(10 * time.Second)
}

What did you expect to see?

I expected to see the memory usage drop back down after the hash was calculated and the result was returned to the caller.

What did you see instead?

I saw the memory usage stay at the peak usage until the process terminated.

screenshot from 2017-04-16 16-00-48

This leads to a lot of problems if the Scrypt parameters are high and Scrypt is called multiple times (not an unlikely scenario).

@bradfitz
Copy link
Contributor

This is normal. It'll be returned to the operating system eventually (by the Go scavenger), if it's not reused by Go before then.

See https://golang.org/pkg/runtime/debug/#FreeOSMemory

@golang golang locked and limited conversation to collaborators Apr 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants