Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp128885ybj; Thu, 19 Sep 2019 11:46:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJO7MEQl4WKVnRc/k+N6wk+vJJlYGxTfwWQjsXLehNqyACSKES7puhg35J9dRTUErb0obd X-Received: by 2002:a50:d096:: with SMTP id v22mr17816996edd.81.1568918760380; Thu, 19 Sep 2019 11:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568918760; cv=none; d=google.com; s=arc-20160816; b=gLFAEaj+MPIanl3D3aIIxDDNB+3kskabcDnj1aFLSeWjAgO9a5MD7NeoM8DouAXTQW OoJ+jCbOaWUYBWEG1TsTKDQDCea+2QY4Lm9OzWave6bAAw+dCZU3k58OwVLRys3L/tF3 3UaKCmNnX+eYetB8qR3bOBHampJ6MjPDcqwPy+g7R9X3Vt573kggoX4xaEE9bSrfyjw/ OVBG9qiWv95sDhpvnLfgIwapygue5IjqkVXBcwGo3LVggPc04+VVZjTb1w0eCdhXRL0N 7mJPdeDhOpUMb52XEjpWC0Fz1P619e/Qc2tZwUzOxhG8Mxrh7fu1B5RM+ER9RJS9wKhS AFig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2D5IwEzybWJpZFdM10ogtIs0+vzthBfjycahnNrmbPo=; b=C+X8sxa/yrEZtWC7DbMzGwjNelex81sA764couh9hqede3aGN8CQ7aABX4vH7dG6a9 WHEN3LgNgwbkKHoYYXQ/qlyD8PXIQUKfoMlUhu9GyE4lAZ9coi6nKXKK6YuBA6CPpvKy 5IJQTiIaRXJz2zZxA9SbkTR8D9AI9VS+wrdVsIA4hKAPNR46H69wqFC8H4bvEHmymeb4 YrKar5Uk4ON+HGVsi68ilJaCS4QOQfy4kUoEZrLEdHKZS45VxU/Qh5CcG7GCwQdiO0br 36V6/ocYjkcziuWMsxYieFcCVd0oxpdT1/ck/8Go8+bsDiXzjOvoU9IIg1vg3wH+Gm9s 2WPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si5021084ejk.250.2019.09.19.11.45.37; Thu, 19 Sep 2019 11:46:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389691AbfISRBw (ORCPT + 99 others); Thu, 19 Sep 2019 13:01:52 -0400 Received: from verein.lst.de ([213.95.11.211]:42775 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731729AbfISRBw (ORCPT ); Thu, 19 Sep 2019 13:01:52 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 80CD768B20; Thu, 19 Sep 2019 19:01:48 +0200 (CEST) Date: Thu, 19 Sep 2019 19:01:48 +0200 From: Christoph Hellwig To: Linus Torvalds Cc: "Darrick J. Wong" , linux-fsdevel , linux-xfs , Dave Chinner , Linux Kernel Mailing List , Eric Sandeen , Christoph Hellwig , Andreas Gruenbacher , Bob Peterson , cluster-devel Subject: Re: [GIT PULL] iomap: new code for 5.4 Message-ID: <20190919170148.GA8908@lst.de> References: <20190917152140.GU2229799@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 18, 2019 at 06:31:29PM -0700, Linus Torvalds wrote: > It seems to have come from "list_empty()", but the difference is that > it actually makes sense to check for emptiness of a list outside > whatever lock that protects the list. It can be one of those very > useful optimizations where you don't even bother taking the lock if > you can optimistically check that the list is empty. > > But the same is _not_ true of an operation like "list_pop()". By > definition, the list you pop something off has to be stable, so the > READ_ONCE() makes no sense here. Indeed. > Anyway, if that was the only issue, I wouldn't care. But looking > closer, the whole thing is just completely wrong. > > All the users seem to do some version of this: > > struct list_head tmp; > > list_replace_init(&ioend->io_list, &tmp); > iomap_finish_ioend(ioend, error); > while ((ioend = list_pop_entry(&tmp, struct iomap_ioend, io_list))) > iomap_finish_ioend(ioend, error); > > which is completely wrong and pointless. > > Why would anybody use that odd "list_pop()" thing in a loop, when what > it really seems to just want is that bog-standard > "list_for_each_entry_safe()" > > struct list_head tmp; > struct iomap_ioend *next; > > list_replace_init(&ioend->io_list, &tmp); > iomap_finish_ioend(ioend, error); > list_for_each_entry_safe(struct iomap_ioend, next, &tmp, io_list) > iomap_finish_ioend(ioend, error); > > which is not only the common pattern, it's more efficient and doesn't > pointlessly re-write the list for each entry, it just walks it (and > the "_safe()" part is because it looks up the next entry early, so > that the entry that it's walking can be deleted). That might be true for the current two cases that operate on a temporary local list, but in general we have lots of cases where we operate on lists that are not just local and where have to delete all the entries. Sure, we could somehow let them dangle and then just do a INIT_LIST_HEAD on the list later, but that is just asking for trouble down the road when people actually use list_empty in the functions called in the loop.