Return-Path: <tiff-bounces@lists.osgeo.org>
Received: from mailfep015.skynet.be ([10.35.4.199])
          by mailafep010-svc.mx.internal
          (InterMail vM.9.07.03.015 201-2473-138-3) with ESMTP
          id <20211216142753.OVLN19969.mailafep010-svc.mx.internal@mailfep015.skynet.be>
          for <chris.lindelaan@skynet.be>; Thu, 16 Dec 2021 15:27:53 +0100
Received: from mailgate214.isp.belgacom.be ([195.238.22.46])
          by mailfep015.skynet.be
          (InterMail vM.8.04.03.28.4 201-2389-100-182-103-20180124)
          with ESMTP
          id <20211216142753.SUZX7430.mailfep015.skynet.be@mailgate214.isp.belgacom.be>
          for <chris.lindelaan@skynet.be>; Thu, 16 Dec 2021 15:27:53 +0100
Authentication-Results: mx201.skynet.be; dkim=none (message not signed) header.i=none; spf=None smtp.pra=tiff-bounces@lists.osgeo.org; spf=Pass smtp.mailfrom=tiff-bounces@lists.osgeo.org; spf=Pass smtp.helo=postmaster@lists.osgeo.org
Received-SPF: None (mx201.skynet.be: no sender authenticity
  information available from domain of
  tiff-bounces@lists.osgeo.org) identity=pra;
  client-ip=140.211.15.3; receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="tiff-bounces@lists.osgeo.org";
  x-conformance=sidf_compatible
Received-SPF: Pass (mx201.skynet.be: domain of
  tiff-bounces@lists.osgeo.org designates 140.211.15.3 as
  permitted sender) identity=mailfrom; client-ip=140.211.15.3;
  receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="tiff-bounces@lists.osgeo.org";
  x-conformance=sidf_compatible; x-record-type="v=spf1";
  x-record-text="v=spf1 mx a:mail.osgeo.org a:lists.osgeo.org
  a:mail.osgeo.osuosl.org a:tracsvn.osgeo.osuosl.org -all"
Received-SPF: Pass (mx201.skynet.be: domain of
  postmaster@lists.osgeo.org designates 140.211.15.3 as
  permitted sender) identity=helo; client-ip=140.211.15.3;
  receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="postmaster@lists.osgeo.org";
  x-conformance=sidf_compatible; x-record-type="v=spf1";
  x-record-text="v=spf1 mx a:mail.osgeo.org a:lists.osgeo.org
  a:mail.osgeo.osuosl.org a:tracsvn.osgeo.osuosl.org -all"
X-Ironport-Dmarc-Check-Result: validskip
IronPort-SDR: wQ/audAbl2I02AOCk2CTF+G0K6tLXImO5/g0mb7j5WYfRtnnw3nKmWckRV06hBS7Q46+Qm8Mlp
 re+SLIGtYGjmyXO8UMrUINtBshkEEB44/XGOB6LStgxrazKBwySBkLhF9jkS7g+V5j7K0yPXvW
 9tM3DL9Chue4hAkSkFDX81h6dKEQ1kjWBFr0SFymoYKVhANUKRTiSgS4O7EERS1NwudAQirZw5
 exwJVxDFFsvjjKBQlpOi+U71pBkXQj4BPSqofa9mhQj+7d7B+2Mmiem7VAF82yl4zSOf3ysgMA
 75H42/lPqWbbHtQs2GFEfphj
X-Proximus-RemoteIp: 140.211.15.3
X-Proximus-Mfrom: tiff-bounces@lists.osgeo.org
X-Proximus-Rcpto: chris.lindelaan@skynet.be
X-IPAS-Result: =?us-ascii?q?A0ELAgBTTLthhwMP04xaHgEBCxIMQIQAGQFlWAEmAwc5i?=
 =?us-ascii?q?BKFOYgQA4sbhnOMMBQBAQIBAQEBAQkqCwoCBAEBAQIBA4gwHwYBBDQTAQIEA?=
 =?us-ascii?q?QEBAQMCAwEBAQEBAQMBAQEEAQEBAgEBAgMCAgEBAhABAQEBDQsJBQgMBR4FN?=
 =?us-ascii?q?gZeagRmBl8EgXQMBgEHJQ2CNQUCAx8BBm6BBwEBAQEBAQEBAQEBAQEBAQEBA?=
 =?us-ascii?q?QEBFgINUmcBAgMBAQE3DAoeCwMDAQIGAQEKGB4EBAgDASMBLwYTBQSCbwGCc?=
 =?us-ascii?q?SYFCrBDgTOBAYMVhQGBY4E6jjJDgUlEehszA4JEMD6CWAsBAwGHOCIEki1SH?=
 =?us-ascii?q?zIMGxwaARsPAQVWdgkpAjgNkXhSjjtgnW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-HdrOrdr: A9a23:Gg3vFa4BtW5gLl+veAPXwBfXdLJyesId70hD6qkRc202TiX8ra
 uTdZsguSMc5Ax/ZJhYo6H+BEDiewK+yXcW2+gs1OyZLWzbUQKTRekJgLcKqAeBJ8SRzIBgPK
 1bAsxD4PqZNykd/L+KmHjCL/8QhPqi+KCsify29QYRcegTUdAb0++mYjzrdXGffGF9dOYE/T
 Gnl7R6mwY=
