main.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. /*
  6. #include <sys/mman.h>
  7. #include <pthread.h>
  8. #include <unistd.h>
  9. void ctor(void) __attribute__((constructor));
  10. static void* thread(void*);
  11. void
  12. ctor(void)
  13. {
  14. // occupy memory where Go runtime would normally map heap
  15. mmap((void*)0x00c000000000, 64<<10, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
  16. // allocate 4K every 10us
  17. pthread_t t;
  18. pthread_create(&t, 0, thread, 0);
  19. }
  20. static void*
  21. thread(void *p)
  22. {
  23. for(;;) {
  24. usleep(10000);
  25. mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  26. }
  27. return 0;
  28. }
  29. */
  30. import "C"
  31. import (
  32. "fmt"
  33. "os"
  34. "path/filepath"
  35. "time"
  36. )
  37. func main() {
  38. start := time.Now()
  39. // ensure that we can function normally
  40. var v [][]byte
  41. for i := 0; i < 1000; i++ {
  42. time.Sleep(10 * time.Microsecond)
  43. v = append(v, make([]byte, 64<<10))
  44. }
  45. fmt.Printf("ok\t%s\t%s\n", filepath.Base(os.Args[0]), time.Since(start).Round(time.Millisecond))
  46. }