From owner-freebsd-current@FreeBSD.ORG  Mon Jun  1 09:54:47 2015
Return-Path: <owner-freebsd-current@FreeBSD.ORG>
Delivered-To: current@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 4F15E6CA
 for <current@freebsd.org>; Mon,  1 Jun 2015 09:54:47 +0000 (UTC)
 (envelope-from zec@fer.hr)
Received: from mail.fer.hr (mail.fer.hr [161.53.72.233])
 (using TLSv1 with cipher AES128-SHA (128/128 bits))
 (Client CN "mail.fer.hr", Issuer "TERENA SSL CA" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id D86E91056
 for <current@freebsd.org>; Mon,  1 Jun 2015 09:54:46 +0000 (UTC)
 (envelope-from zec@fer.hr)
Received: from x23 (161.53.63.210) by MAIL.fer.hr (161.53.72.233) with
 Microsoft SMTP Server (TLS) id 14.2.342.3; Mon, 1 Jun 2015 11:53:31 +0200
Date: Mon, 1 Jun 2015 11:54:11 +0200
From: Marko Zec <zec@fer.hr>
To: Luigi Rizzo <rizzo@iet.unipi.it>
CC: FreeBSD Current <current@freebsd.org>
Subject: Re: superpages in FreeBSD (netmap related) ?
Message-ID: <20150601115411.1f95bd00@x23>
In-Reply-To: <CA+hQ2+h7LZp2cLUpOrqLvWwFmSSWSw4GKT1DJCc_AuH7-t042g@mail.gmail.com>
References: <CA+hQ2+iWq4rO-V0M9VZTHMcVORSJ_Qgn6u0JmSiZjTy-L2MAsQ@mail.gmail.com>
 <CA+hQ2+h7LZp2cLUpOrqLvWwFmSSWSw4GKT1DJCc_AuH7-t042g@mail.gmail.com>
X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.27; amd64-portbld-freebsd10.0)
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Originating-IP: [161.53.63.210]
X-BeenThere: freebsd-current@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: Discussions about the use of FreeBSD-current
 <freebsd-current.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-current>, 
 <mailto:freebsd-current-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-current/>
List-Post: <mailto:freebsd-current@freebsd.org>
List-Help: <mailto:freebsd-current-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>,
 <mailto:freebsd-current-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 01 Jun 2015 09:54:47 -0000

On Mon, 1 Jun 2015 11:34:00 +0200
Luigi Rizzo <rizzo@iet.unipi.it> wrote:

> Hi,
> i was wondering how we can improve the netmap memory allocator
> to make use of 2M pages (through the page promotion trick).
> 
> in netmap, when we allocate packet buffers,
> we issue requests for 4k blocks to contigmalloc(),
> and i have no idea if there is a way to improve the
> chance that the memory is mapped to 2M pages ?

In my (previous life) experience, when requested large enough blocks,
malloc() did a good job at automatically promoting those to superpages,
and in my applications this behavior was 100% consistent, at least on
amd64.  After the block is allocated one can check whether it is
superpage-mapped:

pmap_t pmap = vmspace_pmap(curthread->td_proc->p_vmspace);

if (pmap_mincore(pmap, (vm_offset_t) addr) & MINCORE_SUPER)
	/* you're good */
else
	/* bad luck */

OTOH I'm not aware of any mechanisms for forcing superpage allocations
at malloc() time.

Marko