From patchwork Tue Feb 27 03:02:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13573219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF1ABC5478C for ; Tue, 27 Feb 2024 03:03:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33CB04401E3; Mon, 26 Feb 2024 22:03:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EBF244017F; Mon, 26 Feb 2024 22:03:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13EF84401E3; Mon, 26 Feb 2024 22:03:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0472744017F for ; Mon, 26 Feb 2024 22:03:17 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4F4B140A72 for ; Tue, 27 Feb 2024 03:03:16 +0000 (UTC) X-FDA: 81836087592.30.69AC8C2 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf21.hostedemail.com (Postfix) with ESMTP id 1501F1C0012 for ; Tue, 27 Feb 2024 03:03:14 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709002995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+AeoM9bXyNXnW2+Ff6qKZg8BHvCGSUPxBlTPsvhNgxg=; b=XPio75yyvxYwhJFaWRNIlWkVFF/1NS4XuByjsnt/sg86/0wlVj4dVCaowR477PDcpFEwCU dqI+XIvLEL8Hy55VzG9HZZ4qTrRkDLYAT21s0mxrq0b2/TNKDi6LE+RdjEsLedXInSSI3c BkQu/ZqStLWMBN4gaSu/UNRloTHuzD8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf21.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709002995; a=rsa-sha256; cv=none; b=v67jnbxEecLQ9a+xGHcy4OeEqAu3MXUZ0AiQTvHI7K04IPdUuixte/HIKN/XujQxaepR1i zKuANtU9HTxrDWu9i3tWXOxPwZEM5s0OHyOCJ6DasfOjbqu0fwqbcePLVcupsbyOGmQotH 0n+3845Pqf7D1RKR/kSBlU/WYvsPDJ0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 27 Feb 2024 03:02:54 +0000 Subject: [PATCH 1/2] mm/zsmalloc: don't hold locks of all pages when free_zspage() MIME-Version: 1.0 Message-Id: <20240226-zsmalloc-zspage-rcu-v1-1-456b0ef1a89d@bytedance.com> References: <20240226-zsmalloc-zspage-rcu-v1-0-456b0ef1a89d@bytedance.com> In-Reply-To: <20240226-zsmalloc-zspage-rcu-v1-0-456b0ef1a89d@bytedance.com> To: yosryahmed@google.com, Sergey Senozhatsky , hannes@cmpxchg.org, nphamcs@gmail.com, Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1709002985; l=7649; i=zhouchengming@bytedance.com; s=20240220; h=from:subject:message-id; bh=/Y+8Rr5r7R4qG0VPWtmHKI3CmlgVA1JjzF5IldWYPOo=; b=Ipe8SF91JeqdJP/MV2fbyh7lbm0zV5Funv1K3Qy6bYmAr/Mo669Z/C6TNDwxz1AL+WdI8ItTm pWaD8WRhpRYDB285bxUKML+G8G1G1EV72v/91+bR9W3Kf9H97jTCK7k X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=5+68Wfci+T30FoQos5RH+hfToF6SlC+S9LMPSPBFWuw= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 1501F1C0012 X-Rspamd-Server: rspam12 X-Stat-Signature: 4aksuxe936mn9pixqq36zdqx16io3ecz X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1709002994-447531 X-HE-Meta: U2FsdGVkX18IAfF096MgWj+Q7ltSna/mmn0VKW+VIdjJ0Sr4iRFVBxR2DSBD/PWAR4XqnaJRhuhFJytvtYpsxSb8xJJCKUfCRdgNYDah6/IfoDBywHLC7mHuYiAcsOlidtCMObNn7FL8xn1daks+eKwK38Mk3oQ2RVbct/uxfSpxenNtxpkPgxU8ln0eaHJQ1JVgArMUt+8B6iDHVwhAuz56x7dEp5ZE+VIV8eWMboPZIInYXxX+XoRnB239kef4fKyFXtpSdNOziXifq0jYSXoDNhqw6BDbT56082peFgn+oXTe+MWMs4GjxsaN9n/OVcErswCBESsC8Z2zcdAHnqBET6LYJSo0EK3NDagQ3DAQSVAB5eYAD7Dewj+iejMfUZIRa7KWNDCVoBBiMHfmqACKWAILRCWdoBjp3tl1s0m88zu86I8MxykvMhDBJkHuR/WkZ79Y6M1Btb5AQ6dF5GU+rxeL+ORF2KMVOdaNe96++ye0JaecdVvo6JnoiPj76ZfpEQK40KQiTX6CidRiTADsGn7pJvezbTVIZhx+y7L+XRl7hEWPpRBHDTN0jcN+GU2lPRrOyrAzL20D/tN53pLA4SGhYQ4jqfLaeZRUfeGzNWefBsB/yGbVFmRPOE4rXIdySNZyh/A3GYIu/SaH2AUwmzadmrcsK3rCT/6Ni0OZ/6mwu6F/vVURUDqEY30/JFdXO/JCGoPFKEU1x8+mclOAOMbcrzdHful1p1NtIabmpJ5TMAqtyg8e/1jzSCpgpaZic4oHI4ztsK31Q9R0XZ03ROkHmz7TjNtwTMv/5rikbEsJVWkShr0aiFKppeWSwU49ixHHARb/3KWv0t+Wnpj20QjmBxbW+gEyj1eE10XF9DTFalEmd6i/rLKlYEs0gyy2wo0mEkE910SKlcF4UrVDTLeYiw5amtgrV3vR0jacSa0DvQvCJrbK53KD4gNoHrjqbIKTB6Xu5EYsj0q LY4AqYzE xQYNJEpz9FHOuX99vMdWjRZEpFBZsIcXZFaBOipAzWxTHpqkyCPnBlTwHuQ== 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: List-Subscribe: List-Unsubscribe: free_zspage() has to hold locks of all pages, since zs_page_migrate() path rely on this page lock to protect the race between zs_free() and it, so it can safely get zspage from page->private. But this way is not good and simple enough: 1. Since zs_free() couldn't be sleepable, it can only trylock pages, or has to kick_deferred_free() to defer that to a work. 2. Even in the worker context, async_free_zspage() can't simply lock all pages in lock_zspage(), it's still trylock because of the race between zs_free() and zs_page_migrate(). Please see the commit 2505a981114d ("zsmalloc: fix races between asynchronous zspage free and page migration") for details. Actually, all free_zspage() needs is to get zspage from page safely, we can use RCU to achieve it easily. Then free_zspage() don't need to hold locks of all pages, so don't need the deferred free mechanism at all. The updated zs_page_migrate() now has two more cases to consider: 1. get_zspage_lockless() return NULL: it means free_zspage() has used reset_page() on this page and its reference of page. 2. get_zspage_lockless() return zspage but it's not on pool list: it means zspage has been removed from list and in process of free. I'm not sure what value should be returned in these cases? -EINVAL or -EAGAIN or other value? If the migration caller can find that page has no extra referenced and can just free it, I think we should return -EAGAIN to let the migration caller retry this page later to free it. Now I choose to use -EINVAL to skip migration of this page, it seems not a big deal to fail migration of some pages? Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 97 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 63ec385cd670..b153f2e5fc0f 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -253,6 +253,7 @@ struct zspage { struct list_head list; /* fullness list */ struct zs_pool *pool; rwlock_t lock; + struct rcu_head rcu_head; }; struct mapping_area { @@ -310,6 +311,8 @@ static int create_cache(struct zs_pool *pool) static void destroy_cache(struct zs_pool *pool) { kmem_cache_destroy(pool->handle_cachep); + /* Synchronize RCU to free zspage. */ + synchronize_rcu(); kmem_cache_destroy(pool->zspage_cachep); } @@ -335,6 +338,14 @@ static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage) kmem_cache_free(pool->zspage_cachep, zspage); } +static void rcu_free_zspage(struct rcu_head *h) +{ + struct zspage *zspage = container_of(h, struct zspage, rcu_head); + struct zs_pool *pool = zspage->pool; + + kmem_cache_free(pool->zspage_cachep, zspage); +} + /* pool->lock(which owns the handle) synchronizes races */ static void record_obj(unsigned long handle, unsigned long obj) { @@ -710,14 +721,31 @@ static int fix_fullness_group(struct size_class *class, struct zspage *zspage) return newfg; } +static void set_zspage(struct page *page, struct zspage *zspage) +{ + struct zspage __rcu **private = (struct zspage __rcu **)&page->private; + + rcu_assign_pointer(*private, zspage); +} + static struct zspage *get_zspage(struct page *page) { - struct zspage *zspage = (struct zspage *)page_private(page); + struct zspage __rcu **private = (struct zspage __rcu **)&page->private; + struct zspage *zspage; + zspage = rcu_dereference_protected(*private, true); BUG_ON(zspage->magic != ZSPAGE_MAGIC); return zspage; } +/* Only used in zs_page_migrate() to get zspage locklessly. */ +static struct zspage *get_zspage_lockless(struct page *page) +{ + struct zspage __rcu **private = (struct zspage __rcu **)&page->private; + + return rcu_dereference(*private); +} + static struct page *get_next_page(struct page *page) { struct zspage *zspage = get_zspage(page); @@ -793,32 +821,11 @@ static void reset_page(struct page *page) { __ClearPageMovable(page); ClearPagePrivate(page); - set_page_private(page, 0); + set_zspage(page, NULL); page_mapcount_reset(page); page->index = 0; } -static int trylock_zspage(struct zspage *zspage) -{ - struct page *cursor, *fail; - - for (cursor = get_first_page(zspage); cursor != NULL; cursor = - get_next_page(cursor)) { - if (!trylock_page(cursor)) { - fail = cursor; - goto unlock; - } - } - - return 1; -unlock: - for (cursor = get_first_page(zspage); cursor != fail; cursor = - get_next_page(cursor)) - unlock_page(cursor); - - return 0; -} - static void __free_zspage(struct zs_pool *pool, struct size_class *class, struct zspage *zspage) { @@ -834,13 +841,12 @@ static void __free_zspage(struct zs_pool *pool, struct size_class *class, VM_BUG_ON_PAGE(!PageLocked(page), page); next = get_next_page(page); reset_page(page); - unlock_page(page); dec_zone_page_state(page, NR_ZSPAGES); put_page(page); page = next; } while (page != NULL); - cache_free_zspage(pool, zspage); + call_rcu(&zspage->rcu_head, rcu_free_zspage); class_stat_dec(class, ZS_OBJS_ALLOCATED, class->objs_per_zspage); atomic_long_sub(class->pages_per_zspage, &pool->pages_allocated); @@ -852,16 +858,6 @@ static void free_zspage(struct zs_pool *pool, struct size_class *class, VM_BUG_ON(get_zspage_inuse(zspage)); VM_BUG_ON(list_empty(&zspage->list)); - /* - * Since zs_free couldn't be sleepable, this function cannot call - * lock_page. The page locks trylock_zspage got will be released - * by __free_zspage. - */ - if (!trylock_zspage(zspage)) { - kick_deferred_free(pool); - return; - } - remove_zspage(class, zspage); __free_zspage(pool, class, zspage); } @@ -929,7 +925,7 @@ static void create_page_chain(struct size_class *class, struct zspage *zspage, */ for (i = 0; i < nr_pages; i++) { page = pages[i]; - set_page_private(page, (unsigned long)zspage); + set_zspage(page, zspage); page->index = 0; if (i == 0) { zspage->first_page = page; @@ -978,10 +974,11 @@ static struct zspage *alloc_zspage(struct zs_pool *pool, pages[i] = page; } - create_page_chain(class, zspage, pages); init_zspage(class, zspage); zspage->pool = pool; zspage->class = class->index; + /* RCU set_zspage() after zspage initialized. */ + create_page_chain(class, zspage, pages); return zspage; } @@ -1765,17 +1762,35 @@ static int zs_page_migrate(struct page *newpage, struct page *page, VM_BUG_ON_PAGE(!PageIsolated(page), page); - /* The page is locked, so this pointer must remain valid */ - zspage = get_zspage(page); - pool = zspage->pool; + rcu_read_lock(); + zspage = get_zspage_lockless(page); + if (!zspage) { + rcu_read_unlock(); + return -EINVAL; + } /* * The pool's lock protects the race between zpage migration - * and zs_free. + * and zs_free. We check if the zspage is still in pool with + * pool->lock protection. If the zspage isn't in pool anymore, + * it should be freed by RCU soon. */ + pool = zspage->pool; spin_lock(&pool->lock); class = zspage_class(pool, zspage); + if (list_empty(&zspage->list)) { + spin_unlock(&pool->lock); + rcu_read_unlock(); + return -EINVAL; + } + + /* + * Now the zspage is still on pool, and we held pool->lock, + * it can't be freed in the meantime. + */ + rcu_read_unlock(); + /* the migrate_write_lock protects zpage access via zs_map_object */ migrate_write_lock(zspage); From patchwork Tue Feb 27 03:02:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13573220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EA23C54E4A for ; Tue, 27 Feb 2024 03:03:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D501B4401E4; Mon, 26 Feb 2024 22:03:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD89C44017F; Mon, 26 Feb 2024 22:03:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9EA14401E4; Mon, 26 Feb 2024 22:03:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AA10444017F for ; Mon, 26 Feb 2024 22:03:17 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7B3AD120AAA for ; Tue, 27 Feb 2024 03:03:17 +0000 (UTC) X-FDA: 81836087634.27.634D5B5 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf06.hostedemail.com (Postfix) with ESMTP id 7D86418001D for ; Tue, 27 Feb 2024 03:03:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709002995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wP17AY8f5RHqRLK5CiTTjEaLsliNwcwu3sUBefqbKyQ=; b=RNaujuAFsv2a2X52HYIifCjWSzhgLuYPMYBriB8nVP/wnWs1NG17axmVafuTBTf12cl15W T0LHxR3Pex1dSQb1G8/UYJND+8C5sJjk2bULRtKjpgh0ZiYnQkXLJCpYE+5qZHMyipuECd WJvfP/Suu/1xsj8OzEjxqIXW0I8tzUc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709002995; a=rsa-sha256; cv=none; b=SdA5j1vMvibe8igH6xt4d2qBZ0qoJu2WCiMuH45jP87PWHGBB19hnJsfSPgfZo2JMDFNgO RuLUKsgXSEArEYuEij4lSsm/nKh1XgliqqJO1bimQHROKJM5eKbB0CB/ESj6+lhbW+zkp8 t0TFon6TtAo9ZoHWwDNA6LcOrI/bIWg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 27 Feb 2024 03:02:55 +0000 Subject: [PATCH 2/2] mm/zsmalloc: remove the deferred free mechanism MIME-Version: 1.0 Message-Id: <20240226-zsmalloc-zspage-rcu-v1-2-456b0ef1a89d@bytedance.com> References: <20240226-zsmalloc-zspage-rcu-v1-0-456b0ef1a89d@bytedance.com> In-Reply-To: <20240226-zsmalloc-zspage-rcu-v1-0-456b0ef1a89d@bytedance.com> To: yosryahmed@google.com, Sergey Senozhatsky , hannes@cmpxchg.org, nphamcs@gmail.com, Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1709002985; l=5278; i=zhouchengming@bytedance.com; s=20240220; h=from:subject:message-id; bh=/M8dgwAyEda7XsNe3iFiXBlSIntC0kanjsl4nXxFc+E=; b=HKzHCzoHlRScN2CAHFL2LHEXBGcx4FZexrsgeFkUsWRTeBSsg2wQ+Kv5cGnhN6T8q7yMHkqfy LkC11bU4POFDX84RKgcD2IwlI1sl7CP9Dx9yfr3MiZEdk9Ydr9BUfAL X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=5+68Wfci+T30FoQos5RH+hfToF6SlC+S9LMPSPBFWuw= X-Migadu-Flow: FLOW_OUT X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Queue-Id: 7D86418001D X-Rspamd-Server: rspam11 X-Stat-Signature: sm1ip4h98bgabmzhweywb3qjkj6dhwod X-Rspam: Yes X-HE-Tag: 1709002995-432543 X-HE-Meta: U2FsdGVkX18Phc2Armz/ZoovYtNvW+6diD/Dzfd5J7uFnVeQKatutObi9GlQU/3scd3bApF8P7bDS85cS4ndv53fvpao0Oc/N3XEsALfR6Luhpu7qqyxkae1G32JQVdF7LK8lIThQYeZjZ8ROJ/IyETGfU3UUr1zFCrPqova4svgzwenhI2BxJXhvs3quZi/vBS3aOOMrS+JUPgxDdskvAOb86Yu2MGw7nvRtakg0tNhYDFjRRxLxHrvw/T4NJmpxKS865ix1r4+4h0MWTS31k1O6zr+WJseQ7lS87i/zQrYY8D/Z7itF1ekPeNFErnROZg6QjZfdCHGvcxN8R0mWR9eCSN8U/8F5R1xffzML7LmEcnSpW3hgy8RukXtUHet3dKJ1NIv5iKKPw5pfeb6eygXaf9B1hc2lGlCGtFPIiDlH4CLPZ6nCiugW4rEsbbxQwY+vZJ5jH4tqP1obzdFnlcHKgIP9ht/xO1V2LF9MgVjqeTjfBbSke7WP8G7mM5wYvZnD9JppALsuCigmkccJjCMVWZWkZcRt5cYzkbvePUUvtTz81qUDll/fHnGEjn7CtLm/evzY6wb96HJ3UmoV197+fJoXfh7tiKzVdz7gaCKjjF6n1DgDCSBp6oC+oOeQJ15cs1uDC7+PT2MyuwxAK9o0oV1GxHMRQQ8hnutnHntJBvYjMp4/MddILh03CVrKN7axdo+4lDBItXrMiI/t4qszVqkyPtADi8O0lWpwArUSmuvcCX0egns/47ixhx+j2YD04r0RVtxZJtLIfLIFjtNTBzMDJVhLFC2xwiNZXtSb69GGg/KBqb4quSgM3aAwMGkBOb+amNcGy4cqdDSizF0XwZnSF1iBHmj9+Bc/QmQbyi0ltvmqld+TBsieL+SLFzeVn4ErfhGZ+LCprS2grKyHm4JN3GqvVdKAUygFYp6VSLrfOWoRED0JH9rEFyCMbTLXkvLi6ElzHaFUWU UmfSrJq5 lCTuVZpmgpuMYtdoVn/8WjnSuGCiGgP2eHVT4LboS2Kd8XaWaSgF1x/vfPW9yt1d/Lq+nkz11xuULEAXw5V7C368oMKr1iPVBfqZ/Pr1WGRGLNh+5wBwKA/e1tcJHI5AeGAxyI83zGHH/N8t1WkK9pvawMWdEXp6NHr2fyZ/pcGQcQ4ty2kqI+UtNUIVLQ2xgAranQKT+268jFF/wGyB9iCD8TTn78xa89pWcPA9qJ0TI+99mmr/GQpdPUNRZuY6v4yFXfFqNw5dDwFS+mGyAbK94J7aaBfI38VON+ylqmtf0EM48Tr5Vy9hE3vkwAsil564s00bY6wUutLs= 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: List-Subscribe: List-Unsubscribe: Since the only user of kick_deferred_free() has gone, remove all the deferred mechanism related code. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 109 ---------------------------------------------------------- 1 file changed, 109 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b153f2e5fc0f..1a044690b389 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -232,9 +232,6 @@ struct zs_pool { #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; -#endif -#ifdef CONFIG_COMPACTION - struct work_struct free_work; #endif spinlock_t lock; atomic_t compaction_in_progress; @@ -281,12 +278,8 @@ static void migrate_write_lock(struct zspage *zspage); static void migrate_write_unlock(struct zspage *zspage); #ifdef CONFIG_COMPACTION -static void kick_deferred_free(struct zs_pool *pool); -static void init_deferred_free(struct zs_pool *pool); static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage); #else -static void kick_deferred_free(struct zs_pool *pool) {} -static void init_deferred_free(struct zs_pool *pool) {} static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {} #endif @@ -1632,50 +1625,6 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage) return fullness; } -#ifdef CONFIG_COMPACTION -/* - * To prevent zspage destroy during migration, zspage freeing should - * hold locks of all pages in the zspage. - */ -static void lock_zspage(struct zspage *zspage) -{ - struct page *curr_page, *page; - - /* - * Pages we haven't locked yet can be migrated off the list while we're - * trying to lock them, so we need to be careful and only attempt to - * lock each page under migrate_read_lock(). Otherwise, the page we lock - * may no longer belong to the zspage. This means that we may wait for - * the wrong page to unlock, so we must take a reference to the page - * prior to waiting for it to unlock outside migrate_read_lock(). - */ - while (1) { - migrate_read_lock(zspage); - page = get_first_page(zspage); - if (trylock_page(page)) - break; - get_page(page); - migrate_read_unlock(zspage); - wait_on_page_locked(page); - put_page(page); - } - - curr_page = page; - while ((page = get_next_page(curr_page))) { - if (trylock_page(page)) { - curr_page = page; - } else { - get_page(page); - migrate_read_unlock(zspage); - wait_on_page_locked(page); - put_page(page); - migrate_read_lock(zspage); - } - } - migrate_read_unlock(zspage); -} -#endif /* CONFIG_COMPACTION */ - static void migrate_lock_init(struct zspage *zspage) { rwlock_init(&zspage->lock); @@ -1730,10 +1679,6 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, static bool zs_page_isolate(struct page *page, isolate_mode_t mode) { - /* - * Page is locked so zspage couldn't be destroyed. For detail, look at - * lock_zspage in free_zspage. - */ VM_BUG_ON_PAGE(PageIsolated(page), page); return true; @@ -1848,56 +1793,6 @@ static const struct movable_operations zsmalloc_mops = { .putback_page = zs_page_putback, }; -/* - * Caller should hold page_lock of all pages in the zspage - * In here, we cannot use zspage meta data. - */ -static void async_free_zspage(struct work_struct *work) -{ - int i; - struct size_class *class; - struct zspage *zspage, *tmp; - LIST_HEAD(free_pages); - struct zs_pool *pool = container_of(work, struct zs_pool, - free_work); - - for (i = 0; i < ZS_SIZE_CLASSES; i++) { - class = pool->size_class[i]; - if (class->index != i) - continue; - - spin_lock(&pool->lock); - list_splice_init(&class->fullness_list[ZS_INUSE_RATIO_0], - &free_pages); - spin_unlock(&pool->lock); - } - - list_for_each_entry_safe(zspage, tmp, &free_pages, list) { - list_del(&zspage->list); - lock_zspage(zspage); - - spin_lock(&pool->lock); - class = zspage_class(pool, zspage); - __free_zspage(pool, class, zspage); - spin_unlock(&pool->lock); - } -}; - -static void kick_deferred_free(struct zs_pool *pool) -{ - schedule_work(&pool->free_work); -} - -static void zs_flush_migration(struct zs_pool *pool) -{ - flush_work(&pool->free_work); -} - -static void init_deferred_free(struct zs_pool *pool) -{ - INIT_WORK(&pool->free_work, async_free_zspage); -} - static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) { struct page *page = get_first_page(zspage); @@ -1908,8 +1803,6 @@ static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) unlock_page(page); } while ((page = get_next_page(page)) != NULL); } -#else -static inline void zs_flush_migration(struct zs_pool *pool) { } #endif /* @@ -2121,7 +2014,6 @@ struct zs_pool *zs_create_pool(const char *name) if (!pool) return NULL; - init_deferred_free(pool); spin_lock_init(&pool->lock); atomic_set(&pool->compaction_in_progress, 0); @@ -2229,7 +2121,6 @@ void zs_destroy_pool(struct zs_pool *pool) int i; zs_unregister_shrinker(pool); - zs_flush_migration(pool); zs_pool_stat_destroy(pool); for (i = 0; i < ZS_SIZE_CLASSES; i++) {