lkml.org 
[lkml]   [1997]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: fork: out of memory
    On Tue, 25 Nov 1997, Rogier Wolff wrote:

    > Alan Cox wrote:
    > >
    > > > These extra allocations would go to get_unused_fd() in fs/open.c.
    > > > I didn't find any other place (but I just started working on it, it will
    > > > take some time).
    > >
    > > The socket stuff allocates fd's. Im not sure it goes via fs/open.c properly
    > > (yes it should)
    > >
    > > > Some preliminary searching showed me that I will have to modify at
    > > > least 50 files!!! No big things, but absolutely neccessary if you ask
    > > > me (unless I have problems in logic :)).
    > >
    > > That is a good sign that its time someone took the functions that
    > > reference it directly and replaced them with one or two inline functions
    > >
    > > > When you say "atomically" do you mean "in one place" or with
    > >
    > > I mean "in a way that no other task on any processor can have accessed it
    > > during the change"
    >
    > What's wrong with
    >
    >
    > /* This piece of code allows concurrent read access to the fd
    > array at all times. There are three lines of code that need
    > to be protected against concurrent write access. These are
    > protected by the "aquire/release_write lock". A mechanism
    > for this needs to be in place anyway: we don't want another
    > another thread allocating this very SAME fd concurrently.
    > Don't we? */
    >
    > if (newfd >= files->cur_allocated) {
    > if (newfd > files->cur_allocated) {
    > /* Oops. Someone else must already be updating
    > this, Not now baby.... I have a headache */
    > return -ENOMEM;
    > }
    > newfds = kmalloc (1024 *sizeof (struct file *), GFP_KERNEL);
    > if (!newfds) {
    > return -ENOMEM;
    > }
    > aquire_write_lock (files);
    > memcpy (newfds, files->fd,
    > files->cur_allocated * sizeof (struct file *));
    > /* This is the wrong moment to be changing the old
    > structure. */
    > files->fd = newfds;
    > files->cur_allocated = 1024;
    > release_write_lock (files);
    > /* The old one could be freed, but it is connected to
    > the files structure. */
    > }
    >
    > Left as an excercise for the reader: change 1024 to "cur_allocated * 4"

    Do you have to keep the old fd list around to handle code which may have a
    pointer to it?

    john alvord


    \
     
     \ /
      Last update: 2005-03-22 13:40    [W:0.023 / U:121.076 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site