[xserver-xorg][PATCH 1/1] xwayland: ftruncate if posix_fallocate fails

Yuriy M. Kaminskiy yumkam at gmail.com
Tue Apr 26 12:32:48 UTC 2016


Ian Ray <ian.ray at ge.com> writes:

> On a slow system that is configured with SMART_SCHEDULE_POSSIBLE, large
> posix_fallocate() requests may be interrupted by the SmartScheduleTimer
> (SIGALRM) continuously. Fallback to ftruncate if posix_fallocate fails.
>
> Signed-off-by: Ian Ray <ian.ray at ge.com>
> ---
>  hw/xwayland/xwayland-shm.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/hw/xwayland/xwayland-shm.c b/hw/xwayland/xwayland-shm.c
> index e8545b3..342b723 100644
> --- a/hw/xwayland/xwayland-shm.c
> +++ b/hw/xwayland/xwayland-shm.c
> @@ -142,9 +142,12 @@ os_create_anonymous_file(off_t size)
>  #ifdef HAVE_POSIX_FALLOCATE
>      ret = posix_fallocate(fd, 0, size);
>      if (ret != 0) {
> -        close(fd);
> -        errno = ret;
> -        return -1;

But posix_fallocate() was used here for a reason?

When you use ftruncate(), it creates file with hole. If you mmap() file
with hole, and there will be no disk space at the moment page is
touched, it will trigger SIGBUS.

And this fallback is *especially* bad if posix_fallocate() returned ENOSPACE
or EIO.

> +        /* Fallback to ftruncate in case of failure. */
> +        ret = ftruncate(fd, size);
> +        if (ret < 0) {
> +            close(fd);
> +            return -1;
> +        }
>      }
>  #else
>      ret = ftruncate(fd, size);



More information about the xorg-devel mailing list