[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [lvm-devel] [PATCH 5/5] Set our own in/out buffers



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

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]