From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 18 23:37:51 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B9541065670 for ; Wed, 18 Apr 2012 23:37:51 +0000 (UTC) (envelope-from sushanth_rai@yahoo.com) Received: from nm9.bullet.mail.sp2.yahoo.com (nm9.bullet.mail.sp2.yahoo.com [98.139.91.79]) by mx1.freebsd.org (Postfix) with SMTP id 3F7AE8FC1A for ; Wed, 18 Apr 2012 23:37:51 +0000 (UTC) Received: from [98.139.91.65] by nm9.bullet.mail.sp2.yahoo.com with NNFMP; 18 Apr 2012 23:37:45 -0000 Received: from [98.139.44.80] by tm5.bullet.mail.sp2.yahoo.com with NNFMP; 18 Apr 2012 23:37:45 -0000 Received: from [127.0.0.1] by omp1017.access.mail.sp2.yahoo.com with NNFMP; 18 Apr 2012 23:37:45 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 885835.30569.bm@omp1017.access.mail.sp2.yahoo.com Received: (qmail 58568 invoked by uid 60001); 18 Apr 2012 23:37:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1334792265; bh=hLjWq9yOGZxIvrawoxPfMkxrIsBbgXx1ld3nOt7nvo0=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=iL86dXPaqvSzlgTSXPpooaYOs48bSVOngy2mKzUmBKeAVeYarrYK21EImxKCpM5rkGOAquIRnBTLBcxjT3RibyvKALA8Z8apLVvC8ljoyu3VHy+S+6c45J9UrHDmDuNH6yiUZL5TxSzDhRgGkVvLqmGqbI5AeoSwbWNyiKxhhrg= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ZbABV/+bVhVLAanbciUTZD5mGl6ltUq6WaPu6/HC42dH2aYZb5qmMOXJvms5kLLG0x7h1w8lHO4DpJh3YLAmu8IFuOa6O25xPZ7iSJPlZAtH8O+DDemymYWz1yUPdz25NvTAoxlDH4cJ9gDQKtd8/7EeTmbKBRHGCb85DyUvw6o=; X-YMail-OSG: r5i8wUwVM1lbbeQf5olhwE0itJUworXdsynemTRv2qEt704 2MN9LiaGR9gqpJs28CHY89eKqEMjFSYcvDgTVThD1l6wOQpujjLangZvXxQH sKyc3QNFOBcydCmcicr4_hPb7b47smbuysKDdicE9oAndZjHNFcpHnPbfcwm H7TkmwDQU.lKkVSRxOpYEJhsocYNAEsavWVF3VM5Tiypq8KLedpNdRCQeO6y frK5iMLsUTbWTzjEpsgK9xSXJXwFKHpZzsxh.vyXfuFYYLcQFwyEopOQZYHQ WXy5TlSgG._RZ3BTzpY4qGxQFar2WArfGpOBPM_5ebHD.AwMs1aTPCHGEx8E B1SXkHz10Kf0fD28mAKxuQSmOwlQ6VWiNz5cKj8NeSOwjWOeg8oXAa2pESCk h8ztnnQrBkU7D75E2.PELmOdvkxIsrM4b0JaMroVhPbJirUDShh_LbfSvnRM p.dnP Received: from [75.62.238.5] by web180012.mail.gq1.yahoo.com via HTTP; Wed, 18 Apr 2012 16:37:45 PDT X-Mailer: YahooMailClassic/15.0.5 YahooMailWebService/0.8.117.340979 Message-ID: <1334792265.20401.YahooMailClassic@web180012.mail.gq1.yahoo.com> Date: Wed, 18 Apr 2012 16:37:45 -0700 (PDT) From: Sushanth Rai To: Konstantin Belousov In-Reply-To: <1334601684.58522.YahooMailClassic@web180001.mail.gq1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: alc@freebsd.org, freebsd-hackers@freebsd.org Subject: Re: mlockall() on freebsd 7.2 + amd64 returns EAGAIN X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2012 23:37:51 -0000 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 wrote:=0A= =0A> From: Sushanth Rai =0A> Subject: Re: mlockall(= ) on freebsd 7.2 + amd64 returns EAGAIN=0A> To: "Konstantin Belousov" =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>