From patchwork Mon Jun 11 14:06:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10458059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DEF556020F for ; Mon, 11 Jun 2018 14:13:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1044285E1 for ; Mon, 11 Jun 2018 14:13:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADA0F28571; Mon, 11 Jun 2018 14:13:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C346928571 for ; Mon, 11 Jun 2018 14:12:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B43326B02B8; Mon, 11 Jun 2018 10:08:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC95F6B02BA; Mon, 11 Jun 2018 10:08:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96BB56B02BB; Mon, 11 Jun 2018 10:08:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 4FDE76B02B8 for ; Mon, 11 Jun 2018 10:08:16 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id x25-v6so10304508pfn.21 for ; Mon, 11 Jun 2018 07:08:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=O9uY+J4/RG9YXAAfAsVm7Lcu0R0unVIN2Mssj0GLwEA=; b=VIAjo4Unv/aZOcQwgT9RwEibn5KzmENWNw6r5cdvigSubifViazYlnxDhq7xQhsNqT dtAp0+SAEG4ORJivjOm8sUK+SB42uYiOZUBaX9g6j0S2SKhRMPcDB/1lrM9xuwBpoDbM HcJryd/syHdjR8ykl44VvpYAk/uEf3XaRA9xgGLKtYw2UL9VN9VYUOtC7n8Z8mgOWse3 N68vMMqWt6SRRBHLZubLr4SIQN0j4fSJW9RJcrAkd27cjMPIM8pzTdg/HWe6FB0ilDAV vvfpnfVKtptZHNNxUe31oqBHUR/nBsF+245g5QLLL80BQ1fDfAVSYq4+aYgk5M+233SF kIfQ== X-Gm-Message-State: APt69E1DOWA+SzpDKCS4Igz89TmHge2/U46HIoKFySE6RuGB1qj4ex4S cz7/ytt5hZVS9Zdhh47B303RoFjimUj5TnE80an7yxbosmEq80P7yyL7Lhk1SfJeLzL+2pksG/I tq4Gb0UvoUmNkXu/wyyYgChgUbpxyIj/QYk/r3FN4x8b2vg4z5cKbBzkDvZkkHLvSIw== X-Received: by 2002:a62:418b:: with SMTP id g11-v6mr17818134pfd.51.1528726095988; Mon, 11 Jun 2018 07:08:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJiRQmWZvYVIWkPTSe4xuxdVpOJy57bHmLWggOHvAqPz9L+CpFjQd/13zP4+yb0vpnuj+8r X-Received: by 2002:a62:418b:: with SMTP id g11-v6mr17812643pfd.51.1528726015888; Mon, 11 Jun 2018 07:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726015; cv=none; d=google.com; s=arc-20160816; b=KYoUTwWTFJ8emng1K6nQG0BNJRDKPpDqF572ZAca2HBzXQuBywgF0SshRTMHgxqhQv GDZ3p0knCLbs7xpmyRROE42YwsffaYrzQR0SC0R6W28AfBVA4XWCUiDooPRBdB+iqAK0 bKje5VSeGWwQVTslvg9zAQFe3Nix0lK1z5XPXetSpHE69ycl2jX7slULh8+D2OHzxsFP irHBB6C6WG9F+I602aU1B8OXXKYiGLVMWfuYUNzSXNgpLIvi0ggOSghNf4lkigtAs87z kBN9GZSSKqFriF9GB2BnGUEnYW6zRQ+/91g7Iy5NHWMkm8RP0TmELk+i3O8XwFu6lXF9 zJZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=O9uY+J4/RG9YXAAfAsVm7Lcu0R0unVIN2Mssj0GLwEA=; b=BJjtWBH7NI8V4F+Ta5iLDgjGY8bHfhNWij5tsGsfjDk3wdLN8aXavjlV2IYTY/j5QJ rKP4ceFnyOgVxPF/aYANqbob5NNVC3RoIxztNoLr7oAg/TQ6MBpENP47UeVyv4H/ggoE k7y+dGduiePOBaoelARE5eP35qIdBiYB1oIhwxEak6HlQnxo+Ov8Agz1cb1R6yGXSAPB ktr4bJ/qhROdmhDHqYDyTNBivYCQGIUNvZ/f3+lRfh6eisPNA10UxWukk3xYaPW9VUJ+ sxTBPjDnAfJjrwx+meTe5CE1xuu4fbO17C2fUcCeGQZL4udQ3bPrIJ3Ig/dTi2QOyhCK TtqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=s2QO8zNt; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 17-v6si30803190pfn.37.2018.06.11.07.06.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=s2QO8zNt; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org 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=O9uY+J4/RG9YXAAfAsVm7Lcu0R0unVIN2Mssj0GLwEA=; b=s2QO8zNtN9pjpe+ok+9dK2O0T AnPt7a5dWNQKxMZu5M/x7uVxt9fTcB0U7qV3TTF4Mj7y5ME0MU+no6zXk6qccQguB/KWqoEuYmD48 mrPbFrN0BK+AI1eTeBbyMigaDSpiG/yHtRkf4Dysjic3xno3Mir8ZxvyhHVP71IJBdJ8ourZw1ICs uKZRgHysmXNbgAmPIgu0+LGAd+JrO6k9u9mKAPogiaxZ+0ZCm4S7ebr4qNAhO3PPcCeJ/pjJiMAh1 jp1kwR9vcllU/hlv3dam8+pjk0ozumfLZmIcQb+FnZi8UiI4+qQEKo00m6dBFpLToq6SjAjZTe90+ oF2CreeIQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTD-0004ji-2P; Mon, 11 Jun 2018 14:06:55 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 35/72] mm: Convert workingset to XArray Date: Mon, 11 Jun 2018 07:06:02 -0700 Message-Id: <20180611140639.17215-36-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox We construct a fake XA_STATE and use it to delete the node with xas_store() rather than adding a special function for this unique use case. Signed-off-by: Matthew Wilcox --- include/linux/swap.h | 9 -------- mm/workingset.c | 51 +++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 1b91e7f7bdeb..a450a1d40b19 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -307,15 +307,6 @@ void workingset_update_node(struct xa_node *node); xas_set_update(xas, workingset_update_node); \ } while (0) -/* Returns workingset_update_node() if the mapping has shadow entries. */ -#define workingset_lookup_update(mapping) \ -({ \ - radix_tree_update_node_t __helper = workingset_update_node; \ - if (dax_mapping(mapping) || shmem_mapping(mapping)) \ - __helper = NULL; \ - __helper; \ -}) - /* linux/mm/page_alloc.c */ extern unsigned long totalram_pages; extern unsigned long totalreserve_pages; diff --git a/mm/workingset.c b/mm/workingset.c index bad4e58881cd..564e97bd5934 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -148,7 +148,7 @@ * and activations is maintained (node->inactive_age). * * On eviction, a snapshot of this counter (along with some bits to - * identify the node) is stored in the now empty page cache radix tree + * identify the node) is stored in the now empty page cache * slot of the evicted page. This is called a shadow entry. * * On cache misses for which there are shadow entries, an eligible @@ -162,7 +162,7 @@ /* * Eviction timestamps need to be able to cover the full range of - * actionable refaults. However, bits are tight in the radix tree + * actionable refaults. However, bits are tight in the xarray * entry, and after storing the identifier for the lruvec there might * not be enough left to represent every single actionable refault. In * that case, we have to sacrifice granularity for distance, and group @@ -338,7 +338,7 @@ void workingset_activation(struct page *page) static struct list_lru shadow_nodes; -void workingset_update_node(struct radix_tree_node *node) +void workingset_update_node(struct xa_node *node) { /* * Track non-empty nodes that contain only shadow entries; @@ -370,7 +370,7 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, local_irq_enable(); /* - * Approximate a reasonable limit for the radix tree nodes + * Approximate a reasonable limit for the nodes * containing shadow entries. We don't need to keep more * shadow entries than possible pages on the active list, * since refault distances bigger than that are dismissed. @@ -385,11 +385,11 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, * worst-case density of 1/8th. Below that, not all eligible * refaults can be detected anymore. * - * On 64-bit with 7 radix_tree_nodes per page and 64 slots + * On 64-bit with 7 xa_nodes per page and 64 slots * each, this will reclaim shadow entries when they consume * ~1.8% of available memory: * - * PAGE_SIZE / radix_tree_nodes / node_entries * 8 / PAGE_SIZE + * PAGE_SIZE / xa_nodes / node_entries * 8 / PAGE_SIZE */ if (sc->memcg) { cache = mem_cgroup_node_nr_lru_pages(sc->memcg, sc->nid, @@ -398,7 +398,7 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, cache = node_page_state(NODE_DATA(sc->nid), NR_ACTIVE_FILE) + node_page_state(NODE_DATA(sc->nid), NR_INACTIVE_FILE); } - max_nodes = cache >> (RADIX_TREE_MAP_SHIFT - 3); + max_nodes = cache >> (XA_CHUNK_SHIFT - 3); if (nodes <= max_nodes) return 0; @@ -408,11 +408,11 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, static enum lru_status shadow_lru_isolate(struct list_head *item, struct list_lru_one *lru, spinlock_t *lru_lock, - void *arg) + void *arg) __must_hold(lru_lock) { + XA_STATE(xas, NULL, 0); struct address_space *mapping; - struct radix_tree_node *node; - unsigned int i; + struct xa_node *node; int ret; /* @@ -420,7 +420,7 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, * the shadow node LRU under the i_pages lock and the * lru_lock. Because the page cache tree is emptied before * the inode can be destroyed, holding the lru_lock pins any - * address_space that has radix tree nodes on the LRU. + * address_space that has nodes on the LRU. * * We can then safely transition to the i_pages lock to * pin only the address_space of the particular node we want @@ -449,25 +449,18 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, goto out_invalid; if (WARN_ON_ONCE(node->count != node->nr_values)) goto out_invalid; - for (i = 0; i < RADIX_TREE_MAP_SIZE; i++) { - if (node->slots[i]) { - if (WARN_ON_ONCE(!xa_is_value(node->slots[i]))) - goto out_invalid; - if (WARN_ON_ONCE(!node->nr_values)) - goto out_invalid; - if (WARN_ON_ONCE(!mapping->nrexceptional)) - goto out_invalid; - node->slots[i] = NULL; - node->nr_values--; - node->count--; - mapping->nrexceptional--; - } - } - if (WARN_ON_ONCE(node->nr_values)) - goto out_invalid; + mapping->nrexceptional -= node->nr_values; + xas.xa = node->array; + xas.xa_node = rcu_dereference_protected(node->parent, + lockdep_is_held(&mapping->i_pages.xa_lock)); + xas.xa_offset = node->offset; + xas.xa_update = workingset_update_node; + /* + * We could store a shadow entry here which was the minimum of the + * shadow entries we were tracking ... + */ + xas_store(&xas, NULL); inc_lruvec_page_state(virt_to_page(node), WORKINGSET_NODERECLAIM); - __radix_tree_delete_node(&mapping->i_pages, node, - workingset_lookup_update(mapping)); out_invalid: xa_unlock(&mapping->i_pages);