Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1621809pxb; Thu, 4 Feb 2021 18:57:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxS7vgxGBw2uy3DzoYaz/tsHrjMDBWn5UvNrWEZhwPnEpFD9mc/WQ632g9R065HEeI07bwK X-Received: by 2002:a17:906:9a06:: with SMTP id ai6mr2007583ejc.463.1612493824210; Thu, 04 Feb 2021 18:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612493824; cv=none; d=google.com; s=arc-20160816; b=GvvW33dPySWHIK44tAj32xCqg1aDdtssGWH3wDwKwGwa0FLY3gSuvCyyAOGeHXAzns YQwNWl2gBehZqjIWiqpfCT/1iJIG48Olw62I3MnunBVMQViOB1h794ZaY/BldQAYZOZR XYIETJHUIlFaLPHcTM2oWodVPcRt/MK8M09/UmSpKKx60GijRiyZ0V2R7GjbScC+HVEW dhP1sYzozXHsrg89GiyMXQ+Oc+RAYAKNqBNW20hlyOzQyIOsODr3DGy7tl9ZdsjiU0u8 pNAHpvqoB0Iu7+LweTCxS1dztg33JG+PQv5pS0GolDut+jw4y79ZDSJ4GECl/TdWOGUL PTpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=KYywfQYLR+2R/z2ABIn4D5LvhrsrT61BQlh2hRSX6N0=; b=UxewL5O5SBW2V2SOVCMNxayWpZWRaOXNP6RmY6TbGfFR133T5DqDY2gxmzOrTmxZMo yngr21WhLDN6f+cP7fy2VOw4cEE/dGukPcKEOrKH8mlrUrEixtacJjo+ISkw1V3ioFe0 9kohZ/2ZGXljPurrt3+ooWMceaiE093wvqcwioLHVuXI8pgxy+PczlePbXJ2DUbX42uL wjZ+K+cG6cmi0MmVu8hfYBHL5T1V7JjmppxKz7QGdmz8b4xbwE6oiv19qRYmMtCH+BUi mIhwlUuRtjYFWSqU0fsZ+IQ3Aerbc9Ten3Wekib+GvVAlCJvqWkSGpyFFjsk8GwHauIz TuVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay19si4132487ejb.621.2021.02.04.18.56.38; Thu, 04 Feb 2021 18:57:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbhBECye (ORCPT + 99 others); Thu, 4 Feb 2021 21:54:34 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:12078 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbhBECyb (ORCPT ); Thu, 4 Feb 2021 21:54:31 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DX0Lv3v6HzMVNg; Fri, 5 Feb 2021 10:52:07 +0800 (CST) Received: from [10.174.179.241] (10.174.179.241) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 10:53:43 +0800 Subject: Re: [PATCH v2] mm: memcontrol: replace the loop with a list_for_each_entry() To: Muchun Song CC: , , , , , , References: <20210204163055.56080-1-songmuchun@bytedance.com> From: Miaohe Lin Message-ID: <6f8d9e82-5903-e983-8c93-9dfe3e9b14ca@huawei.com> Date: Fri, 5 Feb 2021 10:53:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210204163055.56080-1-songmuchun@bytedance.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.241] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi: On 2021/2/5 0:30, 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(). > > There is only one caller of the uncharge_list(). So just fold it into > mem_cgroup_uncharge_list() and remove it. > > Signed-off-by: Muchun Song LGTM. Thanks. Reviewed-by: Miaohe Lin > --- > v2: > - Fold uncharge_list() to mem_cgroup_uncharge_list(). > > mm/memcontrol.c | 35 ++++++++--------------------------- > 1 file changed, 8 insertions(+), 27 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index ed5cc78a8dbf..8c035846c7a4 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6862,31 +6862,6 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) > css_put(&ug->memcg->css); > } > > -static void uncharge_list(struct list_head *page_list) > -{ > - struct uncharge_gather ug; > - struct list_head *next; > - > - 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; > - > - uncharge_page(page, &ug); > - } while (next != page_list); > - > - if (ug.memcg) > - uncharge_batch(&ug); > -} > - > /** > * mem_cgroup_uncharge - uncharge a page > * @page: page to uncharge > @@ -6918,11 +6893,17 @@ void mem_cgroup_uncharge(struct page *page) > */ > void mem_cgroup_uncharge_list(struct list_head *page_list) > { > + struct uncharge_gather ug; > + struct page *page; > + > if (mem_cgroup_disabled()) > return; > > - if (!list_empty(page_list)) > - uncharge_list(page_list); > + uncharge_gather_clear(&ug); > + list_for_each_entry(page, page_list, lru) > + uncharge_page(page, &ug); > + if (ug.memcg) > + uncharge_batch(&ug); > } > > /** >