From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 12 02:02:08 2014 Return-Path: Delivered-To: freebsd-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 8639C29A for ; Wed, 12 Feb 2014 02:02:08 +0000 (UTC) Received: from mx11.netapp.com (mx11.netapp.com [216.240.18.76]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6A1721354 for ; Wed, 12 Feb 2014 02:02:07 +0000 (UTC) X-IronPort-AV: E=Sophos;i="4.95,829,1384329600"; d="scan'208";a="101533348" Received: from vmwexceht06-prd.hq.netapp.com ([10.106.77.104]) by mx11-out.netapp.com with ESMTP; 11 Feb 2014 18:02:02 -0800 Received: from SACEXCMBX04-PRD.hq.netapp.com ([169.254.6.187]) by vmwexceht06-prd.hq.netapp.com ([10.106.77.104]) with mapi id 14.03.0123.003; Tue, 11 Feb 2014 18:02:02 -0800 From: "Gumpula, Suresh" To: "freebsd-hackers@freebsd.org" Subject: malloc(9) and its alignment Thread-Topic: malloc(9) and its alignment Thread-Index: Ac8nlkbcQYqIQNi5TDadKkROsoUT6Q== Date: Wed, 12 Feb 2014 02:02:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.106.53.53] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Feb 2014 02:02:08 -0000 Hi, It appears the malloc(9) returns 8 byte aligned ( UMA_ALIGN_PTR) pointers,= but in bus_dmamem_alloc we might end up checking for greater alignment if we take malloc(9) path instead contig_malloc. Can someone please confirm if malloc(9) returns different alignment pointer= s ? bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { /* * XXX: * (dmat->alignment < dmat->maxsize) is just a quick hack; the exac= t * alignment guarantees of malloc need to be nailed down, and the * code below should be rewritten to take that into account. * * In the meantime, we'll warn the user if malloc gets it wrong. */ if ((dmat->maxsize <=3D PAGE_SIZE) && (dmat->alignment < dmat->maxsize) && dmat->lowaddr >=3D ptoa((vm_paddr_t)Maxmem)) { *vaddr =3D malloc(dmat->maxsize, M_DEVBUF, mflags); } else { *vaddr =3D contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : = 1ul, dmat->boundary); }=20 if (vtophys(*vaddr) & (dmat->alignment - 1)) { NETAPP_MUTED_PRINTF("bus_dmamem_alloc failed to align memor= y properly.\n"); Regards, Suresh