Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1090059ybh; Sun, 19 Jul 2020 08:15:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXDbB3zO95C8EMYkpweizmkUCfpXo9wlHcBoNx6uOJDlMt4ZwK9TPBKli9iWl9oxtC8E41 X-Received: by 2002:a05:6402:134e:: with SMTP id y14mr18110224edw.4.1595171753743; Sun, 19 Jul 2020 08:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595171753; cv=none; d=google.com; s=arc-20160816; b=EOqyWAUgsid57kHSSNXkoyH14hkCBm+46gRCzBst3aRn79TH4qJnuTa198fEnApFs2 9LP6CHeFC/0xYwBMTMirvUrMgo2m0vE2SyN+rUK9wRkGgZK5casCi00NatHE7uIfvEOU gBFOhZhMJmzh3FKLbOz3iRpM7z6yZ3QfPot8/igmn1e2zD4Vtw1PyH8wir5HPEzljI3k W7OofosFuMGFRcMwhoSjULuPHYXZ3iY0WOJFQTqIB0rpeljPMxHwoAr1teNLzmfd0hOG j9Jy6xNYf/zoHb5/b4sRjWdN1KNhS78ULMZx9YH+FqYUX0SlEvOTVdEy08kOiWeMPq51 nhWg== 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=KD0HIaFZq56OVyDZqxH1qgBh9ALce1H+dJs/b8P0iG0=; b=lXUVrFKF51aYSQinISbE5z4ZI8MGJc5/czb3z0v0stRFGvUorUokcqlrdHLJb/498i oSs+n8xYGuQR0HesR4JPbqKJQtBAZnFuz+xxF9y42TWu2hq4yqPkiwNMQVp4DQ8vt1+u /JX7s/ZyOW9wjkxqA0AFWijF3LQ+0A3QHqILoDZFuprIn6OwzvyX/PAo78FDBuubHILn C5CvjDsPoS4rrlGOhxQ9OwaJ5hc/J74G+1Ryf86V0e9SWKuDI29cNKX5GuztIUMHtbms 4PQIKQn3on+SLx0FroTbXegwAdMlnu62RlOZu84RpAjVkE/k6i0QnTBZkc1IbC39FEqG Gy5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D6e1D4mO; 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 x8si11133975edl.120.2020.07.19.08.15.22; Sun, 19 Jul 2020 08:15:53 -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=D6e1D4mO; 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 S1726441AbgGSPPE (ORCPT + 99 others); Sun, 19 Jul 2020 11:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbgGSPPD (ORCPT ); Sun, 19 Jul 2020 11:15:03 -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 6C498C0619D2; Sun, 19 Jul 2020 08:15:03 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id v6so15073840iob.4; Sun, 19 Jul 2020 08:15:03 -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=KD0HIaFZq56OVyDZqxH1qgBh9ALce1H+dJs/b8P0iG0=; b=D6e1D4mOo+HLSCzvFU92E3OgGKo/Y61GaP1Wsc1D9JDCraHobxyAqr7b2k5RHTNtA8 SuHImDHowt8DtGQZWdkWX8rZ/2f7WbVDBw7XOomMwhDYKNGBJSankHuY2+RSUJcO0rbe F5c7K0OS5FY/DCtJYYKNlzoTY6b3Ud+RIgyArS/8CSzNbN47Sg+JLniSPFJHt8RkFBAC Js8uZkZBezaWHjXQ9GPf+Fv/77op2/GgPox6RZBCykSZrYEYPf2mdPcOr0WIuE5euVBT BhNObptsociXZSrF6MVSnoMUNWMSBw22lnBh+77SWx7h+dC0ckBsrH3jwnYm8sFf9sGu dSpw== 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=KD0HIaFZq56OVyDZqxH1qgBh9ALce1H+dJs/b8P0iG0=; b=q1RXMVGgop9iZcGJIiStUD1J6LjAXHa0zIGERSw4YogfqL5voXpFSMxBR2gXOLzc5s dzrEVsgc7B+yELYQDYnAo+GSS2ecSiN6S8DWw9U6xp+b6V2gLxACC2hKbNFcDJYx05Sy SQdn9zMA9P0H4JHiGki7IP/NVt+VDaQTRHE1CtdERFKUopv7OvY73o+Q4Etl6MkxLHYs hpr3Ct5aNdX5vnByO18mFB/4ghAuj8LujxHzUheNY1ph9G/YfPsOISwYU4h6Emookv67 XAshakmoI+nMx/p9BeDltmzMylxsS8O9eqWZqj5j7a+m9Rt8xK9KX1wPnw0s96l1nY1J IQIA== X-Gm-Message-State: AOAM533LKwbuvEb2krnHyha7qwEBDqH9qi3yexjLjluAizFusJ6ZVF3W OnmCUCSgzhyCYAfwldkIh32gJjUtbxGQfDJ+rZA= X-Received: by 2002:a05:6638:771:: with SMTP id y17mr21105986jad.96.1595171701844; Sun, 19 Jul 2020 08:15:01 -0700 (PDT) MIME-Version: 1.0 References: <1594429136-20002-1-git-send-email-alex.shi@linux.alibaba.com> <1594429136-20002-19-git-send-email-alex.shi@linux.alibaba.com> <62dfd262-a7ac-d18e-216a-2988c690b256@linux.alibaba.com> In-Reply-To: From: Alexander Duyck Date: Sun, 19 Jul 2020 08:14:50 -0700 Message-ID: Subject: Re: [PATCH v16 18/22] 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" , Michal Hocko , Vladimir Davydov , Rong Chen 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 Sun, Jul 19, 2020 at 2:12 AM Alex Shi wrote= : > > > > =E5=9C=A8 2020/7/18 =E4=B8=8B=E5=8D=8810:15, Alex Shi =E5=86=99=E9=81=93: > >>> > >>> struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb); > >>> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > >>> index 14c668b7e793..36c1680efd90 100644 > >>> --- a/include/linux/mmzone.h > >>> +++ b/include/linux/mmzone.h > >>> @@ -261,6 +261,8 @@ struct lruvec { > >>> atomic_long_t nonresident_age; > >>> /* Refaults at the time of last reclaim cycle */ > >>> unsigned long refaults; > >>> + /* per lruvec lru_lock for memcg */ > >>> + spinlock_t lru_lock; > >>> /* Various lruvec state flags (enum lruvec_flags) */ > >>> unsigned long flags; > >> Any reason for placing this here instead of at the end of the > >> structure? From what I can tell it looks like lruvec is already 128B > >> long so placing the lock on the end would put it into the next > >> cacheline which may provide some performance benefit since it is > >> likely to be bounced quite a bit. > > Rong Chen(Cced) once reported a performance regression when the lock at > > the end of struct, and move here could remove it. > > Although I can't not reproduce. But I trust his report. > > > Oops, Rong's report is on another member which is different with current > struct. > > Compare to move to tail, how about to move it to head of struct, which is > close to lru list? Did you have some data of the place change? I don't have specific data, just anecdotal evidence from the past that usually you want to keep locks away from read-mostly items since they cause obvious cache thrash. My concern was more with the other fields in the structure such as pgdat since it should be a static value and having it evicted would likely be more expensive than just leaving the cacheline as it is. > > ... > > > >>> putback: > >>> - spin_unlock_irq(&zone->zone_pgdat->lru_lock); > >>> pagevec_add(&pvec_putback, pvec->pages[i]); > >>> pvec->pages[i] =3D NULL; > >>> } > >>> - /* tempary disable irq, will remove later */ > >>> - local_irq_disable(); > >>> __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked); > >>> - local_irq_enable(); > >>> + if (lruvec) > >>> + unlock_page_lruvec_irq(lruvec); > >> So I am not a fan of this change. You went to all the trouble of > >> reducing the lock scope just to bring it back out here again. In > >> addition it implies there is a path where you might try to update the > >> page state without disabling interrupts. > > Right. but any idea to avoid this except a extra local_irq_disable? > > > > The following changes would resolve the problem. Is this ok? > @@ -324,7 +322,8 @@ static void __munlock_pagevec(struct pagevec *pvec, s= truct zone *zone) > pagevec_add(&pvec_putback, pvec->pages[i]); > pvec->pages[i] =3D NULL; > } > - __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked); > + if (delta_munlocked) > + __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked); > if (lruvec) > unlock_page_lruvec_irq(lruvec); Why not just wrap the entire thing in a check for "lruvec"? Yes you could theoretically be modding with a value of 0, but it avoids a secondary unnecessary check and branching.