lazy allocation of struct block_device
From [email protected] Sun Sep 2 01:54:52 2001
On Sat, 1 Sep 2001 [email protected] wrote:
> Since the refcount is for the device struct, we cannot do anything > until that count hits zero. Then the release method of the device struct > is called (which frees it, or decrements a refcount for the module).
Wait a minute. You had suggested (upthread) that these objects are allocated by partition code and contain per-partition data. Freeing them once the device is closed looks very odd.
The partition data itself is in the gendisk chain. A device struct contains a pointer to it.
But this is a separate discussion: what is the precise contents of device struct and driver struct.
(I have used different versions. My main interest was always in turning k[b]dev_t into a pointer and removing the arrays. Since some of the arrays are 1-dimensional and some are 2-dimensional, the mechanical conversion leads to a majorstruct that contains the integer major and a name function and the contents of the 1-dimensional arrays, and a minorstruct that contains the integer minor and the contents of the 2-dimensional arrays and a pointer to the majorstruct. People tend to panic "don't you know that there is no 1-1 corr.." when they hear "majorstruct" so I started using "driverstruct".)
Quoted 3 lines
After this
i_bcdevcannot be used anymore.
Since we don't know whether this happened already,i_bcdevmust be recomputed on each open or mount.
... and that means that we can't make devfs-like filesystems just set ->i_bdev (or ->i_cdev) at read_super() (or lookup()) and avoid all mess with major/minor allocation. IMO that's unfortunate, especially since majors allocation is on the permanent freeze.
That majors allocation is frozen is not my problem.
I make life simple with a 64-bit dev_t. Everybody else already has the disadvantages of a 64-bit dev_t, since glibc moves 64 bits around, but not the advantage of a large namespace.
But that is a separate discussion.
Concerning devfs, I don't use it and have not really thought about it. I think my point of view would be that devfs provides a different object. A device node in a filesystem is a pair (pathname, dev_t). Opening it gives the triple (pathname, dev_t, kdev_t).
What devfs provides is (pathname), after opening (pathname, kdev_t). But I think the pointer kdev_t (or i_bcdev) must still be recomputed:
it remains true that modules can be unloaded.
Quoted 5 lines
(One might invent additional data structure to avoid this recomputation, but data structures take memory and add the complication that they must be kept consistent and up-to-date. Since mounting, or opening a block device, are very infrequent operations, it does not matter that we do a possibly superfluous
bdopen().)
Once you look at character devices (they have same set of problems) frequency goes up big way.
True. I still think there would be no problem - this reopen is not expensive.
Alternatives like putting these things in a list are much worse, since that would slow down the handling of all inodes, not only device nodes.
Andries
Quoted 4 lines · On Sun, 2 Sep 2001 [email protected] wrote:
That majors allocation is frozen is not my problem.
I make life simple with a 64-bitdev_t. Everybody else already has the disadvantages of a 64-bitdev_t, since glibc moves 64 bits around, but not the advantage of a large namespace.
Not an option for any tree I'd ever run on my box and IIRC Linus was not likely to inflict that on his. As for the glibc...
a) not everything uses this piece of shit
b) it would be really nice to get rid of it completely someday
Quoted 1 line
But that is a separate discussion.
<nod>
Quoted 5 lines
Concerning devfs, I don't use it and have not really thought about it. I think my point of view would be that devfs provides a different object. A device node in a filesystem is a pair (pathname,
dev_t). Opening it gives the triple (pathname,dev_t,kdev_t).
What devfs provides is (pathname), after opening (pathname,kdev_t).
Wait a second. To hell with devfs, I'm talking about any synthetic tree containing device nodes. Being forced to allocate a point in numeric namespace just to be able to associate a driver-created inode with (also driver-created) device... Looks rather bogus, not to mention the ugliness of maintaining said numeric namespace.
Quoted 2 lines
But I think the pointer
kdev_t(ori_bcdev) must still be recomputed:
it remains true that modules can be unloaded.
Umm... So what? They can be unloaded only when we have device not opened. We might leave both allocation and freeing to driver-side code (and that includes grok_partitions()) and let the freeing code reset ->i_bdev and friends in all relevant inodes.
Quoted 3 lines
Alternatives like putting these things in a list are much worse, since that would slow down the handling of all inodes, not only device nodes.
???blkdev_open() would do list_add()
freeing foo_device would go through the list and reset ->i_bdev/do list_del() for each element.
Where's the overhead for non-device inodes?
Quoted 4 lines
Not an option for any tree I'd ever run on my box and IIRC Linus was not likely to inflict that on his. As for the glibc...
a) not everything uses this piece of shit
b) it would be really nice to get rid of it completely someday
In the userspace world the 64bit dev_t doesn't show up in anyones profiles its an unusual opaque cookie compare, or a cast (and the cast case gcc generates nice code for anyway).
Alan
Quoted 4 lines · Alexander Viro
On Sun, 2 Sep 2001 [email protected] wrote:
Quoted 8 lines
Quoted 4 lines
That majors allocation is frozen is not my problem.
I make life simple with a 64-bitdev_t. Everybody else already has the disadvantages of a 64-bitdev_t, since glibc moves 64 bits around, but not the advantage of a large namespace.Not an option for any tree I'd ever run on my box and IIRC Linus was not likely to inflict that on his. As for the glibc...
a) not everything uses this piece of shit
Nod.
Quoted 1 line
b) it would be really nice to get rid of it completely someday
Or at the very least, to selectively not compile large chunks of stuff that went in that I will never need. Stuff that isn't there on libc5 and other Unices. Something that takes up less than half a floppy. And having source and binary compatibility between major releases wouldn't hurt either!
Quoted 11 lines
Quoted 5 lines
Concerning devfs, I don't use it and have not really thought about it. I think my point of view would be that devfs provides a different object. A device node in a filesystem is a pair (pathname,
dev_t). Opening it gives the triple (pathname,dev_t,kdev_t).
What devfs provides is (pathname), after opening (pathname,kdev_t).Wait a second. To hell with devfs, I'm talking about any synthetic tree containing device nodes. Being forced to allocate a point in numeric namespace just to be able to associate a driver-created inode with (also driver-created) device... Looks rather bogus, not to mention the ugliness of maintaining said numeric namespace.
Nod.
Quoted 7 lines
Quoted 2 lines
But I think the pointer
kdev_t(ori_bcdev) must still be recomputed:
it remains true that modules can be unloaded.Umm... So what? They can be unloaded only when we have device not opened. We might leave both allocation and freeing to driver-side code (and that includes
grok_partitions()) and let the freeing code reset ->i_bdev and friends in all relevant inodes.
Yep. Having to allocate/search for a device structure during open(2) is insane. It's wasteful. For ext2fs you can do it in lookup(), and for devfs (or similar) you can do the ideal thing: when the device entry is registered with the FS (i.e. only once).
Regards, Richard.... Permanent: [email protected] Current: [email protected]
Quoted 4 lines · Richard Gooch
Yep. Having to allocate/search for a device structure during open(2) is insane. It's wasteful. For ext2fs you can do it in
lookup(), and for devfs (or similar) you can do the ideal thing: when the device entry is registered with the FS (i.e. only once).
No. We _must_ do it on ->open() for cases when it had been NULL. Driver might be not there at ->lookup() time and hunting down all inodes with give major/minor is insanity.
Now, if inode had been created by the driver - sure, we create the association between it and <whatever>_device from the very beginning.
We must support device nodes on normal filesystems. Period. They are there on tons of boxen and current support for device nodes on synthetic trees is _not_ suitable for general use (== I'd question sanity of anyone using it on production multiuser boxen).
Support for such beasts is there to stay. However, we shouldn't do things that make allocation of new majors mandatory. IOW, as far as I'm concerned solutions that do not allow "establish connection with foo_device upon inode creation and don't bother with device number for that one" are broken.
Quoted 4 lines · Alexander Viro
On Sun, 2 Sep 2001, Richard Gooch wrote:
Quoted 8 lines
Quoted 4 lines
Yep. Having to allocate/search for a device structure during open(2) is insane. It's wasteful. For ext2fs you can do it in
lookup(), and for devfs (or similar) you can do the ideal thing: when the device entry is registered with the FS (i.e. only once).No. We _must_ do it on ->open() for cases when it had been NULL. Driver might be not there at ->lookup() time and hunting down all inodes with give major/minor is insanity.
Apologies. Let me clarify what I meant: it's insane to only ever allow allocate/search during open(2).
Oh, and yeah: doing allocate/search during lookup() for ext2fs is a bad idea. Wasn't thinking straight.
Quoted 3 lines
Now, if inode had been created by the driver - sure, we create the association between it and <whatever>_device from the very beginning.
Yep. That's what I meant.
Quoted 1 line
We must support device nodes on normal filesystems.
Of course. No argument.
Quoted 5 lines
Support for such beasts is there to stay. However, we shouldn't do things that make allocation of new majors mandatory. IOW, as far as I'm concerned solutions that do not allow "establish connection with
foo_deviceupon inode creation and don't bother with device number for that one" are broken.
Nod.
Regards, Richard.... Permanent: [email protected] Current: [email protected]