Re: dm-crypt using kthread

From: Jeff Garzik (jgarzik_at_pobox.com)
Date: 02/16/04

  • Next message: Christophe Saout: "Re: dm-crypt using kthread (was: Oopsing cryptoapi (or loop device?) on 2.6.*)"
    Date:	Sun, 15 Feb 2004 21:58:39 -0500
    To: Christophe Saout <christophe@saout.de>
    
    

    Christophe Saout wrote:
    > Am Mo, den 16.02.2004 schrieb Jeff Garzik um 03:10:
    >
    >
    >>>+ /*
    >>>+ * if additional pages cannot be allocated without waiting,
    >>>+ * return a partially allocated bio, the caller will then try
    >>>+ * to allocate additional bios while submitting this partial bio
    >>>+ */
    >>>+ if ((i - bio->bi_idx) == (MIN_BIO_PAGES - 1))
    >>>+ gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT;
    >>
    >>If the caller said they can wait, why not wait?
    >
    >
    > How can the caller say this?

    There is a gfp_mask there :)

    >>>+ set_task_state(current, TASK_INTERRUPTIBLE);
    >>>+ while (!(bio = kcryptd_get_bios())) {
    >>>+ schedule();
    >>>+ if (signal_pending(current))
    >>>+ return 0;
    >>>+ }
    >>>+ set_task_state(current, TASK_RUNNING);
    >>
    >>You just keep calling schedule() rapid-fire until you get a bio? That's
    >>a bit sub-optimal.
    >
    >
    > That's wrong anyway. I was just making sure I was calling
    > kcryptd_get_bios after schedule. schedule() will sleep and woken after
    > someone added a bio to the list.
    >
    > I've changed it to an if now and call kcryptd_get_bios after schedule.
    >
    > I'm calling it twice because it is likely that someone started a new
    > list while the old list is being processed and I don't want to sleep in
    > this case, just fall through.
    >
    > The kcryptd_get_bios needs to be after state = TASK_INTERRUPTIBLE to
    > avoid a race. If someone wakes the process after kcryptd_get_bios but
    > before schedule it resets the state to TASK_RUNNING so that the schedule
    > won't sleep.

    This sounds like a lot of work, just to reimplement what a semaphore
    does for you :)

    When you down(), you sleep, waiting for new work. Each time new work
    occurs, on any cpu, you call up(). This is perfect for a kernel thread,
    which can sleep, just like a semaphore needs. If you want to be
    interruptible by signals (such as sysadmin killing your thread, for some
    reason), then use down_interruptible().

    There is typically one special case -- killing your thread on shutdown.
      The typical solution is to set a flag thread_shutdown, and then up().

            Jeff

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Christophe Saout: "Re: dm-crypt using kthread (was: Oopsing cryptoapi (or loop device?) on 2.6.*)"

    Relevant Pages

    • [PATCH 05/05] mm GFP_ATOMIC comment
      ... Clarify in comments that GFP_ATOMIC means both "don't sleep" ... The caller may dip into page reserves a bit more if the caller ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [SCHED] wrong priority calc - SIMPLE test case
      ... 2 to begin treating all new sleep as noninteractive (stern ... These are all /proc settings at the moment, so I can set set my starvation ... pain threshold from super duper desktop to just as fair as a ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Post-halloween doc updates.
      ... > | have at least one working method of putting a laptop to sleep? ... > I have no problem putting the laptop to sleep. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: High CPU temp on Athlon MP w/ recent 2.6 kernels
      ... >haven't got time to contact devs with that, but I do know for sure that ... >AFAIK my xmms uses OSS emulation and rhytmbox is native alsa.) ... >easily we go into sleep. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [patch] stop inotify from sending random DELETE_SELF event under load
      ... >>sleep for a day ... That fd may be available to multiple processes, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)