From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Aligned blocks management: obsolete? Date: Wed, 20 Jun 2012 20:06:44 +0300 Message-ID: <83wr31diaj.fsf@gnu.org> References: <4EE5B744.1090103@yandex.ru> <4EE60A93.9060401@yandex.ru> <4EE6478C.1020701@cs.ucla.edu> <4FE0ADFC.9090504@yandex.ru> <4FE171EC.8000503@yandex.ru> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1340212016 10193 80.91.229.3 (20 Jun 2012 17:06:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 20 Jun 2012 17:06:56 +0000 (UTC) Cc: eggert@cs.ucla.edu, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Dmitry Antipov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 20 19:06:53 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ShOMf-0006R6-5G for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2012 19:06:45 +0200 Original-Received: from localhost ([::1]:49161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShOMe-0004V8-Sp for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2012 13:06:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShOMY-0004UR-Sh for emacs-devel@gnu.org; Wed, 20 Jun 2012 13:06:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ShOMW-0002ui-R3 for emacs-devel@gnu.org; Wed, 20 Jun 2012 13:06:38 -0400 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:37184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShOMW-0002u9-Iu for emacs-devel@gnu.org; Wed, 20 Jun 2012 13:06:36 -0400 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0M5X00600E20ZS00@a-mtaout20.012.net.il> for emacs-devel@gnu.org; Wed, 20 Jun 2012 20:06:30 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.210.75]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M5X003SFE6USUA2@a-mtaout20.012.net.il>; Wed, 20 Jun 2012 20:06:30 +0300 (IDT) In-reply-to: <4FE171EC.8000503@yandex.ru> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 80.179.55.166 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151056 Archived-At: > Date: Wed, 20 Jun 2012 10:47:08 +0400 > From: Dmitry Antipov > CC: Emacs development discussions > > This code tries to utilize system malloc features and falls back to legacy > aligned blocks management code if system malloc implementation is unknown, > broken, or lacks aligned allocation routines. > > It will be great if someone can help to test this on Windows, OSX, old *BSD > and other non-GNU/Linux systems What exactly would you like us to test, beyond the fact that the patched sources compile? Anyway, I don't understand the motivation for the changes you've done relative to the previous version. In particular: > +#if ! HAVE_POSIX_MEMALIGN && ! HAVE_WORKING_MEMALIGN && ! _MSC_VER Why only _MSC_VER is being tested here? This will only catch the MSVC build of Emacs, but will miss the MinGW (GCC-based) Windows build and the MS-DOS build. If you wanted to catch all of them, you should test DOS_NT instead. > +#ifdef HAVE_POSIX_MEMALIGN > + if (posix_memalign (&val, BLOCK_ALIGN, nbytes)) > + val = NULL; > +#elif HAVE_WORKING_MEMALIGN > + val = memalign (BLOCK_ALIGN, nbytes); > +#elif _MSC_VER > + /* Yes, the order of arguments is correct. */ > + val = _aligned_malloc (nbytes, BLOCK_ALIGN); > +#else > + val = internal_align_alloc (nbytes); > +#endif The _MSC_VER part is not right, IMO. The Windows build, whether MinGW or MSVC, uses gmalloc.c for its malloc implementation, with sbrk (implemented in w32heap.c) that calls directly into the VM allocation APIs, and is thus similar to mmap-based memory allocation on Posix hosts, in that it doesn't suffer from fragmentation. By contrast, _aligned_malloc is most probably a very thin wrapper around MS runtime implementation of malloc (MS documentation says "_aligned_malloc is based on malloc"), and we certainly don't want to use that malloc in Emacs, because it will be definitely prone to severe fragmentation problems. So, unless I'm missing something, the MS-Windows build (and also the MS-DOS one) should defined HAVE_POSIX_MEMALIGN and use its implementation provided by gmalloc.c. Unless, that is, you think that gmalloc's implementation of posix_memalign is not good enough, in which case we will be much better off improving it than switching to MS's malloc.