From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7116C11D0C for ; Thu, 20 Feb 2020 17:50:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A30920722 for ; Thu, 20 Feb 2020 17:50:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="VHirKNJD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A30920722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0A8596B0003; Thu, 20 Feb 2020 12:50:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 032846B0007; Thu, 20 Feb 2020 12:50:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3B646B000E; Thu, 20 Feb 2020 12:50:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id C7F336B0003 for ; Thu, 20 Feb 2020 12:50:12 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6805840F4 for ; Thu, 20 Feb 2020 17:50:12 +0000 (UTC) X-FDA: 76511244264.11.actor86_17e85cc0a80d X-HE-Tag: actor86_17e85cc0a80d X-Filterd-Recvd-Size: 5249 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 17:50:10 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id p34so1670098qtb.6 for ; Thu, 20 Feb 2020 09:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9LcvSEumTmXyuKFplLOO57e96BKQQeEk4RY39TL+hio=; b=VHirKNJDDO682guKBEd7Lh4Sdhh51LWyOruN25/r3aHd6uttqamXF0Y2SA7SURFcGF 9L68VvTMCycQxV8a8PVSRKwVlrRBX6dROpPZI2+TYVXxntJtO4mJrARFdxtJn8K2f0LX 7jmviilTZKEOD7cXwUqgwwYTXTAlVCWI4H8HphGY1AyOS0JkzhcsRMoHBwScPbu+Eghl lr3mqrpjO/hI6Mqqpdz1bwAZpagS8xbsNMtYg/gVu4+EkG2nZ7e+seyK7JK9UOIIsSbW iktcaKz88wwRW8q1+2Iz7hLBH+IFUEheTfhVWoJQBx196zKDvstwAtnve1heQWmWVFey OZHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9LcvSEumTmXyuKFplLOO57e96BKQQeEk4RY39TL+hio=; b=TOxTUpEPmww5VS56TI1VCKDXSTmwvOLr4cAyWosLb0I7y8u3VVAkV7Ea3Koox31cro 8sdVgWXVayka12n/yrUjFJrt2kMpJpJAzv0163aqkWzZIHucHg8IGlIde91HYhrd7zkH iLbHEi1CCWOQyUgVZswLcsF9TB+spKuKMxldNRpXlbTjjZlfSVDArCLk2LUqmf4cfxUr HMajkkBUMnE+bnKyWeLBTFxLRPrI4oadH5o/sRySLsaDRkT/s0RUI/HH23Omc2WJm7Rq 7BLqSXKVsGT8JTxIOhYu2JuOek7Xiu1ByFMjbN66vKu58DVTGNYLNPKnd3vCTnNwflLP ly1A== X-Gm-Message-State: APjAAAVpWEMh3cml5wrUXN96nIcrHXhtHxZlhU2sXaj7aC0yLDrWEO6d xL+ze7PWrotdFnQh8iInYxdnXw== X-Google-Smtp-Source: APXvYqzbtO/RIeVYLc6mfivNPQO8ldS0h+Q0UAxefaixOy8FmrW7r/AiWxWUfsQFv7WDc0SriYliDw== X-Received: by 2002:ac8:1ac1:: with SMTP id h1mr27444991qtk.255.1582221004432; Thu, 20 Feb 2020 09:50:04 -0800 (PST) Received: from localhost ([2620:10d:c091:500::1:3504]) by smtp.gmail.com with ESMTPSA id 65sm123024qtc.4.2020.02.20.09.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 09:50:03 -0800 (PST) Date: Thu, 20 Feb 2020 12:50:02 -0500 From: Johannes Weiner To: Dan Schatzberg Cc: Jens Axboe , Tejun Heo , Li Zefan , Michal Hocko , Vladimir Davydov , Andrew Morton , Hugh Dickins , Roman Gushchin , Shakeel Butt , Chris Down , Yang Shi , Thomas Gleixner , "open list:BLOCK LAYER" , open list , "open list:CONTROL GROUP (CGROUP)" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" Subject: Re: [PATCH v3 1/3] loop: Use worker per cgroup instead of kworker Message-ID: <20200220175002.GJ54486@cmpxchg.org> References: <118a1bd99d12f1980c7fc01ab732b40ffd8f0537.1582216294.git.schatzberg.dan@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <118a1bd99d12f1980c7fc01ab732b40ffd8f0537.1582216294.git.schatzberg.dan@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello Dan, On Thu, Feb 20, 2020 at 11:51:51AM -0500, Dan Schatzberg wrote: > +static void loop_process_work(struct loop_worker *worker, > + struct list_head *cmd_list, struct loop_device *lo) > +{ > + int orig_flags = current->flags; > + struct loop_cmd *cmd; > + > + current->flags |= PF_LESS_THROTTLE | PF_MEMALLOC_NOIO; > + while (1) { > + spin_lock_irq(&lo->lo_lock); > + if (list_empty(cmd_list)) > + break; > + > + cmd = container_of( > + cmd_list->next, struct loop_cmd, list_entry); > + list_del(cmd_list->next); > + spin_unlock_irq(&lo->lo_lock); > + loop_handle_cmd(cmd); > + cond_resched(); > + } The loop structure tripped me up, because it's not immediately obvious that the lock will be held coming out. How about the following to make the lock section stand out visually? spin_lock_irq(&lo->lo_lock); while (!list_empty(cmd_list)) { cmd = container_of(cmd_list->next, struct loop_cmd, list_entry); list_del(&cmd->list_entry); spin_unlock_irq(&lo->lo_lock); loop_handle_cmd(cmd); cond_resched(); spin_lock_irq(&lo->lo_lock); } > - loop_handle_cmd(cmd); > + /* > + * We only add to the idle list if there are no pending cmds > + * *and* the worker will not run again which ensures that it > + * is safe to free any worker on the idle list > + */ > + if (worker && !work_pending(&worker->work)) { > + worker->last_ran_at = jiffies; > + list_add_tail(&worker->idle_list, &lo->idle_worker_list); > + loop_set_timer(lo); > + } > + spin_unlock_irq(&lo->lo_lock); > + current->flags = orig_flags;