Received: by 10.223.185.116 with SMTP id b49csp2700428wrg; Mon, 12 Feb 2018 14:26:13 -0800 (PST) X-Google-Smtp-Source: AH8x224MRN2dZpb6Lqm1HtMJv+bPpgN7v2l1D+gI7rpf5gctPAQKQr0LsMI3BPAiAnpPhIEiuKuK X-Received: by 2002:a17:902:8f87:: with SMTP id z7-v6mr11948398plo.242.1518474373052; Mon, 12 Feb 2018 14:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518474373; cv=none; d=google.com; s=arc-20160816; b=Ipx37EYB4T3iLFLzzPSzqC63tQzoRNEUWCYJ5GirlKFjRNbUqIW612jDtSiF5gvkn5 WDFjHdBlVFYo0xn/YcQCsRNmb5HvMrk8ktGqhaKMoJzjLtjvn+hYU0DJ42w/7Ed2LYOV dIv2HHhay8vSQrOPp9ymlCeSv/kk4j6HxC7JppSop4vVjas4Ttk4PaIkmshOoAO3CwWf mUua7SXtgKmGTvvY/mjwmBH9yDfZ+cKP/i1jIC6It6jVBW+64nTDKklfRv7xqfROIL+n FQnlP5LzOruvyxlHcb6MCqJmNgn1u0Rf08p7skHW1Y0Ai6pwsQXtSHHQLHJyMOoJ8mt3 hy6g== 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=DdAOHvGN6FqPoRrBSfebhT6ekxawCmwIZgjjGlBTsn8=; b=0myW0SXqyEQIQoJthHQXSJz5j8LNiB8OtnGuaKIq2TzLi0tl6OUzyv+nHkEU8U90rp OF1aeUIP/ykD4Ln1eRLllSidFMiGtbOiJjUkJgFVapHoqO7OK8G5u9LUWjvFsVCNoUEs nDZNSk9p3Z0V3TWGY9TRTYmct1ifXkPvg4VliqzOHnZ4PUwMNT1DaM/cLOV6xV67ofkc BjBS5StHeag6oivd9zj6CtME4K83+TE6LLqQVkYbZaXo8NnGxQOc+HWSzywEpTHaD4ep WAV+xO8eEvzICDvw4xxApTeDk/ST0f/ocRKwAWUlUAPXAko6ZQjm/VZ8R3NmeMdwPHOw t4ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=Z8bUQCVx; 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 a11si582232pfi.90.2018.02.12.14.25.58; Mon, 12 Feb 2018 14:26:13 -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=Z8bUQCVx; 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 S932669AbeBLWVr (ORCPT + 99 others); Mon, 12 Feb 2018 17:21:47 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:37482 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932627AbeBLWVq (ORCPT ); Mon, 12 Feb 2018 17:21:46 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1CMH07w005515; Mon, 12 Feb 2018 22:21:19 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=DdAOHvGN6FqPoRrBSfebhT6ekxawCmwIZgjjGlBTsn8=; b=Z8bUQCVxBT514+9zulW4BxGxIG6UvxzkjaLbp+ZGuN47htQo+v2Og+Q01kNHGt/bpTAa PFGas+2nOA7bV6OcqFzs6D4ocxKdhA97ikUBZb+ZrVA4ftOT7B8CbolTXzQ67llmaBLx /Y3zBh+BPZ4hdjWY73JVlNET5/cfWw0JKN4RFHH7xJ4VF5GSTwTmz8WzvJZsRy1u50QP Yia4ll/8TLs1KGFniC2W/axM8zBBePgz+MQoYfNlt0lY1rfmI7yyQ3VVBilIt76QHY5B zhdh0M99GqJ2Youlid5NkQu+PWQWm7JMJnF1/yaWXiKpCuIKpl1gO8Vm//+C0tt7A7qO sw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2g3jyb0623-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Feb 2018 22:21:19 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1CMLHlJ008322 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2018 22:21:18 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w1CMLHTX012580; Mon, 12 Feb 2018 22:21:17 GMT Received: from monkey.oracle.com (/98.246.252.205) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Feb 2018 14:21:17 -0800 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Michal Hocko , Christopher Lameter , Guy Shattah , Anshuman Khandual , Michal Nazarewicz , Vlastimil Babka , David Nellans , Laura Abbott , Pavel Machek , Dave Hansen , Mike Kravetz Subject: [RFC PATCH 1/3] mm: make start_isolate_page_range() fail if already isolated Date: Mon, 12 Feb 2018 14:20:54 -0800 Message-Id: <20180212222056.9735-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180212222056.9735-1-mike.kravetz@oracle.com> References: <20180212222056.9735-1-mike.kravetz@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8803 signatures=668668 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=723 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802120282 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org start_isolate_page_range() is used to set the migrate type of a page block to MIGRATE_ISOLATE while attempting to start a migration operation. It is assumed that only one thread is attempting such an operation, and due to the limited number of callers this is generally the case. However, there are no guarantees and it is 'possible' for two threads to operate on the same range. Since start_isolate_page_range() is called at the beginning of such operations, have it return -EBUSY if MIGRATE_ISOLATE is already set. This will allow start_isolate_page_range to serve as a synchronization mechanism and will allow for more general use of callers making use of these interfaces. Signed-off-by: Mike Kravetz --- mm/page_alloc.c | 8 ++++---- mm/page_isolation.c | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 76c9688b6a0a..064458f317bf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7605,11 +7605,11 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, * @gfp_mask: GFP mask to use during compaction * * The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES - * aligned, however it's the caller's responsibility to guarantee that - * we are the only thread that changes migrate type of pageblocks the - * pages fall in. + * aligned. The PFN range must belong to a single zone. * - * The PFN range must belong to a single zone. + * The first thing this routine does is attempt to MIGRATE_ISOLATE all + * pageblocks in the range. Once isolated, the pageblocks should not + * be modified by others. * * Returns zero on success or negative error code. On success all * pages which PFN is in [start, end) are allocated for the caller and diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 165ed8117bd1..e815879d525f 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -28,6 +28,13 @@ static int set_migratetype_isolate(struct page *page, int migratetype, spin_lock_irqsave(&zone->lock, flags); + /* + * We assume we are the only ones trying to isolate this block. + * If MIGRATE_ISOLATE already set, return -EBUSY + */ + if (is_migrate_isolate_page(page)) + goto out; + pfn = page_to_pfn(page); arg.start_pfn = pfn; arg.nr_pages = pageblock_nr_pages; @@ -166,7 +173,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages) * future will not be allocated again. * * start_pfn/end_pfn must be aligned to pageblock_order. - * Returns 0 on success and -EBUSY if any part of range cannot be isolated. + * Returns 0 on success and -EBUSY if any part of range cannot be isolated + * or any part of the range is already set to MIGRATE_ISOLATE. */ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, unsigned migratetype, bool skip_hwpoisoned_pages) -- 2.13.6