Received: by 10.223.185.116 with SMTP id b49csp4141553wrg; Mon, 19 Feb 2018 11:56:08 -0800 (PST) X-Google-Smtp-Source: AH8x225zqBhcJEIcQXzN11nh/iAAMeWxqxgMRrA8IH63mvcIgUxo8VWV9q6aP088EjYc8Kn1nSGv X-Received: by 10.101.81.204 with SMTP id i12mr54184pgq.206.1519070168167; Mon, 19 Feb 2018 11:56:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519070168; cv=none; d=google.com; s=arc-20160816; b=jTu+dVAVG9sz1aO3TZxBeHkeTQ0f2ChB//qtgvb47q+mSiH7k7OXuwpZV4QTtFcBqK VDs9zFeGu/BQ7v5zA2IljE5xtSEIDZ+tqNuEN4At9ECvZkvzdY9sMsK7KAxvAJSYaa3h dtYvs8Ys9SdPVdaSnl8M/4LKMLm4aMwdJzwgRiEVaeKFUlJg/LQgFWU/Rp/uSy+/q6uN PyAkSF7uWRYifC7tIjcwpQfM2JHpTuOMdxScjX653pT+fH/QTkfCFWx4V9FiuOlFmTOM BqLVEU4Dr+Z0GSLbfXV+ukxpic2LnRCFFKVNWUwteZuM7wLqLtec1F3o3w3mA0B21TQT YKFw== 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=obZefIENTzWBFT1mfTGGJHlBt4vonT3fRdBj8MlPUNc=; b=p1ZtYpIjxLMXywqVZGH5d0dKgbt/zyCxVdsx7bh6BidPOXTBSeKnaSFHrNZT/ghLVx ZyqU9lVOpQ5ARCt1/hr/wCKMOW8+R/XoRgQbllRJayCMbDeNITaSxMy0dMFHU/F8X1qK Jki/gVedjwU6wXOAS0b6XHHSleT8Hq05qirnD0VEoXvhcMHH+Ebjgk0xyMM5HwBim7n6 zY9DkQUIaBUEbMmYj7N1YGboNuflhWxRoQA5JOD+XkSwmxEB9qO/nwE+Fd/EV/esj4Yd 2aoWsyt1Qo2kmw9zP+YpWsBcBxQqstnEc/eorhk5wqCfb6NKHyNpGAye+vzj8YAAXlUV 2F0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=iOPZhZ/Z; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si1281987pgq.437.2018.02.19.11.55.53; Mon, 19 Feb 2018 11:56:08 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=iOPZhZ/Z; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932091AbeBSTyU (ORCPT + 99 others); Mon, 19 Feb 2018 14:54:20 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:44894 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753770AbeBSTqW (ORCPT ); Mon, 19 Feb 2018 14:46:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=obZefIENTzWBFT1mfTGGJHlBt4vonT3fRdBj8MlPUNc=; b=iOPZhZ/Ze00OCZ8bz8T3QuzxH unWPawksJbbb2qGHaK84/kdLvZ3D5AevwgeJCtCG90j1SA1vpdN32e5mwyy5pqFzG3PjuPjhphtU4 5skGTm0fp7Tiu9QdZqmvZOH/HKDyHdsRnSApJS1ax11B6pxmyv03Ap665YPZPV5SRjP19BR95FDDA TF0OjN1aSbNYZAPKj+0IcCg3/lMHThI9B3KtpkJL0z5vesTaFBJpr3VrIOtymiSAq9vCrkZX7WWQr MMpK9gKgbzjgbKDjzKxuzv+CUyBoiG5QZLhIdcc+O4R71fpER//9IPlsQ3hz5mr7EP+5U7l65V0Bo 8J0RzstJQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1enrOH-0001sF-JO; Mon, 19 Feb 2018 19:46:21 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v7 39/61] mm: Convert page migration to XArray Date: Mon, 19 Feb 2018 11:45:34 -0800 Message-Id: <20180219194556.6575-40-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180219194556.6575-1-willy@infradead.org> References: <20180219194556.6575-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Signed-off-by: Matthew Wilcox --- mm/migrate.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 184bc1d0e187..bb3698066d79 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -322,7 +322,7 @@ void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, page = migration_entry_to_page(entry); /* - * Once radix-tree replacement of page migration started, page_count + * Once page cache replacement of page migration started, page_count * *must* be zero. And, we don't want to call wait_on_page_locked() * against a page without get_page(). * So, we use get_page_unless_zero(), here. Even failed, page fault @@ -437,10 +437,10 @@ int migrate_page_move_mapping(struct address_space *mapping, struct buffer_head *head, enum migrate_mode mode, int extra_count) { + XA_STATE(xas, &mapping->pages, page_index(page)); struct zone *oldzone, *newzone; int dirty; int expected_count = 1 + extra_count; - void **pslot; /* * Device public or private pages have an extra refcount as they are @@ -466,21 +466,16 @@ int migrate_page_move_mapping(struct address_space *mapping, oldzone = page_zone(page); newzone = page_zone(newpage); - xa_lock_irq(&mapping->pages); - - pslot = radix_tree_lookup_slot(&mapping->pages, - page_index(page)); + xas_lock_irq(&xas); expected_count += 1 + page_has_private(page); - if (page_count(page) != expected_count || - radix_tree_deref_slot_protected(pslot, - &mapping->pages.xa_lock) != page) { - xa_unlock_irq(&mapping->pages); + if (page_count(page) != expected_count || xas_load(&xas) != page) { + xas_unlock_irq(&xas); return -EAGAIN; } if (!page_ref_freeze(page, expected_count)) { - xa_unlock_irq(&mapping->pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -494,7 +489,7 @@ int migrate_page_move_mapping(struct address_space *mapping, if (mode == MIGRATE_ASYNC && head && !buffer_migrate_lock_buffers(head, mode)) { page_ref_unfreeze(page, expected_count); - xa_unlock_irq(&mapping->pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -522,7 +517,7 @@ int migrate_page_move_mapping(struct address_space *mapping, SetPageDirty(newpage); } - radix_tree_replace_slot(&mapping->pages, pslot, newpage); + xas_store(&xas, newpage); /* * Drop cache reference from old page by unfreezing @@ -531,7 +526,7 @@ int migrate_page_move_mapping(struct address_space *mapping, */ page_ref_unfreeze(page, expected_count - 1); - xa_unlock(&mapping->pages); + xas_unlock(&xas); /* Leave irq disabled to prevent preemption while updating stats */ /* @@ -571,22 +566,18 @@ EXPORT_SYMBOL(migrate_page_move_mapping); int migrate_huge_page_move_mapping(struct address_space *mapping, struct page *newpage, struct page *page) { + XA_STATE(xas, &mapping->pages, page_index(page)); int expected_count; - void **pslot; - - xa_lock_irq(&mapping->pages); - - pslot = radix_tree_lookup_slot(&mapping->pages, page_index(page)); + xas_lock_irq(&xas); expected_count = 2 + page_has_private(page); - if (page_count(page) != expected_count || - radix_tree_deref_slot_protected(pslot, &mapping->pages.xa_lock) != page) { - xa_unlock_irq(&mapping->pages); + if (page_count(page) != expected_count || xas_load(&xas) != page) { + xas_unlock_irq(&xas); return -EAGAIN; } if (!page_ref_freeze(page, expected_count)) { - xa_unlock_irq(&mapping->pages); + xas_unlock_irq(&xas); return -EAGAIN; } @@ -595,11 +586,11 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, get_page(newpage); - radix_tree_replace_slot(&mapping->pages, pslot, newpage); + xas_store(&xas, newpage); page_ref_unfreeze(page, expected_count - 1); - xa_unlock_irq(&mapping->pages); + xas_unlock_irq(&xas); return MIGRATEPAGE_SUCCESS; } -- 2.16.1