Received: by 10.223.176.5 with SMTP id f5csp2045565wra; Wed, 31 Jan 2018 15:53:11 -0800 (PST) X-Google-Smtp-Source: AH8x225Zuo+ZAdC3BUpLVgBaiZ8Hawyj2H13wkfYySpABCYU18pnFlsMezn6iD+8ipLm30KlEYI6 X-Received: by 2002:a17:902:9342:: with SMTP id g2-v6mr29881401plp.34.1517442791189; Wed, 31 Jan 2018 15:53:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517442791; cv=none; d=google.com; s=arc-20160816; b=Z11vlz7dzzxPpHRqef/q+bQZ6VFMzORh4i4yEVU3hxkJBHRnZn3dMWmIvQD/0JxTQO B/jqx+l1OXAiQGG+NTZFCvrV9bSCtPQZM8Ii7MgesRHD657ijFY86QZs0f0nhxsmpouq M2lfgg6PAtRuzdd1NHwIuENxWQ/GJJGwQ6qKQ19o2Zbb0tR3SAtNLUAU+o4Ol/bDG5xl JRhpKbMqkzb0dJgbcYNopb08MxljcNbNZMM7kImR4Cwjx2mSheYhQXN2+K4V0yjxqli5 z7XyqzoR13YHcW8x12SBj2JAPIopKwC98bLp26aZ4nW8hpDOhAj4nBTh8O10ht7QRnj/ Es0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BH1vO3YEo3xmKRBqoDZvKKwVdcldb3ZKJ+hqJ9RcUe0=; b=OOV2iJvwHFHUJ368ZVJ/Z6pF+QLIm2iB/RAr4b9YoyO1HJT47iEcmhGgva6yvMRZqF xVOAgeyD9zEfAkB/0PVjpoUr6wgwNT9NYQW5aJT7wJ5mNyDesGKIxTE1xbe22mYJ9d5u 9C+OfTfefIEGs08vCGaGd0sPAiL0ZXir0DkjFsixUVFszpnKke/RUyrAmf9MiC5EBZvg GZ+vuowF6D+LCTeG23qIptw/8pi1XnrobmV1xleXJvWyTi3JxQ3TZ3R4J68s/4NGSzKW lDooc8DEj0ajUdx0YkJOBTSyzSsURl1kz+uU7W+nn5v+pCwlY8HemVIJJHLJCnTE+hkn jg7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=NVbpKxSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si375626pli.142.2018.01.31.15.52.56; Wed, 31 Jan 2018 15:53:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=NVbpKxSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755835AbeAaXM7 (ORCPT + 99 others); Wed, 31 Jan 2018 18:12:59 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:51942 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754545AbeAaXFQ (ORCPT ); Wed, 31 Jan 2018 18:05:16 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0VMpvev120788; Wed, 31 Jan 2018 23:04:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=BH1vO3YEo3xmKRBqoDZvKKwVdcldb3ZKJ+hqJ9RcUe0=; b=NVbpKxSVbK62zd+ulKoZqd0mSKeE5NO9bCSMuZow+aPI7/saAdPZsXCjWyn9EzR6wPga wb0RaAkAhlNR0zaET/fTX4IhMPRA59cOPRMQXOO3lEkxzTpkivCvXWsrBMjlKqOeBVZm rlWQ21tAUktLNdnD9shga9pL7nnS/OS6PpzTxAXMy7OgkTK8RcTHrAjZUGH7IMoZV1eM FVOnDn1ljhURhxnXYxl+GKkIdSUcZxX0XUV2NpE/eGZsYYWYxJ/+WA3vLAoo624L1yUV 8YESEeCPAFBM+6x8EhztUhh4v/xeArZxYbb+zYnouXDWBRbcu4jLfIi1Q+wsA4dSFk6Y fg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2fucd9ke27-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Jan 2018 23:04:35 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0VN4YQ1021902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 31 Jan 2018 23:04:34 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0VN4YKb019195; Wed, 31 Jan 2018 23:04:34 GMT Received: from parnassus.us.oracle.com (/10.39.213.30) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 Jan 2018 15:04:33 -0800 From: daniel.m.jordan@oracle.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: aaron.lu@intel.com, ak@linux.intel.com, akpm@linux-foundation.org, Dave.Dice@oracle.com, dave@stgolabs.net, khandual@linux.vnet.ibm.com, ldufour@linux.vnet.ibm.com, mgorman@suse.de, mhocko@kernel.org, pasha.tatashin@oracle.com, steven.sistare@oracle.com, yossi.lev@oracle.com Subject: [RFC PATCH v1 11/13] mm: use lru_batch locking in release_pages Date: Wed, 31 Jan 2018 18:04:11 -0500 Message-Id: <20180131230413.27653-12-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180131230413.27653-1-daniel.m.jordan@oracle.com> References: <20180131230413.27653-1-daniel.m.jordan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8791 signatures=668659 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=931 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801310283 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce LRU batch locking in release_pages. This is the code path where I see lru_lock contention most often, so this is the one I used in this prototype. Signed-off-by: Daniel Jordan --- mm/swap.c | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 2bb28fcb7cc0..fae766e035a4 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -745,31 +745,21 @@ void release_pages(struct page **pages, int nr) int i; LIST_HEAD(pages_to_free); struct pglist_data *locked_pgdat = NULL; + spinlock_t *locked_lru_batch = NULL; struct lruvec *lruvec; unsigned long uninitialized_var(flags); - unsigned int uninitialized_var(lock_batch); for (i = 0; i < nr; i++) { struct page *page = pages[i]; - /* - * Make sure the IRQ-safe lock-holding time does not get - * excessive with a continuous string of pages from the - * same pgdat. The lock is held only if pgdat != NULL. - */ - if (locked_pgdat && ++lock_batch == SWAP_CLUSTER_MAX) { - lru_unlock_all(locked_pgdat, &flags); - locked_pgdat = NULL; - } - if (is_huge_zero_page(page)) continue; /* Device public page can not be huge page */ if (is_device_public_page(page)) { - if (locked_pgdat) { - lru_unlock_all(locked_pgdat, &flags); - locked_pgdat = NULL; + if (locked_lru_batch) { + lru_batch_unlock(NULL, &locked_lru_batch, + &locked_pgdat, &flags); } put_zone_device_private_or_public_page(page); continue; @@ -780,26 +770,23 @@ void release_pages(struct page **pages, int nr) continue; if (PageCompound(page)) { - if (locked_pgdat) { - lru_unlock_all(locked_pgdat, &flags); - locked_pgdat = NULL; + if (locked_lru_batch) { + lru_batch_unlock(NULL, &locked_lru_batch, + &locked_pgdat, &flags); } __put_compound_page(page); continue; } if (PageLRU(page)) { - struct pglist_data *pgdat = page_pgdat(page); - - if (pgdat != locked_pgdat) { - if (locked_pgdat) - lru_unlock_all(locked_pgdat, &flags); - lock_batch = 0; - locked_pgdat = pgdat; - lru_lock_all(locked_pgdat, &flags); + if (locked_lru_batch) { + lru_batch_unlock(page, &locked_lru_batch, + &locked_pgdat, &flags); } + lru_batch_lock(page, &locked_lru_batch, &locked_pgdat, + &flags); - lruvec = mem_cgroup_page_lruvec(page, locked_pgdat); + lruvec = mem_cgroup_page_lruvec(page, page_pgdat(page)); VM_BUG_ON_PAGE(!PageLRU(page), page); __ClearPageLRU(page); del_page_from_lru_list(page, lruvec, page_off_lru(page)); @@ -811,8 +798,10 @@ void release_pages(struct page **pages, int nr) list_add(&page->lru, &pages_to_free); } - if (locked_pgdat) - lru_unlock_all(locked_pgdat, &flags); + if (locked_lru_batch) { + lru_batch_unlock(NULL, &locked_lru_batch, &locked_pgdat, + &flags); + } mem_cgroup_uncharge_list(&pages_to_free); free_unref_page_list(&pages_to_free); -- 2.16.1