From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 23 10:00:43 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 470EDC5B for ; Mon, 23 Jun 2014 10:00:43 +0000 (UTC) Received: from mail-lb0-x22f.google.com (mail-lb0-x22f.google.com [IPv6:2a00:1450:4010:c04::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C3232254B for ; Mon, 23 Jun 2014 10:00:42 +0000 (UTC) Received: by mail-lb0-f175.google.com with SMTP id n15so1401317lbi.6 for ; Mon, 23 Jun 2014 03:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=+NT+dN0PnL0NbrFeiCi1EnZxOd4a3MGfyIyv9nhVi4s=; b=K5WrDHQtAhhQmUkTW8jDxRoWcd5i3pMhWVbBCtk0HgZ7XcFQt6KVwOxhrdjysOIeKU v1FDDGb+vXIJHYlmntFY2g91M/tgucWnaUDRhbWOd72DoHfmN8vtVBQaGO34oiD/31gF /aGvctd3Ye5DKbFFkSJpK91+KYEDCWwdMF+J7Y4DA33ojUJ7akCx4NqC/eassaZ0wE4+ ZrO4KtkKAw38i7KO89GLEvMNOsKFtSz1sFjVjoF+1svhiH3MwdFj6iPljYZSWQmk6gKw WCyEBJsJZpLfhUsuxmJ2spndZstgdSSHZGC/fB0mX1WcWkZbNfbtuz3KbvoWKkizPMMX kkkA== X-Received: by 10.152.36.67 with SMTP id o3mr15761837laj.48.1403517640560; Mon, 23 Jun 2014 03:00:40 -0700 (PDT) Received: from ?IPv6:2a02:6b8::408:2957:6195:671c:5d00? ([2a02:6b8:0:408:2957:6195:671c:5d00]) by mx.google.com with ESMTPSA id pp8sm2554014lbb.4.2014.06.23.03.00.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 03:00:39 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) Subject: Re: mlock() and vm_max_wired From: Dmitry Sivachenko In-Reply-To: Date: Mon, 23 Jun 2014 14:00:37 +0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: hackers@freebsd.org X-Mailer: Apple Mail (2.1878.2) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jun 2014 10:00:43 -0000 On 23 =D0=B8=D1=8E=D0=BD=D1=8F 2014 =D0=B3., at 13:52, Dmitry Sivachenko = wrote: > Hello! >=20 > I am using FreeBSD-10/stable and have a problem with mlock(). > I have 256GB of memory and a program which does mmap+mlock on a number = of data files. It can process one file several times (so it does mmap() = + mlock() on the same file more than once). > I set vm.max_wired=3D67108864 (67108864 * 4k =3D 256GB), so it is = allowed to mlock() the whole RAM. >=20 > The total size of all files is about 180GB. >=20 > The program fails with mlock: Resource temporarily unavailable error. >=20 > If I increase vm.max_wired even more, the program works fine and after = it starts top(1) shows about 186GB of Wired memory. >=20 > Why does it fail with vm.max_wired=3D67108864? Is it a bug or am I = missing something? >=20 > Thanks. Forgot to add the I suspect the following fragment in vm_mmap.c, in = vm_mlock() function: if (npages + cnt.v_wire_count > vm_page_max_wired) return (EAGAIN); If we mlock() the same region second time, this condition can be true = though after mlock() these pages will not increase total locked pages = counter.=