Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Apr 2012 16:37:45 -0700 (PDT)
From:      Sushanth Rai <sushanth_rai@yahoo.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        alc@freebsd.org, freebsd-hackers@freebsd.org
Subject:   Re: mlockall() on freebsd 7.2 + amd64 returns EAGAIN
Message-ID:  <1334792265.20401.YahooMailClassic@web180012.mail.gq1.yahoo.com>
In-Reply-To: <1334601684.58522.YahooMailClassic@web180001.mail.gq1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Wiring entire address space seems to have interesting side effect. The libc=
 memory allocator calls madvise() to free the dirty unused pages, which doe=
s nothing when the pages are wired. The allocator unmaps only when entire c=
hunk is free (default size of 1MB). That leaves lots for free pages which c=
annot reclaimed even when the system is under memory pressure.=0A=0ASushant=
h=0A=0A--- On Mon, 4/16/12, Sushanth Rai <sushanth_rai@yahoo.com> wrote:=0A=
=0A> From: Sushanth Rai <sushanth_rai@yahoo.com>=0A> Subject: Re: mlockall(=
) on freebsd 7.2 + amd64 returns EAGAIN=0A> To: "Konstantin Belousov" <kost=
ikbel@gmail.com>=0A> Cc: alc@freebsd.org, freebsd-hackers@freebsd.org=0A> D=
ate: Monday, April 16, 2012, 11:41 AM=0A> Many thanks. I verified the patch=
 you=0A> provided and it works fine.=0A> =0A> Sushanth=0A> =0A> =0A> > Oh, =
I see. The problem is the VM_MAP_WIRE_NOHOLES=0A> flag.=0A> > Since we=0A> =
> map only the initial stack fragment even for the=0A> > MCL_WIREFUTURE map=
s,=0A> > there is a hole in the stack region.=0A> > =0A> > In fact, for MCL=
_WIREFUTURE, we probably should map=0A> the=0A> > whole=0A> > stack at once=
, prefaulting all pages.=0A> > =0A> > Below are two patches. The change for=
 vm_mmap.c would=0A> fix=0A> > your immediate=0A> > problem by allowing hol=
es in wired region.=0A> > =0A> > The change for vm_map.c prefaults the whol=
e stack=0A> instead of=0A> > the=0A> > initial fragment. The single-threade=
d programs still=0A> get a=0A> > fault=0A> > on stack growth.=0A> > =0A> > =
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c=0A> > index 6198629..2fd18d1=
 100644=0A> > --- a/sys/vm/vm_map.c=0A> > +++ b/sys/vm/vm_map.c=0A> > @@ -3=
259,7 +3259,10 @@ vm_map_stack(vm_map_t map,=0A> > vm_offset_t addrbos, vm_=
size_t max_ssize,=0A> >=A0 =A0=A0=A0 =A0 =A0 addrbos + max_ssize <=0A> > ad=
drbos)=0A> >=A0 =A0=A0=A0 =A0=A0=A0 return=0A> > (KERN_NO_SPACE);=0A> >=A0 =
=0A> > -=A0=A0=A0 init_ssize =3D (max_ssize < sgrowsiz) ?=0A> > max_ssize :=
 sgrowsiz;=0A> > +=A0=A0=A0 if (map->flags & MAP_WIREFUTURE)=0A> > +=A0=A0=
=A0 =A0=A0=A0 init_ssize =3D=0A> > max_ssize;=0A> > +=A0=A0=A0 else=0A> > +=
=A0=A0=A0 =A0=A0=A0 init_ssize =3D=0A> > (max_ssize < sgrowsiz) ? max_ssize=
 : sgrowsiz;=0A> >=A0 =0A> >=A0 =A0=A0=A0 PROC_LOCK(curthread->td_proc);=0A=
> >=A0 =A0=A0=A0 vmemlim =3D lim_cur(curthread->td_proc,=0A> > RLIMIT_VMEM)=
;=0A> > diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c=0A> > index 2588c8=
5..3fccd9e 100644=0A> > --- a/sys/vm/vm_mmap.c=0A> > +++ b/sys/vm/vm_mmap.c=
=0A> > @@ -1561,9 +1561,11 @@ vm_mmap(vm_map_t map,=0A> vm_offset_t=0A> > *=
addr, vm_size_t size, vm_prot_t prot,=0A> >=A0 =A0=A0=A0 =A0=A0=A0=A0=A0* I=
f the=0A> > process has requested that all future mappings=0A> >=A0 =A0=A0=
=A0 =A0=A0=A0=A0=A0* be=0A> > wired, then heed this.=0A> >=A0 =A0=A0=A0 =A0=
=A0=A0=A0=A0*/=0A> > -=A0=A0=A0 =A0=A0=A0 if (map->flags=0A> > & MAP_WIREFU=
TURE)=0A> > +=A0=A0=A0 =A0=A0=A0 if (map->flags=0A> > & MAP_WIREFUTURE) {=
=0A> >=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=0A> > vm_map_wire(map, *addr, *addr=
 + size,=0A> > -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=0A> > =A0 =A0 VM_MAP_WIRE_USE=
R | VM_MAP_WIRE_NOHOLES);=0A> > +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0=0A> > =A0 =
=A0 VM_MAP_WIRE_USER | ((flags & MAP_STACK) ?=0A> > +=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0=0A> > =A0 =A0 VM_MAP_WIRE_HOLESOK : VM_MAP_WIRE_NOHOLES));=0A> > =
+=A0=A0=A0 =A0=A0=A0 }=0A> >=A0 =A0=A0=A0 } else {=0A> >=A0 =A0=A0=A0 =A0=
=A0=A0 /*=0A> >=A0 =A0=A0=A0 =A0=A0=A0=A0=A0* If this=0A> > mapping was acc=
ounted for in the vnode's=0A> >=0A> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1334792265.20401.YahooMailClassic>