From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 17 17:39:24 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 14A3216A4CE for ; Thu, 17 Feb 2005 17:39:24 +0000 (GMT) Received: from gatekeeper.syskonnect.de (gatekeeper.syskonnect.de [213.144.13.149]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3390943D2D for ; Thu, 17 Feb 2005 17:39:23 +0000 (GMT) (envelope-from gheinig@syskonnect.de) Received: from syskonnect.de (skd.de [10.9.15.1])j1HHdc91005546 for ; Thu, 17 Feb 2005 18:39:38 +0100 (MET) Received: from syskonnect.de (localhost [127.0.0.1]) by syskonnect.de (8.12.11/8.12.11) with ESMTP id j1HHdLBs009484 for ; Thu, 17 Feb 2005 18:39:21 +0100 (MET) Message-ID: <4214D6A0.9010803@syskonnect.de> Date: Thu, 17 Feb 2005 18:38:40 +0100 From: Gerald Heinig User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 To: hackers@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: bus_dmamem_alloc strangeness X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Feb 2005 17:39:24 -0000 Hi hackers, I've come across weird behaviour in bus_dmamem_alloc() whilst trying to allocate small memory blocks (less than PAGE_SIZE) which have to be aligned to PAGE_SIZE. My segment size is 2048, my maximum number of segments is 1 (it MUST be contiguous), my max. total segment size is also 2048 and my alignment constraint is 4k (PAGE_SIZE). However, the DMA memory I'm getting from bus_dmamem_alloc() is NOT aligned to 4k. The relevant code in sys/i386/i386/busdma_machdep.c is: ============================================================= if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) { *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. * XXX Certain AGP hardware does. */ *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); } ============================================================== My lowaddr is BUS_SPACE_MAXADDR and I'm allocating 2k blocks which have to be 4k-aligned, which would imply the first if branch. Surely the code should adhere to the alignment restrictions and not simply allocate memory without checking, or am I missing something here? Cheers, Gerald