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=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 E427CC433DB for ; Thu, 4 Feb 2021 15:56:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 68DD564F65 for ; Thu, 4 Feb 2021 15:56:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68DD564F65 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id ECF4C6B0006; Thu, 4 Feb 2021 10:56:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E80B16B006E; Thu, 4 Feb 2021 10:56:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBCEC6B0080; Thu, 4 Feb 2021 10:56:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id C70C86B0006 for ; Thu, 4 Feb 2021 10:56:23 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9295D1EE6 for ; Thu, 4 Feb 2021 15:56:23 +0000 (UTC) X-FDA: 77781037446.06.knot96_0709edf275dd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 6EF2110043809 for ; Thu, 4 Feb 2021 15:56:23 +0000 (UTC) X-HE-Tag: knot96_0709edf275dd X-Filterd-Recvd-Size: 5042 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 15:56:22 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id x23so857645pfn.6 for ; Thu, 04 Feb 2021 07:56:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bCCaUVi9BPMivSd/JjnmDZicqO5VGVuxEY7PUQjIT88=; b=rlZgV+XQhv7Yhfg2tHnSnXCKKbzm84eznk312M6PxgAwzfTh4Ik7suX8rLMrd8rXzW ELbY53/nujaDFMiP14r3bJRXJe2SLOoDDm7sffhsqmt4GKW+wmpKq6Gdtfj2QdFO17T+ WrG64+XjOEDDvget+WoHZdNRbg5IRNW8ARaNBPxIRGcCFwjnSRzV0hu2+Sg9n5s1otFy dIe6RG99T8b1bYWd9JqmT4Sgzp+tBEy+/04B4IeuCr5ItLShwKeV6hjbqyEvOKR40jJe PdJGOuMShSOj8Gf4D32HY3XPIV4w8c5fUSBIfYPjxjpKYoZdYKnWF1oTvlasKNpW/y0T fP8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bCCaUVi9BPMivSd/JjnmDZicqO5VGVuxEY7PUQjIT88=; b=aEF+5wWJuZr9pYSmKyXm83C/kxOYgo+LdhLU2sxdH/lfyQdrfaJglJyx2+CnoYOJE2 TF/1nyt+QCzfhZaK08m02QKSyJoF3zdYODWh2aF3WWL2+8Pa9GjIF4k9r7J6lCdNRcbz wF5l3hglMxcy4d8VXrYcE5ed0USBrb9Wm0U8QZNHRJhIUvItHfgFl/cf7d1Mbz2NC+r2 nKYg+Bo8Rn+1ODqq2JnAkrTAYEWg6NCJBOxBDySdBbLtNvf9BQdWBmBOeDXC3EFCP09o WNl8Y9Z1ioWm34WPbrOoBcnqMUuHnp/VO1dXwGtubop27TvROHitgV9+e5AWca6Tgj9j sqdg== X-Gm-Message-State: AOAM5303YfaceRSrlA2MW7Is7xAdom30X4gFRck6AJQMr+i95+fFnZYF cSZzbWtDS/iST3DT+7XV3EbPMAVvF6GSXOjz3VI3S5bZVcY= X-Google-Smtp-Source: ABdhPJzXtbVw14PHJVJ/P6K8tkRvunxd2TP14mtVIL9yWCyPsjhzxjQLtCgjheeh3TtrPvDyiMiinT+N4rjzr0uQEhw= X-Received: by 2002:a63:1f21:: with SMTP id f33mr9775637pgf.31.1612454181401; Thu, 04 Feb 2021 07:56:21 -0800 (PST) MIME-Version: 1.0 References: <20210204105320.46072-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Thu, 4 Feb 2021 23:55:45 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: memcontrol: replace the loop with a list_for_each_entry() To: Johannes Weiner Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" 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: On Thu, Feb 4, 2021 at 11:14 PM Johannes Weiner wrote: > > On Thu, Feb 04, 2021 at 06:53:20PM +0800, Muchun Song wrote: > > The rule of list walk has gone since: > > > > commit a9d5adeeb4b2 ("mm/memcontrol: allow to uncharge page without using page->lru field") > > > > So remove the strange comment and replace the loop with a > > list_for_each_entry(). > > > > Signed-off-by: Muchun Song > > --- > > mm/memcontrol.c | 17 ++--------------- > > 1 file changed, 2 insertions(+), 15 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 6c7f1ea3955e..43341bd7ea1c 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -6891,24 +6891,11 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) > > static void uncharge_list(struct list_head *page_list) > > { > > struct uncharge_gather ug; > > - struct list_head *next; > > + struct page *page; > > > > uncharge_gather_clear(&ug); > > - > > - /* > > - * Note that the list can be a single page->lru; hence the > > - * do-while loop instead of a simple list_for_each_entry(). > > - */ > > - next = page_list->next; > > - do { > > - struct page *page; > > - > > - page = list_entry(next, struct page, lru); > > - next = page->lru.next; > > - > > + list_for_each_entry(page, page_list, lru) > > uncharge_page(page, &ug); > > - } while (next != page_list); > > - > > uncharge_batch(&ug); > > Good catch, this makes things much simpler. > > Looking at the surrounding code, there also seems to be no reason > anymore to have uncharge_list() as a separate function: there is only > one caller after the mentioned commit, and it's trivial after your > change. Would you mind folding it into mem_cgroup_uncharge_list()? Will do. Thanks. > > The list_empty() check in that one is also unnecessary now: the > do-while loop required at least one page to be on the list or it would > crash, but list_for_each() will be just fine on an empty list. Right. It makes things more simple. > > Thanks