// Returns the Memory limit if specified.
166998
func (self *ResourceList) Memory() *resource.Quantity {
	if val, ok := (*self)[ResourceMemory]; ok {
		return &val
	}
	return &resource.Quantity{}
}
1216734
func ParseMemory(s string) (Memory, error) {
	i, err := parseMemory(s)
	return Memory(i), err
}
1285582
func memoryStats() (*memory, error) {
	mstat := struct {
		size      uint32
		_         uint32
		totalPhys uint64
		availPhys uint64
		_         [5]uint64
	}{}

	// windows sets return value to 0 when function fails.
	mstat.size = uint32(unsafe.Sizeof(mstat))
	ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mstat)))
	if ret == 0 {
		return nil, err
	}

	// memoryStats functions from other platforms return memory usage in bytes.
	return &memory{
		Usage: mstat.totalPhys - mstat.availPhys,
		Total: mstat.totalPhys,
	}, nil

}
1268672
func (mc MongoClient) getEventsLimit(q bson.M, limit int) (me []models.Event, err error) {
	s := mc.getSessionCopy()
	defer s.Close()

	// Check if limit is 0
	if limit == 0 {
		return []models.Event{}, nil
	}

	err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).Sort("-modified").Limit(limit).All(&me)
	if err != nil {
		return []models.Event{}, errorMap(err)
	}
	return
}
1179832
func (s *ScanOp) Limit(n int) *ScanOp {
	s.limit = n
	return s
}
1357848
func getMemorySize() (size uint64, err error) {
	var mib []C.int = []C.int{ C.CTL_HW, C.HW_MEMSIZE }
	var value C.int64_t = 0
	var length C.size_t = 8
	var unused unsafe.Pointer

	if rc, errno := C.sysctl(&mib[0], 2, unsafe.Pointer(&value), &length, unused, 0); rc == -1 {
		return 0, fmt.Errorf("unable to get memory size: errno=%d", errno)
	}

	return uint64(value), nil
}
1243453
func getMemLimit(cgroupLimit uint64) uint64 {
	si := &syscall.Sysinfo_t{}
	err := syscall.Sysinfo(si)
	if err != nil {
		return cgroupLimit
	}

	physicalLimit := si.Totalram
	if cgroupLimit > physicalLimit {
		return physicalLimit
	}
	return cgroupLimit
}
722081
func (b *SelectBuilder) Limit(count interface{}) *SelectBuilder {
	if b.Select.Limit == nil {
		b.Select.Limit = &Limit{}
	}
	b.Select.Limit.Rowcount = makeValExpr(count)
	return b
}
198048
func (me *Dataset) Limit(limit uint) *Dataset {
	ret := me.copy()
	if limit > 0 {
		ret.clauses.Limit = limit
	} else {
		ret.clauses.Limit = nil
	}
	return ret
}
329083
func GetMaxMemoryLimit() (curLimit, maxLimit uint64, err error) {
	var rlimit syscall.Rlimit
	if err = syscall.Getrlimit(syscall.RLIMIT_DATA, &rlimit); err == nil {
		curLimit = rlimit.Cur
		maxLimit = rlimit.Max
	}

	return curLimit, maxLimit, err
}
1244348
func limit(s string, length int) string {
	if len(s) < length {
		return s
	}

	return s[:length]
}
1250551
func GetMaxOpenFileLimit() (curLimit, maxLimit uint64, err error) {
	var rlimit syscall.Rlimit
	if err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err == nil {
		curLimit = rlimit.Cur
		maxLimit = rlimit.Max
	}

	return curLimit, maxLimit, err
}
1300712
func (c *IterateChain) Limit(n int) *IterateChain {
	c.limit = n
	return c
}
1292590
func (bldr *iisQueryBuilder) Limit(limit int) *iisQueryBuilder {
	bldr.q = bldr.q.Limit(limit)
	if bldr.plugin != nil {
		bldr.plugin.Limit(limit)
	}
	return bldr
}
1292121
func Limit(limit int) DeviceRequestOption {
	return func(opts *deviceRequestOpts) error {
		if limit > 1000 {
			return fmt.Errorf("Limit must not be higher than 1000")
		}
		opts.Limit = limit
		return nil
	}
}
530872
func (r *RateLimiter) Limit(dataSize int) time.Duration {
	r.lock.Lock()
	defer r.lock.Unlock()
	//  update time
	var duration time.Duration = time.Duration(0)
	if r.bandwidth == 0 {
		return duration
	}
	current := time.Now()
	elapsedTime := current.Sub(r.lastUpdate)
	r.lastUpdate = current

	allowance := r.allowance + float64(elapsedTime)*r.bandwidth
	//  allowance can't exceed bandwidth
	if allowance > r.maxAllowance {
		allowance = r.maxAllowance
	}

	allowance -= float64(dataSize)
	if allowance < 0 {
		//  sleep until allowance is back to 0
		duration = time.Duration(-allowance / r.bandwidth)
		//  rate limiting was applied, record stats
		r.count++
		r.duration += duration
	}

	r.allowance = allowance
	return duration
}
747625
func (g *Generator) SetLinuxResourcesMemoryLimit(limit int64) {
	g.initConfigLinuxResourcesMemory()
	g.Config.Linux.Resources.Memory.Limit = &limit
}