All of lore.kernel.org
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 5/5] Set our own in/out buffers
Date: Fri, 29 Apr 2011 13:15:47 +0200	[thread overview]
Message-ID: <4DBA9DE3.9020506@redhat.com> (raw)
In-Reply-To: <0e34a9ec4665a437ec685e7845099d5080a2f659.1303215346.git.zkabelac@redhat.com>

On 04/19/2011 02:55 PM, Zdenek Kabelac wrote:
> Memory lock from critical_section is now being kept over the critical
> section - mallopt() should ensure, that mmap is not used for allocation,
> and we preallocate some memory to be able to satisfy some small
> alloc request. However when glibc needs buffers for line buffering of
> input and output buffers - it allocates these buffers in such way it
> adds memory page for each such buffer and size of unlock memory check will
> mismatch by 1 or 2 pages.

So this will fix that famous 1 page difference in memory lock/unlock.

> +	/* Set in/out stream buffering before glibc */
> +	if (set_buffering) {
> +		/* Allocate 2 buffers */
> +		if (!(cmd->linebuffer = dm_malloc(2 * linebuffer_size))) {
> +			log_error("Failed to allocate line buffer.");
> +			goto out;
> +		}
> +		if ((setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size) ||
> +		     setvbuf(stdout, cmd->linebuffer + linebuffer_size,

IMHO I would better allocate two separate buffers here, if it uses some
stack markers to detect overflow, it will be effectively switched off
for stdin buffer.

(But it is internal glibc thing.)

> +	if (cmd->linebuffer) {
> +		/* Reset stream buffering to defaults */
> +		setlinebuf(stdin);

btw this requires _BSD_SOURCE, isn't better use
setvbuf(stream, (char *) NULL, _IOLBF, 0); ? (see man page)

> +		fflush(stdout);

(I guess flush is implicit but it is not documented so better to be safe.)


ACK, I think we should squeeze it in current release ;-)

Milan


      reply	other threads:[~2011-04-29 11:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-19 12:55 [PATCH 0/5] Fixes Zdenek Kabelac
2011-04-19 12:55 ` [PATCH 1/5] change API to use unsigned for #copies Zdenek Kabelac
2011-04-19 12:55 ` [PATCH 2/5] Cast to 'int' Zdenek Kabelac
2011-04-29 11:21   ` Milan Broz
2011-04-19 12:55 ` [PATCH 3/5] Fix sign warning Zdenek Kabelac
2011-04-19 12:55 ` [PATCH 4/5] Ignore dm_snprintf result Zdenek Kabelac
2011-04-19 12:55 ` [PATCH 5/5] Set our own in/out buffers Zdenek Kabelac
2011-04-29 11:15   ` Milan Broz [this message]

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=4DBA9DE3.9020506@redhat.com \
    --to=mbroz@redhat.com \
    --cc=lvm-devel@redhat.com \
    /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.
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.