From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: malloc and alignment Date: Mon, 16 Jun 2003 10:38:50 -0400 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200306161438.h5GEcodM011551@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1055774754 25405 80.91.224.249 (16 Jun 2003 14:45:54 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 16 Jun 2003 14:45:54 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Jun 16 16:45:51 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19Rv6Z-0005xt-00 for ; Mon, 16 Jun 2003 16:37:07 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19RvU1-0004ts-00 for ; Mon, 16 Jun 2003 17:01:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Rv8Z-0000c1-Pj for emacs-devel@quimby.gnus.org; Mon, 16 Jun 2003 10:39:11 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19Rv8G-0000bR-Ty for emacs-devel@gnu.org; Mon, 16 Jun 2003 10:38:52 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19Rv8F-0000aT-FY for emacs-devel@gnu.org; Mon, 16 Jun 2003 10:38:52 -0400 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Rv8E-0000Z3-U4 for emacs-devel@gnu.org; Mon, 16 Jun 2003 10:38:50 -0400 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h5GEco0i011553 for ; Mon, 16 Jun 2003 10:38:50 -0400 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h5GEcodM011551; Mon, 16 Jun 2003 10:38:50 -0400 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:15126 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15126 I'd like to try and get rid of the markbit on Lisp_Object values. The idea is to scrape off a few more bits (I'd like to bump maxint to 512MB instead of 128MB). And I'd also like to represent floats in 8bytes rather than 12. So the idea is to use a separate bitmap, but in order to quickly find the markbit corresponding to an object, we need to be able to quickly find the bitmap for an arbitrary pointer. The typical solution for this is to allocate things in chunks of such that you can get the base of the bitmap by doing `ptrvalue & bitmask'. But for this, I need to make sure things are properly aligned. Currently alloc.c calls malloc to allocate blocks of about 8KB which are then split into 1000 cons cells or floats or whatever. So all we need is to make sure that those 8KB are properly aligned. But how can I do that ? It seems the only reliable way is to malloc 16KB and then waste the 8KB that happen to be before/after the aligned part. Should I just wrap malloc in my own malloc_aligned such that malloc_aligned calls malloc to allocate chunks of say 1MB and then gives them out in aligned packets of 8KB ? Has anybody played with things like that and could share his/her experience ? Stefan PS: Of course, an alternative is to split my 8KB blocks into aligned subblocks of 256B: 31 cons cells (or floats) plus one 32bit integer for the bitmask. This makes the bitmask access a tiny bit simpler since the bitmap is made of a single integer rather than an array of ints. On another hand, it will waste a lot of cache space unless your cache lines are 256B long.