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 C2CA7C433E0 for ; Thu, 4 Feb 2021 15:14:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1FFCB64F58 for ; Thu, 4 Feb 2021 15:14:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1FFCB64F58 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 68AA66B0005; Thu, 4 Feb 2021 10:14:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63B3B6B0006; Thu, 4 Feb 2021 10:14:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 553BB6B006C; Thu, 4 Feb 2021 10:14:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 3F8CF6B0005 for ; Thu, 4 Feb 2021 10:14:14 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 003FB824999B for ; Thu, 4 Feb 2021 15:14:13 +0000 (UTC) X-FDA: 77780931228.22.cream86_4305445275dd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4D46E18038E72 for ; Thu, 4 Feb 2021 15:14:13 +0000 (UTC) X-HE-Tag: cream86_4305445275dd X-Filterd-Recvd-Size: 4900 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 15:14:12 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id u16so1840737qvo.9 for ; Thu, 04 Feb 2021 07:14:11 -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=rSIFYGhhFddePwX4nFIG//fqjMTXGZtm1TOG4qBhrCg=; b=pUezDEZQ4njLOWPSWqusqTJWSM+RIcwjXnsGMScZPcUpPTHTLLB1LC6j3HQ+NUylpm ce8EnFUHaNH7LO9bmQ6KqtQgQgDiECYrr+oucQSZcgmN/7gQ4qzoiKP7fxpHvrGZDA7X pwpDgvyVTB0QbFuQOArsSuWeibbvA6gJ90GxJyQQ/4a57SykMlMsFMxHY9huq1qYDGHY 1cNeyEnMtrXDJZeswRiBim85+PxB64GJmwA+kZeTJHPsT2NUaIyj7CgvoKXGrF9o6PKn 8iSr36F2vrztBPbao/2Uf1mmJyichJKkZbHjKsxzZD6BJ1+YAWSes7bfeG++EbAgWUtX GbYQ== 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=rSIFYGhhFddePwX4nFIG//fqjMTXGZtm1TOG4qBhrCg=; b=sPP0e4jyBrFr+1zclTJz56OUHaz+AlRM+K4HgYfMRqLa+mlytx3y+HWaW4voaLufj3 m/2nSF0kv7pYAB8NqqcVr7hcYV5azHl1Q+cc4R6Pd7wJnDRDpbS4nWr7gDpNnfpzbc+f hHHVh84P5J76iS0GuJT+1C2+nRJUQ9F4pe5igqN3bDZAwk5PECQhdm74/SEDb0nN3xLb cYh/k8R4XkV3++uSHj0iRQVpyjTn1WRgjr5h5O9SyVRL8JO+vgmomfJz36RyKh4JpuqV wygYMc8LgmjfeK2M98jrDpcVhWoOT8JxT7yo7GcIlzHlqz3p6l+BnJ6ddDnrPTUTzzgv J8og== X-Gm-Message-State: AOAM532UWCvdLIWZsVYY57/Ag4Rdf5xXcrz2F9r8BkoCy549fRcVjr1A rVKy9uVBrEfOM7eRxK0+6RhE0RjlPQXw4Q== X-Google-Smtp-Source: ABdhPJzP8y92J7KSLEQXns0Q1p6Prwa1gm1UJmDRo3mqaTbxA9SwwYF0kVM6eJQzjDycFDbaRyZsDQ== X-Received: by 2002:ad4:5010:: with SMTP id s16mr8126017qvo.24.1612451651559; Thu, 04 Feb 2021 07:14:11 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id u126sm5343288qkc.107.2021.02.04.07.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 07:14:10 -0800 (PST) Date: Thu, 4 Feb 2021 10:14:09 -0500 From: Johannes Weiner To: Muchun Song Cc: mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: memcontrol: replace the loop with a list_for_each_entry() Message-ID: References: <20210204105320.46072-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210204105320.46072-1-songmuchun@bytedance.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: 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()? 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. Thanks