X-IronPort-Anti-Spam-Filtered: true
X-MGA-submission: =?us-ascii?q?MDFqhorhXqkPWqQFshZCj7vc+Z5DwjEs3houTu?=
 =?us-ascii?q?O4NUnFdYWfvXIqoV6qCdAQZn8JClmS5Zvk0FAHtAmir/VZwkKFK+6d6Q?=
 =?us-ascii?q?vu5lLkXl6vZTFz4MnPsQHSs/cBbrNWbnI8uR8=3D?=
Received: from osgeo6.osgeo.osuosl.org (HELO lists.osgeo.org) ([140.211.15.3])
  by mx201.skynet.be with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Dec 2021 15:27:51 +0100
Received: from osgeo6.osgeo.osuosl.org (localhost [127.0.0.1])
	by lists.osgeo.org (Postfix) with ESMTP id 9FBBF611F8DB;
	Thu, 16 Dec 2021 06:27:44 -0800 (PST)
Received: from smtp.simplesystems.org (smtp.simplesystems.org [65.66.246.90])
 by lists.osgeo.org (Postfix) with ESMTPS id D8A61611F8CD
 for <tiff@lists.osgeo.org>; Thu, 16 Dec 2021 06:27:42 -0800 (PST)
Received: from scrappy.simplesystems.org (scrappy.simplesystems.org
 [65.66.246.73])
 by smtp.simplesystems.org (8.14.4+Sun/8.14.4) with ESMTP id 1BGERZ7v027250;
 Thu, 16 Dec 2021 08:27:35 -0600 (CST)
Date: Thu, 16 Dec 2021 08:27:35 -0600 (CST)
From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
X-X-Sender: bfriesen@scrappy.simplesystems.org
To: Milian Wolff <milian.wolff@kdab.com>
cc: tiff@lists.osgeo.org
In-Reply-To: <2795041.3CL6bd3hI7@milian-workstation>
Message-ID: <alpine.GSO.2.20.2112160756480.20994@scrappy.simplesystems.org>
References: <2795041.3CL6bd3hI7@milian-workstation>
User-Agent: Alpine 2.20 (GSO 67 2015-01-07)
MIME-Version: 1.0
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
 (smtp.simplesystems.org [65.66.246.90]); Thu, 16 Dec 2021 08:27:36 -0600 (CST)
Subject: Re: [Tiff] Ensuring buffer alignment when creating tiff files
X-BeenThere: tiff@lists.osgeo.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.osgeo.org>
List-Unsubscribe: <https://lists.osgeo.org/mailman/options/tiff>,
 <mailto:tiff-request@lists.osgeo.org?subject=unsubscribe>
List-Post: <mailto:tiff@lists.osgeo.org>
List-Help: <mailto:tiff-request@lists.osgeo.org?subject=help>
List-Subscribe: <https://lists.osgeo.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.osgeo.org?subject=subscribe>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: tiff-bounces@lists.osgeo.org
Sender: "Tiff" <tiff-bounces@lists.osgeo.org>

On Thu, 16 Dec 2021, Milian Wolff via Tiff wrote:
>
> As you can see, these offsets are misaligned for a 2byte/16bit greyscale
> image.
>
> Looking at the libtiff API, we cannot find anything that would allow us to
> ensure that the SubIFDs are aligned correctly. Are we missing something or is
> this simply not possible currently?
>
> We think that it would only require a small change in the code base, namely
> ensuring that the seek at [1] ends at an aligned address based on the
> BitsPerSample for the current IFD.

The notion of writing 'aligned' data (which requires inserting some 
dead space to assure alignment) is interesting and seems useful. 
This is mostly useful when the data is not compressed.  I have not 
heard of this before in the context of the TIFF format, but some some 
other formats take care to assure it.  Obviously, alignment could only 
be assured if the file is written by a TIFF writer which assures it.

You seem to be talking about aligning the TIFF data samples (a good 
thing), but there may be other beneficial alignment factors such as 
alignment to mmap memory page boundaries, or filesystem block-size 
boundaries.

Regardless, take care not to be sucked into the vortex of using memory 
mapping to read files.  When using memory mapping to read data, your 
program loses control and the thread which is doing the reading is put 
to sleep while the I/O is taking place.  The I/Os are usually the size 
of a memory page, which is often just 4k.  This means that your 
program gets put to sleep more often than desired, with many more 
context switches than if a larger copy-based I/O was used.  If the 
data has recently been read before then memory mapping seems great 
since the data is likely to already be cached in memory.

When reading from a file, it is common for the operating system to try 
to deduce if the reading is sequential or random.  If it is able to 
deduce that the reading is sequential, then it may pre-read data in 
order to lessen the hit (time spent sleeping) when the data is read in 
order.  Operating systems may not have useful support for detecting 
sequential reads when using mmap to do the reading.  TIFF requires 
random access and so the operating system might be slow to detect and 
optimize for a sequential read.

If the operating system does not provide a "unified page cache" with 
the filesystem, then there may be a filesystem data cache, and another 
copy of the data for use with mmap.  This increases memory usage and 
does not avoid a data copy.  It seems like the "unified page cache" 
approach has falled by the wayside since it is difficult to implement 
with the many filesystems available.  Instead operating systems have 
moved toward offering "direct I/O" to lessen caching and data copies.

In summary, the use of mmap and carefully aligned input data might not 
provide actual benefit over larger programmed (or scheduled via 
async-I/O) reads into a aligned buffer, even though it clearly 
requires an extra memory copy.

Bob
-- 
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
Public Key,     http://www.simplesystems.org/users/bfriesen/public-key.txt
_______________________________________________
Tiff mailing list
Tiff@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/tiff
