Bug 430768 - opendir / __alloc_dir tries to malloc st_blksize; may fail
opendir / __alloc_dir tries to malloc st_blksize; may fail
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
rawhide
All Linux
low Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-29 13:20 EST by Eric Sandeen
Modified: 2008-04-10 06:04 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-04-10 06:04:59 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Eric Sandeen 2008-01-29 13:20:56 EST
A filesytem may report its preferred IO size (not fundamental block size) in
st_blksize, and this might be fairly large:

[root@magnesium tmp]# stat mnt
  File: `mnt'
  Size: 27        	Blocks: 0          IO Block: 536870912 directory
Device: 700h/1792d	Inode: 128         Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2008-01-29 11:40:37.091973914 -0600
Modify: 2008-01-29 11:40:50.078976949 -0600
Change: 2008-01-29 11:40:50.078976949 -0600

It appears that opendir / __alloc_dir will attempt to use that size, without
fallback:

[root@magnesium tmp]# strace -otrace ./test
[root@magnesium tmp]# grep -3 53687 trace
open("mnt", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|0x80000) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=27, ...}) = 0
fcntl64(3, F_GETFD)                     = 0x1 (flags FD_CLOEXEC)
mmap2(NULL, 536875008, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x97f86000
munmap(0x97f86000, 536875008)           = 0
close(3)                                = 0
exit_group(0)                           = ?

Since st_blksize is "preferred" and the alternative is an opendir failure,
should this fall back to smaller sizes on ENOMEM?

Thanks,
-Eric
Comment 1 Jakub Jelinek 2008-02-04 04:17:09 EST
And so will many other apps do.  Using such huge preferred IO size is not very wise.
Comment 2 Eric Sandeen 2008-02-04 09:06:57 EST
Agreed, and perhaps even if reporting large IO sizes for files, the fs should
report something smaller for directories.

But in any case, do you think that glibc (and other apps...) should fall back to
smaller sizes if allocation fails?
Comment 3 Ulrich Drepper 2008-03-30 04:52:49 EDT
I've checked in upstream a patch to try a possibly smaller allocation if the
size provided by st_blksize couldn't be fulfilled.
Comment 4 Jakub Jelinek 2008-04-10 06:04:59 EDT
Should be in glibc-2.7.90-14

Note You need to log in before you can comment on or make changes to this bug.