all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, Paul Eggert <eggert@cs.ucla.edu>,
	Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: Aligned blocks management: obsolete?
Date: Wed, 20 Jun 2012 17:54:38 +0400	[thread overview]
Message-ID: <4FE1D61E.8010204@yandex.ru> (raw)
In-Reply-To: <jwvy5niw429.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

On 06/20/2012 04:48 PM, Stefan Monnier wrote:

> I'm not completely sure the test is sufficiently thorough to catch all
> problems, and more importantly it doesn't test the efficiency
> of memalign.

If it's just a matter of configure test, different methods may be used.
For example, attached code checks whether memalign tends to create holes
while allocating (1024 - 8) blocks aligned at 1024-bytes boundary; optimal
pad (BLOCK_PADDING in current code) may be detected with the similar way.

Dmitry

[-- Attachment #2: test-memalign.c --]
[-- Type: text/plain, Size: 1122 bytes --]

/* Simple check whether memalign tends to waste some space.  */

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

int
main (int argc, char *argv[])
{
  int i, j, bad = 0;
  const size_t blksz = 1024, padsz = 8;
  void *p, *prev;

  /* make some chaos in the heap */
  for (i = 0; i <= 1000; i++)
    for (j = 8; j <= 1024; j += 8)
      {
	p = malloc (j);
	if (((i + j) & 7) == 0)
	  free (p);
      }

  /* test asks for BLKSZ - PADSZ bytes aligned at BLKSZ boundary */
  for (i = 0, prev = NULL; i < 16; i++)
    {
      p = memalign (blksz, blksz - padsz);
      if (!p)
	bad++;
      else if (prev && p - prev > blksz)
	bad++;
      prev = p;
    }

  /* make even more chaos with larger chunks */
  for (i = 0; i <= 1000; i++)
    for (j = 8; j <= 1024; j += 8)
      {
	p = malloc (j * 16);
	if (((i + j) & 15) == 0)
	  free (p);
      }

  /* test again */
  for (i = 0, prev = NULL; i < 16; i++)
    {
      p = memalign (blksz, blksz - padsz);
      if (!p)
	bad++;
      else if (prev && p - prev > blksz)
	bad++;
      prev = p;
    }
  
  /* zero means memalign looks good enough */
  return bad;
}

  reply	other threads:[~2012-06-20 13:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  8:11 Aligned blocks management: obsolete? Dmitry Antipov
2011-12-12 13:13 ` Eli Zaretskii
2011-12-12 14:07   ` Dmitry Antipov
2011-12-12 18:11     ` Eli Zaretskii
2011-12-12 18:27     ` Paul Eggert
2012-06-19 16:51       ` Dmitry Antipov
2012-06-19 17:13         ` Eli Zaretskii
2012-06-19 21:34         ` Stefan Monnier
2012-06-20  6:47           ` Dmitry Antipov
2012-06-20 12:48             ` Stefan Monnier
2012-06-20 13:54               ` Dmitry Antipov [this message]
2012-06-20 15:41                 ` Stefan Monnier
2012-06-20 17:10                 ` Eli Zaretskii
2012-06-21  4:27                   ` Dmitry Antipov
2012-06-21 16:29                     ` Eli Zaretskii
2012-07-04  8:39                       ` Old topic(s) again [was: Re: Aligned blocks management: obsolete?] Dmitry Antipov
2012-07-04 13:11                         ` Stefan Monnier
2012-06-21 21:34                     ` Aligned blocks management: obsolete? Richard Stallman
2012-06-20 17:06             ` Eli Zaretskii
2012-06-21  3:30               ` Dmitry Antipov
2012-06-21 16:23                 ` Eli Zaretskii
2012-06-20 17:59             ` Wolfgang Jenkner
2012-06-21  3:12               ` Dmitry Antipov
2012-06-20  6:53         ` Paul Eggert
2011-12-12 18:38 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FE1D61E.8010204@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.