Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp361954ybg; Tue, 28 Jul 2020 07:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQYrqOLqHYjQq4oThT1l75Bxfz6A3SOvcq3x2SvPblM1dNnKQWbv6PYYmOlvAAjwZbuSz2 X-Received: by 2002:a17:906:af72:: with SMTP id os18mr19098299ejb.43.1595948110603; Tue, 28 Jul 2020 07:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595948110; cv=none; d=google.com; s=arc-20160816; b=xe8GnQ0jeC0xDFZ7NQNd2ErtUtmzt+D2wsGSjslVHzn2RAnq7PkMpF6b4yWMlTjqmZ GPxn26pPxvSEjRZGjMm46h15n+onW43aczZy2TM/y3kBf4SkVjyS9iVJnBcGSocOvmF3 2o3Meb9ivAMASa7NHxmFsRhgNsYbkEIDb6+/MTAtcoMcEt+xMq5WJC5hBtXgw4AxY80e ivuNfusKkTsHq3dzEY/I9knFdt10OHK3PJC6RjYRhHtRA+FiyAU5+z31tieukFurAAhL iEMHGMcAa2xm4OQ2uyKlc4/BLi2GS/PyCg44JDcmY3m8vQNuXm6WV8419Q0jqfL01+yD 09jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=rlXEKJ8xEIOgNHiN29J7TVPDIEGm7u8gbZy3u1s9Ctw=; b=IYwecSJiy1Xw3vq4Cfwq+r8NaL0nqhL5GnzkLSkQ7odFg2lY5UATbSPOVBcxi5Dmb9 OF6u7pmBoXaf2VZP/NanfGPZ7w+1JPot+dt+8otWwOFffUXmHzZfCOYku6l9kVdsLnGn D5TFDSf08keo0nOLRiq+XbXwRH35A1+s0k0JIHmHQo6UcGyzLB4ECJqe6cFsTbOYzE7D ij1SFQFu0kaWovQkUuhYVya9lvjE1mv2xo0D4E/zzM6YOVcW7aHS2fDaa+3Kyhs0oTV8 4DSD4Iu+i01JFwCJZuJVoJvQ6S+MeySBSbXjw2opo8o633GBfpuxurO0YxAb4EFfImmI ns9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t5IBgxDm; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h23si7413761ejq.149.2020.07.28.07.54.46; Tue, 28 Jul 2020 07:55:10 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t5IBgxDm; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730508AbgG1OyO (ORCPT + 99 others); Tue, 28 Jul 2020 10:54:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730455AbgG1OyN (ORCPT ); Tue, 28 Jul 2020 10:54:13 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 748C8C061794; Tue, 28 Jul 2020 07:54:13 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id q75so12878716iod.1; Tue, 28 Jul 2020 07:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=rlXEKJ8xEIOgNHiN29J7TVPDIEGm7u8gbZy3u1s9Ctw=; b=t5IBgxDmqzCT6sfkH5/d8FUEdSDdI2dJz1S8qZ1ZiU+8a6LEYgoUdHC7V+GMiMw/5Y TVjf/4KKXxfObmWFzed1Ov64eHn8wDiSC4LJTQC1LV6suKmQw72Wnud2TRs6QafppeYq +RTfvgb55wEeFd2AOM4jJHQOkfgm44l0ROWwTVjPmaW4J3ZwHRF747lsegTE9kOxt2nc lG30esH922EGIPfNLuuuNh+56AJL4x1Zpi8P2J2tfhf/C2+Fpm+kBa9PXCpksfIPy6wv GezNC01nzIpMgnSJn9ve9dutdqJpKucoQxvvzUOJrLX4Sr1u7TwJZ78crHveaaYoHnBY ydWA== 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:content-transfer-encoding; bh=rlXEKJ8xEIOgNHiN29J7TVPDIEGm7u8gbZy3u1s9Ctw=; b=UsxwC6WxKpFg0PRTJcKKF7Ei2X0jpRsh/s1SWw6D0B37XR9wEhlcPid9uPHx08C4Zm 9YEMJc8C4g68rO+R0v6ESKFdQv7v0fBggcXqlW4JzFgH6SK5VyrLt5TN8M1lijuST8Zk XxWy/veAqmGBJqldRQ1ybOXKeJ2EZ88o5yxRmtClQn8m7jOM1xfD4SM7w4tvsY81QE8G xGEr86iGhNhwUGST27ETSqU4lCApgOTLpkTTPQLBDXlSTCYKtuhM3nyvK3OZTRQh8sa7 pSYMXyuY4ZmieGM5xXt5hDvY3/yZxnW4A8qRwLITWXfB8RfH6ZOUKB2qOafc82nwH1GD ZDSw== X-Gm-Message-State: AOAM530P/wb6g7Z6tkrt4W/7/FxhZZJrbTXx3w/RytrukDwhD016mtxk kbVVSmOV/LAEqlTKu8/fNpHevpKXivBz0ZIqpGs= X-Received: by 2002:a05:6638:771:: with SMTP id y17mr32711779jad.96.1595948052581; Tue, 28 Jul 2020 07:54:12 -0700 (PDT) MIME-Version: 1.0 References: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> <1595681998-19193-18-git-send-email-alex.shi@linux.alibaba.com> In-Reply-To: From: Alexander Duyck Date: Tue, 28 Jul 2020 07:54:01 -0700 Message-ID: Subject: Re: [PATCH v17 17/21] mm/lru: replace pgdat lru_lock with lruvec lock To: Alex Shi Cc: Andrew Morton , Mel Gorman , Tejun Heo , Hugh Dickins , Konstantin Khlebnikov , Daniel Jordan , Yang Shi , Matthew Wilcox , Johannes Weiner , kbuild test robot , linux-mm , LKML , cgroups@vger.kernel.org, Shakeel Butt , Joonsoo Kim , Wei Yang , "Kirill A. Shutemov" , Rong Chen , Michal Hocko , Vladimir Davydov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 28, 2020 at 4:20 AM Alex Shi wrote= : > > > > =E5=9C=A8 2020/7/28 =E4=B8=8A=E5=8D=887:34, Alexander Duyck =E5=86=99=E9= =81=93: > >> @@ -1876,6 +1876,12 @@ static unsigned noinline_for_stack move_pages_t= o_lru(struct lruvec *lruvec, > >> * list_add(&pa= ge->lru,) > >> * list_add(&page->lru,) //corrupt > >> */ > >> + new_lruvec =3D mem_cgroup_page_lruvec(page, page_pgdat= (page)); > >> + if (new_lruvec !=3D lruvec) { > >> + if (lruvec) > >> + spin_unlock_irq(&lruvec->lru_lock); > >> + lruvec =3D lock_page_lruvec_irq(page); > >> + } > >> SetPageLRU(page); > >> > >> if (unlikely(put_page_testzero(page))) { > > I was going through the code of the entire patch set and I noticed > > these changes in move_pages_to_lru. What is the reason for adding the > > new_lruvec logic? My understanding is that we are moving the pages to > > the lruvec provided are we not?If so why do we need to add code to get > > a new lruvec? The code itself seems to stand out from the rest of the > > patch as it is introducing new code instead of replacing existing > > locking code, and it doesn't match up with the description of what > > this function is supposed to do since it changes the lruvec. > > this new_lruvec is the replacement of removed line, as following code: > >> - lruvec =3D mem_cgroup_page_lruvec(page, pgdat); > This recheck is for the page move the root memcg, otherwise it cause the = bug: Okay, now I see where the issue is. You moved this code so now it has a different effect than it did before. You are relocking things before you needed to. Don't forget that when you came into this function you already had the lock. In addition the patch is broken as it currently stands as you aren't using similar logic in the code just above this addition if you encounter an evictable page. As a result this is really difficult to review as there are subtle bugs here. I suppose the correct fix is to get rid of this line, but it should be placed everywhere the original function was calling spin_lock_irq(). In addition I would consider changing the arguments/documentation for move_pages_to_lru. You aren't moving the pages to lruvec, so there is probably no need to pass that as an argument. Instead I would pass pgdat since that isn't going to be moving and is the only thing you actually derive based on the original lruvec.