Received: by 10.223.176.5 with SMTP id f5csp2044765wra; Wed, 31 Jan 2018 15:52:06 -0800 (PST) X-Google-Smtp-Source: AH8x2240xPwooSoDKUNd3FpdDZXQpMidQioNUBksDxPZREwf/tcxbfmAVTdk7YIRQcLoUrjZ9cHA X-Received: by 10.99.39.1 with SMTP id n1mr17345767pgn.155.1517442726791; Wed, 31 Jan 2018 15:52:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517442726; cv=none; d=google.com; s=arc-20160816; b=pM9VTnEpr3lIJTdVM6LiER+Jj4z4sVPV0FHWJYJZ8XKrSp+ExiZlDXUh9fyvxJE8FD vV7I4hoWfCBXl7IaLjiisdPuQ4kkcUBG2pUUMLIPuNyqWeFprlZfbBBXSH2kRComn4LC APUroerzuNChHD0ufJGxUJKcG8Kn3HEYCOshqxVEmRgzWyf4o/rgVAX5MuL48dr4zxmQ 3p1dGH4O8KBcD5yv57PkXhPcux8eQHQjgfCjXDjkKby6F9Lt5M2dXFuNuKXoYFMUTPRL nBCejitiLP0VxmFfpBZWStkbg5B/JJD8akc4NxuK7INea3kP4+BYB8MHHMibuPqflI2W Fb7A== 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=yAzwBG/ava8Ydk56hYGrm4RjTwJ+LbW/TmCwp9gPgu4=; b=F7ci1Na4JnrZwYZEPS+2NLYlX9/Ui52HWPj6ClvvkUclTIUqSVXidPnJ7WtR/T5tRL 48zoQbzVNTAbBZKZPDi2NvFZh0aMyUEaB1jjQh3ZvRz6ofKMba9O6Kswpd8gsTSNE/Nw FjICO00LagwC4aMkDx7+K1VyUbGwpwJH0K4DsLyZrgA9U+iE0kssblsSAltMTgth0lgk JxugmPBzPLVR0QeQmjYeOGGt6bvfdbUX0LuQw+kgbXM/rxFCtAyJP9yH+Bxsr1PnODoq 93X9CtHV0BuzUhPRBPB2pPbD077gynZ6jn1IsUmPYjnL+OgngtBQREyfYz7ALZWE6r0J NgBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=hrRTOK9R; 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 o18si2805513pfa.407.2018.01.31.15.51.25; Wed, 31 Jan 2018 15:52:06 -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=hrRTOK9R; 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 S1755827AbeAaXMg (ORCPT + 99 others); Wed, 31 Jan 2018 18:12:36 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:52692 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754582AbeAaXFW (ORCPT ); Wed, 31 Jan 2018 18:05:22 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0VMq78B107900; Wed, 31 Jan 2018 23:04:34 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=yAzwBG/ava8Ydk56hYGrm4RjTwJ+LbW/TmCwp9gPgu4=; b=hrRTOK9RSlF9IPINWmbogFLV1F0X1WZ0LeUMt5LbYemP2qF5jJutS78NBMTZ/Nrct6Lz PtmiO/43DI7DakUiUUjwU1rnd2KlQhKeJydGQwHyL2NWIxeIxa/b43t5SggNKUG4U/i9 ujSpChE32KGF463sUxUS8Y2tXHgl+Uyh2EGrVLNspcKyoFYwTB2IfrtCU8j2PwDS1Iqi zYfaPIFqnrGKqrlTLDtuZdIJDS/TmCVh/OF7rrCOAy8HpLrJiaWsHW+CywPLes1ZHUyK bsC5uKekltMgxuqznzw+1Ur2c27ohtANNmwr7JfJpX6iItc+qx94Nc++0pEkIpePiczW Uw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fuc8kkh36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Jan 2018 23:04:34 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0VN4X4p023156 (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 userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0VN4XZt022417; Wed, 31 Jan 2018 23:04:33 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:32 -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 10/13] mm: add LRU batch lock API's Date: Wed, 31 Jan 2018 18:04:10 -0500 Message-Id: <20180131230413.27653-11-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=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 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 Add the LRU batch locking API's themselves. This adds the final piece of infrastructure necessary for locking batches on an LRU list. The API's lock a specific page on the LRU list, taking only the appropriate LRU batch lock for a non-sentinel page and taking the node's/memcg's lru_lock in addition for a sentinel page. These interfaces are designed for performance: they minimize the number of times we needlessly drop and then reacquire the same lock(s) when used in a loop. They're difficult to use but will do for a prototype. Signed-off-by: Daniel Jordan --- include/linux/mm_inline.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 1f1657c75b1b..11d9fcf93f2b 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -210,6 +210,64 @@ static __always_inline void lru_unlock_all(struct pglist_data *pgdat, local_irq_enable(); } +static __always_inline spinlock_t *page_lru_batch_lock(struct page *page) +{ + return &page_pgdat(page)->lru_batch_locks[page->lru_batch].lock; +} + +/** + * lru_batch_lock - lock an LRU list batch + */ +static __always_inline void lru_batch_lock(struct page *page, + spinlock_t **locked_lru_batch, + struct pglist_data **locked_pgdat, + unsigned long *flags) +{ + spinlock_t *lru_batch = page_lru_batch_lock(page); + struct pglist_data *pgdat = page_pgdat(page); + + VM_BUG_ON(*locked_pgdat && !page->lru_sentinel); + + if (lru_batch != *locked_lru_batch) { + VM_BUG_ON(*locked_pgdat); + VM_BUG_ON(*locked_lru_batch); + spin_lock_irqsave(lru_batch, *flags); + *locked_lru_batch = lru_batch; + if (page->lru_sentinel) { + spin_lock(&pgdat->lru_lock); + *locked_pgdat = pgdat; + } + } else if (!*locked_pgdat && page->lru_sentinel) { + spin_lock(&pgdat->lru_lock); + *locked_pgdat = pgdat; + } +} + +/** + * lru_batch_unlock - unlock an LRU list batch + */ +static __always_inline void lru_batch_unlock(struct page *page, + spinlock_t **locked_lru_batch, + struct pglist_data **locked_pgdat, + unsigned long *flags) +{ + spinlock_t *lru_batch = (page) ? page_lru_batch_lock(page) : NULL; + + VM_BUG_ON(!*locked_lru_batch); + + if (lru_batch != *locked_lru_batch) { + if (*locked_pgdat) { + spin_unlock(&(*locked_pgdat)->lru_lock); + *locked_pgdat = NULL; + } + spin_unlock_irqrestore(*locked_lru_batch, *flags); + *locked_lru_batch = NULL; + } else if (*locked_pgdat && !page->lru_sentinel) { + spin_unlock(&(*locked_pgdat)->lru_lock); + *locked_pgdat = NULL; + } +} + /** * page_lru_base_type - which LRU list type should a page be on? * @page: the page to test -- 2.16.1