util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] fincore: Handle large files on 32 bit without LFS
@ 2018-02-25 19:27 Tobias Stoeckmann
  2018-02-26 10:56 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Stoeckmann @ 2018-02-25 19:27 UTC (permalink / raw)
  To: util-linux

If util-linux is installed on a system without large file support,
an out of memory issue can occur while processing a file which is
2 GB in size:

$ ./configure --disable-largefile && make

$ dd if=/dev/zero of=2gb-file seek=2147483646 count=1 bs=1
$ fincore 2gb-file
(endless loop)
fincore: failed to do mmap: 2gb-file: Cannot allocate memory

Even though iterating with "len" seems counter-intuitive, it fixes
this issue. The variable len is only in the last iteration not a
multiplication of pagesize -- which is the requirement for mmap.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
 misc-utils/fincore.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c
index ab11594cc..f9534e85b 100644
--- a/misc-utils/fincore.c
+++ b/misc-utils/fincore.c
@@ -194,12 +194,11 @@ static int fincore_fd (struct fincore_control *ctl,
 		       off_t *count_incore)
 {
 	size_t window_size = N_PAGES_IN_WINDOW * ctl->pagesize;
-	off_t file_offset;
+	off_t file_offset, len;
 	int rc = 0;
 	int warned_once = 0;
 
-	for (file_offset = 0; file_offset < file_size; file_offset += window_size) {
-		off_t len;
+	for (file_offset = 0; file_offset < file_size; file_offset += len) {
 		void  *window = NULL;
 
 		len = file_size - file_offset;
-- 
2.16.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] fincore: Handle large files on 32 bit without LFS
  2018-02-25 19:27 [PATCH 2/2] fincore: Handle large files on 32 bit without LFS Tobias Stoeckmann
@ 2018-02-26 10:56 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2018-02-26 10:56 UTC (permalink / raw)
  To: Tobias Stoeckmann; +Cc: util-linux

On Sun, Feb 25, 2018 at 08:27:59PM +0100, Tobias Stoeckmann wrote:
>  misc-utils/fincore.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-26 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-25 19:27 [PATCH 2/2] fincore: Handle large files on 32 bit without LFS Tobias Stoeckmann
2018-02-26 10:56 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).