From patchwork Tue Mar 8 03:30:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12772938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A3D8C433EF for ; Tue, 8 Mar 2022 03:30:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 986808D0002; Mon, 7 Mar 2022 22:30:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 936DD8D0001; Mon, 7 Mar 2022 22:30:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FD868D0002; Mon, 7 Mar 2022 22:30:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 6E2048D0001 for ; Mon, 7 Mar 2022 22:30:50 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 09A5B231CD for ; Tue, 8 Mar 2022 03:30:50 +0000 (UTC) X-FDA: 79219792260.07.A75BF13 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 2D7AD20002 for ; Tue, 8 Mar 2022 03:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646710248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=LNwVCeJy2W4936L8AHDamoyiB9luRsDhmFKbaQe32xM=; b=Q/vO3igKOXzl4eOuO5nE3/pVnYvWzVEFW1mVn1t9bqHHrUpVFsP8Tzr8fcAV7Mi5Wpvbqp U4/neTAC+bBi/AYl1HbiJ7ez/R8qNrasK7MKX+iKe2fUbuUAvFRjdrGI6zFggbnrD4GML2 JlpNTBQpl8BXKZCn57ANC2vyxdyREVY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-179-2VisahEoNqykJaONccaTrQ-1; Mon, 07 Mar 2022 22:30:45 -0500 X-MC-Unique: 2VisahEoNqykJaONccaTrQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB7C01006AA8; Tue, 8 Mar 2022 03:30:43 +0000 (UTC) Received: from llong.com (unknown [10.22.10.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCCA06AB87; Tue, 8 Mar 2022 03:30:27 +0000 (UTC) From: Waiman Long To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Waiman Long Subject: [PATCH] mm/list_lru: Optimize memcg_drain_list_lru_node() Date: Mon, 7 Mar 2022 22:30:09 -0500 Message-Id: <20220308033009.1400464-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2D7AD20002 X-Stat-Signature: tidtp9y8rh4ozjxc6h659cbuxifum973 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Q/vO3igK"; spf=none (imf03.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1646710249-417199 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: Since commit 2c80cd57c743 ("mm/list_lru.c: fix list_lru_count_node() to be race free"), we are tracking the total number of lru entries in a list_lru_node in its nr_items field. In the case of memcg_drain_list_lru_node(), there is nothing to be done if nr_items is 0. We don't even need to take the nlru->lock as no new lru entry could be added by a racing list_lru_add() to the draining src_idx memcg at this point. Signed-off-by: Waiman Long --- mm/list_lru.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/list_lru.c b/mm/list_lru.c index 0cd5e89ca063..100ca453e885 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -518,6 +518,12 @@ static void memcg_drain_list_lru_node(struct list_lru *lru, int nid, int dst_idx = dst_memcg->kmemcg_id; struct list_lru_one *src, *dst; + /* + * If there is no lru entry in this nlru, we can skip it immediately. + */ + if (!READ_ONCE(nlru->nr_items)) + return; + /* * Since list_lru_{add,del} may be called under an IRQ-safe lock, * we have to use IRQ-safe primitives here to avoid deadlock.